Skip to content

feat: allow scheduling a message with a shared location - #2016

Merged
MartinCupela merged 75 commits into
masterfrom
feat/scheduled-messages-shared-location
Nov 25, 2026
Merged

MartinCupela merged 75 commits into
masterfrom
feat/scheduled-messages-shared-location

Conversation

@MartinCupela

@MartinCupela MartinCupela commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why and How?

Ticket: https://linear.app/stream/issue/REACT-1385

Stacked on feat/cha-5934-scheduled-messages-v10. A message with a shared location can now be scheduled. Until now the composer refused it with "This message can't be scheduled", which was a client-side policy: the backend accepts shared_location in scheduled messages. The React side is GetStream/stream-chat-react#3426.

Lifting the block alone would have broken two things, so this PR fixes them too:

  • Edits kept dropping the location. An update replaces the whole scheduled message on the server, but the SDK treated shared_location as server-owned and left it out of the update. Editing just the text would have deleted the location. It is now a composer-owned field: editing loads it into the location composer, and the update sends the composer's copy, or none once it is removed.
  • Live locations would have been rejected. A live location's end_at was counted from now, but the server requires it to be at least 59 seconds after the send time. A live location scheduled further ahead than its duration would always fail. Its sharing now starts when the message is sent: LocationComposer.validateLocation({ sharingStartsAt }) resolves durationMs from the given start, the shared-location middleware passes the send time while scheduling, and validLocation still resolves from now.

Breaking changes (to APIs only on the feature branch, unreleased)

  • ScheduledMessageBlockReason.SharedLocation is removed.

Still possible

A scheduled live location's end time is fixed once it is scheduled. Rescheduling the message past that end time is rejected by the server, and the reschedule dialog shows the error.

Testing

  • Scheduling a static location sends it; a live location's end_at is the send time plus its duration.
  • scheduleBlockReason is undefined with a location.
  • An edit keeps a stored location, with its end_at, in the update, and drops one removed in the composer.
  • Results: yarn types and yarn lint are clean; 5,322 tests pass.
  • Checked in the React vite example: with a 15-minute live location on a message due at 12:00 UTC, the composed end_at was 12:15 UTC.

Changelog

  • A message with a shared location can be scheduled; editing a scheduled message keeps its location, and a live location starts sharing when the message is sent.

NikolaGoranNaumovski and others added 22 commits November 3, 2026 16:12
Add the scheduled message API error codes 114 to 124, and the helpers
the state and UI layers build on: error reason detection on
StreamAPIError, channel limits read from the server config, and the
status, failure, error, block, composition end and event constants.
The runtime constants for statuses and failure reasons are upper-case
objects typed by the generated unions, so they do not clash with the
generated ScheduledMessageStatus and ScheduledMessageFailureReason types.
Port the scheduled message state layer to v10 as client.scheduledMessages.
The manager keeps the active scheduled messages in a StateStore, applies
scheduled_message events, loads and pages through the query endpoint, and
wraps update, delete and send-now so the store follows each response.
Ordering compares the nanosecond timestamps numerically, newer stored
versions win, sent and deleted ids stay tombstoned, and a snapshot keeps
messages stored while its request was in flight.

Unlike v9, the manager loads itself: once registered it loads whenever
the socket turns healthy for a connected, non-anonymous user, which also
covers reconnects, and it stops loading automatically once the feature
is reported disabled. It is reset on disconnectUser.
Channel responses that carry scheduled_messages, from
queryChannelsAndHydrate or from requestChannelState (query, watch and
create), replace the stored scheduled messages of that channel. Each
request captures the store version first, so a message stored while it
was in flight is kept. A sendMessage response with a scheduled_message
is stored, while the sent message never reaches the message paginator.
MessageComposer.schedule(at) composes the message and sends it with
scheduled_at through channel.sendMessage, so it never enters the message
list or the offline queue. editScheduledMessage() and
updateScheduledMessage() edit a scheduled message in the composer, and
rescheduleFailedMessage() loads a failed one to schedule or send again;
the failed message is deleted once the new one goes out, including when
it is sent now. Drafts pause while a scheduled message is in the
composer, and the earlier composition comes back when it ends.

