Skip to content

feat: [CHA-6554] add played marks on voice notes - #3962

Closed
xicoalmeida wants to merge 2 commits into
developfrom
feature/cha-6554-message-marks
Closed

xicoalmeida wants to merge 2 commits into
developfrom
feature/cha-6554-message-marks

Conversation

@xicoalmeida

Copy link
Copy Markdown

What changed

A recipient's first unpaused play of an audio / voice-recording attachment sends channel.sendMessageMark({ id }, { type: 'played' }) β€” once per message per mount, only where the channel grants the send-message-mark capability, and never for a preview, a thread reply, the author's own message, or a message already played (own_marks). The author's copy of a voice note renders a "Played" indicator once mark_groups.played carries a count.

  • AudioAttachment.tsx: gating + send on first unpaused play; "Played" indicator on the author's side.
  • send-message-mark added to allOwnCapabilities (flows into OwnCapabilitiesContextValue with no further wiring).
  • New i18n prose key attachment.audio.played.label with inline English copy, per the runtimeDefaults rule; generated keys.ts + catalog fixture updated.
  • 9 new tests covering the full gating matrix (double-press, own message, preview, thread reply, missing capability, already played, rejected promise).

Design decision (brief)

The mark is sent client-side at the moment of first unpaused playback, deduped per mount with a ref and relying on the server write being idempotent β€” no persisted client state, no optimistic UI beyond the author-side count read from mark_groups.

Review-flagged items (please double-check)

  • Event payload shape: the author-side indicator reads mark_groups.played.count (and skip-if-played reads own_marks) β€” flagging the payload shape for reviewer confirmation against the backend marks event.
  • omitempty: the branch assumes mark_groups / own_marks are absent (not empty objects) when there are no marks; gating treats missing as "not played".
  • v10 call shape: channel.sendMessageMark({ id }, { type: 'played' }) was verified directly against the stream-chat-js marks branch (ChatApi.ts createMessageMark(pathParams: {id}, CreateMessageMarkRequest) re-exported via channel.ts) β€” please confirm it survives to the published release.

Tests / verification

  • jest src/components/Attachment: 13 suites / 82 tests green (3 consecutive runs; new suite 9/9 warm and cold-cache).
  • eslint --max-warnings 0 and prettier --list-different clean on all 5 touched files.
  • CI typecheck will be red on this draft: 7 TS errors, all from the published stream-chat@10.0.0 types lacking sendMessageMark / own_marks / mark_groups. They disappear when the JS marks branch merges and releases β€” this PR stays draft until that release ships. Runtime tests do not depend on it.

Refs CHA-6554

xicoalmeida and others added 2 commits November 9, 2026 15:58
A recipient's first unpaused play of an audio or voice-recording
attachment sends channel.sendMessageMark(message.id, 'played'), once
per message per mount, only where the channel grants
send-message-mark, never for a preview, a thread reply, the author's
own message or a message already played. The author's own voice notes
show "Played" when mark_groups.played has a count. New own capability
send-message-mark. Needs the stream-chat release that carries
sendMessageMark, mark_groups and own_marks.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Francisco Almeida <francisco.almeida@getstream.io>
Two lines, invariants only: the per-mount dedupe and the idempotent
server-side write. The gate conditions read directly from the code.

Signed-off-by: Francisco Almeida <francisco.almeida@getstream.io>
@isekovanic

Copy link
Copy Markdown
Contributor

Closing this in favor of #4023

@isekovanic isekovanic closed this Nov 23, 2026
isekovanic added a commit that referenced this pull request Nov 25, 2026
Ticket: https://linear.app/stream/issue/RN-542 (backend:
https://linear.app/stream/issue/CHA-6554)

Replaces #3962. Depends on GetStream/stream-chat-js#2039. Typecheck
fails until a `stream-chat` release ships `markMessagePlayed`,
`channel.config.markTypes`, the marks types and the offline DB's
`getMessageMarks` and `insertMessageMark`. The synced design tokens come
from GetStream/design-system-tokens#83.

## 🎯 Goal

Show the author of a voice note, audio file or video that other users
played it, following the "Message Marks" design.

## πŸ›  Implementation details

