feat(messages): mention counting, read-state sync & space_id in unreads#27
Merged
Merged
Conversation
Parse @everyone/@here and @username mentions server-side, resolve handles to space members, and persist mention_everyone + mentions on each message. Increment a durable per-channel mention counter for each mentioned member so unread badges survive restarts. Add space_id to the unread payload (READY + REST) so multi-server clients can route notifications to the right space. Broadcast a targeted read_state.update on ack so reading on one device clears the badge on the user's other sessions. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
@everyone/@hereand@usernamementions server-side (no regex crate — hand-rolled parser insrc/mentions.rs), resolve handles to space members, and persistmention_everyone+mentionsJSON on each message.space_idto the unread payload in both the gateway READY andGET /users/@me/read-states, so multi-server clients can route a notification to the correct space.read_state.updategateway event onPOST /channels/{id}/ack, so reading on one device clears the unread badge on the user's other sessions.Details
src/mentions.rs(new):parse_mentions(content)returnsParsedMentions { everyone, usernames }. Guards@against email domains, restricts handle chars to[A-Za-z0-9_], case-insensitive everyone/here, deduped usernames. 4 unit tests.src/db/members.rs:resolve_mention_user_idsmaps usernames → member IDs scoped to the space.src/db/messages.rs:create_messageparses + resolves + stores mention data (signature unchanged).src/routes/messages.rs:apply_mention_countsincrements the per-channel counter for each mentioned non-author after message creation (both JSON and multipart paths).src/db/read_states.rs+src/routes/read_states.rs:space_idthreaded throughUnreadChanneland the REST payload; targetedread_state.updatebroadcast on ack (carries nospace_id, so it is not muted-channel-suppressed).Deliberately out of scope (follow-ups)
@everyone/@herecurrently set the message flag only; they do not bulk-increment every member's counter (avoids a large-space write amplification footgun) and are not yet gated behind a mention-everyone permission.Test plan
cargo test— 122 passing (incl. 4 new mention-parser tests)@usermessage, verify mention_count increments and persists across reconnectread_state.updateclears badge on another session🤖 Generated with Claude Code