schedule() and updateScheduledMessage() never reject. They return a
ScheduledMessageSubmitResult and, unlike send(), keep the composition on
failure, since a scheduled message has no list item that could hold it.
A composition with a command, poll or location can't be scheduled:
scheduleBlockReason exposes why, and a composition middleware placed
before poll-only discards it with a warning. An edit ends with a warning
when its message is sent, deleted or fails elsewhere, and is refreshed
by newer updates. New core notification types cover these cases.
UI SDKs render a stored scheduled message with their message preview
components, which take a LocalMessage. Export the helper that builds
one, so they do not duplicate its required fields.
queryChannelsAndHydrate iterated the response channels for scheduled
message hydration without the guard the rest of the method uses, so a
response without channels threw.
Port the v9 composer suite to v10: schedule, edit, reschedule a failed
message, the result contract that keeps the composition on failure,
blocked compositions, pending and failed uploads, draft pausing, the
restore point, scheduled message events ending or refreshing an edit,
the update payload built from the stored message, and the preview
helper. Also cover sending a failed-message composition now, which
deletes the failed scheduled message once the send succeeds.
Loads the scheduled messages of one channel, or of all channels, page by page
over a shared store, sorted as the server returns them: pending before failed,
each by scheduled_at.
ScheduledMessageManager holds a list of all scheduled messages and one per
channel, all backed by one EntityStore, and routes events, responses and
channel hydration to every list. Lists load when the UI needs them and reload
after connection.recovered instead of on every connect.
ScheduledMessageManager runs scheduled_message.* and connection.recovered
through one EventHandlerPipeline per event type, as ChannelManager does.
The defaults are labeled, so an app can add, replace or remove them with
addEventHandler, setEventHandlers and removeEventHandlers, or pass its own
set to the constructor, without forking the manager.
The manager decides which copy of a scheduled message wins before it reaches
the lists or the store: a sent or canceled copy is final, otherwise the newer
updated_at wins. Sent and deleted events record the final status instead of
removing the message, so each list drops it through its filter and the store
keeps the finished record that any older copy loses to. This replaces the
set of removed ids.
…connect

