Skip to content

Implement MSC4429: Profile Updates for Legacy Sync#5246

Merged
dbkr merged 31 commits into
developfrom
hs/profile-sync-endpoints
Apr 23, 2026
Merged

Implement MSC4429: Profile Updates for Legacy Sync#5246
dbkr merged 31 commits into
developfrom
hs/profile-sync-endpoints

Conversation

@Half-Shot

@Half-Shot Half-Shot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

matrix-org/matrix-spec-proposals#4429

This implements half functional support for profile updates over legacy sync. It does not yet fully support storing them over sessions, but does handle updates.

Now stores updates in indexeddb with write-through caching on the get API so they'll eventually all be stored in the database even if you turn the feature flag on after your initial sync.

Closes https://github.com/element-hq/wat-internal/issues/464

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

Comment thread spec/unit/matrix-client.spec.ts Outdated
Comment thread src/sync.ts Outdated
Comment thread src/sync.ts
and grammar correction
dbkr added 2 commits April 10, 2026 15:09
and rename and comment the functions a bit
and fix bugs with mismatched array/string keys

It's not clear why all our key paths are arrays, even for single keys.
I suspect someone — probably me — misreading the docs many years ago, but
the queries need to match the object store creation.
@dbkr dbkr marked this pull request as ready for review April 16, 2026 16:28
@dbkr dbkr requested a review from a team as a code owner April 16, 2026 16:28
@dbkr dbkr requested review from florianduros and t3chguy April 16, 2026 16:28
Comment thread src/models/user.ts Outdated
Comment thread src/store/index.ts Outdated
* Store user profile details from a sync. Existing profiles will be overwritten.
* @param userProfileTuples - A set of userIds to profiles.
*/
storeUserProfiles(userProfileTuples: Array<[string, SyncUserProfile]>): Promise<void>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooi why is it an array of tuples vs a record/similar?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like there was no particular reason - I've gone with a map because non-static keys, although it has to be said that when called with a single update this is now the same with the addition of a Map constructor.

Comment thread src/sync.ts Outdated
Comment thread src/sync-accumulator.ts Outdated
Comment thread src/sync-accumulator.ts Outdated
Comment thread src/filter.ts Outdated
Comment thread src/filter.ts
Comment thread src/filter.ts Outdated
Comment thread src/store/index.ts
* Store user profile details from a sync. Existing profiles will be overwritten.
* @param userProfiles - A map of userIds to profiles.
*/
storeUserProfiles(userProfiles: Map<string, SyncUserProfile>): Promise<void>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type referencing unknown makes it very weak. Why are we using unknown in storage? Using unknown for "down sync" as the jsdoc says is fine, if it is then validated and upgraded to a stronger type

Comment thread src/models/user.ts Outdated
/**
* An object of extended profile attributes for a user as it arrives down the sync stream.
*/
export type SyncUserProfile = Record<string, unknown>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably this isn't truly unknown, given its JSON it can be a much more specific type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move (or copy) https://github.com/element-hq/element-web/blob/develop/apps/web/src/%40types/json.ts to js-sdk which would make it a bit more specific but I think that's about it. For storage, we don't really know much more other than that it's not null or undefined I think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well presumably we do know a lot more, for it to even be storable, given we presumably can't store complex cyclic objects

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec is broad https://spec.matrix.org/v1.17/client-server-api/#profiles allowing any JSON type - so yeah possibly we should copy the types from EW

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. should be a little less vague now.

dbkr added 2 commits April 23, 2026 11:55
and use them to type the user profiles a bit more than just unknown
Comment thread src/@types/json.ts
@@ -0,0 +1,16 @@
/*
Copyright 2024 New Vector Ltd.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inheriting the copyright might be fine but I think we need to give up the license, least because it refers to LICENSE files which do not exist in this repo

Comment thread src/@types/json.ts
export interface JsonObject {
[key: string]: JsonObject | JsonArray | JsonValue;
}
export type Json = JsonArray | JsonObject;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be JsonDocument

@dbkr dbkr added this pull request to the merge queue Apr 23, 2026
Merged via the queue into develop with commit b5c2d89 Apr 23, 2026
37 checks passed
@dbkr dbkr deleted the hs/profile-sync-endpoints branch April 23, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants