@@ -5,6 +5,7 @@ import 'package:intl/intl.dart' hide TextDirection;
5
5
6
6
import '../api/model/model.dart' ;
7
7
import '../generated/l10n/zulip_localizations.dart' ;
8
+ import '../model/message.dart' ;
8
9
import '../model/message_list.dart' ;
9
10
import '../model/narrow.dart' ;
10
11
import '../model/store.dart' ;
@@ -1515,22 +1516,86 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
1515
1516
1516
1517
final MessageListOutboxMessageItem item;
1517
1518
1519
+ // TODO should we restore the topic as well?
1520
+ void _handlePress (BuildContext context) {
1521
+ final content = item.message.content.endsWith ('\n ' )
1522
+ ? item.message.content : '${item .message .content }\n ' ;
1523
+
1524
+ final composeBoxController =
1525
+ MessageListPage .ancestorOf (context).composeBoxState! .controller;
1526
+ composeBoxController.content.insertPadded (content);
1527
+ if (! composeBoxController.contentFocusNode.hasFocus) {
1528
+ composeBoxController.contentFocusNode.requestFocus ();
1529
+ }
1530
+
1531
+ final store = PerAccountStoreWidget .of (context);
1532
+ assert (store.outboxMessages.containsKey (item.message.localMessageId));
1533
+ store.removeOutboxMessage (item.message.localMessageId);
1534
+ }
1535
+
1518
1536
@override
1519
1537
Widget build (BuildContext context) {
1520
- final message = item.message;
1521
- return Padding (
1522
- padding: const EdgeInsets .symmetric (vertical: 4 ),
1523
- child: Column (children: [
1524
- if (item.showSender)
1525
- _SenderRow (message: message, showTimestamp: false ),
1526
- Padding (
1527
- padding: const EdgeInsets .symmetric (horizontal: 16 ),
1528
- // This is adapated from [MessageContent].
1529
- // TODO(#576): Offer InheritedMessage ancestor once we are ready
1530
- // to support local echoing images and lightbox.
1531
- child: DefaultTextStyle (
1532
- style: ContentTheme .of (context).textStylePlainParagraph,
1533
- child: BlockContentList (nodes: item.content.nodes))),
1534
- ]));
1538
+ final designVariables = DesignVariables .of (context);
1539
+ final zulipLocalizations = ZulipLocalizations .of (context);
1540
+ final isComposeBoxOffered =
1541
+ MessageListPage .ancestorOf (context).composeBoxState != null ;
1542
+
1543
+ final GestureTapCallback ? handleTap;
1544
+ final double opacity;
1545
+ final Widget bottom;
1546
+ switch (item.message.state) {
1547
+ case OutboxMessageState .hidden:
1548
+ assert (false ,
1549
+ 'Hidden OutboxMessage messages should not appear in message lists' );
1550
+ handleTap = null ;
1551
+ opacity = 1.0 ;
1552
+ bottom = SizedBox .shrink ();
1553
+
1554
+ case OutboxMessageState .waiting:
1555
+ handleTap = null ;
1556
+ opacity = 1.0 ;
1557
+ bottom = LinearProgressIndicator (
1558
+ minHeight: 2 ,
1559
+ color: designVariables.foreground.withFadedAlpha (0.5 ),
1560
+ backgroundColor: designVariables.foreground.withFadedAlpha (0.2 ));
1561
+
1562
+ case OutboxMessageState .failed:
1563
+ case OutboxMessageState .waitPeriodExpired:
1564
+ handleTap = isComposeBoxOffered ? () => _handlePress (context) : null ;
1565
+ opacity = 0.6 ;
1566
+ bottom = Text (
1567
+ zulipLocalizations.messageIsntSentLabel,
1568
+ textAlign: TextAlign .end,
1569
+ style: TextStyle (
1570
+ color: designVariables.btnLabelAttLowIntDanger,
1571
+ fontSize: 12 ,
1572
+ height: 12 / 12 ,
1573
+ letterSpacing: proportionalLetterSpacing (
1574
+ context, 0.006 , baseFontSize: 12 ),
1575
+ ).merge (weightVariableTextStyle (context, wght: 400 )));
1576
+ }
1577
+
1578
+ return GestureDetector (
1579
+ onTap: handleTap,
1580
+ behavior: HitTestBehavior .opaque,
1581
+ child: Opacity (opacity: opacity, child: Padding (
1582
+ padding: const EdgeInsets .symmetric (vertical: 4 ),
1583
+ child: Column (children: [
1584
+ if (item.showSender)
1585
+ _SenderRow (message: item.message, showTimestamp: false ),
1586
+ Padding (
1587
+ padding: const EdgeInsets .symmetric (horizontal: 16 ),
1588
+ child: Column (crossAxisAlignment: CrossAxisAlignment .stretch,
1589
+ children: [
1590
+ // This is adapated from [MessageContent].
1591
+ // TODO(#576): Offer InheritedMessage ancestor once we are ready
1592
+ // to support local echoing images and lightbox.
1593
+ DefaultTextStyle (
1594
+ style: ContentTheme .of (context).textStylePlainParagraph,
1595
+ child: BlockContentList (nodes: item.content.nodes)),
1596
+
1597
+ bottom,
1598
+ ])),
1599
+ ]))));
1535
1600
}
1536
1601
}
0 commit comments