Skip to content

Commit f4fdacd

Browse files
committed
actions: Omit 'Mark as unread' for messages in unsubscribed streams.
earlier, the 'Mark as unread' button was displayed for any read message even if they were unsubscribed . This pr change adds a condition that should only show the button for direct messages or for stream messages where the subscription exists. The corresponding test is added to verify this new behavior which uses the `setupToMessageActionSheet` helper, dismissing the action sheet and also firing the `SubscriptionRemoveEvent`, and then re-opening the sheet to confirm that the button is now not present there
1 parent 91246ee commit f4fdacd

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/widgets/action_sheet.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
607607
final isMessageRead = message.flags.contains(MessageFlag.read);
608608
final markAsUnreadSupported = store.zulipFeatureLevel >= 155; // TODO(server-6)
609609
final showMarkAsUnreadButton = markAsUnreadSupported && isMessageRead &&
610-
(message is! StreamMessage || store.subscriptions[message.streamId] != null);
610+
(message is! StreamMessage || store.subscriptions[message.streamId] != null);
611611

612612
final isSenderMuted = store.isUserMuted(message.senderId);
613613

test/widgets/action_sheet_test.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,38 @@ void main() {
13411341
check(find.byIcon(Icons.mark_chat_unread_outlined).evaluate()).single;
13421342
});
13431343

1344+
testWidgets('not visible if message is in unsubscribed stream', (tester) async {
1345+
// Setup with a read message, so the button is potentially visible.
1346+
final readMessage = eg.streamMessage(flags: [MessageFlag.read]);
1347+
1348+
// this will use the common helper function .
1349+
// This will subscribe to the stream and open the action sheet .
1350+
await setupToMessageActionSheet(tester,
1351+
message: readMessage, narrow: TopicNarrow.ofMessage(readMessage));
1352+
1353+
// Initially, the button should be visible because the helper subscribes to the stream.
1354+
check(find.byIcon(Icons.mark_chat_unread_outlined).evaluate()).single;
1355+
1356+
// Close the action sheet
1357+
await tester.tapAt(const Offset(0, 0)); // Tap outside to dismiss it
1358+
await tester.pumpAndSettle();
1359+
1360+
// Now, we will fire an event to unsubscribe from the stream.
1361+
await store.handleEvent(SubscriptionRemoveEvent(
1362+
id: 999, // dummy event ID
1363+
streamIds: [readMessage.streamId]));
1364+
1365+
// this will Process the state change
1366+
await tester.pump();
1367+
1368+
// Open the action sheet again after unsubscribing from the stream
1369+
await tester.longPress(find.byType(MessageContent), warnIfMissed: false);
1370+
await tester.pump(const Duration(milliseconds: 250));
1371+
1372+
// After the rebuild, the button should be gone.
1373+
check(find.byIcon(Icons.mark_chat_unread_outlined).evaluate()).isEmpty();
1374+
});
1375+
13441376
group('onPressed', () {
13451377
testWidgets('smoke test', (tester) async {
13461378
final message = eg.streamMessage(flags: [MessageFlag.read]);
@@ -1547,7 +1579,6 @@ void main() {
15471579
of: find.byWidget(snackbar.content),
15481580
matching: find.text(zulipLocalizations.successMessageTextCopied)));
15491581
});
1550-
15511582
testWidgets('request has an error', (tester) async {
15521583
final message = eg.streamMessage();
15531584
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

0 commit comments

Comments
 (0)