From cd50460939a49084f28ce0e9bae63a49cd44a99b Mon Sep 17 00:00:00 2001 From: choreo development Date: Thu, 24 Oct 2024 16:36:29 -0400 Subject: [PATCH 01/19] got rid of practice activity for non target language --- lib/pangea/enum/message_mode_enum.dart | 10 +++- .../widgets/chat/message_display_card.dart | 47 +++++++++++++++++++ .../chat/message_selection_overlay.dart | 9 ++++ lib/pangea/widgets/chat/message_toolbar.dart | 16 +++++++ .../widgets/chat/message_toolbar_buttons.dart | 2 +- 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 lib/pangea/widgets/chat/message_display_card.dart diff --git a/lib/pangea/enum/message_mode_enum.dart b/lib/pangea/enum/message_mode_enum.dart index c8659f0fc..544e2a270 100644 --- a/lib/pangea/enum/message_mode_enum.dart +++ b/lib/pangea/enum/message_mode_enum.dart @@ -9,6 +9,7 @@ enum MessageMode { definition, translation, speechToText, + nullMode } extension MessageModeExtension on MessageMode { @@ -25,6 +26,7 @@ extension MessageModeExtension on MessageMode { return Icons.book; case MessageMode.practiceActivity: return Symbols.fitness_center; + case MessageMode.nullMode: default: return Icons.error; // Icon to indicate an error or unsupported mode } @@ -42,6 +44,7 @@ extension MessageModeExtension on MessageMode { return L10n.of(context)!.definitions; case MessageMode.practiceActivity: return L10n.of(context)!.practice; + case MessageMode.nullMode: default: return L10n.of(context)! .oopsSomethingWentWrong; // Title to indicate an error or unsupported mode @@ -60,18 +63,23 @@ extension MessageModeExtension on MessageMode { return L10n.of(context)!.define; case MessageMode.practiceActivity: return L10n.of(context)!.practice; + case MessageMode.nullMode: default: return L10n.of(context)! .oopsSomethingWentWrong; // Title to indicate an error or unsupported mode } } - bool isValidMode(Event event) { + bool shouldShowAsToolbarButton(Event event) { switch (this) { case MessageMode.translation: + return event.messageType == MessageTypes.Text; case MessageMode.textToSpeech: + return event.messageType == MessageTypes.Text; case MessageMode.definition: return event.messageType == MessageTypes.Text; + case MessageMode.nullMode: + return false; case MessageMode.speechToText: return event.messageType == MessageTypes.Audio; case MessageMode.practiceActivity: diff --git a/lib/pangea/widgets/chat/message_display_card.dart b/lib/pangea/widgets/chat/message_display_card.dart new file mode 100644 index 000000000..9deba5d27 --- /dev/null +++ b/lib/pangea/widgets/chat/message_display_card.dart @@ -0,0 +1,47 @@ +import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; +import 'package:fluffychat/pangea/utils/bot_style.dart'; +import 'package:flutter/material.dart'; + +class MessageDisplayCard extends StatelessWidget { + final PangeaMessageEvent messageEvent; + final String? displayText; + + const MessageDisplayCard({ + super.key, + required this.messageEvent, + required this.displayText, + }); + + @override + Widget build(BuildContext context) { + // If no display text is provided, show a message indicating no content + if (displayText == null || displayText!.isEmpty) { + return const Center( + child: Text( + 'No content available.', + style: TextStyle(color: Colors.black54, fontSize: 16), + ), + ); + } + + return Padding( + padding: const EdgeInsets.all(8), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: Column( + children: [ + // Display the provided text + Text( + displayText!, + style: BotStyle.text(context), + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/pangea/widgets/chat/message_selection_overlay.dart b/lib/pangea/widgets/chat/message_selection_overlay.dart index db421dd15..507c6c000 100644 --- a/lib/pangea/widgets/chat/message_selection_overlay.dart +++ b/lib/pangea/widgets/chat/message_selection_overlay.dart @@ -63,6 +63,10 @@ class MessageOverlayController extends State int activitiesLeftToComplete = neededActivities; + bool get messageInUserL2 => + pangeaMessageEvent.messageDisplayLangCode == + MatrixState.pangeaController.languageController.userL2?.langCode; + PangeaMessageEvent get pangeaMessageEvent => widget._pangeaMessageEvent; @override @@ -143,6 +147,11 @@ class MessageOverlayController extends State toolbarMode = MessageMode.speechToText; return; } + // if (!messageInUserL2) { + // activitiesLeftToComplete = 0; + // toolbarMode = MessageMode.nullMode; + // return; + // } if (activitiesLeftToComplete > 0) { toolbarMode = MessageMode.practiceActivity; diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index bcffbdf2a..dceffdf7f 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -6,6 +6,7 @@ import 'package:fluffychat/pangea/enum/message_mode_enum.dart'; import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/widgets/chat/message_audio_card.dart'; +import 'package:fluffychat/pangea/widgets/chat/message_display_card.dart'; import 'package:fluffychat/pangea/widgets/chat/message_selection_overlay.dart'; import 'package:fluffychat/pangea/widgets/chat/message_speech_to_text_card.dart'; import 'package:fluffychat/pangea/widgets/chat/message_translation_card.dart'; @@ -39,7 +40,22 @@ class MessageToolbar extends StatelessWidget { ); } + // Check if the message is in the user's second language + final bool messageInUserL2 = pangeaMessageEvent.messageDisplayLangCode == + MatrixState.pangeaController.languageController.userL2?.langCode; + + // If not in the target language, set to nullMode + if (!messageInUserL2) { + overLayController.toolbarMode = MessageMode.nullMode; + } + switch (overLayController.toolbarMode) { + case MessageMode.nullMode: + return MessageDisplayCard( + messageEvent: pangeaMessageEvent, // Pass the message event here + displayText: + "Message not in target language", // Pass the display text, + ); case MessageMode.translation: return MessageTranslationCard( messageEvent: pangeaMessageEvent, diff --git a/lib/pangea/widgets/chat/message_toolbar_buttons.dart b/lib/pangea/widgets/chat/message_toolbar_buttons.dart index 41cd47c6a..190a0fdff 100644 --- a/lib/pangea/widgets/chat/message_toolbar_buttons.dart +++ b/lib/pangea/widgets/chat/message_toolbar_buttons.dart @@ -22,7 +22,7 @@ class ToolbarButtons extends StatelessWidget { overlayController.pangeaMessageEvent; List get modes => MessageMode.values - .where((mode) => mode.isValidMode(pangeaMessageEvent.event)) + .where((mode) => mode.shouldShowAsToolbarButton(pangeaMessageEvent.event)) .toList(); static const double iconWidth = 36.0; From fa8526d58d8d901927a579edc3b1d809c11ec642 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 09:15:12 -0400 Subject: [PATCH 02/19] added copy to arb file, added padding to widget to show text in toolbar --- assets/l10n/intl_en.arb | 3 +- lib/pangea/enum/message_mode_enum.dart | 6 --- .../widgets/chat/message_display_card.dart | 47 ------------------- lib/pangea/widgets/chat/message_toolbar.dart | 23 +++++---- ..._define.dart => message_display_card.dart} | 10 ++-- pubspec.yaml | 2 +- 6 files changed, 20 insertions(+), 71 deletions(-) delete mode 100644 lib/pangea/widgets/chat/message_display_card.dart rename lib/pangea/widgets/{select_to_define.dart => message_display_card.dart} (69%) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index a9f2f1db0..c54d4e7b0 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -4365,5 +4365,6 @@ "chooseVoice": "Choose a voice", "enterLanguageLevel": "Please enter a language level", "enterDiscussionTopic": "Please enter a discussion topic", - "selectBotChatMode": "Select chat mode" + "selectBotChatMode": "Select chat mode", + "messageNotInTargetLang": "Message not in target language" } \ No newline at end of file diff --git a/lib/pangea/enum/message_mode_enum.dart b/lib/pangea/enum/message_mode_enum.dart index 544e2a270..cfc42f63b 100644 --- a/lib/pangea/enum/message_mode_enum.dart +++ b/lib/pangea/enum/message_mode_enum.dart @@ -9,7 +9,6 @@ enum MessageMode { definition, translation, speechToText, - nullMode } extension MessageModeExtension on MessageMode { @@ -26,7 +25,6 @@ extension MessageModeExtension on MessageMode { return Icons.book; case MessageMode.practiceActivity: return Symbols.fitness_center; - case MessageMode.nullMode: default: return Icons.error; // Icon to indicate an error or unsupported mode } @@ -44,7 +42,6 @@ extension MessageModeExtension on MessageMode { return L10n.of(context)!.definitions; case MessageMode.practiceActivity: return L10n.of(context)!.practice; - case MessageMode.nullMode: default: return L10n.of(context)! .oopsSomethingWentWrong; // Title to indicate an error or unsupported mode @@ -63,7 +60,6 @@ extension MessageModeExtension on MessageMode { return L10n.of(context)!.define; case MessageMode.practiceActivity: return L10n.of(context)!.practice; - case MessageMode.nullMode: default: return L10n.of(context)! .oopsSomethingWentWrong; // Title to indicate an error or unsupported mode @@ -78,8 +74,6 @@ extension MessageModeExtension on MessageMode { return event.messageType == MessageTypes.Text; case MessageMode.definition: return event.messageType == MessageTypes.Text; - case MessageMode.nullMode: - return false; case MessageMode.speechToText: return event.messageType == MessageTypes.Audio; case MessageMode.practiceActivity: diff --git a/lib/pangea/widgets/chat/message_display_card.dart b/lib/pangea/widgets/chat/message_display_card.dart deleted file mode 100644 index 9deba5d27..000000000 --- a/lib/pangea/widgets/chat/message_display_card.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; -import 'package:fluffychat/pangea/utils/bot_style.dart'; -import 'package:flutter/material.dart'; - -class MessageDisplayCard extends StatelessWidget { - final PangeaMessageEvent messageEvent; - final String? displayText; - - const MessageDisplayCard({ - super.key, - required this.messageEvent, - required this.displayText, - }); - - @override - Widget build(BuildContext context) { - // If no display text is provided, show a message indicating no content - if (displayText == null || displayText!.isEmpty) { - return const Center( - child: Text( - 'No content available.', - style: TextStyle(color: Colors.black54, fontSize: 16), - ), - ); - } - - return Padding( - padding: const EdgeInsets.all(8), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible( - child: Column( - children: [ - // Display the provided text - Text( - displayText!, - style: BotStyle.text(context), - ), - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index b17bf78a2..36b3cc45c 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -6,18 +6,18 @@ import 'package:fluffychat/pangea/enum/message_mode_enum.dart'; import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/widgets/chat/message_audio_card.dart'; -import 'package:fluffychat/pangea/widgets/chat/message_display_card.dart'; import 'package:fluffychat/pangea/widgets/chat/message_selection_overlay.dart'; import 'package:fluffychat/pangea/widgets/chat/message_speech_to_text_card.dart'; import 'package:fluffychat/pangea/widgets/chat/message_translation_card.dart'; import 'package:fluffychat/pangea/widgets/chat/message_unsubscribed_card.dart'; import 'package:fluffychat/pangea/widgets/chat/tts_controller.dart'; import 'package:fluffychat/pangea/widgets/igc/word_data_card.dart'; +import 'package:fluffychat/pangea/widgets/message_display_card.dart'; import 'package:fluffychat/pangea/widgets/practice_activity/practice_activity_card.dart'; -import 'package:fluffychat/pangea/widgets/select_to_define.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; const double minCardHeight = 70; @@ -33,7 +33,7 @@ class MessageToolbar extends StatelessWidget { required this.tts, }); - Widget get toolbarContent { + Widget toolbarContent(BuildContext context) { final bool subscribed = MatrixState.pangeaController.subscriptionController.isSubscribed; @@ -49,16 +49,13 @@ class MessageToolbar extends StatelessWidget { // If not in the target language, set to nullMode if (!messageInUserL2) { - overLayController.toolbarMode = MessageMode.nullMode; + return MessageDisplayCard( + displayText: + L10n.of(context)!.messageNotInTargetLang, // Pass the display text, + ); } switch (overLayController.toolbarMode) { - case MessageMode.nullMode: - return MessageDisplayCard( - messageEvent: pangeaMessageEvent, // Pass the message event here - displayText: - "Message not in target language", // Pass the display text, - ); case MessageMode.translation: return MessageTranslationCard( messageEvent: pangeaMessageEvent, @@ -78,7 +75,9 @@ class MessageToolbar extends StatelessWidget { ); case MessageMode.definition: if (!overLayController.isSelection) { - return const SelectToDefine(); + return MessageDisplayCard( + displayText: L10n.of(context)!.selectToDefine, + ); } else { try { final selectedText = overLayController.targetText; @@ -143,7 +142,7 @@ class MessageToolbar extends StatelessWidget { child: SingleChildScrollView( child: AnimatedSize( duration: FluffyThemes.animationDuration, - child: toolbarContent, + child: toolbarContent(context), ), ), ); diff --git a/lib/pangea/widgets/select_to_define.dart b/lib/pangea/widgets/message_display_card.dart similarity index 69% rename from lib/pangea/widgets/select_to_define.dart rename to lib/pangea/widgets/message_display_card.dart index 968eaa147..8536f2c99 100644 --- a/lib/pangea/widgets/select_to_define.dart +++ b/lib/pangea/widgets/message_display_card.dart @@ -1,10 +1,12 @@ import 'package:fluffychat/pangea/utils/bot_style.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; -class SelectToDefine extends StatelessWidget { - const SelectToDefine({ +class MessageDisplayCard extends StatelessWidget { + final String displayText; + + const MessageDisplayCard({ super.key, + required this.displayText, }); @override @@ -12,7 +14,7 @@ class SelectToDefine extends StatelessWidget { return Padding( padding: const EdgeInsets.fromLTRB(16, 20, 16, 16), child: Text( - L10n.of(context)!.selectToDefine, + displayText, style: BotStyle.text(context), textAlign: TextAlign.center, ), diff --git a/pubspec.yaml b/pubspec.yaml index 80906d77c..2ae643555 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ description: Learn a language while texting your friends. # Pangea# publish_to: none # On version bump also increase the build number for F-Droid -version: 1.22.6+3556 +version: 1.22.7+3557 environment: sdk: ">=3.0.0 <4.0.0" From cf1f79147a601d007ec7d45d07160e17f82a8790 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 09:20:50 -0400 Subject: [PATCH 03/19] don't allow users to edit the input bar during IT --- lib/pages/chat/chat.dart | 2 +- lib/pages/chat/chat_input_row.dart | 1 + lib/pages/chat/input_bar.dart | 2 ++ lib/pangea/choreographer/controllers/choreographer.dart | 9 +++++---- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index cb1c86f5e..ebfd384bc 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -1419,7 +1419,7 @@ class ChatController extends State void onSelectMessage(Event event) { // #Pangea - if (choreographer.itController.isOpen) { + if (choreographer.itController.willOpen) { return; } // Pangea# diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index cc931ef12..57360d25d 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -321,6 +321,7 @@ class ChatInputRow extends StatelessWidget { // #Pangea // hintText: L10n.of(context)!.writeAMessage, hintText: hintText(), + disabledBorder: InputBorder.none, // Pangea# hintMaxLines: 1, border: InputBorder.none, diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index c0939f278..347d68786 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -478,6 +478,8 @@ class InputBar extends StatelessWidget { // builder: (context, controller, focusNode) => TextField( builder: (context, _, focusNode) => TextField( enableSuggestions: false, + readOnly: + controller != null && controller!.choreographer.isRunningIT, // Pangea# controller: controller, focusNode: focusNode, diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index df254d49c..9d1691620 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -261,7 +261,7 @@ class Choreographer { // debugger(when: kDebugMode); } - await (choreoMode == ChoreoMode.it && !itController.isTranslationDone + await (isRunningIT ? itController.getTranslationData(_useCustomInput) : igc.getIGCTextData( onlyTokensAndLanguageDetection: onlyTokensAndLanguageDetection, @@ -418,7 +418,7 @@ class Choreographer { setState(); } - giveInputFocus() { + void giveInputFocus() { Future.delayed(Duration.zero, () { chatController.inputFocus.requestFocus(); }); @@ -478,6 +478,9 @@ class Choreographer { bool get _noChange => _lastChecked != null && _lastChecked == _textController.text; + bool get isRunningIT => + choreoMode == ChoreoMode.it && !itController.isTranslationDone; + void startLoading() { _lastChecked = _textController.text; isFetching = true; @@ -505,8 +508,6 @@ class Choreographer { } } - bool get showIsError => !itController.isOpen && errorService.isError; - LayerLinkAndKey get itBarLinkAndKey => MatrixState.pAnyState.layerLinkAndKey(itBarTransformTargetKey); From 49588b91cfe4fbaf88b4e927fa179b618956566c Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 09:44:18 -0400 Subject: [PATCH 04/19] don't allow send + make send button red while running IT --- .../controllers/choreographer.dart | 22 ++++++++++++++++--- .../controllers/igc_controller.dart | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index 9d1691620..3d39a308b 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -68,7 +68,7 @@ class Choreographer { } void send(BuildContext context) { - if (isFetching) return; + if (!canSendMessage) return; if (pangeaController.subscriptionController.subscriptionStatus == SubscriptionStatus.showPaywall) { @@ -92,7 +92,7 @@ class Choreographer { } Future _sendWithIGC(BuildContext context) async { - if (!igc.canSendMessage) { + if (!canSendMessage) { igc.showFirstMatch(context); return; } @@ -571,7 +571,7 @@ class Choreographer { return AssistanceState.noMessage; } - if (igc.igcTextData?.matches.isNotEmpty ?? false) { + if ((igc.igcTextData?.matches.isNotEmpty ?? false) || isRunningIT) { return AssistanceState.fetched; } @@ -585,4 +585,20 @@ class Choreographer { return AssistanceState.complete; } + + bool get canSendMessage { + if (isFetching) return false; + if (errorService.isError) return true; + if (itEnabled && isRunningIT) return false; + + final hasITMatches = + igc.igcTextData!.matches.any((match) => match.isITStart); + final hasIGCMatches = + igc.igcTextData!.matches.any((match) => !match.isITStart); + + if ((itEnabled && hasITMatches) || (igcEnabled && hasIGCMatches)) { + return false; + } + return true; + } } diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index 1acb37332..2b66dbd5d 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -202,8 +202,8 @@ class IgcController { } return !((choreographer.itEnabled && - igcTextData!.matches.any((match) => match.isOutOfTargetMatch)) || + igcTextData!.matches.any((match) => match.isITStart)) || (choreographer.igcEnabled && - igcTextData!.matches.any((match) => !match.isOutOfTargetMatch))); + igcTextData!.matches.any((match) => !match.isITStart))); } } From f4c0637f83d69f335e722a2456b42eaad4973ab5 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 09:49:53 -0400 Subject: [PATCH 05/19] only reset IT source text if the user hasn't gone through any IT steps --- lib/pangea/choreographer/controllers/it_controller.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pangea/choreographer/controllers/it_controller.dart b/lib/pangea/choreographer/controllers/it_controller.dart index b618386f8..e30f30b3d 100644 --- a/lib/pangea/choreographer/controllers/it_controller.dart +++ b/lib/pangea/choreographer/controllers/it_controller.dart @@ -68,9 +68,10 @@ class ITController { } void closeIT() { - //if they close it before completing, just put their text back - //PTODO - explore using last itStep - choreographer.textController.text = sourceText ?? ""; + // if the user hasn't gone through any IT steps, reset the text + if (completedITSteps.isEmpty && sourceText != null) { + choreographer.textController.text = sourceText!; + } clear(); } From 01f07c558426a201891bf74a48e2c10dbab1b99e Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 09:51:39 -0400 Subject: [PATCH 06/19] move canSend function from igcController to choreographer --- .../choreographer/controllers/igc_controller.dart | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index 2b66dbd5d..ed770cca4 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -192,18 +192,4 @@ class IgcController { // Not sure why this is here // MatrixState.pAnyState.closeOverlay(); } - - bool get canSendMessage { - if (choreographer.isFetching) return false; - if (igcTextData == null || - choreographer.errorService.isError || - igcTextData!.matches.isEmpty) { - return true; - } - - return !((choreographer.itEnabled && - igcTextData!.matches.any((match) => match.isITStart)) || - (choreographer.igcEnabled && - igcTextData!.matches.any((match) => !match.isITStart))); - } } From 380689cf03d39e48510372598f1d02d785355e38 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 10:04:59 -0400 Subject: [PATCH 07/19] if running language assistance after going through IT, clear the itController --- lib/pangea/choreographer/controllers/choreographer.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index 3d39a308b..f3e48a8b6 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -255,10 +255,13 @@ class Choreographer { } startLoading(); + + // if getting language assistance after finishing IT, + // reset the itController if (choreoMode == ChoreoMode.it && itController.isTranslationDone && !onlyTokensAndLanguageDetection) { - // debugger(when: kDebugMode); + itController.clear(); } await (isRunningIT From 4c3fccd55f960538f534f1d5a2a7a6f1003c2893 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 10:08:13 -0400 Subject: [PATCH 08/19] bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2ae643555..e24350240 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ description: Learn a language while texting your friends. # Pangea# publish_to: none # On version bump also increase the build number for F-Droid -version: 1.22.7+3557 +version: 1.22.8+3558 environment: sdk: ">=3.0.0 <4.0.0" From 54975adbb33991d5513478e7e3f3ae66c6cb1bbd Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 10:13:15 -0400 Subject: [PATCH 09/19] require non-null error in card error widget --- lib/pangea/choreographer/widgets/it_feedback_card.dart | 2 +- lib/pangea/widgets/chat/message_speech_to_text_card.dart | 2 +- lib/pangea/widgets/igc/card_error_widget.dart | 4 ++-- lib/pangea/widgets/igc/word_data_card.dart | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pangea/choreographer/widgets/it_feedback_card.dart b/lib/pangea/choreographer/widgets/it_feedback_card.dart index dd72f2457..f006e2552 100644 --- a/lib/pangea/choreographer/widgets/it_feedback_card.dart +++ b/lib/pangea/choreographer/widgets/it_feedback_card.dart @@ -103,7 +103,7 @@ class ITFeedbackCardController extends State { @override Widget build(BuildContext context) => error == null ? ITFeedbackCardView(controller: this) - : CardErrorWidget(error: error); + : CardErrorWidget(error: error!); } class ITFeedbackCardView extends StatelessWidget { diff --git a/lib/pangea/widgets/chat/message_speech_to_text_card.dart b/lib/pangea/widgets/chat/message_speech_to_text_card.dart index aae3b3eeb..cf61c3d49 100644 --- a/lib/pangea/widgets/chat/message_speech_to_text_card.dart +++ b/lib/pangea/widgets/chat/message_speech_to_text_card.dart @@ -152,7 +152,7 @@ class MessageSpeechToTextCardState extends State { // done fetchig but not results means some kind of error if (speechToTextResponse == null) { return CardErrorWidget( - error: error, + error: error ?? "Failed to fetch speech to text", maxWidth: AppConfig.toolbarMinWidth, ); } diff --git a/lib/pangea/widgets/igc/card_error_widget.dart b/lib/pangea/widgets/igc/card_error_widget.dart index 8c810391b..bbe1bc63b 100644 --- a/lib/pangea/widgets/igc/card_error_widget.dart +++ b/lib/pangea/widgets/igc/card_error_widget.dart @@ -6,14 +6,14 @@ import 'package:fluffychat/pangea/widgets/igc/card_header.dart'; import 'package:flutter/material.dart'; class CardErrorWidget extends StatelessWidget { - final Object? error; + final Object error; final Choreographer? choreographer; final int? offset; final double? maxWidth; const CardErrorWidget({ super.key, - this.error, + required this.error, this.choreographer, this.offset, this.maxWidth, diff --git a/lib/pangea/widgets/igc/word_data_card.dart b/lib/pangea/widgets/igc/word_data_card.dart index ff494bb38..06e7a1ed7 100644 --- a/lib/pangea/widgets/igc/word_data_card.dart +++ b/lib/pangea/widgets/igc/word_data_card.dart @@ -167,7 +167,7 @@ class WordDataCardView extends StatelessWidget { Widget build(BuildContext context) { if (controller.wordNetError != null) { return CardErrorWidget( - error: controller.wordNetError, + error: controller.wordNetError!, maxWidth: AppConfig.toolbarMinWidth, ); } From cd5f2379b8a380512d61be01fccd41ccb6faf700 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 10:46:50 -0400 Subject: [PATCH 10/19] if staging user tries to login to production (or vice versa), log them out --- lib/main.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index 6be6edc91..846c34d23 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:collection/collection.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/controllers/language_list_controller.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/firebase_analytics.dart'; @@ -100,6 +101,18 @@ Future startGui(List clients, SharedPreferences store) async { await firstClient?.accountDataLoading; ErrorWidget.builder = (details) => FluffyChatErrorWidget(details); + + // #Pangea + // errors seems to happen a lot when users switch better production / staging + // while testing by accident. If the account is a production account but server is + // staging or vice versa, logout. + final isStagingUser = firstClient?.userID?.domain?.contains("staging"); + final isStagingServer = Environment.isStaging; + if (isStagingServer != isStagingUser) { + await firstClient?.logout(); + } + // Pangea# + runApp(FluffyChatApp(clients: clients, pincode: pin, store: store)); } From 212632a913c82c98339bac5f88bee0e2fb6b75b4 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 11:05:59 -0400 Subject: [PATCH 11/19] if userID is null, don't try to get isRoomAdmin --- .../pangea_room_extension/room_analytics_extension.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pangea/extensions/pangea_room_extension/room_analytics_extension.dart b/lib/pangea/extensions/pangea_room_extension/room_analytics_extension.dart index 73371b080..b0224f929 100644 --- a/lib/pangea/extensions/pangea_room_extension/room_analytics_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension/room_analytics_extension.dart @@ -10,7 +10,7 @@ extension AnalyticsRoomExtension on Room { return; } - if (!isRoomAdmin) return; + if (client.userID == null || !isRoomAdmin) return; final spaceHierarchy = await client.getSpaceHierarchy( id, maxDepth: 1, From df9f8e09161da7093b9aea25f36fd98d11c9a9fc Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 11:37:36 -0400 Subject: [PATCH 12/19] prevent null check error in send button --- lib/pangea/choreographer/controllers/choreographer.dart | 1 + lib/pangea/choreographer/widgets/send_button.dart | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index f3e48a8b6..63895d550 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -593,6 +593,7 @@ class Choreographer { if (isFetching) return false; if (errorService.isError) return true; if (itEnabled && isRunningIT) return false; + if (igc.igcTextData == null) return false; final hasITMatches = igc.igcTextData!.matches.any((match) => match.isITStart); diff --git a/lib/pangea/choreographer/widgets/send_button.dart b/lib/pangea/choreographer/widgets/send_button.dart index f5e358a31..6fba75395 100644 --- a/lib/pangea/choreographer/widgets/send_button.dart +++ b/lib/pangea/choreographer/widgets/send_button.dart @@ -56,7 +56,10 @@ class ChoreographerSendButtonState extends State { color: widget.controller.choreographer.assistanceState .stateColor(context), onPressed: () { - widget.controller.choreographer.send(context); + widget.controller.choreographer.canSendMessage + ? widget.controller.choreographer.send(context) + : widget.controller.choreographer.igc + .showFirstMatch(context); }, tooltip: L10n.of(context)!.send, ), From 693c1b833473dfe6cf5a5749869ff49231123edb Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 11:38:04 -0400 Subject: [PATCH 13/19] bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e24350240..c4662cdbd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ description: Learn a language while texting your friends. # Pangea# publish_to: none # On version bump also increase the build number for F-Droid -version: 1.22.8+3558 +version: 1.22.9+3559 environment: sdk: ">=3.0.0 <4.0.0" From e110c0a6344b3eb2a06c17e6ca7b9e8e204a4cb1 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 11:42:54 -0400 Subject: [PATCH 14/19] commenting out code to logout on server mixup until tested further --- lib/main.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 846c34d23..05e4ca5cc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,5 @@ import 'package:collection/collection.dart'; import 'package:fluffychat/config/app_config.dart'; -import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/controllers/language_list_controller.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/firebase_analytics.dart'; @@ -106,11 +105,11 @@ Future startGui(List clients, SharedPreferences store) async { // errors seems to happen a lot when users switch better production / staging // while testing by accident. If the account is a production account but server is // staging or vice versa, logout. - final isStagingUser = firstClient?.userID?.domain?.contains("staging"); - final isStagingServer = Environment.isStaging; - if (isStagingServer != isStagingUser) { - await firstClient?.logout(); - } + // final isStagingUser = firstClient?.userID?.domain?.contains("staging"); + // final isStagingServer = Environment.isStaging; + // if (isStagingServer != isStagingUser) { + // await firstClient?.logout(); + // } // Pangea# runApp(FluffyChatApp(clients: clients, pincode: pin, store: store)); From ee167f01e4bd65627e15e74eaa129ace90399508 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 11:47:59 -0400 Subject: [PATCH 15/19] fixed error in server mixup test --- lib/main.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 05e4ca5cc..9f5e656bd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:collection/collection.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/controllers/language_list_controller.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/firebase_analytics.dart'; @@ -105,13 +106,14 @@ Future startGui(List clients, SharedPreferences store) async { // errors seems to happen a lot when users switch better production / staging // while testing by accident. If the account is a production account but server is // staging or vice versa, logout. - // final isStagingUser = firstClient?.userID?.domain?.contains("staging"); - // final isStagingServer = Environment.isStaging; - // if (isStagingServer != isStagingUser) { - // await firstClient?.logout(); - // } + if (firstClient?.userID?.domain != null) { + final isStagingUser = firstClient!.userID!.domain!.contains("staging"); + final isStagingServer = Environment.isStaging; + if (isStagingServer != isStagingUser) { + await firstClient.logout(); + } + } // Pangea# - runApp(FluffyChatApp(clients: clients, pincode: pin, store: store)); } From 6791e410bd355311c9c81c99daf803fba7fd7edc Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 11:56:33 -0400 Subject: [PATCH 16/19] close choreo error button on press --- lib/pangea/choreographer/widgets/has_error_button.dart | 9 +++++---- lib/pangea/widgets/chat/chat_floating_action_button.dart | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pangea/choreographer/widgets/has_error_button.dart b/lib/pangea/choreographer/widgets/has_error_button.dart index 007820139..77a7170d9 100644 --- a/lib/pangea/choreographer/widgets/has_error_button.dart +++ b/lib/pangea/choreographer/widgets/has_error_button.dart @@ -1,15 +1,15 @@ +import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; import 'package:flutter/material.dart'; -import '../../controllers/pangea_controller.dart'; import '../controllers/error_service.dart'; class ChoreographerHasErrorButton extends StatelessWidget { final ChoreoError error; - final PangeaController pangeaController; + final Choreographer choreographer; const ChoreographerHasErrorButton( - this.pangeaController, - this.error, { + this.error, + this.choreographer, { super.key, }); @@ -26,6 +26,7 @@ class ChoreographerHasErrorButton extends StatelessWidget { ), ), ); + choreographer.errorService.resetError(); } }, mini: true, diff --git a/lib/pangea/widgets/chat/chat_floating_action_button.dart b/lib/pangea/widgets/chat/chat_floating_action_button.dart index 35ea1c3eb..ce4128700 100644 --- a/lib/pangea/widgets/chat/chat_floating_action_button.dart +++ b/lib/pangea/widgets/chat/chat_floating_action_button.dart @@ -76,8 +76,8 @@ class ChatFloatingActionButtonState extends State { } if (widget.controller.choreographer.errorService.error != null) { return ChoreographerHasErrorButton( - widget.controller.pangeaController, widget.controller.choreographer.errorService.error!, + widget.controller.choreographer, ); } From 99d25932c00e2429f03b520c772447efd545d22e Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 25 Oct 2024 12:15:21 -0400 Subject: [PATCH 17/19] check if overlay renderbox has size before getting size/offset --- lib/pangea/widgets/chat/message_selection_overlay.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/pangea/widgets/chat/message_selection_overlay.dart b/lib/pangea/widgets/chat/message_selection_overlay.dart index 299029a10..4c5cf86da 100644 --- a/lib/pangea/widgets/chat/message_selection_overlay.dart +++ b/lib/pangea/widgets/chat/message_selection_overlay.dart @@ -395,6 +395,10 @@ class MessageOverlayController extends State } Size? get messageSize { + if (messageRenderBox == null || !messageRenderBox!.hasSize) { + return null; + } + try { return messageRenderBox?.size; } catch (e, s) { @@ -404,6 +408,10 @@ class MessageOverlayController extends State } Offset? get messageOffset { + if (messageRenderBox == null || !messageRenderBox!.hasSize) { + return null; + } + try { return messageRenderBox?.localToGlobal(Offset.zero); } catch (e, s) { From 73026c39b367c3a775b0c439c7570da64eb742b5 Mon Sep 17 00:00:00 2001 From: WilsonLe Date: Fri, 25 Oct 2024 23:32:11 +0700 Subject: [PATCH 18/19] create bot options before invite --- .../widgets/conversation_bot/conversation_bot_settings.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart index 833ba8924..044fcc214 100644 --- a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart +++ b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart @@ -241,6 +241,8 @@ class ConversationBotSettingsDialogState updateFromTextControllers(); + Navigator.of(context).pop(botOptions); + final bool isBotRoomMember = await widget.room.botIsInRoom; if (addBot && !isBotRoomMember) { @@ -248,8 +250,6 @@ class ConversationBotSettingsDialogState } else if (!addBot && isBotRoomMember) { await widget.room.kick(BotName.byEnvironment); } - - Navigator.of(context).pop(botOptions); }, child: Text(L10n.of(context)!.confirm), ), From a3c5ab15d8f21e727b25eb44642bfa18164f87fa Mon Sep 17 00:00:00 2001 From: William Jordan-Cooley Date: Mon, 28 Oct 2024 14:53:10 -0400 Subject: [PATCH 19/19] allow sending if in manual igc mode --- .../controllers/choreographer.dart | 18 +++++++++++++++--- lib/pangea/widgets/chat/message_toolbar.dart | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index 63895d550..6f65ea836 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -590,19 +590,31 @@ class Choreographer { } bool get canSendMessage { - if (isFetching) return false; + // if there's an error, let them send. we don't want to block them from sending in this case if (errorService.isError) return true; + + // if they're in IT mode, don't let them send if (itEnabled && isRunningIT) return false; - if (igc.igcTextData == null) return false; + // if they've turned off IGC then let them send the message when they want + if (!isAutoIGCEnabled) return true; + + // if we're in the middle of fetching results, don't let them send + if (isFetching) return false; + + // they're supposed to run IGC but haven't yet, don't let them send + if (isAutoIGCEnabled && igc.igcTextData == null) return false; + + // if they have relevant matches, don't let them send final hasITMatches = igc.igcTextData!.matches.any((match) => match.isITStart); final hasIGCMatches = igc.igcTextData!.matches.any((match) => !match.isITStart); - if ((itEnabled && hasITMatches) || (igcEnabled && hasIGCMatches)) { return false; } + + // otherwise, let them send return true; } } diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 36b3cc45c..bc6ed54bc 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -47,7 +47,7 @@ class MessageToolbar extends StatelessWidget { final bool messageInUserL2 = pangeaMessageEvent.messageDisplayLangCode == MatrixState.pangeaController.languageController.userL2?.langCode; - // If not in the target language, set to nullMode + // If not in the target language show specific messsage if (!messageInUserL2) { return MessageDisplayCard( displayText: