zulip / zulip-flutter

Future Zulip client using Flutter
Apache License 2.0
158 stars 131 forks source link

Implement outbox system #133

Open chrisbobbe opened 1 year ago

chrisbobbe commented 1 year ago

Something like this, maybe. From discussion:

            User cancels the scheduled send.
           ┌────────────────────────────────────────────────────────────────────────┐
           │                                                                        │
           │                                                                        │
           │                                   User cancels during send (#4170).    │
           │                                  ┌───────────────────────────────────┐ │
           │                                  │                                   │ │
           │                                  │                                   │ │
           │                                  │                Event received,    │ │
(create)   │      Time for the scheduled      │                or we abandoned    │ │
  │        │      send (a try/retry).         │    200.        the queue.         ▼ ▼
  └► should-send ───────────────────────► sending ─────► sent ────────────────► (delete)
       │ ▲ ▲                                │ │                                     ▲
       │ │ │                                │ │                                     │
       │ │ │ App quit: schedule auto-retry. │ │                                     │
       │ │ │                                │ │                                     │
       │ │ │ 5xx, network error, or (with   │ │                                     │
       │ │ │ #4170) 60s network timeout:    │ │                                     │
       │ │ │ schedule auto-retry with       │ │                                     │
       │ │ │ backoff.                       │ │ 4xx.                                │
       │ │ └────────────────────────────────┘ └───────────────────────┐             │
       │ │                                                            │             │
       │ │                                                            │    User     │
       │ │ User requested a retry; schedule to run immediately.       ▼    cancels. │
       │ └──────────────────────────────────────────────────────── failed ──────────┘
       │                                                              ▲
       │                                                              │
       │ Too old: message is "better never than late". Too much time  │
       │ from creation or last user-requested retry.                  │
       └──────────────────────────────────────────────────────────────┘
gnprice commented 1 year ago

From a user perspective this feature means:

gnprice commented 5 months ago

An implementation note: this is what the method PerAccountStore.sendMessage is for.

Currently that method does nothing other than make the underlying sendMessage API request. When we implement this issue, the same method will instead create a new outbox-message in the subsystem described above.

As a matter of code organization, that outbox data will probably want to live on its own class defined in its own file; PerAccountStore will just hold onto an instance of that class, and PerAccountStore.sendMessage will delegate to that. See Inbox and StreamStore for existing examples (showing two somewhat different versions of that pattern).