Skip to content

feat(sdk): Add ThreadInfo with its own ReadReceipts - #6893

Draft
Hywan wants to merge 9 commits into
matrix-org:mainfrom
Hywan:feat-sdk-event-cache-thread-read-receipt
Draft

feat(sdk): Add ThreadInfo with its own ReadReceipts#6893
Hywan wants to merge 9 commits into
matrix-org:mainfrom
Hywan:feat-sdk-event-cache-thread-read-receipt

Conversation

@Hywan

@Hywan Hywan commented Aug 18, 2026

Copy link
Copy Markdown
Member

These patches add the ability to compute ReadReceipts for thread. It does several things (in logical order):

  • It creates the new:
    struct ThreadInfo {
        read_receipts: ReadReceipts,
    }
  • It updates the threads table to add a new info column/field,
  • It updates EventCacheStore to remove remember_thread and to add load_thread_info and update_thread_info,
  • It makes event_cache::read_receipts::compute_unread_counts “timeline agnostic” so that it supports both room and thread,
  • It updates ThreadEventCache::handle_timeline to receive ephemeral events (which include the read receipt events),
  • It combines all that to compute the read receipts for threads!

Tasks

  • Write more tests


  • I've documented the public API changes in the appropriate changelog files (see Writing changelog entries).
  • This PR was made with the help of AI.

Signed-off-by:

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.26804% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.08%. Comparing base (b479a6f) to head (bff5d12).
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../matrix-sdk/src/event_cache/caches/thread/state.rs 82.60% 4 Missing and 4 partials ⚠️
crates/matrix-sdk-sqlite/src/event_cache_store.rs 82.50% 1 Missing and 6 partials ⚠️
...matrix-sdk/src/event_cache/caches/read_receipts.rs 98.05% 3 Missing and 2 partials ⚠️
crates/matrix-sdk-common/src/serde_helpers.rs 75.00% 3 Missing ⚠️
...es/matrix-sdk/src/event_cache/caches/thread/mod.rs 75.00% 2 Missing and 1 partial ⚠️
crates/matrix-sdk/src/event_cache/redecryptor.rs 0.00% 2 Missing ⚠️
...es/matrix-sdk/src/event_cache/caches/room/state.rs 83.33% 0 Missing and 1 partial ⚠️
...ix-sdk/src/event_cache/caches/thread/pagination.rs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6893      +/-   ##
==========================================
- Coverage   90.10%   90.08%   -0.02%     
==========================================
  Files         407      408       +1     
  Lines      115745   115976     +231     
  Branches   115745   115976     +231     
==========================================
+ Hits       104294   104481     +187     
- Misses       7540     7562      +22     
- Partials     3911     3933      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks
⏩ 22 skipped benchmarks1


Comparing Hywan:feat-sdk-event-cache-thread-read-receipt (df54bb0) with main (8c9144d)

Open in CodSpeed

Footnotes

  1. 22 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Hywan
Hywan force-pushed the feat-sdk-event-cache-thread-read-receipt branch 4 times, most recently from b7e6a3b to 55b86ff Compare August 19, 2026 07:18
Hywan added 5 commits August 19, 2026 09:23
This patch refactors `compute_unread_counts` to filter events candidates
for the read receipt calculation.

This patch does that by introducing a new `EventFilter` trait.
This trait is implemented in a single type for the moment:
`ReadReceiptsForRoom`. Another type for threads will follow.
In `RoomEventCacheState::handle_sync`, when all events are duplicated,
there is nothing left to do, except running the post-processing. Because
the post-processing consists of iterating over all the new events +
updating the read receipts, the previous author took a shortcut by not
calling the post-processing method, and by updating the read receipts
directly. I believe this is error-prone as (i) it hides the fact we want
to run the post-processing here, (ii) if the post-processing method is
updated, it's easy to forget this place in particular.

This patch updates the code by calling `post_process_upserted_events`
with an empty iterator of events, as it is supposed to be. The semantics
is clearer and the code is more robust.
This patch introduces the new `ThreadInfo` type. This patch also updates
all stores to store this new `ThreadInfo` in the `threads` table.
@Hywan
Hywan force-pushed the feat-sdk-event-cache-thread-read-receipt branch 2 times, most recently from 9df4a34 to df54bb0 Compare August 19, 2026 07:29
Hywan added 4 commits August 19, 2026 11:34
This patch removes `EventCacheStore::remember_threads` and adds
`load_thread_info` along with `update_thread_info`.

Notice that `ThreadEventCacheState` gains a new `thread_info:
ThreadInfo` field at the same time!
…de_helpers`.

This patch moves `extract_read_receipt` from
`matrix_sdk::event_cache::caches::room::state` to
`matrix_sdk_common::serde_helpers`. This way, it can be re-used
elsewhere, like in `matrix_sdk::event_cache::caches::thread::state` ;-).
This patch updates `Caches` and `ThreadEventCache` to receive
ephemeral events, up to extract read receipt events and passing them to
`post_process_upserted_events`.

This is an intermediate patch to facilitate the review.
…adReceipts`.

This patch updates `ThreadEventCacheState` to add the
`update_read_receipts` method, to run `compute_unread_counts` with a
dedicated `ReadReceiptsForThread` value. This allows to compute the
`ReadReceipts` for a thread!
@Hywan
Hywan force-pushed the feat-sdk-event-cache-thread-read-receipt branch from df54bb0 to bff5d12 Compare August 19, 2026 09:34
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.

1 participant