connection.recovered now runs ScheduledMessageManager.recover(), which reloads
the loaded lists except the channel lists that a channel response hydrated
since the socket dropped. reload() still reloads every loaded list.
Adds scheduleMessageRequest, updateScheduledMessageRequest,
deleteScheduledMessageRequest and sendScheduledMessageNowRequest to the
channel request handlers, with the same (params, defaultRequest) signature as
sendMessageRequest. Scheduling goes through the new
ScheduledMessageManager.scheduleMessage(), so all four requests follow the same
path and a replaced request still stores its result.
channel.scheduledMessages.enabled is ANDed with the app having the feature,
which the scheduled message limits in the channel server config tell, and with
the schedule-message capability in channel.scheduledMessagesEnabled. The
composer blocks scheduling when it is off. Missing limits now mean the feature
is off instead of falling back to defaults, and client.scheduledMessages.paginator
sets the paging of every scheduled message list.
Since #1994 connection.recovered is dispatched on every reconnect, also with
connection recovery turned off, and the scheduled message lists reload on it like
the thread list. The channel list test hydrates before the real recovery
dispatches the event instead of turning recovery off.
…4) (#2013)

## CLA

- [x] I have signed the [Stream
CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform)
(required).
- [x] Code changes are tested

## Description of the changes, What, Why and How?

Ticket: https://linear.app/stream/issue/REACT-1385

Stacked on #1990 (`feat/cha-5934-scheduled-messages-v10`): this PR
changes how the scheduled-message lists are owned and kept consistent,
and simplifies the composer's scheduling API. The React side that uses
it is GetStream/stream-chat-react#3426.

The full design, with the reasoning, is in
[`specs/scheduled-message-lists/spec.md`](https://github.com/GetStream/stream-chat-js/blob/feat/scheduled-messages-store-redesign/specs/scheduled-message-lists/spec.md).

### How it differs from #1990

In #1990, one `ScheduledMessageManager` (`client.scheduledMessages`)
owned every list: a global one, a per-channel map, their shared store,
its own consistency layer (`resolveLatest`, receive versions,
`hydratedCids`, a `version` read around every channel query) and every
action. That made it the owner of data that belongs elsewhere:

| Problem in #1990 | This PR |
|---|---|
| A channel's list belonged to the manager; `Channel` read the manager's
`version` before each query and handed `scheduled_messages` back to it.
| The channel owns its list: `channel.scheduledMessagesPaginator`,
filled by the channel query like pinned messages. |
| The per-channel map only grew: a channel's paginator lived until
logout, even after the channel was disposed. | The list lives and goes
with its channel. |
| The manager decided which lists exist: no way to add a "failed only"
list, and the global list existed whether the UI showed it or not. |
`client.scheduledMessagePaginators` holds only the lists the integrator
registers (`insertPaginator`), like `ChannelManager`, with an
`EventHandlerPipeline` per event type. |
| Consistency rules lived outside the store; every writer had to go
through the manager. | The rules live in the store: `EntityStore` gained
`shouldReplace` and tombstones, so a stale copy can never overwrite a
newer one, whoever writes. |

### Other improvements

- **One publish per response.** `BasePaginator.batch(fn, { coalesce:
true })` collects store notifications and publishes the list once, so
hydrating a page doesn't re-render once per message.
- **Filters follow `ReminderPaginator`'s pattern.** The default statuses
(scheduled, sending, failed) are applied only when matching. Setting
`filter` resets the list.
- **Channel and thread scopes come from the SDK.** The server can't
filter scheduled messages by thread: `ScheduledMessagesFilter` has only
`cid` and `status` (the Swift SDK has the same two keys). So a channel's
list holds its own messages and its thread replies together, and the UI
had to split them.
- `channel.scheduledMessages` (the channel's own messages) and
`thread.scheduledMessages` (one thread's replies) are
`ScheduledMessagesView`s of the channel's list. Nothing is copied into
threads, and a thread doesn't need its data loaded first.
- They're built on a new generic `PaginatorView<T>`: a read-only view of
any paginator's loaded items, narrowed by a predicate. It follows the
paginator while registered (ref-counted), keeps the same array when
nothing it shows changed, and offers the paginator's own `toHead` /
`toTail` and their debounced versions.
- An app that registers a cross-channel list shows it with `new
ScheduledMessagesView({ paginator })`.
- **Empty complete lists:** `BasePaginator.placePage` now starts an
interval in a list that's loaded, complete and empty. Before, a message
arriving there was lost.
- **Composer, one field instead of two:** `failedScheduledMessage` is
merged into `editedScheduledMessage`.
- The message's status decides what submitting does: a pending message
is saved as an edit (`updateScheduledMessage()`), a failed one is sent
or scheduled again as a new message.
- `rescheduleFailedMessage` and `cancelRescheduleFailedMessage` are
gone; `editScheduledMessage` and `cancelEditScheduledMessage` cover both
cases.
- **Polls can be scheduled.** The backend accepts them, so
`ScheduledMessageBlockReason.Poll` is removed. Shared locations stay
blocked: a static one would be out of date when sent, and a live one's
sharing window would start counting before the message is sent.
- **`schedule()` releases the composition like `send()`.** With the
default poll-only step, the composer keeps the text after a poll goes
out, instead of clearing everything.

### Breaking changes (to APIs only on the feature branch, unreleased)

`client.scheduledMessages` → `client.scheduledMessagePaginators`. Its
actions moved to the channel (`channel.scheduleMessage`,
`updateScheduledMessage`, `deleteScheduledMessage`,
`sendScheduledMessageNow`). The global list is no longer built in:
register your own. The full table is in the spec under "Breaking
changes".

### Review against the Figma designs (SDK side)

| Design point | Status |
|---|---|
| Polls can be scheduled | Done |
| Locations are not offered for scheduling | Kept blocked |
| The banner shows `scheduled_message.scheduled_at` from the server, not
the picked time | The server's copy is what the lists hold |
| Scheduling offline is queued and sent with the same ID on reconnect |
**Open.** Web has no offline queue for `scheduleMessage`; this needs an
SDK decision. |
| Rows sorted earliest first; messages scheduled for the same time sort
alphabetically | Done. Failed messages come first by time alone, since
they failed at their send time, so the pending-before-failed rule from
#1990 is gone. |
| Deleting a message already canceled elsewhere (code 124) drops it
quietly | **Open.** Handled for 404 only; the status code 124 comes back
with is unconfirmed. |

### Review fixes

A review of this stack found these; they're fixed in 696d109.

- **A message removed in one list stayed in the others.** When two lists
held the same message, only the first to take a `deleted` or `sent`
event dropped it; the other kept showing it as canceled or sent. Now a
winning removal removes the store entry, so every list drops it through
`onEntityRemoved`.
- **Other changes didn't reach a second list.** A list now re-places an
item that another list changed in the store, so a `failed` message
leaves a pending-only list and a new `scheduled_at` re-sorts it in every
list.
- **A sent message could come back as pending.** `dispatchEvent` records
a tombstone for every `sent` and `deleted` event, even when no list
holds the message. A `queryChannels` response read before the event can
no longer list it again.
- **Reloads emptied the list.** `ScheduledMessagePaginator.reload()` now
keeps the list until the response lands and joins a reload already
running, as `ThreadPaginator.reload()` does. `hydrate` replaces a list
that isn't complete instead of merging into it. Recovery reloads every
registered list that loaded a page, empty ones included.
- **Edits dropped uploads.** `updateScheduledMessage()` waits for
uploads in progress and refuses an edit with a failed upload, as
`schedule()` does.

## Testing

- `EntityStore`: `shouldReplace` and tombstones.
- The scheduled-message state machine, including stale copies after
cancel and delete.
- `BasePaginator`: empty complete pages and batched publishing.
- Channel hydration from `query()`, `watch()` and `queryChannels`.
- The manager's pipelines, recovery and reset.
- The composer: schedule, edit, retry, polls, the merged state, and
draft pausing.
- `PaginatorView` and the channel and thread scheduled-message views.
- Results: `yarn types` and ESLint are clean; 5,319 tests pass.

## Changelog

- Scheduled-message lists are owned by the channel
(`channel.scheduledMessagesPaginator`) and by
`client.scheduledMessagePaginators`, and backed by a store that keeps
the newest copy.
- The composer holds one `editedScheduledMessage` for both edits and
retries of failed messages.
- Polls can be scheduled.
- `channel.scheduledMessages` and `thread.scheduledMessages` list a
channel's own scheduled messages and a thread's scheduled replies, as
views built on the new `PaginatorView`.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- A shared location no longer blocks scheduling; ScheduledMessageBlockReason
  drops SharedLocation. The backend accepts locations in scheduled messages.
- Editing a scheduled message keeps its location: shared_location is a
  composer-owned field, so the composer loads it and the update sends the
  composer's copy, or none once it is removed. An update replaces the whole
  message, so leaving it out would have deleted the location.
- A live location shared in a scheduled message starts sharing when the
  message is sent: LocationComposer.validateLocation({ sharingStartsAt })
  resolves durationMs from the send time, and validLocation from now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the scheduled-message request lifecycle off Channel into a dedicated
ScheduledMessageOperations, the sibling of MessageOperations. It owns request-handler
resolution, attachment sanitizing, the not-found -> cancel rule, and the single
fan-out seam (ingest) into the channel's list and the registered cross-channel lists.

Channel keeps the four public methods (scheduleMessage, updateScheduledMessage,
deleteScheduledMessage, sendScheduledMessageNow) as one-line delegations, with the
same signatures and return values. Behavior is unchanged (still response-only).
…CHA-5934)

Introduce ScheduledMessageComposition, which owns scheduling, editing a pending
scheduled message, and holding a failed one to schedule or send again. It drives the
MessageComposer through its public API and reuses the composer's snapshot/restore and
compose primitives, so MessageComposer no longer carries scheduled-message state,
methods, or event subscriptions - it only composes.

The scheduled-message block middleware now decides whether a composition is being
scheduled from a `scheduling` intent flag on the composition middleware state, instead
of reaching into the composer.

Tests move onto composer.scheduledMessageComposition.*.
NikolaGoranNaumovski and others added 14 commits November 19, 2026 15:00
…ads like a send (CHA-5934)

Adds 'schedule' to OperationKind and removes SequencedOperationKind, which
existed only to let sequenceRequests order schedules behind sends. The state
policy handles the new kind as a no-op, since scheduling runs through
ScheduledMessageStatePolicy and is never optimistic.

Drops withSettledScheduledUploads. withSettledUploads is unchanged from master;
scheduleMessage and updateScheduledMessage call it as 'schedule' when the
composer handed over a local message, which is the only source of pending
uploads.
…composer methods (CHA-5934)

ScheduledMessageComposition is no longer exported or reachable from outside:
MessageComposer keeps it private and exposes scheduleMessage,
editScheduledMessage, updateScheduledMessage, cancelScheduledMessageEdit,
editedScheduledMessage and scheduleBlockReason instead.

initState gains a scheduled message mode next to the draft and message ones.
It takes an EditedScheduledMessageComposition (the scheduled message plus its
resolved quoted message and mentioned users), loads the sub-composers from it,
and sets editedScheduledMessage in the composer state with no draftId or
editedMessage, a fresh id, and the stored show_in_channel. Its editing audit
state follows a message edit, from updated_at. This replaces the draft
disguise (toScheduledMessageComposition) and the separate composition store.
…-v10' into feat/scheduled-messages-shared-location

# Conflicts:
#	src/scheduledMessages/composition.ts
#	test/unit/MessageComposer/scheduledMessages.test.ts
…(CHA-5934)

Removes EditedScheduledMessageComposition. initState takes the
ScheduledMessageResponse itself, the way it takes a draft or a message, and
recognises it by scheduled_at. The scheduled check runs first: a scheduled
message also has a `message` field, which the draft check matches, and a string
`status`, which the local message check matches.

The scheduled message stores only the ids of its quoted message and mentioned
users, so initState cannot fill them. editScheduledMessage fetches them first
and sets them right after initState.
…-v10' into feat/scheduled-messages-shared-location

# Conflicts:
#	src/scheduledMessages/composition.ts
getChannelLevelScheduledMessages and getThreadScheduledMessages were root-exported but used nowhere
in the SDK. A channel's and a thread's scheduled messages are scoped by their ScheduledMessagesView,
whose thread scope is already covered by its own tests.
Channel.sendMessage wrote the response's scheduled_message to the store, and the
ScheduledMessageStatePolicy success step wrote it again. The override is back to master's, so the
policy is the only write after a schedule request. A direct channel.sendMessage with scheduled_at
still reaches the channel's list through the scheduled_message.created event.
…s (CHA-5934)

Removes what this PR added and nothing uses: the ScheduledMessageEvent type,
isScheduledMessageError, and PaginatorView.setPredicate, along with their tests. The view's
predicate is now readonly. Also drops unused locals and an unused import in the PR's tests.
Channel.scheduleMessage, updateScheduledMessage, deleteScheduledMessage and
sendScheduledMessageNow only forwarded to MessageOperations. Each action now has one way to do it,
channel.messageOperations. Removing a failed scheduled message and the tests go through it.
A scheduled edit no longer saves the composition it replaces and no longer brings it back when it
ends, the same as a normal edit. This removes saveCompositionBeforeEdit, restoreAfterEdit,
handleDraftWhileEditing and clearDraftWhileEditing. An ended edit now clears the composer directly.

Drafts are still ignored while a scheduled message (or a failed one) is open: the draft.updated and
draft.deleted listeners skip on pausesDrafts, and initStateFromChannelResponse skips while
editedScheduledMessage is set, so a channel query or reconnect cannot replace the edit.

The handler for the sent, deleted and failed events is renamed to closeEditWhenMessageEnds.
… internal (CHA-5934)

releaseSubmittedComposition and reportSubmitFailure were private on master. The scheduled message
composition is a separate class and calls them, so they stay callable and are marked @internal.
…hannel wrappers (CHA-5934)

Channel.scheduleMessage, updateScheduledMessage, deleteScheduledMessage and sendScheduledMessageNow
come back as thin requests, like channel.sendReaction: they take the generated method's arguments
and return its response. They do not go through MessageOperations, so they write no local state;
the lists update from the scheduled_message events. channel.messageOperations stays the path that
settles uploads, keeps send order and writes the result into the store.
…A-5934)

scheduleMessage and updateScheduledMessage composed twice when scheduling was blocked, once only to
let the composition middleware show the warning. They now compose once and report blocked from
scheduleBlockReason when the composition is discarded. The composer reads editedScheduledMessage
for pausesDrafts instead of a forwarding getter, and the internal class's own
editedScheduledMessage getter is private.
Base automatically changed from feat/cha-5934-scheduled-messages-v10 to master November 25, 2026 09:49
@MartinCupela
MartinCupela merged commit 10d338e into master Nov 25, 2026
7 checks passed
@MartinCupela
MartinCupela deleted the feat/scheduled-messages-shared-location branch November 25, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants