Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msglist: In single-conversation view, make recipient headers not tappable. #1193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,9 @@ class RecipientHeader extends StatelessWidget {
final message = this.message;
return switch (message) {
StreamMessage() => StreamMessageRecipientHeader(message: message,
showStream: _containsDifferentChannels(narrow)),
DmMessage() => DmRecipientHeader(message: message),
showStream: _containsDifferentChannels(narrow),
inTopicNarrow: narrow is TopicNarrow),
DmMessage() => DmRecipientHeader(message: message, inDmNarrow: narrow is DmNarrow),
};
}
}
Expand Down Expand Up @@ -1015,10 +1016,12 @@ class StreamMessageRecipientHeader extends StatelessWidget {
super.key,
required this.message,
required this.showStream,
required this.inTopicNarrow,
});

final StreamMessage message;
final bool showStream;
final bool inTopicNarrow;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -1105,9 +1108,9 @@ class StreamMessageRecipientHeader extends StatelessWidget {
]));

return GestureDetector(
onTap: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: TopicNarrow.ofMessage(message))),
onTap: !inTopicNarrow
? () => Navigator.push(context, MessageListPage.buildRoute(context: context, narrow: TopicNarrow.ofMessage(message)))
: null,
onLongPress: () => showTopicActionSheet(context,
channelId: message.streamId, topic: topic),
child: ColoredBox(
Expand All @@ -1126,9 +1129,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.inDmNarrow});

final DmMessage message;
final bool inDmNarrow;

@override
Widget build(BuildContext context) {
Expand All @@ -1149,9 +1153,9 @@ class DmRecipientHeader extends StatelessWidget {
final messageListTheme = MessageListTheme.of(context);

return GestureDetector(
onTap: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: DmNarrow.ofMessage(message, selfUserId: store.selfUserId))),
onTap: !inDmNarrow
? () => Navigator.push(context, MessageListPage.buildRoute(context: context, narrow: DmNarrow.ofMessage(message, selfUserId: store.selfUserId)))
: null,
child: ColoredBox(
color: messageListTheme.dmRecipientHeaderBg,
child: Padding(
Expand Down
149 changes: 149 additions & 0 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,85 @@ void main() {
await tester.pump();
tester.widget(find.text('new stream name'));
});

testWidgets('navigates to TopicNarrow on tapping topic in CombinedFeedNarrow', (tester) async {
final pushedRoutes = <Route<void>>[];
final navObserver = TestNavigatorObserver()
..onPushed = (route, prevRoute) => pushedRoutes.add(route);

final stream = eg.stream(name: 'stream name');
final message = eg.streamMessage(stream: stream, topic: 'topic name');

await setupMessageListPage(
tester,
narrow: const CombinedFeedNarrow(),
messages: [message],
subscriptions: [eg.subscription(stream)],
navObservers: [navObserver],
);

assert(pushedRoutes.length == 1);
pushedRoutes.clear();

await tester.pump();
check(findInMessageList('stream name')).length.equals(1);
check(findInMessageList('topic name')).length.equals(1);

connection.prepare(json: eg.newestGetMessagesResult(
messages: [message],
foundOldest: true,
).toJson());

final topicFinder = find.descendant(
of: find.byType(StreamMessageRecipientHeader),
matching: find.text('topic name'),
);

expect(topicFinder, findsOneWidget);
await tester.tap(topicFinder);
await tester.pumpAndSettle();

expect(pushedRoutes.length, equals(1));
final pushedRoute = pushedRoutes.first;
expect(pushedRoute, isA<WidgetRoute>());
expect((pushedRoute as WidgetRoute).page, isA<MessageListPage>());
final messageListPage = pushedRoute.page as MessageListPage;
expect(messageListPage.initNarrow, isA<TopicNarrow>());
final topicNarrow = messageListPage.initNarrow as TopicNarrow;
expect(topicNarrow.streamId, equals(stream.streamId));
expect(topicNarrow.topic, equals('topic name'));
});

testWidgets('does not navigate on tapping topic in TopicNarrow', (tester) async {
lakshya1goel marked this conversation as resolved.
Show resolved Hide resolved
final pushedRoutes = <Route<void>>[];
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', () {
Expand Down Expand Up @@ -987,6 +1066,76 @@ void main() {
tester.widget(find.textContaining(RegExp("Dec 1[89], 2022")));
tester.widget(find.textContaining(RegExp("Aug 2[23], 2022")));
});

testWidgets('navigates to DmNarrow on tapping recipient header in CombinedFeedNarrow', (tester) async {
final pushedRoutes = <Route<void>>[];
final navObserver = TestNavigatorObserver()
..onPushed = (route, prevRoute) {
pushedRoutes.add(route);
};

final dmMessage = eg.dmMessage(from: eg.selfUser, to: [eg.otherUser]);

await setupMessageListPage(
tester,
narrow: const CombinedFeedNarrow(),
messages: [dmMessage],
navObservers: [navObserver],
);

assert(pushedRoutes.length == 1);
pushedRoutes.clear();

await tester.pumpAndSettle();

connection.prepare(json: eg.newestGetMessagesResult(
messages: [dmMessage],
foundOldest: true,
).toJson());

final recipientHeaderFinder = find.byType(DmRecipientHeader);
expect(recipientHeaderFinder.evaluate().length, equals(1));

await tester.tap(recipientHeaderFinder);
await tester.pumpAndSettle();

expect(pushedRoutes.length, equals(1));

final pushedRoute = pushedRoutes.first;
expect(pushedRoute, isA<WidgetRoute>());
expect((pushedRoute as WidgetRoute).page, isA<MessageListPage>());
final messageListPage = pushedRoute.page as MessageListPage;
expect(messageListPage.initNarrow, isA<DmNarrow>());
final dmNarrow = messageListPage.initNarrow as DmNarrow;
expect(dmNarrow.otherRecipientIds, contains(eg.otherUser.userId));
});

testWidgets('does not navigate on tapping recipient header in DmNarrow', (tester) async {
final pushedRoutes = <Route<void>>[];
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', () {
Expand Down