- Marking follows the player, not the component. Audio and video players
take an optional `onPlaybackStarted` callback, called on each progress
once playback advances, after any download and buffering, until it
returns `true`. The message is marked once it actually plays, even if
its bubble scrolled away while the audio buffered. A pool keeps a
player's callback when a later caller passes none.
- `AudioAttachment` passes a callback for its message. Composer previews
pass none and are never marked.
- `AnimatedGalleryVideo` passes a callback for the video's message.
`openImageGallery` takes an optional `channel`, which `Gallery` and the
channel details `MediaList` pass. A gallery opened without one marks
nothing.
- Apps decide what playing media does through `ChatConfigProvider`,
which takes an optional `handlePlaybackStarted({ attachment, markPlayed,
message, player })`. It is called as playback advances until it returns
`true`, so returning `false` can wait for a minimum played time, and it
can skip marking or branch on `attachment.type` or `message.cid`.
Without it the message is marked as soon as playback starts. Render the
provider above `OverlayProvider` so it also reaches gallery videos. The
types are `HandlePlaybackStarted` and `PlaybackStartedParams`.
- `useMarkMessagePlayed` is public, for a custom player that does not
use the SDK's players.

### Gallery autoplay fix

- With `autoPlayVideo` on, every gallery player was created playing, so
the slides next to the shown one played off screen, sound included, and
moving to another slide paused nothing, because autoplay never went
through `play()` and the pool had no active player. The same code is in
v9.
- Players now start paused, and a slide plays its video once it is
shown, through a store subscription that renders nothing. Moving to
another slide pauses the old video before the new index is published, so
the new slide's autoplay is not paused right after it starts.
- Only the shown video plays now, so marking no longer needs to skip
slides that are not shown.
- The client decides whether to send: it skips channel types without the
`played` mark, the user's own messages and messages the user already
marked, and queues the mark while offline. A failed mark is ignored.
- A new `MessageMark` slot shows the mark in the footer's status row,
before the delivery status and separated from it by a dot. A direct
message reads "Played", any other channel "Played by" and the count,
capped at 99+. It uses the read colour and the theme tokens, with theme
keys `messageItemView.mark.{container,text,separator}`.
- The mark shows only once someone played the message and only when
`channel.config.markTypes` includes `played`. There is no opt-in prop.
Turning marks on for the channel type is the switch.
- Played messages stay in their group. An earlier message in a group
shows only the mark, without the delivery status or timestamp, so the
time is not read as the time it was played. The last message keeps the
full row.
- The `Message` and `MessageFooter` memo comparators and
`stringifyMessage` include the played count, so a mark that arrives
while the channel is open re-renders the row.

### Offline mark lists

