diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index d02b12f1a..fa2f72f86 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2303,6 +2303,12 @@ "user": {} } }, + "invitedBy": "📩 Invited by {user}", + "@invitedBy": { + "placeholders": { + "user": {} + } + }, "youInvitedUser": "📩 You invited {user}", "@youInvitedUser": { "placeholders": { @@ -4126,5 +4132,6 @@ "errorTypes": "Error Types", "level": "Level", "canceledSend": "Canceled send", - "morphsUsed": "Morphs Used" + "morphsUsed": "Morphs Used", + "translationChoicesBody": "Click and hold an option for a hint." } \ No newline at end of file diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 16637925e..ba9908240 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -63,13 +63,11 @@ abstract class AppConfig { path: '/krille-chan/fluffychat/issues/new', ); // #Pangea - // static bool renderHtml = true; static const bool enableSentry = true; static const String sentryDns = 'https://8591d0d863b646feb4f3dda7e5dcab38@o256755.ingest.sentry.io/5243143'; - static bool renderHtml = false; - // static bool renderHtml = true; // Pangea# + static bool renderHtml = true; static bool hideRedactedEvents = false; static bool hideUnknownEvents = true; static bool hideUnimportantStateEvents = true; diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index c0a444c4b..9cd0d9696 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -15,15 +15,12 @@ import 'package:fluffychat/pages/chat/event_info_dialog.dart'; import 'package:fluffychat/pages/chat/recording_dialog.dart'; import 'package:fluffychat/pages/chat_details/chat_details.dart'; import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; -import 'package:fluffychat/pangea/constants/pangea_event_types.dart'; import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart'; import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; import 'package:fluffychat/pangea/models/choreo_record.dart'; -import 'package:fluffychat/pangea/models/game_state_model.dart'; import 'package:fluffychat/pangea/models/representation_content_model.dart'; import 'package:fluffychat/pangea/models/tokens_event_content_model.dart'; -import 'package:fluffychat/pangea/pages/games/story_game/round_model.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/firebase_analytics.dart'; import 'package:fluffychat/pangea/utils/report_message.dart'; @@ -115,12 +112,9 @@ class ChatController extends State with WidgetsBindingObserver { // #Pangea final PangeaController pangeaController = MatrixState.pangeaController; + late Choreographer choreographer = Choreographer(pangeaController, this); - - /// Model of the current story game round - GameRoundModel? currentRound; // Pangea# - Room get room => sendingClient.getRoomById(roomId) ?? widget.room; late Client sendingClient; @@ -300,27 +294,6 @@ class ChatController extends State } } - // #Pangea - /// Recursive function that sets the current round, waits for it to - /// finish, sets it, etc. until the chat view is no longer mounted. - void setRound() { - currentRound?.dispose(); - currentRound = GameRoundModel(room: room); - room.client.onRoomState.stream.firstWhere((update) { - if (update.roomId != roomId) return false; - if (update.state is! Event) return false; - if ((update.state as Event).type != PangeaEventTypes.storyGame) { - return false; - } - - final game = GameModel.fromJson((update.state as Event).content); - return game.previousRoundEndTime != null; - }).then((_) { - if (mounted) setRound(); - }); - } - // Pangea# - @override void initState() { scrollController.addListener(_updateScrollController); @@ -336,7 +309,6 @@ class ChatController extends State sendingClient = Matrix.of(context).client; WidgetsBinding.instance.addObserver(this); // #Pangea - setRound(); if (!mounted) return; Future.delayed(const Duration(seconds: 1), () async { if (!mounted) return; @@ -561,7 +533,6 @@ class ChatController extends State //#Pangea choreographer.stateListener.close(); choreographer.dispose(); - currentRound?.dispose(); //Pangea# super.dispose(); } diff --git a/lib/pages/chat/chat_event_list.dart b/lib/pages/chat/chat_event_list.dart index 1e216094a..9bca32169 100644 --- a/lib/pages/chat/chat_event_list.dart +++ b/lib/pages/chat/chat_event_list.dart @@ -6,7 +6,6 @@ import 'package:fluffychat/pages/chat/typing_indicators.dart'; import 'package:fluffychat/pages/user_bottom_sheet/user_bottom_sheet.dart'; import 'package:fluffychat/pangea/enum/instructions_enum.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart'; -import 'package:fluffychat/pangea/utils/bot_name.dart'; import 'package:fluffychat/pangea/widgets/chat/locked_chat_message.dart'; import 'package:fluffychat/utils/account_config.dart'; import 'package:fluffychat/utils/adaptive_bottom_sheet.dart'; @@ -28,21 +27,7 @@ class ChatEventList extends StatelessWidget { final horizontalPadding = FluffyThemes.isColumnMode(context) ? 8.0 : 0.0; final events = controller.timeline!.events - .where( - (event) => - event.isVisibleInGui - // #Pangea - && - // In story game, hide messages sent by non-bot users in previous round - (event.type != EventTypes.Message || - event.senderId == BotName.byEnvironment || - controller.currentRound?.previousRoundEnd == null || - event.originServerTs.isAfter( - controller.currentRound!.previousRoundEnd!, - )) - // Pangea# - , - ) + .where((event) => event.isVisibleInGui) .toList(); final animateInEventIndex = controller.animateInEventIndex; diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index b1174fd2c..bee8a1af8 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -1,9 +1,8 @@ import 'package:animations/animations.dart'; import 'package:fluffychat/config/app_config.dart'; -import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; +import 'package:fluffychat/pages/chat/input_bar.dart'; import 'package:fluffychat/pangea/choreographer/widgets/send_button.dart'; import 'package:fluffychat/pangea/constants/language_constants.dart'; -import 'package:fluffychat/pangea/widgets/chat/input_bar_wrapper.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; @@ -34,7 +33,7 @@ class ChatInputRow extends StatelessWidget { controller.pangeaController.languageController.activeL2Model(); String hintText() { - if (controller.choreographer.choreoMode == ChoreoMode.it) { + if (controller.choreographer.itController.willOpen) { return L10n.of(context)!.buildTranslation; } return activel1 != null && @@ -322,10 +321,7 @@ class ChatInputRow extends StatelessWidget { Expanded( child: Padding( padding: const EdgeInsets.symmetric(vertical: 0.0), - // #Pangea - // child: InputBar( - child: InputBarWrapper( - // Pangea# + child: InputBar( room: controller.room, minLines: 1, maxLines: 8, diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 12437c8ac..7b49f7cf4 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -5,7 +5,6 @@ import 'package:fluffychat/pages/chat/chat_app_bar_list_tile.dart'; import 'package:fluffychat/pages/chat/chat_app_bar_title.dart'; import 'package:fluffychat/pages/chat/chat_emoji_picker.dart'; import 'package:fluffychat/pages/chat/chat_event_list.dart'; -import 'package:fluffychat/pages/chat/chat_input_row.dart'; import 'package:fluffychat/pages/chat/pinned_events.dart'; import 'package:fluffychat/pages/chat/reactions_picker.dart'; import 'package:fluffychat/pages/chat/reply_display.dart'; @@ -14,7 +13,7 @@ import 'package:fluffychat/pangea/choreographer/widgets/start_igc_button.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart'; import 'package:fluffychat/pangea/widgets/animations/gain_points.dart'; import 'package:fluffychat/pangea/widgets/chat/chat_floating_action_button.dart'; -import 'package:fluffychat/pangea/widgets/chat/round_timer.dart'; +import 'package:fluffychat/pangea/widgets/chat/input_bar_wrapper.dart'; import 'package:fluffychat/utils/account_config.dart'; import 'package:fluffychat/widgets/chat_settings_popup_menu.dart'; import 'package:fluffychat/widgets/connection_status_header.dart'; @@ -121,10 +120,6 @@ class ChatView extends StatelessWidget { // #Pangea } else { return [ - RoundTimer(controller: controller), - const SizedBox( - width: 10, - ), ChatSettingsPopupMenu( controller.room, (!controller.room.isDirectChat && !controller.room.isArchived), @@ -514,7 +509,9 @@ class ChatView extends StatelessWidget { ), ReactionsPicker(controller), ReplyDisplay(controller), - ChatInputRow(controller), + ChatInputRowWrapper( + controller: controller, + ), ChatEmojiPicker(controller), ], ), diff --git a/lib/pages/chat/event_info_dialog.dart b/lib/pages/chat/event_info_dialog.dart index 8b8f1e703..38acdc84c 100644 --- a/lib/pages/chat/event_info_dialog.dart +++ b/lib/pages/chat/event_info_dialog.dart @@ -1,12 +1,14 @@ import 'dart:convert'; +import 'package:flutter/material.dart'; + +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:matrix/matrix.dart'; + import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/adaptive_bottom_sheet.dart'; import 'package:fluffychat/utils/date_time_extension.dart'; import 'package:fluffychat/widgets/avatar.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; -import 'package:matrix/matrix.dart'; extension EventInfoDialogExtension on Event { void showInfoDialog(BuildContext context) => showAdaptiveBottomSheet( @@ -47,16 +49,15 @@ class EventInfoDialog extends StatelessWidget { children: [ ListTile( leading: Avatar( - // mxContent: event.senderFromMemoryOrFallback.avatarUrl, - // name: event.senderFromMemoryOrFallback.calcDisplayname(), - name: "?", + mxContent: event.senderFromMemoryOrFallback.avatarUrl, + name: event.senderFromMemoryOrFallback.calcDisplayname(), client: event.room.client, - // presenceUserId: event.senderId, + presenceUserId: event.senderId, ), title: Text(L10n.of(context)!.sender), - // subtitle: Text( - // '${event.senderFromMemoryOrFallback.calcDisplayname()} [${event.senderId}]', - // ), + subtitle: Text( + '${event.senderFromMemoryOrFallback.calcDisplayname()} [${event.senderId}]', + ), ), ListTile( title: Text(L10n.of(context)!.time), diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index 5c0a3ae29..3a6b7030c 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -263,10 +263,9 @@ class Message extends StatelessWidget { final user = snapshot.data ?? event.senderFromMemoryOrFallback; return Avatar( - // mxContent: user.avatarUrl, - // name: user.calcDisplayname(), - // presenceUserId: user.stateKey, - name: "?", + mxContent: user.avatarUrl, + name: user.calcDisplayname(), + presenceUserId: user.stateKey, presenceBackgroundColor: avatarPresenceBackgroundColor, onTap: () => onAvatarTab(event), @@ -289,11 +288,10 @@ class Message extends StatelessWidget { : FutureBuilder( future: event.fetchSenderUser(), builder: (context, snapshot) { - // final displayname = snapshot.data - // ?.calcDisplayname() ?? - // event.senderFromMemoryOrFallback - // .calcDisplayname(); - const displayname = "?"; + final displayname = snapshot.data + ?.calcDisplayname() ?? + event.senderFromMemoryOrFallback + .calcDisplayname(); return Text( displayname, style: TextStyle( diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 2010e47f2..5468b59e8 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -96,16 +96,12 @@ class MessageContent extends StatelessWidget { ListTile( contentPadding: EdgeInsets.zero, leading: Avatar( - // mxContent: sender.avatarUrl, - // name: sender.calcDisplayname(), - // presenceUserId: sender.stateKey, - name: "?", + mxContent: sender.avatarUrl, + name: sender.calcDisplayname(), + presenceUserId: sender.stateKey, client: event.room.client, ), - title: const Text( - // sender.calcDisplayname(), - "?", - ), + title: Text(sender.calcDisplayname()), subtitle: Text(event.originServerTs.localizedTime(context)), trailing: const Icon(Icons.lock_outlined), ), @@ -269,10 +265,9 @@ class MessageContent extends StatelessWidget { builder: (context, snapshot) { final reason = event.redactedBecause?.content.tryGet('reason'); - // final redactedBy = snapshot.data?.calcDisplayname() ?? - // event.redactedBecause?.senderId.localpart ?? - // L10n.of(context)!.user; - const redactedBy = "?"; + final redactedBy = snapshot.data?.calcDisplayname() ?? + event.redactedBecause?.senderId.localpart ?? + L10n.of(context)!.user; return _ButtonContent( label: reason == null ? L10n.of(context)!.redactedBy(redactedBy) @@ -390,9 +385,8 @@ class MessageContent extends StatelessWidget { builder: (context, snapshot) { return _ButtonContent( label: L10n.of(context)!.userSentUnknownEvent( - // snapshot.data?.calcDisplayname() ?? - // event.senderFromMemoryOrFallback.calcDisplayname(), - "?", + snapshot.data?.calcDisplayname() ?? + event.senderFromMemoryOrFallback.calcDisplayname(), event.type, ), icon: 'ℹ️', diff --git a/lib/pages/chat/events/reply_content.dart b/lib/pages/chat/events/reply_content.dart index a31765d38..b48f16cd9 100644 --- a/lib/pages/chat/events/reply_content.dart +++ b/lib/pages/chat/events/reply_content.dart @@ -59,8 +59,7 @@ class ReplyContent extends StatelessWidget { future: displayEvent.fetchSenderUser(), builder: (context, snapshot) { return Text( - // '${snapshot.data?.calcDisplayname() ?? displayEvent.senderFromMemoryOrFallback.calcDisplayname()}:', - '?:', + '${snapshot.data?.calcDisplayname() ?? displayEvent.senderFromMemoryOrFallback.calcDisplayname()}:', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 61ce641fc..aea82a886 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -1,9 +1,13 @@ import 'package:emojis/emoji.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/pages/chat/command_hints.dart'; import 'package:fluffychat/pangea/widgets/igc/pangea_text_controller.dart'; import 'package:fluffychat/utils/platform_infos.dart'; +import 'package:fluffychat/widgets/avatar.dart'; +import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:matrix/matrix.dart'; import 'package:pasteboard/pasteboard.dart'; @@ -225,106 +229,117 @@ class InputBar extends StatelessWidget { Map suggestion, Client? client, ) { + const size = 30.0; // #Pangea - // const size = 30.0; // const padding = EdgeInsets.all(4.0); - // if (suggestion['type'] == 'command') { - // final command = suggestion['name']!; - // final hint = commandHint(L10n.of(context)!, command); - // return Tooltip( - // message: hint, - // waitDuration: const Duration(days: 1), // don't show on hover - // child: Container( - // padding: padding, - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Text( - // commandExample(command), - // style: const TextStyle(fontFamily: 'monospace'), - // ), - // Text( - // hint, - // maxLines: 1, - // overflow: TextOverflow.ellipsis, - // style: Theme.of(context).textTheme.bodySmall, - // ), - // ], - // ), - // ), - // ); - // } - // if (suggestion['type'] == 'emoji') { - // final label = suggestion['label']!; - // return Tooltip( - // message: label, - // waitDuration: const Duration(days: 1), // don't show on hover - // child: Container( - // padding: padding, - // child: Text(label, style: const TextStyle(fontFamily: 'monospace')), - // ), - // ); - // } - // if (suggestion['type'] == 'emote') { - // return Container( - // padding: padding, - // child: Row( - // crossAxisAlignment: CrossAxisAlignment.center, - // children: [ - // MxcImage( - // // ensure proper ordering ... - // key: ValueKey(suggestion['name']), - // uri: suggestion['mxc'] is String - // ? Uri.parse(suggestion['mxc'] ?? '') - // : null, - // width: size, - // height: size, - // ), - // const SizedBox(width: 6), - // Text(suggestion['name']!), - // Expanded( - // child: Align( - // alignment: Alignment.centerRight, - // child: Opacity( - // opacity: suggestion['pack_avatar_url'] != null ? 0.8 : 0.5, - // child: suggestion['pack_avatar_url'] != null - // ? Avatar( - // mxContent: Uri.tryParse( - // suggestion.tryGet('pack_avatar_url') ?? '', - // ), - // name: suggestion.tryGet('pack_display_name'), - // size: size * 0.9, - // client: client, - // ) - // : Text(suggestion['pack_display_name']!), - // ), - // ), - // ), - // ], - // ), - // ); - // } - // if (suggestion['type'] == 'user' || suggestion['type'] == 'room') { - // final url = Uri.parse(suggestion['avatar_url'] ?? ''); - // return Container( - // padding: padding, - // child: Row( - // crossAxisAlignment: CrossAxisAlignment.center, - // children: [ - // Avatar( - // mxContent: url, - // name: suggestion.tryGet('displayname') ?? - // suggestion.tryGet('mxid'), - // size: size, - // client: client, - // ), - // const SizedBox(width: 6), - // Text(suggestion['displayname'] ?? suggestion['mxid']!), - // ], - // ), - // ); - // } + const padding = EdgeInsets.all(8.0); // Pangea# + if (suggestion['type'] == 'command') { + final command = suggestion['name']!; + final hint = commandHint(L10n.of(context)!, command); + return Tooltip( + message: hint, + waitDuration: const Duration(days: 1), // don't show on hover + child: Container( + padding: padding, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + commandExample(command), + style: const TextStyle(fontFamily: 'monospace'), + ), + Text( + hint, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ), + ), + ); + } + if (suggestion['type'] == 'emoji') { + final label = suggestion['label']!; + return Tooltip( + message: label, + waitDuration: const Duration(days: 1), // don't show on hover + child: Container( + padding: padding, + child: Text(label, style: const TextStyle(fontFamily: 'monospace')), + ), + ); + } + if (suggestion['type'] == 'emote') { + return Container( + padding: padding, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + MxcImage( + // ensure proper ordering ... + key: ValueKey(suggestion['name']), + uri: suggestion['mxc'] is String + ? Uri.parse(suggestion['mxc'] ?? '') + : null, + width: size, + height: size, + ), + const SizedBox(width: 6), + Text(suggestion['name']!), + Expanded( + child: Align( + alignment: Alignment.centerRight, + child: Opacity( + opacity: suggestion['pack_avatar_url'] != null ? 0.8 : 0.5, + child: suggestion['pack_avatar_url'] != null + ? Avatar( + mxContent: Uri.tryParse( + suggestion.tryGet('pack_avatar_url') ?? '', + ), + name: suggestion.tryGet('pack_display_name'), + size: size * 0.9, + client: client, + ) + : Text(suggestion['pack_display_name']!), + ), + ), + ), + ], + ), + ); + } + if (suggestion['type'] == 'user' || suggestion['type'] == 'room') { + final url = Uri.parse(suggestion['avatar_url'] ?? ''); + return Container( + padding: padding, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Avatar( + mxContent: url, + name: suggestion.tryGet('displayname') ?? + suggestion.tryGet('mxid'), + size: size, + client: client, + ), + const SizedBox(width: 6), + // #Pangea + Flexible( + child: + // Pangea# + Text( + suggestion['displayname'] ?? suggestion['mxid']!, + // #Pangea + overflow: TextOverflow.ellipsis, + // Pangea# + ), + ), + ], + ), + ); + } return const SizedBox.shrink(); } @@ -533,6 +548,15 @@ class InputBar extends StatelessWidget { // fix loading briefly flickering a dark box emptyBuilder: (BuildContext context) => const SizedBox .shrink(), // fix loading briefly showing no suggestions + // #Pangea + // If we ever want to change the suggestion background color + // here is the code for it + // decorationBuilder: (context, child) => Material( + // borderRadius: BorderRadius.circular(AppConfig.borderRadius), + // color: Theme.of(context).colorScheme.surfaceContainerHigh, + // child: child, + // ), + // Pangea# ), ), ), diff --git a/lib/pages/chat/seen_by_row.dart b/lib/pages/chat/seen_by_row.dart index 21fd6794e..af8b82069 100644 --- a/lib/pages/chat/seen_by_row.dart +++ b/lib/pages/chat/seen_by_row.dart @@ -37,10 +37,9 @@ class SeenByRow extends StatelessWidget { ? seenByUsers.sublist(0, maxAvatars) : seenByUsers) .map( - (user) => const Avatar( - // mxContent: user.avatarUrl, - // name: user.calcDisplayname(), - name: "?", + (user) => Avatar( + mxContent: user.avatarUrl, + name: user.calcDisplayname(), size: 16, ), ), diff --git a/lib/pages/chat/typing_indicators.dart b/lib/pages/chat/typing_indicators.dart index e02d59d1e..35fbf5d25 100644 --- a/lib/pages/chat/typing_indicators.dart +++ b/lib/pages/chat/typing_indicators.dart @@ -1,11 +1,12 @@ import 'dart:async'; +import 'package:flutter/material.dart'; + import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/pages/chat/chat.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; -import 'package:flutter/material.dart'; class TypingIndicators extends StatelessWidget { final ChatController controller; @@ -55,11 +56,10 @@ class TypingIndicators extends StatelessWidget { child: Stack( children: [ if (typingUsers.isNotEmpty) - const Avatar( + Avatar( size: avatarSize, - // mxContent: typingUsers.first.avatarUrl, - // name: typingUsers.first.calcDisplayname(), - name: "?", + mxContent: typingUsers.first.avatarUrl, + name: typingUsers.first.calcDisplayname(), ), if (typingUsers.length == 2) Padding( @@ -69,10 +69,9 @@ class TypingIndicators extends StatelessWidget { mxContent: typingUsers.length == 2 ? typingUsers.last.avatarUrl : null, - // name: typingUsers.length == 2 - // ? typingUsers.last.calcDisplayname() - // : '+${typingUsers.length - 1}', - name: "?", + name: typingUsers.length == 2 + ? typingUsers.last.calcDisplayname() + : '+${typingUsers.length - 1}', ), ), ], diff --git a/lib/pages/chat_details/participant_list_item.dart b/lib/pages/chat_details/participant_list_item.dart index 4f63a6238..9b5580692 100644 --- a/lib/pages/chat_details/participant_list_item.dart +++ b/lib/pages/chat_details/participant_list_item.dart @@ -39,10 +39,9 @@ class ParticipantListItem extends StatelessWidget { ), title: Row( children: [ - const Expanded( + Expanded( child: Text( - // user.calcDisplayname(), - "?", + user.calcDisplayname(), overflow: TextOverflow.ellipsis, ), ), @@ -89,9 +88,8 @@ class ParticipantListItem extends StatelessWidget { subtitle: Text(user.id), leading: Avatar( mxContent: user.avatarUrl, - // name: user.calcDisplayname(), - // presenceUserId: user.stateKey, - name: "?", + name: user.calcDisplayname(), + presenceUserId: user.stateKey, ), ), ); diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index 54995d31d..76c75e83b 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -1,9 +1,11 @@ import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart'; +import 'package:fluffychat/pangea/utils/get_chat_list_item_subtitle.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; import 'package:fluffychat/utils/room_status_extension.dart'; import 'package:fluffychat/widgets/hover_builder.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; @@ -238,52 +240,51 @@ class ChatListItem extends StatelessWidget { softWrap: false, ) // #Pangea - : const SizedBox(), - // FutureBuilder( - // future: room.lastEvent != null - // ? GetChatListItemSubtitle().getSubtitle( - // L10n.of(context)!, - // room.lastEvent, - // MatrixState.pangeaController, - // ) - // : Future.value(L10n.of(context)!.emptyChat), - // builder: (context, snapshot) { - // // Pangea# - // return Text( - // room.membership == Membership.invite - // ? isDirectChat - // ? L10n.of(context)!.invitePrivateChat - // : L10n.of(context)!.inviteGroupChat - // // #Pangea - // : snapshot.data ?? - // // Pangea# - // room.lastEvent - // ?.calcLocalizedBodyFallback( - // MatrixLocals(L10n.of(context)!), - // hideReply: true, - // hideEdit: true, - // plaintextBody: true, - // removeMarkdown: true, - // withSenderNamePrefix: !isDirectChat || - // directChatMatrixId != - // room.lastEvent?.senderId, - // ) ?? - // L10n.of(context)!.emptyChat, - // softWrap: false, - // maxLines: 1, - // overflow: TextOverflow.ellipsis, - // style: TextStyle( - // fontWeight: unread || room.hasNewMessages - // ? FontWeight.bold - // : null, - // color: theme.colorScheme.onSurfaceVariant, - // decoration: room.lastEvent?.redacted == true - // ? TextDecoration.lineThrough - // : null, - // ), - // ); - // }, - // ), + : FutureBuilder( + future: room.lastEvent != null + ? GetChatListItemSubtitle().getSubtitle( + L10n.of(context)!, + room.lastEvent, + MatrixState.pangeaController, + ) + : Future.value(L10n.of(context)!.emptyChat), + builder: (context, snapshot) { + // Pangea# + return Text( + room.membership == Membership.invite + ? isDirectChat + ? L10n.of(context)!.invitePrivateChat + : L10n.of(context)!.inviteGroupChat + // #Pangea + : snapshot.data ?? + // Pangea# + room.lastEvent + ?.calcLocalizedBodyFallback( + MatrixLocals(L10n.of(context)!), + hideReply: true, + hideEdit: true, + plaintextBody: true, + removeMarkdown: true, + withSenderNamePrefix: !isDirectChat || + directChatMatrixId != + room.lastEvent?.senderId, + ) ?? + L10n.of(context)!.emptyChat, + softWrap: false, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontWeight: unread || room.hasNewMessages + ? FontWeight.bold + : null, + color: theme.colorScheme.onSurfaceVariant, + decoration: room.lastEvent?.redacted == true + ? TextDecoration.lineThrough + : null, + ), + ); + }, + ), ), const SizedBox(width: 8), // #Pangea diff --git a/lib/pages/chat_search/chat_search_message_tab.dart b/lib/pages/chat_search/chat_search_message_tab.dart index 68e627282..7542d6ae9 100644 --- a/lib/pages/chat_search/chat_search_message_tab.dart +++ b/lib/pages/chat_search/chat_search_message_tab.dart @@ -1,13 +1,15 @@ -import 'package:fluffychat/utils/date_time_extension.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; -import 'package:fluffychat/utils/url_launcher.dart'; -import 'package:fluffychat/widgets/avatar.dart'; import 'package:flutter/material.dart'; + import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; +import 'package:fluffychat/utils/date_time_extension.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; +import 'package:fluffychat/utils/url_launcher.dart'; +import 'package:fluffychat/widgets/avatar.dart'; + class ChatSearchMessageTab extends StatelessWidget { final String searchQuery; final Room room; @@ -96,10 +98,9 @@ class ChatSearchMessageTab extends StatelessWidget { } final event = events[i]; final sender = event.senderFromMemoryOrFallback; - // final displayname = sender.calcDisplayname( - // i18n: MatrixLocals(L10n.of(context)!), - // ); - const displayname = "?"; + final displayname = sender.calcDisplayname( + i18n: MatrixLocals(L10n.of(context)!), + ); return _MessageSearchResultListTile( sender: sender, displayname: displayname, diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart index 7bd189288..ef79c0e31 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart @@ -22,10 +22,9 @@ class UserBottomSheetView extends StatelessWidget { Widget build(BuildContext context) { final user = controller.widget.user; final userId = (user?.id ?? controller.widget.profile?.userId)!; - // final displayname = (user?.calcDisplayname() ?? - // controller.widget.profile?.displayName ?? - // controller.widget.profile?.userId.localpart)!; - const displayname = "?"; + final displayname = (user?.calcDisplayname() ?? + controller.widget.profile?.displayName ?? + controller.widget.profile?.userId.localpart)!; final avatarUrl = user?.avatarUrl ?? controller.widget.profile?.avatarUrl; final client = Matrix.of(controller.widget.outerContext).client; @@ -40,7 +39,7 @@ class UserBottomSheetView extends StatelessWidget { title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text(displayname), + Text(displayname), PresenceBuilder( userId: userId, client: client, @@ -214,7 +213,7 @@ class UserBottomSheetView extends StatelessWidget { foregroundColor: Theme.of(context).colorScheme.onSurface, ), - label: const Text( + label: Text( displayname, maxLines: 1, overflow: TextOverflow.ellipsis, diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index ab0e48669..aae7104d4 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -4,12 +4,14 @@ import 'dart:developer'; import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; import 'package:fluffychat/pangea/choreographer/controllers/error_service.dart'; import 'package:fluffychat/pangea/choreographer/controllers/span_data_controller.dart'; +import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; import 'package:fluffychat/pangea/models/igc_text_data_model.dart'; import 'package:fluffychat/pangea/models/pangea_match_model.dart'; import 'package:fluffychat/pangea/repo/igc_repo.dart'; import 'package:fluffychat/pangea/widgets/igc/span_card.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:matrix/matrix.dart'; import '../../models/span_card_model.dart'; import '../../utils/error_handler.dart'; @@ -39,10 +41,12 @@ class IgcController { final IGCRequestBody reqBody = IGCRequestBody( fullText: choreographer.currentText, + userId: choreographer.pangeaController.userController.userId!, userL1: choreographer.l1LangCode!, userL2: choreographer.l2LangCode!, enableIGC: choreographer.igcEnabled && !onlyTokensAndLanguageDetection, enableIT: choreographer.itEnabled && !onlyTokensAndLanguageDetection, + prevMessages: prevMessages(), ); final IGCTextData igcTextDataResponse = await IgcRepo.getIGC( @@ -125,6 +129,49 @@ class IgcController { ); } + /// Get the content of previous text and audio messages in chat. + /// Passed to IGC request to add context. + List prevMessages({int numMessages = 5}) { + final List events = choreographer.chatController.visibleEvents + .where( + (e) => + e.type == EventTypes.Message && + (e.messageType == MessageTypes.Text || + e.messageType == MessageTypes.Audio), + ) + .toList(); + + final List messages = []; + for (final Event event in events) { + final String? content = event.messageType == MessageTypes.Text + ? event.content.toString() + : PangeaMessageEvent( + event: event, + timeline: choreographer.chatController.timeline!, + ownMessage: event.senderId == + choreographer.pangeaController.matrixState.client.userID, + ) + .getSpeechToTextLocal( + choreographer.l1LangCode, + choreographer.l2LangCode, + ) + ?.transcript + .text; + if (content == null) continue; + messages.add( + PreviousMessage( + content: content, + sender: event.senderId, + timestamp: event.originServerTs, + ), + ); + if (messages.length >= numMessages) { + return messages; + } + } + return messages; + } + bool get hasRelevantIGCTextData { if (igcTextData == null) return false; diff --git a/lib/pangea/choreographer/controllers/it_controller.dart b/lib/pangea/choreographer/controllers/it_controller.dart index 0067eee86..0bb82aa63 100644 --- a/lib/pangea/choreographer/controllers/it_controller.dart +++ b/lib/pangea/choreographer/controllers/it_controller.dart @@ -4,6 +4,7 @@ import 'dart:developer'; import 'package:fluffychat/pangea/choreographer/controllers/error_service.dart'; import 'package:fluffychat/pangea/constants/choreo_constants.dart'; import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart'; +import 'package:fluffychat/pangea/enum/instructions_enum.dart'; import 'package:fluffychat/pangea/models/pangea_token_model.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:flutter/foundation.dart'; @@ -56,6 +57,23 @@ class ITController { choreographer.setState(); } + bool _closingHint = false; + Duration get animationSpeed => (_closingHint || !_willOpen) + ? const Duration(milliseconds: 500) + : const Duration(milliseconds: 2000); + + void closeHint() { + _closingHint = true; + final String hintKey = InlineInstructions.translationChoices.toString(); + final instructionsController = choreographer.pangeaController.instructions; + instructionsController.turnOffInstruction(hintKey); + instructionsController.updateEnableInstructions(hintKey, true); + choreographer.setState(); + Future.delayed(const Duration(milliseconds: 500), () { + _closingHint = false; + }); + } + Future initializeIT(ITStartData itStartData) async { _willOpen = true; Future.delayed(const Duration(microseconds: 100), () { diff --git a/lib/pangea/choreographer/widgets/it_bar.dart b/lib/pangea/choreographer/widgets/it_bar.dart index 5d47cce7e..78e199ca1 100644 --- a/lib/pangea/choreographer/widgets/it_bar.dart +++ b/lib/pangea/choreographer/widgets/it_bar.dart @@ -8,7 +8,9 @@ import 'package:fluffychat/pangea/choreographer/widgets/it_feedback_card.dart'; import 'package:fluffychat/pangea/choreographer/widgets/translation_finished_flow.dart'; import 'package:fluffychat/pangea/constants/choreo_constants.dart'; import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart'; +import 'package:fluffychat/pangea/enum/instructions_enum.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; +import 'package:fluffychat/pangea/utils/inline_tooltip.dart'; import 'package:fluffychat/pangea/widgets/animations/gain_points.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -47,12 +49,16 @@ class ITBarState extends State { super.dispose(); } + bool get instructionsTurnedOff => + widget.choreographer.pangeaController.instructions + .wereInstructionsTurnedOff( + InlineInstructions.translationChoices.toString(), + ); + @override Widget build(BuildContext context) { return AnimatedSize( - duration: itController.willOpen - ? const Duration(milliseconds: 2000) - : const Duration(milliseconds: 500), + duration: itController.animationSpeed, curve: Curves.fastOutSlowIn, clipBehavior: Clip.none, child: !itController.willOpen @@ -60,9 +66,7 @@ class ITBarState extends State { : CompositedTransformTarget( link: widget.choreographer.itBarLinkAndKey.link, child: AnimatedOpacity( - duration: itController.willOpen - ? const Duration(milliseconds: 2000) - : const Duration(milliseconds: 500), + duration: itController.animationSpeed, opacity: itController.willOpen ? 1.0 : 0.0, child: Container( key: widget.choreographer.itBarLinkAndKey.key, @@ -116,6 +120,12 @@ class ITBarState extends State { // const SizedBox(height: 40.0), OriginalText(controller: itController), const SizedBox(height: 7.0), + if (!instructionsTurnedOff) + InlineTooltip( + body: InlineInstructions.translationChoices + .body(context), + onClose: itController.closeHint, + ), IntrinsicHeight( child: Container( constraints: @@ -158,6 +168,7 @@ class ITBarState extends State { ), ), ), + // ), ), ); } @@ -312,7 +323,11 @@ class ITChoices extends StatelessWidget { chosenContinuance: controller.currentITStep!.continuances[index].text, bestContinuance: controller.currentITStep!.best.text, - feedbackLang: controller.targetLangCode, + // TODO: we want this to eventually switch between target and source lang, + // based on the learner's proficiency - maybe with the words involved in the translation + // maybe overall. For now, we'll just use the source lang. + feedbackLang: controller.choreographer.l1Lang?.langCode ?? + controller.sourceLangCode, sourceTextLang: controller.sourceLangCode, targetLang: controller.targetLangCode, ), diff --git a/lib/pangea/choreographer/widgets/it_feedback_card.dart b/lib/pangea/choreographer/widgets/it_feedback_card.dart index f959715ce..06f2493d1 100644 --- a/lib/pangea/choreographer/widgets/it_feedback_card.dart +++ b/lib/pangea/choreographer/widgets/it_feedback_card.dart @@ -146,8 +146,11 @@ class ITFeedbackCardView extends StatelessWidget { controller.res!.text, style: BotStyle.text(context), ), - // if res is not null, show a button to translate the text - if (controller.res != null && controller.translatedFeedback == null) + // if res is not null and feedback not in the userL1, show a button to translate the text + if (controller.res != null && + controller.translatedFeedback == null && + controller.widget.req.feedbackLang != + controller.controller.languageController.userL1?.langCode) Column( children: [ const SizedBox(height: 10), diff --git a/lib/pangea/constants/game_constants.dart b/lib/pangea/constants/game_constants.dart deleted file mode 100644 index 6b0b22fbb..000000000 --- a/lib/pangea/constants/game_constants.dart +++ /dev/null @@ -1,3 +0,0 @@ -class GameConstants { - static const int timerMaxSeconds = 120; -} diff --git a/lib/pangea/constants/model_keys.dart b/lib/pangea/constants/model_keys.dart index e427cf098..195e919b4 100644 --- a/lib/pangea/constants/model_keys.dart +++ b/lib/pangea/constants/model_keys.dart @@ -69,6 +69,10 @@ class ModelKey { static const String permissions = "permissions"; static const String enableIGC = "enable_igc"; static const String enableIT = "enable_it"; + static const String prevMessages = "prev_messages"; + static const String prevContent = "prev_content"; + static const String prevSender = "prev_sender"; + static const String prevTimestamp = "prev_timestamp"; static const String originalSent = "original_sent"; static const String originalWritten = "original_written"; @@ -119,8 +123,4 @@ class ModelKey { static const String prevEventId = "prev_event_id"; static const String prevLastUpdated = "prev_last_updated"; - - static const String gameState = "game_state"; - static const String currentRoundStartTime = "start_time"; - static const String previousRoundEndTime = "message_visible_from"; } diff --git a/lib/pangea/constants/pangea_event_types.dart b/lib/pangea/constants/pangea_event_types.dart index ab5d655a7..9ca975dc0 100644 --- a/lib/pangea/constants/pangea_event_types.dart +++ b/lib/pangea/constants/pangea_event_types.dart @@ -35,6 +35,4 @@ class PangeaEventTypes { /// A record of completion of an activity. There /// can be one per user per activity. static const activityRecord = "pangea.activity_completion"; - - static const storyGame = "p.game.story"; } diff --git a/lib/pangea/enum/instructions_enum.dart b/lib/pangea/enum/instructions_enum.dart index 4e12c12b8..48544925e 100644 --- a/lib/pangea/enum/instructions_enum.dart +++ b/lib/pangea/enum/instructions_enum.dart @@ -58,6 +58,7 @@ extension InstructionsEnumExtension on InstructionsEnum { enum InlineInstructions { speechToText, l1Translation, + translationChoices, } extension InlineInstructionsExtension on InlineInstructions { @@ -67,6 +68,21 @@ extension InlineInstructionsExtension on InlineInstructions { return L10n.of(context)!.speechToTextBody; case InlineInstructions.l1Translation: return L10n.of(context)!.l1TranslationBody; + case InlineInstructions.translationChoices: + return L10n.of(context)!.translationChoicesBody; + } + } + + bool get toggledOff { + final instructionSettings = + MatrixState.pangeaController.userController.profile.instructionSettings; + switch (this) { + case InlineInstructions.speechToText: + return instructionSettings.showedSpeechToTextTooltip; + case InlineInstructions.l1Translation: + return instructionSettings.showedL1TranslationTooltip; + case InlineInstructions.translationChoices: + return instructionSettings.showedTranslationChoicesTooltip; } } } diff --git a/lib/pangea/extensions/sync_update_extension.dart b/lib/pangea/extensions/sync_update_extension.dart index 68c1f684a..6adb55c69 100644 --- a/lib/pangea/extensions/sync_update_extension.dart +++ b/lib/pangea/extensions/sync_update_extension.dart @@ -1,20 +1,85 @@ import 'package:matrix/matrix.dart'; extension MembershipUpdate on SyncUpdate { - List messages(Room chat) { - if (rooms?.join == null || - !rooms!.join!.containsKey(chat.id) || - rooms!.join![chat.id]!.timeline?.events == null) { - return []; + bool isMembershipUpdate(String userId) { + return isMembershipUpdateByType(Membership.join, userId) || + isMembershipUpdateByType(Membership.leave, userId) || + isMembershipUpdateByType(Membership.invite, userId); + } + + bool isMembershipUpdateByType(Membership type, String userId) { + final List? updates = getRoomUpdates(type); + if (updates?.isEmpty ?? true) { + return false; } - return rooms!.join![chat.id]!.timeline!.events! - .where( - (event) => - event.type == EventTypes.Message && - !event.eventId.startsWith("Pangea Chat"), - ) - .map((event) => Event.fromMatrixEvent(event, chat)) - .toList(); + for (final SyncRoomUpdate update in updates!) { + final List? events = getRoomUpdateEvents(type, update); + if (hasMembershipUpdate( + events, + type.name, + userId, + )) { + return true; + } + } + return false; + } + + List? getRoomUpdates(Membership type) { + switch (type) { + case Membership.join: + return rooms?.join?.values.toList(); + case Membership.leave: + return rooms?.leave?.values.toList(); + case Membership.invite: + return rooms?.invite?.values.toList(); + default: + return null; + } + } + + bool isSpaceChildUpdate(String activeSpaceId) { + if (rooms?.join?.isEmpty ?? true) { + return false; + } + for (final update in rooms!.join!.entries) { + final String spaceId = update.key; + final List? timelineEvents = update.value.timeline?.events; + final bool isUpdate = timelineEvents != null && + spaceId == activeSpaceId && + timelineEvents.any((event) => event.type == EventTypes.SpaceChild); + if (isUpdate) return true; + } + return false; } } + +List? getRoomUpdateEvents(Membership type, SyncRoomUpdate update) { + switch (type) { + case Membership.join: + return (update as JoinedRoomUpdate).timeline?.events; + case Membership.leave: + return (update as LeftRoomUpdate).timeline?.events; + case Membership.invite: + return (update as InvitedRoomUpdate).inviteState; + default: + return null; + } +} + +bool hasMembershipUpdate( + List? events, + String membershipType, + String userId, +) { + if (events == null) { + return false; + } + return events.any( + (event) => + event.type == EventTypes.RoomMember && + event.stateKey == userId && + event.content['membership'] == membershipType, + ); +} diff --git a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart index bfa7564cf..a6bcb1575 100644 --- a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart +++ b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart @@ -264,6 +264,21 @@ class PangeaMessageEvent { null; }).toSet(); + SpeechToTextModel? getSpeechToTextLocal( + String? l1Code, + String? l2Code, + ) { + if (l1Code == null || l2Code == null) { + return null; + } + return representations + .firstWhereOrNull( + (element) => element.content.speechToText != null, + ) + ?.content + .speechToText; + } + Future getSpeechToText( String l1Code, String l2Code, diff --git a/lib/pangea/models/analytics/constructs_model.dart b/lib/pangea/models/analytics/constructs_model.dart index e618c4307..045453228 100644 --- a/lib/pangea/models/analytics/constructs_model.dart +++ b/lib/pangea/models/analytics/constructs_model.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:collection/collection.dart'; import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:flutter/foundation.dart'; @@ -95,7 +96,8 @@ class OneConstructUse { factory OneConstructUse.fromJson(Map json) { return OneConstructUse( useType: ConstructUseTypeEnum.values - .firstWhere((e) => e.string == json['useType']), + .firstWhereOrNull((e) => e.string == json['useType']) ?? + ConstructUseTypeEnum.unk, lemma: json['lemma'], form: json['form'], constructType: json['constructType'] != null diff --git a/lib/pangea/models/game_state_model.dart b/lib/pangea/models/game_state_model.dart deleted file mode 100644 index 12e1bb695..000000000 --- a/lib/pangea/models/game_state_model.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'dart:developer'; - -import 'package:fluffychat/pangea/constants/model_keys.dart'; -import 'package:fluffychat/pangea/constants/pangea_event_types.dart'; -import 'package:fluffychat/pangea/utils/error_handler.dart'; -import 'package:flutter/foundation.dart'; -import 'package:matrix/matrix_api_lite/generated/model.dart'; - -class GameModel { - DateTime? currentRoundStartTime; - DateTime? previousRoundEndTime; - - GameModel({ - this.currentRoundStartTime, - this.previousRoundEndTime, - }); - - factory GameModel.fromJson(json) { - return GameModel( - currentRoundStartTime: json[ModelKey.currentRoundStartTime] != null - ? DateTime.parse(json[ModelKey.currentRoundStartTime]) - : null, - previousRoundEndTime: json[ModelKey.previousRoundEndTime] != null - ? DateTime.parse(json[ModelKey.previousRoundEndTime]) - : null, - ); - } - - Map toJson() { - final data = {}; - try { - data[ModelKey.currentRoundStartTime] = - currentRoundStartTime?.toIso8601String(); - data[ModelKey.previousRoundEndTime] = - previousRoundEndTime?.toIso8601String(); - return data; - } catch (e, s) { - debugger(when: kDebugMode); - ErrorHandler.logError(e: e, s: s); - return data; - } - } - - StateEvent get toStateEvent => StateEvent( - content: toJson(), - type: PangeaEventTypes.storyGame, - ); -} diff --git a/lib/pangea/models/user_model.dart b/lib/pangea/models/user_model.dart index 180422576..24db180dc 100644 --- a/lib/pangea/models/user_model.dart +++ b/lib/pangea/models/user_model.dart @@ -186,11 +186,18 @@ class UserInstructions { bool showedBlurMeansTranslate; bool showedTooltipInstructions; + bool showedSpeechToTextTooltip; + bool showedL1TranslationTooltip; + bool showedTranslationChoicesTooltip; + UserInstructions({ this.showedItInstructions = false, this.showedClickMessage = false, this.showedBlurMeansTranslate = false, this.showedTooltipInstructions = false, + this.showedSpeechToTextTooltip = false, + this.showedL1TranslationTooltip = false, + this.showedTranslationChoicesTooltip = false, }); factory UserInstructions.fromJson(Map json) => @@ -203,6 +210,12 @@ class UserInstructions { json[InstructionsEnum.blurMeansTranslate.toString()] ?? false, showedTooltipInstructions: json[InstructionsEnum.tooltipInstructions.toString()] ?? false, + showedL1TranslationTooltip: + json[InlineInstructions.l1Translation.toString()] ?? false, + showedTranslationChoicesTooltip: + json[InlineInstructions.translationChoices.toString()] ?? false, + showedSpeechToTextTooltip: + json[InlineInstructions.speechToText.toString()] ?? false, ); Map toJson() { @@ -213,6 +226,12 @@ class UserInstructions { showedBlurMeansTranslate; data[InstructionsEnum.tooltipInstructions.toString()] = showedTooltipInstructions; + data[InlineInstructions.l1Translation.toString()] = + showedL1TranslationTooltip; + data[InlineInstructions.translationChoices.toString()] = + showedTranslationChoicesTooltip; + data[InlineInstructions.speechToText.toString()] = + showedSpeechToTextTooltip; return data; } @@ -238,6 +257,21 @@ class UserInstructions { ?.content[InstructionsEnum.tooltipInstructions.toString()] as bool?) ?? false, + showedL1TranslationTooltip: + (accountData[InlineInstructions.l1Translation.toString()] + ?.content[InlineInstructions.l1Translation.toString()] + as bool?) ?? + false, + showedTranslationChoicesTooltip: (accountData[ + InlineInstructions.translationChoices.toString()] + ?.content[InlineInstructions.translationChoices.toString()] + as bool?) ?? + false, + showedSpeechToTextTooltip: + (accountData[InlineInstructions.speechToText.toString()] + ?.content[InlineInstructions.speechToText.toString()] + as bool?) ?? + false, ); } } diff --git a/lib/pangea/pages/games/story_game/round_model.dart b/lib/pangea/pages/games/story_game/round_model.dart deleted file mode 100644 index 3b43b86b5..000000000 --- a/lib/pangea/pages/games/story_game/round_model.dart +++ /dev/null @@ -1,145 +0,0 @@ -import 'dart:async'; - -import 'package:fluffychat/pangea/constants/game_constants.dart'; -import 'package:fluffychat/pangea/constants/pangea_event_types.dart'; -import 'package:fluffychat/pangea/extensions/sync_update_extension.dart'; -import 'package:fluffychat/pangea/models/game_state_model.dart'; -import 'package:fluffychat/pangea/utils/bot_name.dart'; -import 'package:matrix/matrix.dart'; - -/// A model of a game round. Manages the round's state and duration. -class GameRoundModel { - final Duration roundDuration = const Duration( - seconds: GameConstants.timerMaxSeconds, - ); - - final Room room; - - // All the below state variables are used for sending and managing - // round start and end times. Once the bot starts doing that, they should be removed. - late DateTime createdAt; - Timer? timer; - StreamSubscription? syncSubscription; - final List userMessageIDs = []; - final List botMessageIDs = []; - - GameRoundModel({ - required this.room, - }) { - createdAt = DateTime.now(); - - // if, on creation, the current round is already ongoing, - // start the timer (or reset it if the round went over) - if (currentRoundStart != null) { - final currentRoundDuration = DateTime.now().difference( - currentRoundStart!, - ); - final roundFinished = currentRoundDuration > roundDuration; - - if (roundFinished) { - endRound(); - } - } - - // listen to syncs for new bot messages to start and stop rounds - syncSubscription ??= room.client.onSync.stream.listen(_handleSync); - } - - GameModel get gameState => GameModel.fromJson( - room.getState(PangeaEventTypes.storyGame)?.content ?? {}, - ); - - DateTime? get currentRoundStart => gameState.currentRoundStartTime; - DateTime? get previousRoundEnd => gameState.previousRoundEndTime; - - void _handleSync(SyncUpdate update) { - final newMessages = update - .messages(room) - .where((msg) => msg.originServerTs.isAfter(createdAt)) - .toList(); - - final botMessages = newMessages - .where((msg) => msg.senderId == BotName.byEnvironment) - .toList(); - final userMessages = newMessages - .where((msg) => msg.senderId != BotName.byEnvironment) - .toList(); - - final hasNewBotMessage = botMessages.any( - (msg) => !botMessageIDs.contains(msg.eventId), - ); - - if (hasNewBotMessage) { - if (currentRoundStart == null) { - startRound(); - } else { - endRound(); - return; - } - } - - if (currentRoundStart != null) { - for (final message in botMessages) { - if (!botMessageIDs.contains(message.eventId)) { - botMessageIDs.add(message.eventId); - } - } - - for (final message in userMessages) { - if (!userMessageIDs.contains(message.eventId)) { - userMessageIDs.add(message.eventId); - } - } - } - } - - /// Set the start and end times of the current and previous rounds. - Future setRoundTimes({ - DateTime? currentRoundStart, - DateTime? previousRoundEnd, - }) async { - final game = GameModel.fromJson( - room.getState(PangeaEventTypes.storyGame)?.content ?? {}, - ); - - game.currentRoundStartTime = currentRoundStart; - game.previousRoundEndTime = previousRoundEnd; - - await room.client.setRoomStateWithKey( - room.id, - PangeaEventTypes.storyGame, - '', - game.toJson(), - ); - } - - /// Start a new round. - void startRound() { - setRoundTimes( - currentRoundStart: DateTime.now(), - previousRoundEnd: null, - ).then((_) => timer = Timer(roundDuration, endRound)); - } - - /// End and cleanup after the current round. - void endRound() { - syncSubscription?.cancel(); - syncSubscription = null; - - timer?.cancel(); - timer = null; - - setRoundTimes( - currentRoundStart: null, - previousRoundEnd: DateTime.now(), - ); - } - - void dispose() { - syncSubscription?.cancel(); - syncSubscription = null; - - timer?.cancel(); - timer = null; - } -} diff --git a/lib/pangea/repo/igc_repo.dart b/lib/pangea/repo/igc_repo.dart index e32f6cab7..bb5c27062 100644 --- a/lib/pangea/repo/igc_repo.dart +++ b/lib/pangea/repo/igc_repo.dart @@ -94,12 +94,43 @@ class IgcRepo { } } +/// Previous text/audio message sent in chat +/// Contain message content, sender, and timestamp +class PreviousMessage { + String content; + String sender; + DateTime timestamp; + + PreviousMessage({ + required this.content, + required this.sender, + required this.timestamp, + }); + + factory PreviousMessage.fromJson(Map json) => + PreviousMessage( + content: json[ModelKey.prevContent] ?? "", + sender: json[ModelKey.prevSender] ?? "", + timestamp: json[ModelKey.prevTimestamp] == null + ? DateTime.now() + : DateTime.parse(json[ModelKey.prevTimestamp]), + ); + + Map toJson() => { + ModelKey.prevContent: content, + ModelKey.prevSender: sender, + ModelKey.prevTimestamp: timestamp.toIso8601String(), + }; +} + class IGCRequestBody { String fullText; String userL1; String userL2; bool enableIT; bool enableIGC; + String userId; + List prevMessages; IGCRequestBody({ required this.fullText, @@ -107,6 +138,8 @@ class IGCRequestBody { required this.userL2, required this.enableIGC, required this.enableIT, + required this.userId, + required this.prevMessages, }); Map toJson() => { @@ -115,5 +148,8 @@ class IGCRequestBody { ModelKey.userL2: userL2, "enable_it": enableIT, "enable_igc": enableIGC, + ModelKey.userId: userId, + ModelKey.prevMessages: + jsonEncode(prevMessages.map((x) => x.toJson()).toList()), }; } diff --git a/lib/pangea/utils/inline_tooltip.dart b/lib/pangea/utils/inline_tooltip.dart index 21fc7321a..f82a11682 100644 --- a/lib/pangea/utils/inline_tooltip.dart +++ b/lib/pangea/utils/inline_tooltip.dart @@ -26,7 +26,7 @@ class InlineTooltip extends StatelessWidget { onPressed: onClose, ), ), - child: Container( + child: DecoratedBox( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Theme.of(context).colorScheme.primary.withAlpha(20), diff --git a/lib/pangea/utils/instructions.dart b/lib/pangea/utils/instructions.dart index 165bfa460..78dab6f6c 100644 --- a/lib/pangea/utils/instructions.dart +++ b/lib/pangea/utils/instructions.dart @@ -25,9 +25,15 @@ class InstructionsController { final Map _instructionsShown = {}; /// Returns true if the user requested this popup not be shown again - bool? toggledOff(String key) => InstructionsEnum.values - .firstWhereOrNull((value) => value.toString() == key) - ?.toggledOff; + bool? toggledOff(String key) { + final bool? instruction = InstructionsEnum.values + .firstWhereOrNull((value) => value.toString() == key) + ?.toggledOff; + final bool? tooltip = InlineInstructions.values + .firstWhereOrNull((value) => value.toString() == key) + ?.toggledOff; + return instruction ?? tooltip; + } InstructionsController(PangeaController pangeaController) { _pangeaController = pangeaController; @@ -58,6 +64,15 @@ class InstructionsController { if (key == InstructionsEnum.tooltipInstructions.toString()) { profile.instructionSettings.showedTooltipInstructions = value; } + if (key == InlineInstructions.speechToText.toString()) { + profile.instructionSettings.showedSpeechToTextTooltip = value; + } + if (key == InlineInstructions.l1Translation.toString()) { + profile.instructionSettings.showedL1TranslationTooltip = value; + } + if (key == InlineInstructions.translationChoices.toString()) { + profile.instructionSettings.showedTranslationChoicesTooltip = value; + } return profile; }); } diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 9441312bd..6c6f80218 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -1,48 +1,23 @@ import 'dart:async'; -import 'dart:typed_data'; -import 'package:fluffychat/pages/chat/input_bar.dart'; +import 'package:fluffychat/pages/chat/chat.dart'; +import 'package:fluffychat/pages/chat/chat_input_row.dart'; import 'package:fluffychat/pangea/widgets/igc/pangea_text_controller.dart'; import 'package:flutter/material.dart'; -import 'package:matrix/matrix.dart'; -class InputBarWrapper extends StatefulWidget { - final Room room; - final int? minLines; - final int? maxLines; - final TextInputType? keyboardType; - final TextInputAction? textInputAction; - final ValueChanged? onSubmitted; - final ValueChanged? onSubmitImage; - final FocusNode? focusNode; - final PangeaTextController? controller; - final InputDecoration? decoration; - final ValueChanged? onChanged; - final bool? autofocus; - final bool readOnly; +class ChatInputRowWrapper extends StatefulWidget { + final ChatController controller; - const InputBarWrapper({ - required this.room, - this.minLines, - this.maxLines, - this.keyboardType, - this.onSubmitted, - this.onSubmitImage, - this.focusNode, - this.controller, - this.decoration, - this.onChanged, - this.autofocus, - this.textInputAction, - this.readOnly = false, + const ChatInputRowWrapper({ + required this.controller, super.key, }); @override - State createState() => InputBarWrapperState(); + State createState() => ChatInputRowWrapperState(); } -class InputBarWrapperState extends State { +class ChatInputRowWrapperState extends State { StreamSubscription? _choreoSub; String _currentText = ''; @@ -50,7 +25,7 @@ class InputBarWrapperState extends State { void initState() { // Rebuild the widget each time there's an update from choreo _choreoSub = - widget.controller?.choreographer.stateListener.stream.listen((_) { + widget.controller.choreographer.stateListener.stream.listen((_) { setState(() {}); }); super.initState(); @@ -63,10 +38,6 @@ class InputBarWrapperState extends State { } void refreshOnChange(String text) { - if (widget.onChanged != null) { - widget.onChanged!(text); - } - final bool decreasedFromMaxLength = _currentText.length >= PangeaTextController.maxLength && text.length < PangeaTextController.maxLength; @@ -81,21 +52,5 @@ class InputBarWrapperState extends State { } @override - Widget build(BuildContext context) { - return InputBar( - room: widget.room, - minLines: widget.minLines, - maxLines: widget.maxLines, - keyboardType: widget.keyboardType, - onSubmitted: widget.onSubmitted, - onSubmitImage: widget.onSubmitImage, - focusNode: widget.focusNode, - controller: widget.controller, - decoration: widget.decoration, - onChanged: refreshOnChange, - autofocus: widget.autofocus, - textInputAction: widget.textInputAction, - readOnly: widget.readOnly, - ); - } + Widget build(BuildContext context) => ChatInputRow(widget.controller); } diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 3c63c81fc..7c5682933 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -59,8 +59,12 @@ class ToolbarDisplayController { } void showToolbar(BuildContext context, {MessageMode? mode}) { - // Close keyboard, if open - FocusManager.instance.primaryFocus?.unfocus(); + // Don't show toolbar if keyboard open + if (controller.inputFocus.hasFocus) { + FocusManager.instance.primaryFocus?.unfocus(); + return; + } + bool toolbarUp = true; if (highlighted) return; if (controller.selectMode) { @@ -86,13 +90,12 @@ class ToolbarDisplayController { if (targetOffset.dy < 320) { final spaceBeneath = MediaQuery.of(context).size.height - (targetOffset.dy + transformTargetSize.height); - // If toolbar is open, opening toolbar beneath without scrolling can cause issues - // if (spaceBeneath >= 320) { - // toolbarUp = false; - // } + if (spaceBeneath >= 320) { + toolbarUp = false; + } // See if it's possible to scroll up to make space - if (controller.scrollController.offset - targetOffset.dy + 320 >= + else if (controller.scrollController.offset - targetOffset.dy + 320 >= controller.scrollController.position.minScrollExtent && controller.scrollController.offset - targetOffset.dy + 320 <= controller.scrollController.position.maxScrollExtent) { diff --git a/lib/pangea/widgets/chat/round_timer.dart b/lib/pangea/widgets/chat/round_timer.dart deleted file mode 100644 index 5153fee12..000000000 --- a/lib/pangea/widgets/chat/round_timer.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'dart:async'; - -import 'package:fluffychat/pages/chat/chat.dart'; -import 'package:fluffychat/pangea/constants/game_constants.dart'; -import 'package:fluffychat/pangea/constants/pangea_event_types.dart'; -import 'package:fluffychat/pangea/models/game_state_model.dart'; -import 'package:fluffychat/widgets/matrix.dart'; -import 'package:flutter/material.dart'; -import 'package:matrix/matrix.dart'; - -/// Create a timer that counts down to the given time -/// Default duration is 180 seconds -class RoundTimer extends StatefulWidget { - final ChatController controller; - const RoundTimer({ - super.key, - required this.controller, - }); - - @override - RoundTimerState createState() => RoundTimerState(); -} - -class RoundTimerState extends State { - int currentSeconds = 0; - Timer? timer; - StreamSubscription? stateSubscription; - - @override - void initState() { - super.initState(); - - final roundStartTime = widget.controller.currentRound?.currentRoundStart; - if (roundStartTime != null) { - final roundDuration = DateTime.now().difference(roundStartTime).inSeconds; - if (roundDuration > GameConstants.timerMaxSeconds) return; - - currentSeconds = roundDuration; - timer = Timer.periodic(const Duration(seconds: 1), (Timer t) { - currentSeconds++; - if (currentSeconds >= GameConstants.timerMaxSeconds) { - t.cancel(); - } - setState(() {}); - }); - } - - stateSubscription = Matrix.of(context) - .client - .onRoomState - .stream - .where(isRoundUpdate) - .listen(onRoundUpdate); - } - - bool isRoundUpdate(update) { - return update.roomId == widget.controller.room.id && - update.state is Event && - (update.state as Event).type == PangeaEventTypes.storyGame; - } - - void onRoundUpdate(update) { - final GameModel gameState = GameModel.fromJson( - (update.state as Event).content, - ); - final startTime = gameState.currentRoundStartTime; - final endTime = gameState.previousRoundEndTime; - - if (startTime == null && endTime == null) return; - timer?.cancel(); - timer = null; - - // if this update is the start of a round - if (startTime != null) { - timer = Timer.periodic(const Duration(seconds: 1), (Timer t) { - currentSeconds++; - if (currentSeconds >= GameConstants.timerMaxSeconds) { - t.cancel(); - } - setState(() {}); - }); - return; - } - - // if this update is the end of a round - currentSeconds = 0; - setState(() {}); - } - - @override - void dispose() { - super.dispose(); - - stateSubscription?.cancel(); - stateSubscription = null; - - timer?.cancel(); - timer = null; - } - - int get remainingTime => GameConstants.timerMaxSeconds - currentSeconds; - - String get timerText => - '${(remainingTime ~/ 60).toString().padLeft(2, '0')}: ${(remainingTime % 60).toString().padLeft(2, '0')}'; - - @override - Widget build(BuildContext context) { - return Material( - color: const Color.fromARGB(255, 126, 22, 14), - child: Padding( - padding: const EdgeInsets.all(5), - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(timerText), - const Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - // IconButton( - // onPressed: widget.currentRound.timer == null - // ? widget.currentRound.startRound - // : null, - // icon: Icon( - // widget.currentRound.timer != null - // ? Icons.pause_circle - // : Icons.play_circle, - // ), - // ), - ], - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/pangea/widgets/common/aligned_dialog.dart b/lib/pangea/widgets/common/aligned_dialog.dart deleted file mode 100644 index c7bc5da59..000000000 --- a/lib/pangea/widgets/common/aligned_dialog.dart +++ /dev/null @@ -1,206 +0,0 @@ -import 'package:flutter/material.dart'; - -Future showAlignedDialog({ - required BuildContext context, - required WidgetBuilder builder, - bool barrierDismissible = true, - Color? barrierColor = Colors.black54, - String? barrierLabel, - bool useRootNavigator = true, - RouteSettings? routeSettings, - Alignment followerAnchor = Alignment.center, - Alignment targetAnchor = Alignment.center, - Size? refChildSize, - Offset offset = Offset.zero, - bool avoidOverflow = false, - bool isGlobal = false, - RouteTransitionsBuilder? transitionsBuilder, - Duration? duration, -}) { - assert(debugCheckHasMaterialLocalizations(context)); - - final CapturedThemes themes = InheritedTheme.capture( - from: context, - to: Navigator.of( - context, - rootNavigator: useRootNavigator, - ).context, - ); - - final RenderBox targetBox = context.findRenderObject()! as RenderBox; - final RenderBox overlay = - Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox; - Offset position = targetBox - .localToGlobal(targetAnchor.alongSize(targetBox.size), ancestor: overlay); - - if (isGlobal) { - position = overlay.localToGlobal(followerAnchor.alongSize(overlay.size)); - } - - return Navigator.of(context, rootNavigator: useRootNavigator).push( - AlignedDialogRoute( - followerAlignment: followerAnchor, - position: position, - context: context, - builder: builder, - barrierColor: barrierColor, - barrierDismissible: barrierDismissible, - barrierLabel: barrierLabel, - useSafeArea: isGlobal == true, - settings: routeSettings, - themes: themes, - transitionsBuilder: transitionsBuilder, - duration: duration, - avoidOverflow: avoidOverflow, - offset: offset, - ), - ); -} - -class AlignedDialogRoute extends RawDialogRoute { - /// A dialog route with Material entrance and exit animations, - /// modal barrier color, and modal barrier behavior (dialog is dismissible - /// with a tap on the barrier). - AlignedDialogRoute({ - required BuildContext context, - required WidgetBuilder builder, - required Alignment followerAlignment, - required Offset position, - CapturedThemes? themes, - super.barrierColor = Colors.transparent, - super.barrierDismissible, - String? barrierLabel, - bool useSafeArea = false, - super.settings, - RouteTransitionsBuilder? transitionsBuilder, - Duration? duration, - bool avoidOverflow = false, - Offset offset = Offset.zero, - }) : super( - pageBuilder: ( - BuildContext buildContext, - Animation animation, - Animation secondaryAnimation, - ) { - final Widget pageChild = Builder(builder: builder); - Widget dialog = Builder( - builder: (BuildContext context) { - final MediaQueryData mediaQuery = MediaQuery.of(context); - return CustomSingleChildLayout( - delegate: _FollowerDialogRouteLayout( - followerAlignment, - position, - Directionality.of(context), - mediaQuery.padding.top, - mediaQuery.padding.bottom, - offset, - avoidOverflow, - ), - child: pageChild, - ); - }, - ); - dialog = themes?.wrap(dialog) ?? dialog; - if (useSafeArea) { - dialog = SafeArea(child: dialog); - } - return dialog; - }, - barrierLabel: barrierLabel ?? - MaterialLocalizations.of(context).modalBarrierDismissLabel, - transitionDuration: duration ?? const Duration(milliseconds: 200), - transitionBuilder: - transitionsBuilder ?? _buildMaterialDialogTransitions, - ); -} - -// Positioning of the menu on the screen. -class _FollowerDialogRouteLayout extends SingleChildLayoutDelegate { - _FollowerDialogRouteLayout( - this.followerAnchor, - this.position, - this.textDirection, - this.topPadding, - this.bottomPadding, - this.offset, - this.avoidOverflow, - ); - - final Alignment followerAnchor; - - final Offset position; - - final TextDirection textDirection; - - final double topPadding; - - final double bottomPadding; - - final Offset offset; - final bool avoidOverflow; - - @override - BoxConstraints getConstraintsForChild(BoxConstraints constraints) { - // The menu can be at most the size of the overlay minus 8.0 pixels in each - // direction. - return BoxConstraints.loose(constraints.biggest) - .deflate(EdgeInsets.only(top: topPadding, bottom: bottomPadding)); - } - - @override - Offset getPositionForChild(Size size, Size childSize) { - Offset rst = followerAnchor.alongSize(childSize); - rst = position - rst; - rst += offset; - if (avoidOverflow) { - if (rst.dx < 0) rst = Offset(0, rst.dy); - if (rst.dy < 0) rst = Offset(rst.dx, 0); - if (rst.dx + childSize.width > size.width) { - rst = Offset(size.width - childSize.width, rst.dy); - } - if (rst.dy + childSize.height > size.height) { - rst = Offset(rst.dx, size.height - childSize.height); - } - } - return rst; - } - - @override - bool shouldRelayout(_FollowerDialogRouteLayout oldDelegate) { - return followerAnchor != oldDelegate.followerAnchor || - position != oldDelegate.position || - offset != oldDelegate.offset || - avoidOverflow != oldDelegate.avoidOverflow || - textDirection != oldDelegate.textDirection || - topPadding != oldDelegate.topPadding || - bottomPadding != oldDelegate.bottomPadding; - } -} - -Widget _buildMaterialDialogTransitions( - BuildContext context, - Animation animation, - Animation secondaryAnimation, - Widget child, -) { - return FadeTransition( - opacity: CurvedAnimation( - parent: animation, - curve: Curves.easeOut, - ), - child: child, - ); -} - -Offset _buildOffSet( - BuildContext context, { - required Size refChildSize, - required Offset offset, -}) { - final Size screenSize = MediaQuery.of(context).size; - final Size maxAvilableArea = Size( - screenSize.width - refChildSize.width, - screenSize.height - refChildSize.height, - ); - return const Offset(0, 0); -} diff --git a/lib/utils/error_reporter.dart b/lib/utils/error_reporter.dart index d44b48dcb..650277bf1 100644 --- a/lib/utils/error_reporter.dart +++ b/lib/utils/error_reporter.dart @@ -21,13 +21,18 @@ class ErrorReporter { // Exits early to prevent further execution return; } - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - l10n.oopsSomethingWentWrong, // Use the non-null L10n instance to get the error message + + try { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + l10n.oopsSomethingWentWrong, // Use the non-null L10n instance to get the error message + ), ), - ), - ); + ); + } catch (err) { + debugPrint("Failed to show error snackbar."); + } } // final text = '$error\n${stackTrace ?? ''}'; // await showAdaptiveDialog( diff --git a/lib/utils/matrix_sdk_extensions/flutter_matrix_dart_sdk_database/cipher.dart b/lib/utils/matrix_sdk_extensions/flutter_matrix_dart_sdk_database/cipher.dart index bfe1251dc..0134b50b3 100644 --- a/lib/utils/matrix_sdk_extensions/flutter_matrix_dart_sdk_database/cipher.dart +++ b/lib/utils/matrix_sdk_extensions/flutter_matrix_dart_sdk_database/cipher.dart @@ -14,9 +14,25 @@ Future getDatabaseCipher() async { String? password; try { - const secureStorage = FlutterSecureStorage(); + // #Pangea + // mogol/flutter_secure_storage#532 + // mogol/flutter_secure_storage#524 + // Pangea# + const secureStorage = FlutterSecureStorage( + // #Pangea + iOptions: IOSOptions(accessibility: KeychainAccessibility.first_unlock), + // Pangea# + ); + // #Pangea + await secureStorage.read(key: _passwordStorageKey); + // Pangea# final containsEncryptionKey = await secureStorage.read(key: _passwordStorageKey) != null; + // #Pangea + Sentry.addBreadcrumb( + Breadcrumb(message: 'containsEncryptionKey: $containsEncryptionKey'), + ); + // Pangea# if (!containsEncryptionKey) { final rng = Random.secure(); final list = Uint8List(32); @@ -29,18 +45,41 @@ Future getDatabaseCipher() async { } // workaround for if we just wrote to the key and it still doesn't exist password = await secureStorage.read(key: _passwordStorageKey); - if (password == null) throw MissingPluginException(); + if (password == null) { + throw MissingPluginException( + // #Pangea + "password is null after storing new password", + // Pangea# + ); + } } on MissingPluginException catch (e) { const FlutterSecureStorage() .delete(key: _passwordStorageKey) .catchError((_) {}); Logs().w('Database encryption is not supported on this platform', e); + // #Pangea + Sentry.addBreadcrumb( + Breadcrumb( + message: + 'Database encryption is not supported on this platform. Error message: ${e.message}', + data: {'exception': e}, + ), + ); + // Pangea# _sendNoEncryptionWarning(e); } catch (e, s) { const FlutterSecureStorage() .delete(key: _passwordStorageKey) .catchError((_) {}); Logs().w('Unable to init database encryption', e, s); + // #Pangea + Sentry.addBreadcrumb( + Breadcrumb( + message: 'Unable to init database encryption', + data: {'exception': e, 'stackTrace': s}, + ), + ); + // Pangea# _sendNoEncryptionWarning(e); } diff --git a/lib/utils/matrix_sdk_extensions/matrix_locals.dart b/lib/utils/matrix_sdk_extensions/matrix_locals.dart index ee0b12b02..cbba6b630 100644 --- a/lib/utils/matrix_sdk_extensions/matrix_locals.dart +++ b/lib/utils/matrix_sdk_extensions/matrix_locals.dart @@ -184,9 +184,9 @@ class MatrixLocals extends MatrixLocalizations { @override String redactedAnEvent(Event redactedEvent) { return l10n.redactedAnEvent( - // redactedEvent.redactedBecause?.senderFromMemoryOrFallback - // .calcDisplayname() ?? - l10n.user, + redactedEvent.redactedBecause?.senderFromMemoryOrFallback + .calcDisplayname() ?? + l10n.user, ); } @@ -198,8 +198,7 @@ class MatrixLocals extends MatrixLocalizations { @override String removedBy(Event redactedEvent) { return l10n.redactedBy( - // redactedEvent.senderFromMemoryOrFallback.calcDisplayname(), - "?", + redactedEvent.senderFromMemoryOrFallback.calcDisplayname(), ); } @@ -347,8 +346,5 @@ class MatrixLocals extends MatrixLocalizations { l10n.startedKeyVerification(senderName); @override - String invitedBy(String senderName) => l10n.youInvitedBy(senderName); - - @override - String get cancelledSend => l10n.canceledSend; + String invitedBy(String senderName) => l10n.invitedBy(senderName); } diff --git a/lib/utils/room_status_extension.dart b/lib/utils/room_status_extension.dart index 277894473..02c70b088 100644 --- a/lib/utils/room_status_extension.dart +++ b/lib/utils/room_status_extension.dart @@ -1,4 +1,5 @@ import 'package:flutter/widgets.dart'; + import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; @@ -19,21 +20,17 @@ extension RoomStatusExtension on Room { } else if (typingUsers.length == 1) { typingText = L10n.of(context)!.isTyping; if (typingUsers.first.id != directChatMatrixID) { - typingText = L10n.of(context)!.userIsTyping( - // typingUsers.first.calcDisplayname(), - "?", - ); + typingText = + L10n.of(context)!.userIsTyping(typingUsers.first.calcDisplayname()); } } else if (typingUsers.length == 2) { typingText = L10n.of(context)!.userAndUserAreTyping( - // typingUsers.first.calcDisplayname(), - // typingUsers[1].calcDisplayname(), - "?", "?", + typingUsers.first.calcDisplayname(), + typingUsers[1].calcDisplayname(), ); } else if (typingUsers.length > 2) { typingText = L10n.of(context)!.userAndOthersAreTyping( - // typingUsers.first.calcDisplayname(), - "?", + typingUsers.first.calcDisplayname(), (typingUsers.length - 1).toString(), ); }