@@ -8,6 +8,7 @@ import 'package:intl/intl.dart' hide TextDirection;
8
8
9
9
import '../api/model/model.dart' ;
10
10
import '../generated/l10n/zulip_localizations.dart' ;
11
+ import '../model/message.dart' ;
11
12
import '../model/message_list.dart' ;
12
13
import '../model/narrow.dart' ;
13
14
import '../model/store.dart' ;
@@ -1478,21 +1479,86 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
1478
1479
1479
1480
final MessageListOutboxMessageItem item;
1480
1481
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
+
1481
1499
@override
1482
1500
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
+ ]))));
1497
1563
}
1498
1564
}
0 commit comments