Skip to content

Commit 6d8c858

Browse files
committed
msglist: Support retrieving failed outbox message content
1 parent eaecdf2 commit 6d8c858

13 files changed

+271
-22
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
@@ -1169,6 +1169,12 @@ abstract class ZulipLocalizations {
11691169
/// **'MOVED'**
11701170
String get messageIsMovedLabel;
11711171

1172+
/// Label for a message that isn't sent. (Use ALL CAPS for cased alphabets: Latin, Greek, Cyrillic, etc.)
1173+
///
1174+
/// In en, this message translates to:
1175+
/// **'MESSAGE ISN\'T SENT. CHECK YOUR CONNECTION.'**
1176+
String get messageIsntSentLabel;
1177+
11721178
/// The list of people who voted for a poll option, wrapped in parentheses.
11731179
///
11741180
/// 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/generated/l10n/zulip_localizations_uk.dart

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class ZulipLocalizationsUk 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/model/message.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,8 @@ mixin _OutboxMessageStore on PerAccountStoreBase {
276276
void _handleMessageEventOutbox(MessageEvent event) {
277277
if (event.localMessageId != null) {
278278
final localMessageId = int.parse(event.localMessageId!, radix: 10);
279-
// The outbox message can be missing if the user removes it (to be
280-
// implemented in #1441) before the event arrives.
281-
// Nothing to do in that case.
279+
// The outbox message can be missing if the user removes it before the
280+
// event arrives. Nothing to do in that case.
282281
_outboxMessages.remove(localMessageId);
283282
_outboxMessageDebounceTimers.remove(localMessageId)?.cancel();
284283
_outboxMessageWaitPeriodTimers.remove(localMessageId)?.cancel();

lib/widgets/message_list.dart

+80-14
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';
@@ -1478,21 +1479,86 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
14781479

14791480
final MessageListOutboxMessageItem item;
14801481

1482+
// TODO should we restore the topic as well?
1483+
void _handlePress(BuildContext context) {
1484+
final content = item.message.content.endsWith('\n')
1485+
? item.message.content : '${item.message.content}\n';
1486+
1487+
final composeBoxController =
1488+
MessageListPage.ancestorOf(context).composeBoxController;
1489+
composeBoxController!.content.insertPadded(content);
1490+
if (!composeBoxController.contentFocusNode.hasFocus) {
1491+
composeBoxController.contentFocusNode.requestFocus();
1492+
}
1493+
1494+
final store = PerAccountStoreWidget.of(context);
1495+
assert(store.outboxMessages.containsKey(item.message.localMessageId));
1496+
store.removeOutboxMessage(item.message.localMessageId);
1497+
}
1498+
14811499
@override
14821500
Widget build(BuildContext context) {
1483-
final message = item.message;
1484-
return Padding(
1485-
padding: const EdgeInsets.symmetric(vertical: 4),
1486-
child: Column(children: [
1487-
if (item.showSender) _SenderRow(message: message, showTimestamp: false),
1488-
Padding(
1489-
padding: const EdgeInsets.symmetric(horizontal: 16),
1490-
// This is adapated from [MessageContent].
1491-
// TODO(#576): Offer InheritedMessage ancestor once we are ready
1492-
// to support local echoing images and lightbox.
1493-
child: DefaultTextStyle(
1494-
style: ContentTheme.of(context).textStylePlainParagraph,
1495-
child: BlockContentList(nodes: item.content.nodes))),
1496-
]));
1501+
final designVariables = DesignVariables.of(context);
1502+
final zulipLocalizations = ZulipLocalizations.of(context);
1503+
final isComposeBoxOffered =
1504+
MessageListPage.ancestorOf(context).composeBoxController != null;
1505+
1506+
final GestureTapCallback? handleTap;
1507+
final double opacity;
1508+
final Widget bottom;
1509+
switch (item.message.state) {
1510+
case OutboxMessageState.hidden:
1511+
assert(false,
1512+
'Hidden OutboxMessage messages should not appear in message lists');
1513+
handleTap = null;
1514+
opacity = 1.0;
1515+
bottom = SizedBox.shrink();
1516+
1517+
case OutboxMessageState.waiting:
1518+
handleTap = null;
1519+
opacity = 1.0;
1520+
bottom = LinearProgressIndicator(
1521+
minHeight: 2,
1522+
color: designVariables.foreground.withFadedAlpha(0.5),
1523+
backgroundColor: designVariables.foreground.withFadedAlpha(0.2));
1524+
1525+
case OutboxMessageState.failed:
1526+
case OutboxMessageState.waitPeriodExpired:
1527+
handleTap = isComposeBoxOffered ? () => _handlePress(context) : null;
1528+
opacity = 0.6;
1529+
bottom = Text(
1530+
zulipLocalizations.messageIsntSentLabel,
1531+
textAlign: TextAlign.end,
1532+
style: TextStyle(
1533+
color: designVariables.btnLabelAttLowIntDanger,
1534+
fontSize: 12,
1535+
height: 12 / 12,
1536+
letterSpacing: proportionalLetterSpacing(
1537+
context, 0.006, baseFontSize: 12),
1538+
).merge(weightVariableTextStyle(context, wght: 400)));
1539+
}
1540+
1541+
return GestureDetector(
1542+
onTap: handleTap,
1543+
behavior: HitTestBehavior.opaque,
1544+
child: Opacity(opacity: opacity, child: Padding(
1545+
padding: const EdgeInsets.symmetric(vertical: 4),
1546+
child: Column(children: [
1547+
if (item.showSender)
1548+
_SenderRow(message: item.message, showTimestamp: false),
1549+
Padding(
1550+
padding: const EdgeInsets.symmetric(horizontal: 16),
1551+
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch,
1552+
children: [
1553+
// This is adapated from [MessageContent].
1554+
// TODO(#576): Offer InheritedMessage ancestor once we are ready
1555+
// to support local echoing images and lightbox.
1556+
DefaultTextStyle(
1557+
style: ContentTheme.of(context).textStylePlainParagraph,
1558+
child: BlockContentList(nodes: item.content.nodes)),
1559+
1560+
bottom,
1561+
])),
1562+
]))));
14971563
}
14981564
}

0 commit comments

Comments
 (0)