diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index d97eba68c..86d333ca1 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -253,9 +253,14 @@ class ChatController extends State final Set unfolded = {}; - Event? replyEvent; + // #Pangea + // Event? replyEvent; - Event? editEvent; + // Event? editEvent; + + ValueNotifier replyEvent = ValueNotifier(null); + ValueNotifier editEvent = ValueNotifier(null); + // Pangea# bool _scrolledUp = false; @@ -898,10 +903,10 @@ class ChatController extends State // Also, adding PangeaMessageData Future send() async { final message = sendController.text; - final edit = editEvent; - final reply = replyEvent; - editEvent = null; - replyEvent = null; + final edit = editEvent.value; + final reply = replyEvent.value; + editEvent.value = null; + replyEvent.value = null; pendingText = ''; final tempEventId = await sendFakeMessage(edit, reply); @@ -956,7 +961,7 @@ class ChatController extends State sendController.setSystemText("", EditTypeEnum.other); } - final previousEdit = editEvent; + final previousEdit = edit; if (showEmojiPicker) { hideEmojiPicker(); } @@ -1011,8 +1016,8 @@ class ChatController extends State data: { 'roomId': roomId, 'text': message, - 'inReplyTo': replyEvent?.eventId, - 'editEventId': editEvent?.eventId, + 'inReplyTo': reply?.eventId, + 'editEventId': edit?.eventId, }, ); return; @@ -1032,8 +1037,8 @@ class ChatController extends State data: { 'roomId': roomId, 'text': message, - 'inReplyTo': replyEvent?.eventId, - 'editEventId': editEvent?.eventId, + 'inReplyTo': reply?.eventId, + 'editEventId': edit?.eventId, }, ); }); @@ -1161,8 +1166,8 @@ class ChatController extends State ); // #Pangea - final reply = replyEvent; - replyEvent = null; + final reply = replyEvent.value; + replyEvent.value = null; // Pangea# await room @@ -1530,7 +1535,7 @@ class ChatController extends State void replyAction({Event? replyTo}) { // #Pangea - replyEvent = replyTo ?? selectedEvents.first; + replyEvent.value = replyTo ?? selectedEvents.first; clearSelectedEvents(); // setState(() { // replyEvent = replyTo ?? selectedEvents.first; @@ -1688,9 +1693,9 @@ class ChatController extends State // selectedEvents.clear(); // }); pendingText = sendController.text; - editEvent = selectedEvents.first; + editEvent.value = selectedEvents.first; sendController.text = - editEvent!.getDisplayEvent(timeline!).calcLocalizedBodyFallback( + editEvent.value!.getDisplayEvent(timeline!).calcLocalizedBodyFallback( MatrixLocals(L10n.of(context)), withSenderNamePrefix: false, hideReply: true, @@ -1972,15 +1977,17 @@ class ChatController extends State } void cancelReplyEventAction() => setState(() { - if (editEvent != null) { - // #Pangea - // sendController.text = pendingText; - sendController.setSystemText(pendingText, EditTypeEnum.other); - // Pangea# - pendingText = ''; - } - replyEvent = null; - editEvent = null; + // #Pangea + // sendController.text = pendingText; + sendController.setSystemText(pendingText, EditTypeEnum.other); + // Pangea# + pendingText = ''; + // #Pangea + // replyEvent = null; + // editEvent = null; + replyEvent.value = null; + editEvent.value = null; + // Pangea# }); // #Pangea ValueNotifier depressMessageButton = ValueNotifier(false); diff --git a/lib/pages/chat/reply_display.dart b/lib/pages/chat/reply_display.dart index c7c9f8a8a..8d2df4b2d 100644 --- a/lib/pages/chat/reply_display.dart +++ b/lib/pages/chat/reply_display.dart @@ -16,35 +16,57 @@ class ReplyDisplay extends StatelessWidget { Widget build(BuildContext context) { final theme = Theme.of(context); - return AnimatedContainer( - duration: FluffyThemes.animationDuration, - curve: FluffyThemes.animationCurve, - height: controller.editEvent != null || controller.replyEvent != null - ? 56 - : 0, - clipBehavior: Clip.hardEdge, - decoration: BoxDecoration( - color: theme.colorScheme.onInverseSurface, - ), - child: Row( - children: [ - IconButton( - tooltip: L10n.of(context).close, - icon: const Icon(Icons.close), - onPressed: controller.cancelReplyEventAction, + // #Pangea + return ListenableBuilder( + listenable: + Listenable.merge([controller.replyEvent, controller.editEvent]), + builder: (context, __) { + final editEvent = controller.editEvent.value; + final replyEvent = controller.replyEvent.value; + // Pangea# + return AnimatedContainer( + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + // #Pangea + // height: controller.editEvent != null || controller.replyEvent != null + height: editEvent != null || replyEvent != null + // Pangea# + ? 56 + : 0, + clipBehavior: Clip.hardEdge, + decoration: BoxDecoration( + color: theme.colorScheme.onInverseSurface, ), - Expanded( - child: controller.replyEvent != null - ? ReplyContent( - controller.replyEvent!, - timeline: controller.timeline!, - ) - : _EditContent( - controller.editEvent?.getDisplayEvent(controller.timeline!), - ), + child: Row( + children: [ + IconButton( + tooltip: L10n.of(context).close, + icon: const Icon(Icons.close), + onPressed: controller.cancelReplyEventAction, + ), + Expanded( + // #Pangea + // child: controller.replyEvent != null + child: replyEvent != null + // Pangea# + ? ReplyContent( + // #Pangea + // controller.replyEvent, + replyEvent, + // Pangea# + timeline: controller.timeline!, + ) + : _EditContent( + // #Pangea + // controller.editEvent?.getDisplayEvent(controller.timeline!), + editEvent?.getDisplayEvent(controller.timeline!), + // Pangea# + ), + ), + ], ), - ], - ), + ); + }, ); } }