Skip to content

Commit 21e4b4b

Browse files
committed
squash! implement retry UX
See if the tests can be simplified
1 parent 79205c9 commit 21e4b4b

11 files changed

+217
-15
lines changed

assets/l10n/app_en.arb

+4
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@
801801
"@messageIsMovedLabel": {
802802
"description": "Label for a moved message. (Use ALL CAPS for cased alphabets: Latin, Greek, Cyrillic, etc.)"
803803
},
804+
"messageIsntSentLabel": "MESSAGE ISN'T SENT. CHECK YOUR CONNECTION.",
805+
"@messageIsntSentLabel": {
806+
"description": "Label for a message that isn't sent. (Use ALL CAPS for cased alphabets: Latin, Greek, Cyrillic, etc.)"
807+
},
804808
"pollVoterNames": "({voterNames})",
805809
"@pollVoterNames": {
806810
"description": "The list of people who voted for a poll option, wrapped in parentheses.",

lib/generated/l10n/zulip_localizations.dart

+6
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,12 @@ abstract class ZulipLocalizations {
11671167
/// **'MOVED'**
11681168
String get messageIsMovedLabel;
11691169

1170+
/// Label for a message that isn't sent. (Use ALL CAPS for cased alphabets: Latin, Greek, Cyrillic, etc.)
1171+
///
1172+
/// In en, this message translates to:
1173+
/// **'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.'**
1174+
String get messageIsntSentLabel;
1175+
11701176
/// The list of people who voted for a poll option, wrapped in parentheses.
11711177
///
11721178
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'MOVED';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/generated/l10n/zulip_localizations_en.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'MOVED';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/generated/l10n/zulip_localizations_ja.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'MOVED';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/generated/l10n/zulip_localizations_nb.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'MOVED';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/generated/l10n/zulip_localizations_pl.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'PRZENIESIONO';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/generated/l10n/zulip_localizations_ru.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'ПЕРЕМЕЩЕНО';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/generated/l10n/zulip_localizations_sk.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
625625
@override
626626
String get messageIsMovedLabel => 'PRESUNUTÉ';
627627

628+
@override
629+
String get messageIsntSentLabel => 'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.';
630+
628631
@override
629632
String pollVoterNames(String voterNames) {
630633
return '($voterNames)';

lib/widgets/message_list.dart

+60-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:intl/intl.dart' hide TextDirection;
88

99
import '../api/model/model.dart';
1010
import '../generated/l10n/zulip_localizations.dart';
11+
import '../model/message.dart';
1112
import '../model/message_list.dart';
1213
import '../model/narrow.dart';
1314
import '../model/store.dart';
@@ -1481,21 +1482,67 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
14811482

14821483
final MessageListOutboxMessageItem item;
14831484

1485+
// TODO should we restore the topic as well?
1486+
void _handlePress(BuildContext context) {
1487+
final content = item.message.content.endsWith('\n')
1488+
? item.message.content : '${item.message.content}\n';
1489+
1490+
final composeBoxController =
1491+
MessageListPage.ancestorOf(context).composeBoxController;
1492+
composeBoxController!.content.insertPadded(content);
1493+
if (!composeBoxController.contentFocusNode.hasFocus) {
1494+
composeBoxController.contentFocusNode.requestFocus();
1495+
}
1496+
1497+
final store = PerAccountStoreWidget.of(context);
1498+
assert(store.outboxMessages.containsKey(item.message.localMessageId));
1499+
store.removeOutboxMessage(item.message.localMessageId);
1500+
}
1501+
14841502
@override
14851503
Widget build(BuildContext context) {
1504+
final designVariables = DesignVariables.of(context);
1505+
final zulipLocalizations = ZulipLocalizations.of(context);
14861506
final message = item.message;
1487-
return Padding(
1488-
padding: const EdgeInsets.symmetric(vertical: 4),
1489-
child: Column(children: [
1490-
if (item.showSender) _SenderRow(message: message),
1491-
Padding(
1492-
padding: const EdgeInsets.symmetric(horizontal: 16),
1493-
// This is adapated from [MessageContent].
1494-
// TODO(#576): Offer InheritedMessage ancestor once we are ready
1495-
// to support local echoing images and lightbox.
1496-
child: DefaultTextStyle(
1497-
style: ContentTheme.of(context).textStylePlainParagraph,
1498-
child: BlockContentList(nodes: item.content.nodes))),
1499-
]));
1507+
final opacity = message.state == OutboxMessageLifecycle.failed ? 0.6 : 1.0;
1508+
1509+
final isComposeBoxOffered =
1510+
MessageListPage.ancestorOf(context).composeBoxController != null;
1511+
1512+
return GestureDetector(
1513+
onTap: isComposeBoxOffered && message.state == OutboxMessageLifecycle.failed
1514+
? () => _handlePress(context) : null,
1515+
behavior: HitTestBehavior.opaque,
1516+
child: Padding(
1517+
padding: const EdgeInsets.symmetric(vertical: 4),
1518+
child: Column(children: [
1519+
if (item.showSender) Opacity(opacity: opacity, child: _SenderRow(message: message)),
1520+
Padding(
1521+
padding: const EdgeInsets.symmetric(horizontal: 16),
1522+
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch,
1523+
children: [
1524+
Opacity(opacity: opacity,
1525+
// This is adapated from [MessageContent].
1526+
// TODO(#576): Offer InheritedMessage ancestor once we are ready
1527+
// to support local echoing images and lightbox.
1528+
child: DefaultTextStyle(
1529+
style: ContentTheme.of(context).textStylePlainParagraph,
1530+
child: BlockContentList(nodes: item.content.nodes))),
1531+
1532+
if (message.state == OutboxMessageLifecycle.failed)
1533+
Text(zulipLocalizations.messageIsntSentLabel,
1534+
textAlign: TextAlign.end,
1535+
style: TextStyle(
1536+
color: designVariables.btnLabelAttLowIntDanger,
1537+
fontSize: 12,
1538+
height: 12 / 12,
1539+
letterSpacing: proportionalLetterSpacing(
1540+
context, 0.006, baseFontSize: 12),
1541+
).merge(weightVariableTextStyle(context, wght: 400)))
1542+
else LinearProgressIndicator(minHeight: 2,
1543+
color: designVariables.foreground.withFadedAlpha(0.5),
1544+
backgroundColor: designVariables.foreground.withFadedAlpha(0.2)),
1545+
])),
1546+
])));
15001547
}
15011548
}

test/widgets/message_list_test.dart

+126-2
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,9 @@ void main() {
13651365
of: find.byType(MessageItem),
13661366
matching: find.text(content, findRichText: true)).hitTestable();
13671367

1368+
Finder messageIsntSentErrorFinder = find.text(
1369+
'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.').hitTestable();
1370+
13681371
testWidgets('sent message appear in message list after debounce timeout', (tester) async {
13691372
await setupMessageListPage(tester,
13701373
narrow: eg.topicNarrow(stream.streamId, 'topic'), streams: [stream],
@@ -1374,10 +1377,131 @@ void main() {
13741377
await tester.enterText(contentInputFinder, content);
13751378
await tester.tap(find.byIcon(ZulipIcons.send));
13761379
await tester.pump(Duration.zero);
1377-
check(findTextInMessages(content)).findsNothing();
1380+
check(outboxMessageFinder).findsNothing();
13781381

13791382
await tester.pump(kLocalEchoDebounceDuration);
1380-
check(findTextInMessages(content)).findsOne();
1383+
check(outboxMessageFinder).findsOne();
1384+
check(find.descendant(
1385+
of: find.byType(MessageItem),
1386+
matching: find.byType(LinearProgressIndicator))).findsOne();
1387+
});
1388+
1389+
testWidgets('failed to send message, retrieve the content to compose box', (tester) async {
1390+
await setupMessageListPage(tester,
1391+
narrow: eg.topicNarrow(stream.streamId, 'topic'), streams: [stream],
1392+
messages: []);
1393+
1394+
// Send a message and fail. Dismiss the error dialog as it pops up.
1395+
connection.prepare(apiException: eg.apiBadRequest());
1396+
await tester.enterText(contentInputFinder, content);
1397+
await tester.tap(find.byIcon(ZulipIcons.send));
1398+
await tester.pump(Duration.zero);
1399+
await tester.tap(find.byWidget(
1400+
checkErrorDialog(tester, expectedTitle: 'Message not sent')));
1401+
await tester.pump();
1402+
check(outboxMessageFinder).findsOne();
1403+
check(messageIsntSentErrorFinder).findsOne();
1404+
1405+
final controller = tester.state<ComposeBoxState>(find.byType(ComposeBox)).controller;
1406+
check(controller.content).text.isNotNull().isEmpty();
1407+
1408+
// Tap the message. This should put its content back into the compose box
1409+
// and remove it.
1410+
await tester.tap(outboxMessageFinder);
1411+
await tester.pump();
1412+
check(outboxMessageFinder).findsNothing();
1413+
check(controller.content).text.equals('$content\n\n');
1414+
1415+
await tester.pump(kLocalEchoDebounceDuration);
1416+
});
1417+
1418+
testWidgets('tapping does nothing if compose box is not offered', (tester) async {
1419+
final messages = [eg.streamMessage(stream: stream, topic: 'some topic')];
1420+
await setupMessageListPage(tester,
1421+
narrow: const CombinedFeedNarrow(), streams: [stream], subscriptions: [eg.subscription(stream)],
1422+
messages: messages);
1423+
1424+
// Navigate to a message list page in a topic narrow,
1425+
// which has a compose box.
1426+
connection.prepare(json:
1427+
eg.newestGetMessagesResult(foundOldest: true, messages: messages).toJson());
1428+
await tester.tap(find.text('some topic'));
1429+
await tester.pump(); // handle tap
1430+
await tester.pump(); // wait for navigation
1431+
1432+
// Send a message and fail. Dismiss the error dialog as it pops up.
1433+
connection.prepare(apiException: eg.apiBadRequest());
1434+
await tester.enterText(contentInputFinder, content);
1435+
await tester.tap(find.byIcon(ZulipIcons.send));
1436+
await tester.pump(Duration.zero);
1437+
await tester.tap(find.byWidget(
1438+
checkErrorDialog(tester, expectedTitle: 'Message not sent')));
1439+
await tester.pump(); // handle tap
1440+
check(outboxMessageFinder).findsOne();
1441+
check(messageIsntSentErrorFinder).findsOne();
1442+
1443+
// Navigate back to the message list page without a compose box,
1444+
// where the failed to send message should still be visible.
1445+
await tester.pageBack();
1446+
await tester.pump(); // handle tap
1447+
await tester.pump(); // wait for navigation
1448+
check(contentInputFinder).findsNothing();
1449+
check(outboxMessageFinder).findsOne();
1450+
check(messageIsntSentErrorFinder).findsOne();
1451+
1452+
// Tap the failed to send message.
1453+
// This should not remove it from the message list.
1454+
await tester.tap(outboxMessageFinder);
1455+
await tester.pump();
1456+
check(outboxMessageFinder).findsOne();
1457+
});
1458+
1459+
testWidgets('tapping does nothing if message was successfully sent', (tester) async {
1460+
await setupMessageListPage(tester,
1461+
narrow: eg.topicNarrow(stream.streamId, 'topic'), streams: [stream],
1462+
messages: []);
1463+
final controller = tester.state<ComposeBoxState>(find.byType(ComposeBox)).controller;
1464+
1465+
// Send a message and wait until the debounce timer expires.
1466+
connection.prepare(json: SendMessageResult(id: 1).toJson());
1467+
await tester.enterText(contentInputFinder, content);
1468+
await tester.tap(find.byIcon(ZulipIcons.send));
1469+
await tester.pump(Duration.zero);
1470+
await tester.pump(kLocalEchoDebounceDuration);
1471+
check(controller.content).text.isNotNull().isEmpty();
1472+
1473+
await tester.tap(outboxMessageFinder);
1474+
await tester.pump();
1475+
check(outboxMessageFinder).findsOne();
1476+
check(controller.content).text.isNotNull().isEmpty();
1477+
});
1478+
1479+
testWidgets('tapping does nothing if message is still being sent', (tester) async {
1480+
await setupMessageListPage(tester,
1481+
narrow: eg.topicNarrow(stream.streamId, 'topic'), streams: [stream],
1482+
messages: []);
1483+
final controller = tester.state<ComposeBoxState>(find.byType(ComposeBox)).controller;
1484+
1485+
// Send a message and wait until the debounce timer expires but before
1486+
// the message is successfully sent.
1487+
connection.prepare(json: SendMessageResult(id: 1).toJson(),
1488+
delay: kLocalEchoDebounceDuration + Duration(seconds: 1));
1489+
await tester.enterText(contentInputFinder, content);
1490+
await tester.tap(find.byIcon(ZulipIcons.send));
1491+
await tester.pump(Duration.zero);
1492+
await tester.pump(kLocalEchoDebounceDuration);
1493+
check(controller.content).text.isNotNull().isEmpty();
1494+
1495+
await tester.tap(outboxMessageFinder);
1496+
await tester.pump();
1497+
check(outboxMessageFinder).findsOne();
1498+
check(controller.content).text.isNotNull().isEmpty();
1499+
1500+
// Wait till the send request completes. The outbox message should
1501+
// remain visible because the message event didn't arrive.
1502+
await tester.pump(Duration(seconds: 1));
1503+
check(outboxMessageFinder).findsOne();
1504+
check(controller.content).text.isNotNull().isEmpty();
13811505
});
13821506
});
13831507

0 commit comments

Comments
 (0)