Set hasCurrentUserParticipated when the current user sends a thread reply - #5516
Open
nathanael-h wants to merge 1 commit into
Open
Set hasCurrentUserParticipated when the current user sends a thread reply#5516nathanael-h wants to merge 1 commit into
nathanael-h wants to merge 1 commit into
Conversation
…eply
`Thread.hasCurrentUserParticipated` was only ever populated from the
server's bundled `current_user_participated` flag on the thread root, so
it stayed false right after the local user replied in a thread until the
next root event bundle refresh. Participated views ("My threads" in the
per-room Threads panel, the Threads Activity Centre) therefore dropped
just-sent replies.
Latch the flag when the current user authors an m.thread reply, matching
the server's participated semantics (a thread relation, not a reaction
or an edit).
Fixes matrix-org#5515
Signed-off-by: Nathanaël HANNEBERT <nathanael.hannebert@vates.tech>
Open
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5515
Problem
Thread.hasCurrentUserParticipatedis only ever populated from the homeserver's bundledcurrent_user_participatedfield on the thread root's aggregatedm.threadrelation (processRootEvent()), and cleared on full thread redaction. Nothing sets it when the current user actually replies.onEcho()does callupdateThreadMetadata(), but the root-bundle refresh is guarded to run only once (if (!this.processRootEventPromise)), so no re-fetch happens. The flag therefore staysfalseimmediately after the local user replies in a thread they hadn't participated in, until the server re-sends the root event's bundled relation — which, outside a gappy/limitedsync, may not happen for a long time.Consequences:
Room.updateThreadRootEventsonly adds a root to the participated timeline set when the flag is set, so the per-room Threads panel "My threads" filter drops just-replied threads on the live path (usually masked by the authoritative?include=participatedseed on open); and element-web's Threads Activity Centre mis-sorts such a thread into Other threads. See the issue for the full analysis.Change
In
addEvent(), latch the flag when the current user authors anm.threadreply:THREAD_RELATION_TYPErather than any relation, so the current user's own reactions and edits don't count as participation — matching the server'scurrent_user_participatedsemantics. (THREAD_RELATION_TYPEis already in scope; no new imports.)Annotation/Replaceearly-return branch so it isn't skipped, but the relation gate means those events still don't latch.addEvent()is the common path for local echo and remote sync events, so this covers both "I just replied here" and "my reply arrived from another device".Known limitation (deliberate)
A gappy sync (
onTimelineReset) or a redaction of the thread's last event resetsprocessRootEventPromise, so a laterupdateThreadMetadata()re-runsprocessRootEvent()and overwrites the flag from the server bundle. By that point the server has normally registered our reply, so it comes back astrue; but a refresh landing between local echo and the send being acked could briefly regress it tofalse.I kept the change minimal rather than making the latch sticky, since stickiness would need care around redaction of the user's only reply. Happy to make it sticky instead if you'd prefer that.
Tests
New
describe("hasCurrentUserParticipated")block inspec/unit/models/thread.spec.tscovering: the current user's reply sets the flag (fails without this change), another user's reply does not, and the current user's reaction does not.spec/unit/models/room.spec.ts,spec/unit/room.spec.tsandspec/integ/matrix-client-syncing.spec.tsalso pass (300 tests).tsc --noEmitreports no errors in the changed files.Downstream
element-web currently works around this in
useUnreadThreadRooms.ts(hasCurrentUserSentInThread, inspecting the local timeline for a sentm.threadreply) — see element-hq/element-web#32851. Once this lands and element-web bumps its js-sdk, that can be dropped.Checklist
public/exportedsymbols have accurate TSDoc documentation.tscrun locally;oxlint/oxfmtwere not runnable in my checkout, so relying on CI for those — happy to push a fixup if the formatter disagrees.)I cannot apply labels as a community contributor, so the
Preview Changelogcheck is failing on the missing type label — please addT-Defect(the PR title works as the changelog entry).