@@ -530,12 +530,14 @@ const kSendMessageOfferRestoreWaitPeriod = Duration(seconds: 10); // TODO(#1441
530
530
/// [MessageStore.sendMessage] call and before its eventual deletion.
531
531
///
532
532
/// ```
533
- /// Got an [ApiRequestException].
534
- /// ┌──────┬──────────┬─────────────► failed
535
- /// (create) │ │ │ │
536
- /// └► hidden waiting waitPeriodExpired ──┴──────────────► (delete)
537
- /// │ ▲ │ ▲ User restores
538
- /// └──────┘ └──────┘ the draft.
533
+ /// Got an [ApiRequestException].
534
+ /// ┌──────┬────────────────────────────┬──────────► failed
535
+ /// │ │ │ │
536
+ /// │ │ [sendMessage] │ │
537
+ /// (create) │ │ request succeeds. │ │
538
+ /// └► hidden waiting ◄─────────────── waitPeriodExpired ──┴─────► (delete)
539
+ /// │ ▲ │ ▲ User restores
540
+ /// └──────┘ └─────────────────────┘ the draft.
539
541
/// Debounce [sendMessage] request
540
542
/// timed out. not finished when
541
543
/// wait period timed out.
@@ -559,7 +561,8 @@ enum OutboxMessageState {
559
561
/// outbox message is shown to the user.
560
562
///
561
563
/// This state can be reached after staying in [hidden] for
562
- /// [kLocalEchoDebounceDuration] .
564
+ /// [kLocalEchoDebounceDuration] , or when the request succeeds after the
565
+ /// outbox message reaches [OutboxMessageState.waitPeriodExpired] .
563
566
waiting,
564
567
565
568
/// The [sendMessage] HTTP request did not finish in time and the user is
@@ -717,7 +720,8 @@ mixin _OutboxMessageStore on PerAccountStoreBase {
717
720
final isStateTransitionValid = switch (newState) {
718
721
OutboxMessageState .hidden => false ,
719
722
OutboxMessageState .waiting =>
720
- oldState == OutboxMessageState .hidden,
723
+ oldState == OutboxMessageState .hidden
724
+ || oldState == OutboxMessageState .waitPeriodExpired,
721
725
OutboxMessageState .waitPeriodExpired =>
722
726
oldState == OutboxMessageState .waiting,
723
727
OutboxMessageState .failed =>
@@ -803,6 +807,14 @@ mixin _OutboxMessageStore on PerAccountStoreBase {
803
807
// Cancel the timer that would have had us start presuming that the
804
808
// send might have failed.
805
809
_outboxMessageWaitPeriodTimers.remove (localMessageId)? .cancel ();
810
+ if (_outboxMessages[localMessageId]! .state
811
+ == OutboxMessageState .waitPeriodExpired) {
812
+ // The user was offered to restore the message since the request did not
813
+ // complete for a while. Since the request was successful, we expect the
814
+ // message event to arrive eventually. Stop inviting the the user to
815
+ // retry, to avoid double-sends.
816
+ _updateOutboxMessage (localMessageId, newState: OutboxMessageState .waiting);
817
+ }
806
818
}
807
819
808
820
TopicName _processTopicLikeServer (TopicName topic, {
0 commit comments