Skip to content

Commit 7d73858

Browse files
committed
msglist: In unsubscribed channel, refresh on message-send success
This fixes half of the "first buggy behavior" described in zulip#1798, specifically the send-message case. We'll fix it for the edit-message case too, coming up. Fixes-partly: zulip#1798
1 parent f1370a2 commit 7d73858

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

lib/widgets/compose_box.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,13 +1324,14 @@ class _SendButtonState extends State<_SendButton> {
13241324
return;
13251325
}
13261326

1327-
final store = PerAccountStoreWidget.of(context);
1327+
PerAccountStore store = PerAccountStoreWidget.of(context);
13281328
final content = controller.content.textNormalized;
13291329

13301330
controller.content.clear();
13311331

13321332
try {
13331333
await store.sendMessage(destination: widget.getDestination(), content: content);
1334+
if (!mounted) return;
13341335
} on ApiRequestException catch (e) {
13351336
if (!mounted) return;
13361337
final zulipLocalizations = ZulipLocalizations.of(context);
@@ -1343,6 +1344,20 @@ class _SendButtonState extends State<_SendButton> {
13431344
message: message);
13441345
return;
13451346
}
1347+
1348+
store = PerAccountStoreWidget.of(context);
1349+
final destination = widget.getDestination();
1350+
if (
1351+
destination is StreamDestination
1352+
&& store.subscriptions[destination.streamId] == null
1353+
) {
1354+
// We don't get new-message events for unsubscribed channels,
1355+
// but we can refresh the view when a send-message request succeeds,
1356+
// so the user will at least see their own messages without having to
1357+
// exit and re-enter. See the "first buggy behavior" in
1358+
// https://github.com/zulip/zulip-flutter/issues/1798 .
1359+
MessageListPage.ancestorOf(context).refresh(AnchorCode.newest);
1360+
}
13461361
}
13471362

13481363
@override

test/widgets/compose_box_test.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:flutter/material.dart';
1414
import 'package:image_picker/image_picker.dart';
1515
import 'package:zulip/api/model/events.dart';
1616
import 'package:zulip/api/model/model.dart';
17+
import 'package:zulip/api/model/narrow.dart';
1718
import 'package:zulip/api/route/channels.dart';
1819
import 'package:zulip/api/route/messages.dart';
1920
import 'package:zulip/model/localizations.dart';
@@ -972,6 +973,59 @@ void main() {
972973
'You do not have permission to initiate direct message conversations.'),
973974
)));
974975
});
976+
977+
testWidgets('if channel is unsubscribed, refresh on message-send success', (tester) async {
978+
// Regression test for the "first buggy behavior"
979+
// in https://github.com/zulip/zulip-flutter/issues/1798 .
980+
TypingNotifier.debugEnable = false;
981+
addTearDown(TypingNotifier.debugReset);
982+
assert(MessageStoreImpl.debugOutboxEnable);
983+
984+
final channel = eg.stream();
985+
final narrow = eg.topicNarrow(channel.streamId, 'some topic');
986+
final messages = [eg.streamMessage(stream: channel, topic: 'some topic')];
987+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
988+
await prepareComposeBox(tester,
989+
narrow: narrow,
990+
streams: [channel],
991+
messages: messages);
992+
assert(store.subscriptions[channel.streamId] == null);
993+
994+
await enterContent(tester, 'hello world');
995+
996+
connection.prepare(
997+
json: SendMessageResult(id: 456).toJson(), delay: Duration(seconds: 1));
998+
await tester.tap(find.byTooltip(zulipLocalizations.composeBoxSendTooltip));
999+
await tester.pump(Duration(milliseconds: 500));
1000+
check(connection.takeRequests()).single.isA<http.Request>()
1001+
..method.equals('POST')
1002+
..url.path.equals('/api/v1/messages');
1003+
1004+
final newMessage = eg.streamMessage(
1005+
stream: channel, topic: 'some topic',
1006+
content: '<p>hello world</p>');
1007+
connection.prepare(json: eg.newestGetMessagesResult(
1008+
foundOldest: true, messages: [...messages, newMessage]).toJson());
1009+
await tester.pump(Duration(milliseconds: 500));
1010+
check(connection.lastRequest).isA<http.Request>()
1011+
..method.equals('GET')
1012+
..url.path.equals('/api/v1/messages')
1013+
..url.queryParameters.deepEquals({
1014+
'narrow': jsonEncode(resolveApiNarrowForServer(
1015+
narrow.apiEncode(), connection.zulipFeatureLevel!)),
1016+
'anchor': 'newest',
1017+
'num_before': '100',
1018+
'num_after': '100',
1019+
'allow_empty_topic_name': 'true',
1020+
});
1021+
check(find.descendant(
1022+
of: find.byType(MessageWithPossibleSender),
1023+
matching: find.text('hello world'))
1024+
).findsOne();
1025+
// TODO(#1798) There's actually a lingering OutboxMessageWithPossibleSender,
1026+
// too (the "third buggy behavior" in #1798). We'll fix that soon,
1027+
// and it'll be convenient to test that here too.
1028+
});
9751029
});
9761030

9771031
group('sending to empty topic', () {

0 commit comments

Comments
 (0)