Skip to content

Commit 522df03

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

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/widgets/compose_box.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ class _EditMessageBannerTrailing extends StatelessWidget {
18691869
// disappears, which may be long after the banner disappears.)
18701870
final pageContext = PageRoot.contextOf(context);
18711871

1872-
final store = PerAccountStoreWidget.of(pageContext);
1872+
PerAccountStore store = PerAccountStoreWidget.of(pageContext);
18731873
final controller = composeBoxState.controller;
18741874
if (controller is! EditMessageComposeBoxController) return; // TODO(log)
18751875
final zulipLocalizations = ZulipLocalizations.of(pageContext);
@@ -1900,6 +1900,7 @@ class _EditMessageBannerTrailing extends StatelessWidget {
19001900
messageId: messageId,
19011901
originalRawContent: originalRawContent,
19021902
newContent: newContent);
1903+
if (!pageContext.mounted) return;
19031904
} on ApiRequestException catch (e) {
19041905
if (!pageContext.mounted) return;
19051906
final zulipLocalizations = ZulipLocalizations.of(pageContext);
@@ -1912,6 +1913,18 @@ class _EditMessageBannerTrailing extends StatelessWidget {
19121913
message: message);
19131914
return;
19141915
}
1916+
1917+
store = PerAccountStoreWidget.of(pageContext);
1918+
final messageListPageState = MessageListPage.ancestorOf(pageContext);
1919+
final narrow = messageListPageState.narrow;
1920+
if (narrow is ChannelNarrow && store.subscriptions[narrow.streamId] == null) {
1921+
// We don't get edit-message events for unsubscribed channels,
1922+
// but we can refresh the view when an edit-message request succeeds,
1923+
// so the user will at least see their updated message without having to
1924+
// exit and re-enter. See the "first buggy behavior" in
1925+
// https://github.com/zulip/zulip-flutter/issues/1798 .
1926+
messageListPageState.refresh(NumericAnchor(messageId));
1927+
}
19151928
}
19161929

19171930
@override

test/widgets/compose_box_test.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import '../api/fake_api.dart';
3535
import '../example_data.dart' as eg;
3636
import '../flutter_checks.dart';
3737
import '../model/binding.dart';
38+
import '../model/content_test.dart';
3839
import '../model/message_list_test.dart';
3940
import '../model/store_checks.dart';
4041
import '../model/test_store.dart';
@@ -2413,6 +2414,57 @@ void main() {
24132414
testCancel(narrow: channelNarrow, start: _EditInteractionStart.restoreFailedEdit);
24142415
// testCancel(narrow: topicNarrow, start: _EditInteractionStart.restoreFailedEdit);
24152416
// testCancel(narrow: dmNarrow, start: _EditInteractionStart.restoreFailedEdit);
2417+
2418+
testWidgets('if channel is unsubscribed, refresh on message-edit success', (tester) async {
2419+
// Regression test for the "first buggy behavior"
2420+
// in https://github.com/zulip/zulip-flutter/issues/1798 .
2421+
2422+
final channel = eg.stream();
2423+
final narrow = ChannelNarrow(channel.streamId);
2424+
final message = eg.streamMessage(stream: channel, sender: eg.selfUser);
2425+
2426+
await prepareComposeBox(tester, narrow: narrow, streams: [channel]);
2427+
await store.addMessages([message]);
2428+
check(store.subscriptions[channel.streamId]).isNull();
2429+
await tester.pump(); // message list updates
2430+
2431+
await startEditInteractionFromActionSheet(tester,
2432+
messageId: message.id, originalRawContent: 'foo');
2433+
await tester.pump(Duration(seconds: 1)); // fetch-raw-content request
2434+
checkContentInputValue(tester, 'foo');
2435+
2436+
final newMarkdownContent = ContentExample.emojiUnicode.markdown!;
2437+
await enterContent(tester, newMarkdownContent);
2438+
2439+
connection.prepare(json: UpdateMessageResult().toJson(), delay: Duration(seconds: 1));
2440+
await tester.tap(find.widgetWithText(ZulipWebUiKitButton, 'Save'));
2441+
await tester.pump(Duration(milliseconds: 500));
2442+
checkRequest(message.id, prevContent: 'foo', content: newMarkdownContent);
2443+
2444+
final updatedMessage =
2445+
Message.fromJson(message.toJson()..['content'] = ContentExample.emojiUnicode.html);
2446+
connection.prepare(json: eg.newestGetMessagesResult(
2447+
foundOldest: true, messages: [updatedMessage]).toJson());
2448+
await tester.pump(Duration(milliseconds: 500));
2449+
check(connection.lastRequest).isA<http.Request>()
2450+
..method.equals('GET')
2451+
..url.path.equals('/api/v1/messages')
2452+
..url.queryParameters.deepEquals({
2453+
'narrow': jsonEncode(resolveApiNarrowForServer(
2454+
narrow.apiEncode(), connection.zulipFeatureLevel!)),
2455+
'anchor': '${message.id}',
2456+
'num_before': '100',
2457+
'num_after': '100',
2458+
'allow_empty_topic_name': 'true',
2459+
});
2460+
check(find.descendant(
2461+
of: find.byType(MessageWithPossibleSender),
2462+
matching: find.text(ContentExample.emojiUnicode.expectedText!))
2463+
).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.
2467+
});
24162468
});
24172469
}
24182470

0 commit comments

Comments
 (0)