Skip to content

Commit 2be8ead

Browse files
committed
msglist: In unsubscribed channel, clear edit progress on request success
This fixes the rest of the "third buggy behavior" described in zulip#1798: it fixes it for the edit-message case. Fixes-partly: zulip#1798
1 parent 522df03 commit 2be8ead

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

lib/model/message.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
519519
content: newContent,
520520
prevContentSha256: sha256.convert(utf8.encode(originalRawContent)).toString());
521521
// On success, we'll clear the status from _editMessageRequests
522-
// when we get the event.
522+
// when we get the event (or below, if in an unsubscribed channel).
523+
if (_disposed) return;
523524
} catch (e) {
524525
// TODO(log) if e is something unexpected
525526

@@ -536,6 +537,15 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
536537
_notifyMessageListViewsForOneMessage(messageId);
537538
rethrow;
538539
}
540+
541+
final message = messages[messageId];
542+
if (message is StreamMessage && subscriptions[message.streamId] == null) {
543+
// The message is in an unsubscribed channel. We don't expect an event
544+
// (see "third buggy behavior" in #1798) but we know the edit request
545+
// succeeded, so, clear the pending-edit state.
546+
_editMessageRequests.remove(messageId);
547+
_notifyMessageListViewsForOneMessage(messageId);
548+
}
539549
}
540550

541551
@override

test/model/message_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,30 @@ void main() {
10531053
check(store.getEditMessageErrorStatus(message.id)).isNull();
10541054
checkNotNotified();
10551055
}));
1056+
1057+
test('request succeeds, in unsubscribed channel', () => awaitFakeAsync((async) async {
1058+
final channel = eg.stream();
1059+
message = eg.streamMessage(stream: channel, sender: eg.selfUser);
1060+
await prepare(
1061+
narrow: ChannelNarrow(channel.streamId),
1062+
stream: channel,
1063+
isChannelSubscribed: false,
1064+
);
1065+
await prepareMessages([message]);
1066+
check(connection.takeRequests()).length.equals(1); // message-list fetchInitial
1067+
1068+
connection.prepare(
1069+
json: UpdateMessageResult().toJson(), delay: Duration(seconds: 1));
1070+
unawaited(store.editMessage(messageId: message.id,
1071+
originalRawContent: 'old content', newContent: 'new content'));
1072+
checkRequest(message.id, prevContent: 'old content', content: 'new content');
1073+
checkNotifiedOnce();
1074+
1075+
async.elapse(Duration(seconds: 1));
1076+
// Outbox status cleared already (we don't expect an edit-message event).
1077+
check(store.getEditMessageErrorStatus(message.id)).isNull();
1078+
checkNotifiedOnce();
1079+
}));
10561080
});
10571081

10581082
group('selfCanDeleteMessage', () {

test/widgets/compose_box_test.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,21 @@ void main() {
21072107
checkContentInputValue(tester, expectedContentText);
21082108
}
21092109

2110+
/// Check whether the message in the message list says "SAVING EDIT…".
2111+
///
2112+
/// This state is tested more thoroughly
2113+
/// in test/widgets/message_list_test.dart, naturally.
2114+
void checkEditInProgressInMsglist(WidgetTester tester,
2115+
{required int messageId, required bool expected}) {
2116+
final messageFinder = find.byWidgetPredicate((widget) =>
2117+
widget is MessageWithPossibleSender && widget.item.message.id == messageId);
2118+
2119+
check(find.descendant(
2120+
of: messageFinder,
2121+
matching: find.text('SAVING EDIT…'),
2122+
).evaluate().length).equals(expected ? 1 : 0);
2123+
}
2124+
21102125
void testSmoke({required Narrow narrow, required _EditInteractionStart start}) {
21112126
testWidgets('smoke: $narrow, ${start.message()}', (tester) async {
21122127
await prepareEditMessage(tester, narrow: narrow);
@@ -2157,6 +2172,10 @@ void main() {
21572172
prevContent: 'foo', content: 'some new content[file.jpg](/path/file.jpg)');
21582173
await tester.pump(Duration.zero);
21592174
checkNotInEditingMode(tester, narrow: narrow);
2175+
2176+
// We'll say "SAVING EDIT…" in the message list until the event arrives.
2177+
// (No need to make the event arrive here; message-list tests do that.)
2178+
checkEditInProgressInMsglist(tester, messageId: messageId, expected: true);
21602179
});
21612180
}
21622181
testSmoke(narrow: channelNarrow, start: _EditInteractionStart.actionSheet);
@@ -2461,9 +2480,9 @@ void main() {
24612480
of: find.byType(MessageWithPossibleSender),
24622481
matching: find.text(ContentExample.emojiUnicode.expectedText!))
24632482
).findsOne();
2464-
// TODO(#1798) The message actually appears in the "SAVING EDIT…" state
2465-
// (the "third buggy behavior" in #1798). We'll fix that soon,
2466-
// and it'll be convenient to test that here too.
2483+
// Regression coverage for the "third buggy behavior"
2484+
// in https://github.com/zulip/zulip-flutter/issues/1798 .
2485+
checkEditInProgressInMsglist(tester, messageId: message.id, expected: false);
24672486
});
24682487
});
24692488
}

0 commit comments

Comments
 (0)