Merge pull request #102 from pangeachat/bot-dm
widened criteria for bot DM rooms and prevent new one from being crea…
This commit is contained in:
commit
f3eeb1ffc7
4 changed files with 35 additions and 14 deletions
|
|
@ -14,6 +14,7 @@ import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
|||
import 'package:fluffychat/pangea/controllers/text_to_speech_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/user_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/word_net_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/guard/p_vguard.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
@ -164,7 +165,11 @@ class PangeaController {
|
|||
void startChatWithBotIfNotPresent() {
|
||||
Future.delayed(const Duration(milliseconds: 10000), () async {
|
||||
// check if user is logged in
|
||||
if (!matrixState.client.isLogged()) return;
|
||||
if (!matrixState.client.isLogged() ||
|
||||
(await matrixState.client.hasBotDM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await matrixState.client.startDirectChat(
|
||||
BotName.byEnvironment,
|
||||
|
|
|
|||
|
|
@ -168,4 +168,15 @@ extension PangeaClient on Client {
|
|||
)
|
||||
.firstOrNull
|
||||
?.classSettings;
|
||||
|
||||
Future<bool> get hasBotDM async {
|
||||
final List<Room> chats = rooms
|
||||
.where((room) => !room.isSpace && room.membership == Membership.join)
|
||||
.toList();
|
||||
|
||||
for (final Room chat in chats) {
|
||||
if (await chat.isBotDM) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -995,6 +995,9 @@ extension PangeaRoom on Room {
|
|||
);
|
||||
}
|
||||
|
||||
Future<bool> get isBotDM async =>
|
||||
(await isBotRoom) && getParticipants().length == 2;
|
||||
|
||||
BotOptionsModel? get botOptions {
|
||||
if (isSpace) return null;
|
||||
return BotOptionsModel.fromJson(
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:developer';
|
|||
|
||||
import 'package:fluffychat/pangea/constants/age_limits.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/p_user_age/p_user_age_view.dart';
|
||||
import 'package:fluffychat/pangea/utils/p_extension.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
|
|
@ -34,19 +35,20 @@ class PUserAgeController extends State<PUserAge> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.delayed(
|
||||
Duration.zero,
|
||||
() => Matrix.of(context)
|
||||
.client
|
||||
.startDirectChat(
|
||||
BotName.byEnvironment,
|
||||
enableEncryption: false,
|
||||
)
|
||||
.onError(
|
||||
(error, stackTrace) =>
|
||||
ErrorHandler.logError(e: error, s: stackTrace),
|
||||
),
|
||||
);
|
||||
Future.delayed(Duration.zero, () async {
|
||||
if (!(await Matrix.of(context).client.hasBotDM)) {
|
||||
Matrix.of(context)
|
||||
.client
|
||||
.startDirectChat(
|
||||
BotName.byEnvironment,
|
||||
enableEncryption: false,
|
||||
)
|
||||
.onError(
|
||||
(error, stackTrace) =>
|
||||
ErrorHandler.logError(e: error, s: stackTrace),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String? dobValidator() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue