feat(presence): Support MSC4532 revised social presence #2489

Open
eleboucher wants to merge 10 commits from eleboucher/continuwuity:feat/msc4532 into main
Contributor

Implements MSC4532 (revised social presence) under the unstable prefix.

  • active/idle/busy/offline states, collated across a user's devices
  • Override and status via m.presence.persistent account data
  • The server no longer marks clients idle: users of unreachable remotes and dead appservices are shown offline
  • presence_idle_timeout_s and presence_timeout_remote_users are removed; presence_offline_timeout_s now defaults to 5 minute

Pull request checklist:

  • This pull request targets the main branch, and the branch is named something other than
    main.
  • I have written an appropriate pull request title and my description is clear.
  • I understand I am responsible for the contents of this pull request.
  • I have followed the contributing guidelines:
<!-- In order to help reviewers know what your pull request does at a glance, you should ensure that 1. Your PR title is a short, single sentence describing what you changed 2. You have described in more detail what you have changed, why you have changed it, what the intended effect is, and why you think this will be beneficial to the project. If you have made any potentially strange/questionable design choices, but didn't feel they'd benefit from code comments, please don't mention them here - after opening your pull request, go to "files changed", and click on the "+" symbol in the line number gutter, and attach comments to the lines that you think would benefit from some clarification. --> Implements [MSC4532](https://github.com/matrix-org/matrix-spec-proposals/pull/4532) (revised social presence) under the unstable prefix. - `active`/`idle`/`busy`/`offline` states, collated across a user's devices - Override and status via `m.presence.persistent` account data - The server no longer marks clients idle: users of unreachable remotes and dead appservices are shown offline - `presence_idle_timeout_s` and `presence_timeout_remote_users` are removed; `presence_offline_timeout_s` now defaults to 5 minute <!-- Example: This pull request allows us to warp through time and space ten times faster than before by double-inverting the warp drive with hyperheated jump fluid, both making the drive faster and more efficient. This resolves the common issue where we have to wait more than 10 milliseconds to engage, use, and disengage the warp drive when travelling between galaxies. --> <!-- Closes: #... --> <!-- Fixes: #... --> <!-- Uncomment the above line(s) if your pull request fixes an issue or closes another pull request by superseding it. Replace `#...` with the issue/pr number, such as `#123`. --> **Pull request checklist:** <!-- You need to complete these before your PR can be considered. If you aren't sure about some, feel free to ask for clarification in #dev:continuwuity.org. --> - [x] This pull request targets the `main` branch, and the branch is named something other than `main`. - [x] I have written an appropriate pull request title and my description is clear. - [x] I understand I am responsible for the contents of this pull request. - I have followed the [contributing guidelines][c1]: - [x] My contribution follows the [code style][c2], if applicable. - [x] I ran [pre-commit checks][c1pc] before opening/drafting this pull request. - [x] I have [tested my contribution][c1t] (or proof-read it for documentation-only changes) myself, if applicable. This includes ensuring code compiles. - [x] My commit messages follow the [commit message format][c1cm] and are descriptive. <!-- Notes on these requirements: - While not required, we encourage you to sign your commits with GPG or SSH to attest the authenticity of your changes. - While we allow LLM-assisted contributions, we do not appreciate contributions that are low quality, which is typical of machine-generated contributions that have not had a lot of love and care from a human. Please do not open a PR if all you have done is asked ChatGPT to tidy up the codebase with a +-100,000 diff. - In the case of code style violations, reviewers may leave review comments/change requests indicating what the ideal change would look like. For example, a reviewer may suggest you lower a log level, or use `match` instead of `if/else` etc. - In the case of code style violations, pre-commit check failures, minor things like typos/spelling errors, and in some cases commit format violations, reviewers may modify your branch directly, typically by making changes and adding a commit. Particularly in the latter case, a reviewer may rebase your commits to squash "spammy" ones (like "fix", "fix", "actually fix"), and reword commit messages that don't satisfy the format. - Pull requests MUST pass the `Checks` CI workflows to be capable of being merged. This can only be bypassed in exceptional circumstances. If your CI flakes, let us know in matrix:r/dev:continuwuity.org. - Pull requests have to be based on the latest `main` commit before being merged. If the main branch changes while you're making your changes, you should make sure you rebase on main before opening a PR. Your branch will be rebased on main before it is merged if it has fallen behind. - We typically only do fast-forward merges, so your entire commit log will be included. Once in main, it's difficult to get out cleanly, so put on your best dress, smile for the cameras! --> [c1]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md [c2]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/docs/development/code_style.mdx [c1pc]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#pre-commit-checks [c1t]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#running-tests-locally [c1cm]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#commit-messages
feat(presence): Support MSC4532 revised social presence
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Auto Labeler / Apply labels based on changed files (pull_request_target) Successful in 4s
Checks / Prek / Check changed files (pull_request) Successful in 9s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 11s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m15s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m24s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 52m40s
67000dd25b
eleboucher force-pushed feat/msc4532 from 67000dd25b
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Auto Labeler / Apply labels based on changed files (pull_request_target) Successful in 4s
Checks / Prek / Check changed files (pull_request) Successful in 9s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 11s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m15s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m24s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 52m40s
to d2d67fde96
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 12s
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Check changed files (pull_request) Successful in 8s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m25s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 21m16s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 11m43s
2026-11-10 22:39:12 +00:00
Compare
thetayloredman left a comment

with my "co-author of the proposal" hat on:
Thanks Erwan, nice work!

These are my initial notes from a brief (and admittedly, maybe too tired to be doing a code review) read of the diff. Primarily, I noticed a lack of database changes I would expect, and it appears extensible status is being dropped outright?

For the sake of not needing to rewrite the more complex PR, this might want to wait behind #2034.
r? @lveneris would be nice to have you give this a look wrt msc compliance as it is written too

<sub>with my "co-author of the proposal" hat on:</sub> Thanks Erwan, nice work! These are my initial notes from a brief (and admittedly, maybe too tired to be doing a code review) read of the diff. Primarily, I noticed a lack of database changes I would expect, and it appears extensible status is being dropped outright? For the sake of not needing to rewrite the more complex PR, this might want to wait behind #2034. r? @lveneris would be nice to have you give this a look wrt msc compliance as it is written too
@ -12,3 +20,3 @@
/// # `PUT /_matrix/client/r0/presence/{userId}/status`
///
/// Sets the presence state of the sender user.
/// Sets the presence state of the sender user. `status_msg` is ignored, as
Contributor

I'm not sure whether the deprecation in the proposal means servers don't accept status_msg via this endpoint in the interim? It probably needs to be kept for the sake of backwards compatibility, but I'm not sure and will cc @lveneris here.

I'm not sure whether the deprecation in the proposal means servers don't accept status_msg via this endpoint in the interim? It probably needs to be kept for the sake of backwards compatibility, but I'm not sure and will cc @lveneris here.
Author
Contributor

Yes, GET returns both status and status_msg with the same value. Inbound, status.msg is used and status_msg is the fallback, per the backwards-compatibility section of the MSC.

Yes, GET returns both status and status_msg with the same value. Inbound, status.msg is used and status_msg is the fallback, per the backwards-compatibility section of the MSC.
Member

I would have assumed it would remain accepted until it is actually dropped by the spec, but few clients actually use this behaviour to my knowledge, or at least few people use clients that use it, so it doesn't matter too much.

