From 59f7f42693e651be652f4d6a64b791f0755049b5 Mon Sep 17 00:00:00 2001 From: lakshya1goel Date: Sat, 21 Dec 2024 15:32:57 +0530 Subject: [PATCH] msglist: In single-conversation view, make recipient headers not tappable. Updated onTap for recipient headers in single-conversation view. Adjusted GestureDetector logic to conditionally enable navigation. Simplified ColoredBox structure for non-tappable recipient headers. Improves user experience by removing unnecessary tap interactions. Fixes: #1171 --- lib/widgets/message_list.dart | 20 ++++++---- test/widgets/message_list_test.dart | 58 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/lib/widgets/message_list.dart b/lib/widgets/message_list.dart index 8c32a12115..371339247c 100644 --- a/lib/widgets/message_list.dart +++ b/lib/widgets/message_list.dart @@ -896,11 +896,14 @@ class RecipientHeader extends StatelessWidget { @override Widget build(BuildContext context) { + final isTopicNarrow = narrow is TopicNarrow; + final isDmNarrow = narrow is DmNarrow; final message = this.message; return switch (message) { StreamMessage() => StreamMessageRecipientHeader(message: message, - showStream: _containsDifferentChannels(narrow)), - DmMessage() => DmRecipientHeader(message: message), + showStream: _containsDifferentChannels(narrow), + isTopicNarrow: isTopicNarrow), + DmMessage() => DmRecipientHeader(message: message, isDmNarrow: isDmNarrow), }; } } @@ -1015,10 +1018,12 @@ class StreamMessageRecipientHeader extends StatelessWidget { super.key, required this.message, required this.showStream, + required this.isTopicNarrow, }); final StreamMessage message; final bool showStream; + final bool isTopicNarrow; @override Widget build(BuildContext context) { @@ -1105,9 +1110,9 @@ class StreamMessageRecipientHeader extends StatelessWidget { ])); return GestureDetector( - onTap: () => Navigator.push(context, + onTap: () => !isTopicNarrow? Navigator.push(context, MessageListPage.buildRoute(context: context, - narrow: TopicNarrow.ofMessage(message))), + narrow: TopicNarrow.ofMessage(message))): null, onLongPress: () => showTopicActionSheet(context, channelId: message.streamId, topic: topic), child: ColoredBox( @@ -1126,9 +1131,10 @@ class StreamMessageRecipientHeader extends StatelessWidget { } class DmRecipientHeader extends StatelessWidget { - const DmRecipientHeader({super.key, required this.message}); + const DmRecipientHeader({super.key, required this.message, required this.isDmNarrow}); final DmMessage message; + final bool isDmNarrow; @override Widget build(BuildContext context) { @@ -1149,9 +1155,9 @@ class DmRecipientHeader extends StatelessWidget { final messageListTheme = MessageListTheme.of(context); return GestureDetector( - onTap: () => Navigator.push(context, + onTap: () => !isDmNarrow? Navigator.push(context, MessageListPage.buildRoute(context: context, - narrow: DmNarrow.ofMessage(message, selfUserId: store.selfUserId))), + narrow: DmNarrow.ofMessage(message, selfUserId: store.selfUserId))): null, child: ColoredBox( color: messageListTheme.dmRecipientHeaderBg, child: Padding( diff --git a/test/widgets/message_list_test.dart b/test/widgets/message_list_test.dart index b1f443c8b5..29f2c16839 100644 --- a/test/widgets/message_list_test.dart +++ b/test/widgets/message_list_test.dart @@ -922,6 +922,37 @@ void main() { await tester.pump(); tester.widget(find.text('new stream name')); }); + + testWidgets('does not navigate on tapping topic in TopicNarrow', (tester) async { + final pushedRoutes = >[]; + final navObserver = TestNavigatorObserver() + ..onPushed = (route, prevRoute) => pushedRoutes.add(route); + + final channel = eg.stream(name: 'stream name'); + final msg = eg.streamMessage(stream: channel, topic: 'topic name'); + + await setupMessageListPage( + tester, + narrow: TopicNarrow(channel.streamId, 'topic name'), + navObservers: [navObserver], + streams: [channel], + messages: [msg], + ); + + assert(pushedRoutes.length == 1); + pushedRoutes.clear(); + + final topicFinder = find.descendant( + of: find.byType(StreamMessageRecipientHeader), + matching: find.text('topic name'), + ); + + expect(topicFinder.evaluate().length, equals(1)); + await tester.tap(topicFinder); + await tester.pumpAndSettle(); + + expect(pushedRoutes.length, equals(0)); + }); }); group('DmRecipientHeader', () { @@ -987,6 +1018,33 @@ void main() { tester.widget(find.textContaining(RegExp("Dec 1[89], 2022"))); tester.widget(find.textContaining(RegExp("Aug 2[23], 2022"))); }); + + testWidgets('does not navigate on tapping recipient header in DmNarrow', (tester) async { + final pushedRoutes = >[]; + final navObserver = TestNavigatorObserver() + ..onPushed = (route, prevRoute) => pushedRoutes.add(route); + + final dmMessage = eg.dmMessage(from: eg.selfUser, to: [eg.otherUser]); + + await setupMessageListPage( + tester, + narrow: DmNarrow.withUser(eg.otherUser.userId, selfUserId: eg.selfUser.userId), + navObservers: [navObserver], + messages: [dmMessage], + ); + + assert(pushedRoutes.length == 1); + pushedRoutes.clear(); + + final recipientHeaderFinder = find.byType(DmRecipientHeader); + + expect(recipientHeaderFinder.evaluate().length, equals(1)); + + await tester.tap(recipientHeaderFinder); + await tester.pumpAndSettle(); + + expect(pushedRoutes.length, equals(0)); + }); }); group('formatHeaderDate', () {