From 8e0a807d4e56afcf41357b5f73ad7fc7ae72fcb5 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Tue, 22 Oct 2024 09:45:06 -0400 Subject: [PATCH] removed UI logic for if bot settings is in new group page since it was removed --- .../conversation_bot_settings.dart | 134 ++---------------- 1 file changed, 15 insertions(+), 119 deletions(-) diff --git a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart index 963949a78..7d94b6624 100644 --- a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart +++ b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart @@ -15,14 +15,12 @@ import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:matrix/matrix.dart'; class ConversationBotSettings extends StatefulWidget { - final Room? room; - final bool startOpen; + final Room room; final String? activeSpaceId; const ConversationBotSettings({ super.key, - this.room, - this.startOpen = false, + required this.room, this.activeSpaceId, }); @@ -32,10 +30,7 @@ class ConversationBotSettings extends StatefulWidget { class ConversationBotSettingsState extends State { late BotOptionsModel botOptions; - late bool isOpen; - late bool isCreating; bool addBot = false; - Room? parentSpace; ConversationBotSettingsState({Key? key}); @@ -49,19 +44,13 @@ class ConversationBotSettingsState extends State { @override void initState() { super.initState(); - isOpen = widget.startOpen; - botOptions = widget.room?.botOptions != null - ? BotOptionsModel.fromJson(widget.room?.botOptions?.toJson()) + botOptions = widget.room.botOptions != null + ? BotOptionsModel.fromJson(widget.room.botOptions?.toJson()) : BotOptionsModel(); - widget.room?.botIsInRoom.then((bool isBotRoom) { - setState(() { - addBot = isBotRoom; - }); + + widget.room.botIsInRoom.then((bool isBotRoom) { + setState(() => addBot = isBotRoom); }); - parentSpace = widget.activeSpaceId != null - ? Matrix.of(context).client.getRoomById(widget.activeSpaceId!) - : null; - isCreating = widget.room == null; discussionKeywordsController.text = botOptions.discussionKeywords ?? ""; discussionTopicController.text = botOptions.discussionTopic ?? ""; @@ -69,10 +58,9 @@ class ConversationBotSettingsState extends State { } Future setBotOption() async { - if (widget.room == null) return; try { await Matrix.of(context).client.setRoomStateWithKey( - widget.room!.id, + widget.room.id, PangeaEventTypes.botOptions, '', botOptions.toJson(), @@ -99,14 +87,13 @@ class ConversationBotSettingsState extends State { ); } - void updateAllBotOptions() { + void updateFromTextControllers() { botOptions.discussionTopic = discussionTopicController.text; botOptions.discussionKeywords = discussionKeywordsController.text; botOptions.customSystemPrompt = customSystemPromptController.text; } Future showBotOptionsDialog() async { - if (isCreating) return; final bool? confirm = await showDialog( context: context, builder: (BuildContext context) { @@ -141,65 +128,18 @@ class ConversationBotSettingsState extends State { ); if (confirm == true) { - updateAllBotOptions(); + updateFromTextControllers(); updateBotOption(() => botOptions = botOptions); - final bool isBotRoomMember = await widget.room?.botIsInRoom ?? false; + final bool isBotRoomMember = await widget.room.botIsInRoom; if (addBot && !isBotRoomMember) { - await widget.room?.invite(BotName.byEnvironment); + await widget.room.invite(BotName.byEnvironment); } else if (!addBot && isBotRoomMember) { - await widget.room?.kick(BotName.byEnvironment); + await widget.room.kick(BotName.byEnvironment); } } } - Future showNewRoomBotOptionsDialog() async { - final bool? confirm = await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: addBot - ? Text( - L10n.of(context)!.addConversationBotButtonTitleRemove, - ) - : Text( - L10n.of(context)!.addConversationBotDialogTitleInvite, - ), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(false); - }, - child: Text(L10n.of(context)!.cancel), - ), - TextButton( - onPressed: () { - Navigator.of(context).pop(!addBot); - }, - child: addBot - ? Text( - L10n.of(context)! - .addConversationBotDialogRemoveConfirmation, - ) - : Text( - L10n.of(context)! - .addConversationBotDialogInviteConfirmation, - ), - ), - ], - ); - }, - ); - - if (confirm == true) { - setState(() => addBot = true); - widget.room?.invite(BotName.byEnvironment); - } else { - setState(() => addBot = false); - widget.room?.kick(BotName.byEnvironment); - } - } - final GlobalKey formKey = GlobalKey(); @override @@ -212,17 +152,12 @@ class ConversationBotSettingsState extends State { children: [ ListTile( title: Text( - isCreating - ? L10n.of(context)!.addConversationBot - : L10n.of(context)!.botConfig, + L10n.of(context)!.botConfig, style: TextStyle( color: Theme.of(context).colorScheme.secondary, fontWeight: FontWeight.bold, ), ), - subtitle: isCreating - ? Text(L10n.of(context)!.addConversationBotDesc) - : null, leading: CircleAvatar( backgroundColor: Theme.of(context).scaffoldBackgroundColor, foregroundColor: Theme.of(context).textTheme.bodyLarge!.color, @@ -231,48 +166,9 @@ class ConversationBotSettingsState extends State { expression: BotExpression.idle, ), ), - trailing: isCreating - ? ElevatedButton( - onPressed: showNewRoomBotOptionsDialog, - child: Text( - addBot - ? L10n.of(context)!.addConversationBotButtonRemove - : L10n.of(context)!.addConversationBotButtonInvite, - ), - ) - : const Icon(Icons.settings), + trailing: const Icon(Icons.settings), onTap: showBotOptionsDialog, ), - if (isCreating && addBot) - Padding( - padding: const EdgeInsets.all(16), - child: Column( - children: [ - Align( - alignment: Alignment.centerLeft, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 12), - child: Text( - L10n.of(context)!.botConfig, - style: Theme.of(context).textTheme.titleLarge, - ), - ), - ), - Form( - key: formKey, - child: ConversationBotSettingsForm( - botOptions: botOptions, - formKey: formKey, - discussionKeywordsController: - discussionKeywordsController, - discussionTopicController: discussionTopicController, - customSystemPromptController: - customSystemPromptController, - ), - ), - ], - ), - ), ], ), );