I would have assumed it would remain accepted until it is actually dropped by the spec, but few clients actually use this behaviour to my knowledge, or at least few people use clients that use it, so it doesn't matter too much.
@ -90,2 +94,2 @@
| _ => Err!(Request(NotFound("Presence state for this user was not found"))),
}
Ok(assign!(get_presence::v3::Response::new(content.presence), {
status_msg: content.status.msg.clone(),
Contributor

We might want to use status_msg here, so that a remote presence EDU from another server without the proposal is still readable

Edit: It looks like we grab status_msg and store it in extensible status on inbound handling. Does that sound correct?

We might want to use status_msg here, so that a remote presence EDU from another server without the proposal is still readable Edit: It looks like we grab status_msg and store it in extensible status on inbound handling. Does that sound correct?
@ -491,0 +501,4 @@
.map(|(user_id, event)| {
let mut content = event.content;
if !revised {
crate::client::to_legacy(&mut content);
Contributor

nit: this should probably be named better

nit: this should probably be named better
eleboucher marked this conversation as resolved
@ -152,2 +154,3 @@
self.presenceid_presence
.raw_stream()
.raw_stream_from(&from)
Contributor

Nice!

Nice!
nex marked this conversation as resolved
@ -36,0 +52,4 @@
struct Device {
id: Option<OwnedDeviceId>,
state: State,
seen_ms: u64,
Contributor

seen_ms? is this last_seen_ts?

seen_ms? is this `last_seen_ts`?
@ -319,6 +341,23 @@ impl Service {
}
}
async fn load_persistent(&self, user_id: &UserId) -> (Option<State>, Option<String>) {
Contributor

Do we delete extensible status fields here?

Do we delete extensible status fields here?
Author
Contributor

We did, fixed in 7f11e7348. The whole PresenceStatus is now passed through.

We did, fixed in 7f11e7348. The whole PresenceStatus is now passed through.
eleboucher marked this conversation as resolved
@ -37,0 +48,4 @@
pub(super) struct Presence {
pub(super) state: State,
pub(super) last_active_ts: Option<u64>,
pub(super) status_msg: Option<String>,
Contributor

Do we not store extensible status here? The proposal allows for any future fields to be added to status, but I don't see this represented anywhere.

Ruma's PresenceStatus has a field that holds additional data that could be used here.

Note that extensible status is not a hypothetical, we have a future proposal which will use it

Do we not store extensible status here? The proposal allows for any future fields to be added to `status`, but I don't see this represented anywhere. Ruma's `PresenceStatus` has a field that holds additional data that could be used here. Note that extensible status is not a hypothetical, we have a future proposal which will use it
@ -37,0 +52,4 @@
}
#[derive(Deserialize)]
struct Stored {
Contributor

I don't see this struct used anywhere besides the TryFrom. Is this meant to provide compatibility with presence events from before the DB changes?

It's probably safe to just empty the entire relevant CFs, since presence is ephemeral anyway

I don't see this struct used anywhere besides the TryFrom. Is this meant to provide compatibility with presence events from before the DB changes? It's probably safe to just empty the entire relevant CFs, since presence is ephemeral anyway
fix(presence): Keep extensible status fields
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m29s
Checks / Prek / Check changed files (pull_request) Successful in 8s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m44s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 9m14s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 8s
63f2deba25
nex changed title from feat(presence): Support MSC4532 revised social presence to WIP: feat(presence): Support MSC4532 revised social presence 2026-11-13 06:23:23 +00:00
nex changed title from WIP: feat(presence): Support MSC4532 revised social presence to feat(presence): Support MSC4532 revised social presence 2026-11-13 06:23:25 +00:00
Owner

misclick

misclick
lveneris left a comment

I haven't had a chance to read through this fully yet, but this is what I have for now. It should at least suffice until those two open discussions are resolved.

I haven't had a chance to read through this fully yet, but this is what I have for now. It should at least suffice until those two open discussions are resolved.
Lines 1596-1597
@ -1601,1 +1594,4 @@
# Defaults to 30 minutes.
# How many seconds a client can go without syncing, or setting its
# presence, before it is considered offline. A user is offline once all
# their clients are. Clients decide for themselves when they are idle;
# the server never does. Defaults to 5 minutes.
Member

This reads strangely. "Clients determine when they are idle." or "The server does not automatically mark clients as idle." would probably suffice.

This reads strangely. "Clients determine when they are idle." or "The server does not automatically mark clients as idle." would probably suffice.
eleboucher marked this conversation as resolved
@ -170,0 +249,4 @@
self.db.put(user_id, Some(count), &row)
}
pub fn set_remote_reachable(&self, server: &ServerName, reachable: bool) {
Member

I would also prefer if this relied on the broader remote health tracking system.

I would also prefer if this relied on the broader remote health tracking system.
@ -274,0 +383,4 @@
debug!(?down, ?up, "Updated presence of users on unreachable servers");
}
async fn probe_appservices(&self) {
Member

If this is possible and it would be helpful in other areas, I would like to see appservice monitoring factored out of the presence module. Ideally, it could be merged with the broader remote health tracking system.

Process note: I have also opened this as a discussion in the dev room awaiting maintainer feedback.

If this is possible and it would be helpful in other areas, I would like to see appservice monitoring factored out of the presence module. Ideally, it could be merged with the broader remote health tracking system. Process note: I have also opened this as a [discussion in the dev room](matrix:roomid/c10y-8Hm3mAW99j9KEKoWPQH2M_FxGwG-EVHK06iLKg/e/B-BSBk6ae3ibPMIvemikkUXZB6vie28UsFfPo-hHu68?via=kludgecs.com&via=gingershaped.computer&via=federated.nexus) awaiting maintainer feedback.
@ -35,2 +31,4 @@
}
#[must_use]
pub fn to_wire(self) -> PresenceState {
Member

Is there any reason not to offer From<State> for PresenceState?

Is there any reason not to offer `From<State> for PresenceState`?
eleboucher marked this conversation as resolved
@ -37,0 +47,4 @@
pub(super) struct Presence {
pub(super) state: State,
pub(super) last_active_ts: Option<u64>,
/// Kept whole so fields other than `msg` survive.
Member

This comment is redundant. It is kept whole because it is a collection, not a single item.

This comment is redundant. It is kept whole because it is a collection, not a single item.
eleboucher marked this conversation as resolved
@ -37,0 +51,4 @@
pub(super) status: PresenceStatus,
/// State to restore once the user's unreachable server answers again.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(super) suppressed: Option<State>,
Member

There is only one state used when things are unreachable. On this basis, instead of having two places to store state, would it not be tidier and more effective to just make suppressed a boolean?

There is only one state used when things are unreachable. On this basis, instead of having two places to store state, would it not be tidier and more effective to just make `suppressed` a boolean?
eleboucher marked this conversation as resolved
@ -39,3 +60,4 @@
.map_err(|_| Error::bad_database("Invalid presence data in database"))
}
/// The row following `prev`. `last_active_ts` is when the user last left
Member

I am not sure why last_active_ts is documented on this function instead of the struct itself.

I am not sure why `last_active_ts` is documented on this function instead of the struct itself.
eleboucher marked this conversation as resolved
@ -199,3 +196,1 @@
.presence
.ping_presence(user_id, &PresenceState::Online)
.await;
let _ = self.services.presence.bump(user_id).await;
Member

Can this and all related functionality be dropped? Following discussion in the Presence v2 room, it seems wholly unnecessary. We are not aware of any clients that use it, the avatar_url and displayname fields of m.presence in sync are optional, and using presence to communicate profile updates is silly. The information is not carried over federation regardless. I believe that would aid in further simplifying the system.

Process note: I have also opened this as a discussion in the dev room awaiting maintainer feedback.

Can this and all related functionality be dropped? Following discussion in the Presence v2 room, it seems wholly unnecessary. We are not aware of any clients that use it, the `avatar_url` and `displayname` fields of `m.presence` in sync are optional, and using presence to communicate profile updates is silly. The information is not carried over federation regardless. I believe that would aid in further simplifying the system. Process note: I have also opened this as a [discussion in the dev room](https://matrix.to/#/!c10y-8Hm3mAW99j9KEKoWPQH2M_FxGwG-EVHK06iLKg/%24GmaduYbkbuIoMA_9miVjG3mNgWOjnVLFYrFDctdcVTA?via=kludgecs.com&via=gingershaped.computer&via=federated.nexus) awaiting maintainer feedback.
refactor(presence): Address review feedback
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 8s
Checks / Prek / Check changed files (pull_request) Successful in 8s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m19s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m26s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 8m44s
1b17ced199
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 8s
Required
Details
Checks / Prek / Check changed files (pull_request) Successful in 8s
Required
Details
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m19s
Required
Details
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m26s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 8m44s
Required
Details
This pull request has changes conflicting with the target branch.
  • src/service/migrations.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feat/msc4532:eleboucher-feat/msc4532'
git switch 'eleboucher-feat/msc4532'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
continuwuation/continuwuity!2489
No description provided.