Skip to content

Commit 0a12c33

Browse files
committed
msglist: Retrieve topic from failed-to-send messages
Fixes: #1441
1 parent f35aabb commit 0a12c33

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

lib/widgets/compose_box.dart

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,15 +1251,8 @@ class _SendButtonState extends State<_SendButton> {
12511251
final content = controller.content.textNormalized;
12521252

12531253
controller.content.clear();
1254-
// The following `stoppedComposing` call is currently redundant,
1255-
// because clearing input sends a "typing stopped" notice.
1256-
// It will be necessary once we resolve #720.
1257-
store.typingNotifier.stoppedComposing();
12581254

12591255
try {
1260-
// TODO(#720) clear content input only on success response;
1261-
// while waiting, put input(s) and send button into a disabled
1262-
// "working on it" state (letting input text be selected for copying).
12631256
await store.sendMessage(destination: widget.getDestination(), content: content);
12641257
} on ApiRequestException catch (e) {
12651258
if (!mounted) return;
@@ -1351,7 +1344,6 @@ class _ComposeBoxContainer extends StatelessWidget {
13511344
border: Border(top: BorderSide(color: designVariables.borderBar)),
13521345
boxShadow: ComposeBoxTheme.of(context).boxShadow,
13531346
),
1354-
// TODO(#720) try a Stack for the overlaid linear progress indicator
13551347
child: Material(
13561348
color: designVariables.composeBoxBg,
13571349
child: Column(
@@ -1636,10 +1628,6 @@ class _ErrorBanner extends _Banner {
16361628

16371629
@override
16381630
Widget? buildTrailing(context) {
1639-
// TODO(#720) "x" button goes here.
1640-
// 24px square with 8px touchable padding in all directions?
1641-
// and `bool get padEnd => false`; see Figma:
1642-
// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=4031-17029&m=dev
16431631
return null;
16441632
}
16451633
}
@@ -1770,11 +1758,6 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
17701758
}
17711759
}
17721760

1773-
// TODO(#720) dismissable message-send error, maybe something like:
1774-
// if (controller.sendMessageError.value != null) {
1775-
// errorBanner = _ErrorBanner(label:
1776-
// ZulipLocalizations.of(context).errorSendMessageTimeout);
1777-
// }
17781761
return _ComposeBoxContainer(body: body, banner: null);
17791762
}
17801763
}

lib/widgets/message_list.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
14911491

14921492
final MessageListOutboxMessageItem item;
14931493

1494-
// TODO restore the topic too
14951494
void _handlePress(BuildContext context) {
14961495
final content = item.message.content.endsWith('\n')
14971496
? item.message.content : '${item.message.content}\n';
@@ -1503,6 +1502,13 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
15031502
composeBoxController.contentFocusNode.requestFocus();
15041503
}
15051504

1505+
if (composeBoxController case StreamComposeBoxController(:final topic)) {
1506+
final conversation = item.message.conversation;
1507+
if (conversation is StreamConversation) {
1508+
topic.setTopic(conversation.topic);
1509+
}
1510+
}
1511+
15061512
final store = PerAccountStoreWidget.of(context);
15071513
assert(store.outboxMessages.containsKey(item.message.localMessageId));
15081514
store.removeOutboxMessage(item.message.localMessageId);

test/widgets/message_list_test.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:zulip/api/model/events.dart';
1111
import 'package:zulip/api/model/initial_snapshot.dart';
1212
import 'package:zulip/api/model/model.dart';
1313
import 'package:zulip/api/model/narrow.dart';
14+
import 'package:zulip/api/route/channels.dart';
1415
import 'package:zulip/api/route/messages.dart';
1516
import 'package:zulip/model/actions.dart';
1617
import 'package:zulip/model/localizations.dart';
@@ -1421,6 +1422,8 @@ void main() {
14211422
final stream = eg.stream();
14221423
const content = 'outbox message content';
14231424

1425+
final topicInputFinder = find.byWidgetPredicate(
1426+
(widget) => widget is TextField && widget.controller is ComposeTopicController);
14241427
final contentInputFinder = find.byWidgetPredicate(
14251428
(widget) => widget is TextField && widget.controller is ComposeContentController);
14261429

@@ -1471,7 +1474,32 @@ void main() {
14711474
localMessageId: store.outboxMessages.keys.single));
14721475
});
14731476

1474-
testWidgets('failed to send message, retrieve the content to compose box', (tester) async {
1477+
testWidgets('in channel narrow, failed to send message, retrieve both topic and content to compose box', (tester) async {
1478+
await setupMessageListPage(tester,
1479+
narrow: ChannelNarrow(stream.streamId), streams: [stream],
1480+
messages: []);
1481+
1482+
connection.prepare(json: GetStreamTopicsResult(topics: []).toJson());
1483+
await tester.enterText(topicInputFinder, 'test topic');
1484+
await sendMessageAndFail(tester);
1485+
1486+
final controller = tester.state<ComposeBoxState>(find.byType(ComposeBox)).controller;
1487+
controller as StreamComposeBoxController;
1488+
await tester.enterText(topicInputFinder, 'different topic');
1489+
check(controller.content).text.isNotNull().isEmpty();
1490+
1491+
// Tap the message. This should put its content back into the compose box
1492+
// and remove it.
1493+
await tester.tap(outboxMessageFinder);
1494+
await tester.pump();
1495+
check(outboxMessageFinder).findsNothing();
1496+
check(controller.topic).text.equals('test topic');
1497+
check(controller.content).text.equals('$content\n\n');
1498+
1499+
await tester.pump(kLocalEchoDebounceDuration);
1500+
});
1501+
1502+
testWidgets('in topic narrow, failed to send message, retrieve the content to compose box', (tester) async {
14751503
await setupMessageListPage(tester,
14761504
narrow: eg.topicNarrow(stream.streamId, 'topic'), streams: [stream],
14771505
messages: []);

0 commit comments

Comments
 (0)