- The offline database stores marks the way it stores reactions, so a
"Played by" list (`MessageMarkPaginator` in `stream-chat`) opens offline
from the stored marks while its first page loads.
- A new `messageMarks` table holds one row per marker (`messageId`,
`userId`, `type`, `createdAt`), deleted with its message. Rows come from
each stored message's `mark_groups`, which carries the newest markers
per type (up to 100), and from `message.mark_added`.
- `mark_groups` and `own_marks` move out of `extraData` into their own
`markGroups` and `ownMarks` columns, as `reaction_groups` has
`reactionGroups`, so a new mark updates them without rewriting the
message.
- `OfflineDB` implements `getMessageMarks`, the stored marks on a
message newest first and joined to the stored users (a mark whose user
is not stored lists with the user's ID), and `insertMessageMark`, which
stores the mark, the user who made it and the two columns.
- `SqliteClient.dbVersion` goes from 19 to 20, so existing installs
rebuild their offline database once on update.

### Design tokens

- The generated tokens are synced to the latest design-system-tokens
build (last synced in June). The token repo has since renamed or removed
55 semantic tokens (`chat*` β†’ `messageBubble*`, `presence*` β†’
`avatarPresence*`, the `avatarPalette*` set, ...). Its React Native
build now keeps every old name mapped to the current token
(GetStream/design-system-tokens#83), so `theme.semantics` only gains
keys and the SDK compiles unchanged. The old names are removed in the
next major.
- Some token values changed in the design. Dark-mode mention text is now
`blue200` instead of `blue400`. `accentWarning` and the avatar default
colours changed too, but no SDK component reads them directly.
- `AGENTS.md` now says where the tokens come from, that the old names
are adapters kept in the token repo, and that new code uses the current
names.

### Avatars

- Avatars without an image use `avatarBgDefault` and `avatarTextDefault`
instead of a colour picked per user or channel from the 5-colour
palette, following the current design. Light mode matches what palette 1
looked like. In dark mode the default is the mode-aware brand colour.
The `avatarPalette*` keys stay in `theme.semantics` through the token
adapter, so integrators can still use them.

## 🎨 UI Changes

<details>
<summary>iOS</summary>


<table>
    <thead>
        <tr>
            <td>Before</td>
            <td>After</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <!--<img src="" /> -->
            </td>
            <td>
                <!--<img src="" /> -->
            </td>
        </tr>
    </tbody>
</table>
</details>


<details>
<summary>Android</summary>

<table>
    <thead>
        <tr>
            <td>Before</td>
            <td>After</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <!--<img src="" /> -->
            </td>
            <td>
                <!--<img src="" /> -->
            </td>
        </tr>
    </tbody>
</table>
</details>

## πŸ§ͺ Testing

- Unit tests cover the footer mark, with no mark before a play or
without the `played` mark type, "Played" in a direct message, the count
and 99+ in a channel, a mark that arrives live, and the mark-only row on
an earlier message in a group.
- Player tests cover calling `onPlaybackStarted` once on the first
progress, asking again until it returns `true`, nothing while paused, an
autoplaying video only once it advances, Expo's `progress`, and the
callback on a reused player. Gallery video tests render the gallery with
a real pool and cover autoplay playing only the shown video, moving to
another slide pausing it and playing the new one, no autoplay without
`autoPlayVideo`, marking the shown video, a handler from
`ChatConfigProvider` deciding, and nothing without a channel.
`AudioAttachment` tests render it in a `Channel`: a press alone does not
mark, the first progress does, a preview never does, and a configured
handler decides. `useMarkMessagePlayed` has its own tests.
- Tested in the SampleApp on the iOS simulator against the `stream-chat`
branch. As the author, in a direct message, no mark before a play, then
"Played" alone under the earlier voice note and "Played Β· βœ“ time" on the
last message, both live and after a reload. As the recipient, playing a
voice note and playing a video in the gallery each wrote the mark only
once playback started, and the author saw "Played Β· βœ“βœ“ time" under the
video. Rechecked after moving the override to `ChatConfigProvider`. With
autoplay on and a message with two videos, logging each slide's progress
showed the off-screen slide playing alongside the shown one before the
fix, and only the shown slide playing after it, opening either slide.
Moving between slides, a custom `handlePlaybackStarted` and "Played by"
with a count are covered by the unit tests only.
- Store tests run against real SQLite: a message's markers are stored
and read back newest first with their users, filtered by type and
limited, an updated message adds its new markers, the marks are deleted
with their message, a thread reply stores none, `mark_groups` lives in
its column and not in `extraData` and reads back, and
`insertMessageMark` stores the mark, its user and the columns without
touching the rest of the message, stores the user's own mark on another
user's message, and skips a message the database never held without
aborting the rest of the batch.
- Offline mark lists ran on the Android emulator with a "Played by"
sheet over 30 throwaway members: a list opened in airplane mode came
from the stored marks with names and stopped at its page size without
retrying, a mark added on the server while offline appeared at the top
after the reconnect, and the list then paged to all 31. A live mark with
the channel open landed as its row, its user and the updated
`markGroups`, with `mark_groups` gone from `extraData`. The channel list
still showed its cached channels on an offline cold start.
- With the synced tokens and the avatar change, typecheck and lint are
clean and the full unit suite passes. The `MessageSystem`,
`TypingIndicator`, `MessageAuthor` and `Thread` snapshots are updated
for the token references and the avatar colour.

## β˜‘οΈ Checklist

- [x] I have signed the [Stream
CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform)
(required)
- [x] PR targets the `develop` branch
- [ ] Documentation is updated
- [ ] New code is tested in main example apps, including all possible
scenarios
  - [ ] SampleApp iOS and Android
  - [ ] Expo iOS and Android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants