-
Notifications
You must be signed in to change notification settings - Fork 13.7k
feat(federation): notify user name changes #39750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8371f1b
update user name when receiving event
sampaiodiego 3f816de
feat(federation): notify user name changes
sampaiodiego 2879963
doc: add changeset
sampaiodiego ca98c04
update @rocket.chat/federation-sdk
sampaiodiego ea9a1d1
why?
sampaiodiego 2392534
test: add tests
sampaiodiego 3bf52b4
add missing method to interface
sampaiodiego 56003fb
debounce name update per userId
sampaiodiego b562beb
reset synapse's admin name
sampaiodiego 52e00dd
remove logs
sampaiodiego abcdad0
don't wait federation update name
sampaiodiego e0d8a54
delete debounce map when done
sampaiodiego 12d6391
always update name on join event
sampaiodiego fdbd94c
reset name to matrix id
sampaiodiego 0955713
use mem
sampaiodiego afc2ae2
skip tests
sampaiodiego d6d9603
test: uses user name to check dms now that we respect displayname
sampaiodiego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/federation-matrix': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Adds support to name changes on federated rooms |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { | |
| isUserNativeFederated, | ||
| UserStatus, | ||
| } from '@rocket.chat/core-typings'; | ||
| import type { MessageQuoteAttachment, IMessage, IRoom, IUser, IRoomNativeFederated } from '@rocket.chat/core-typings'; | ||
| import type { MessageQuoteAttachment, IMessage, IRoom, IUser, IRoomNativeFederated, ISubscription } from '@rocket.chat/core-typings'; | ||
| import { eventIdSchema, roomIdSchema, userIdSchema, federationSDK, FederationRequestError } from '@rocket.chat/federation-sdk'; | ||
| import type { EventID, FileMessageType, PresenceState } from '@rocket.chat/federation-sdk'; | ||
| import { Logger } from '@rocket.chat/logger'; | ||
|
|
@@ -948,4 +948,33 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS | |
| ...(threadEventId && { threadId: eventIdSchema.parse(threadEventId) }), | ||
| }); | ||
| } | ||
|
|
||
| // when a user changes their username, we need to send a new event for every room the user is a member | ||
| async updateUserName(user: IUser): Promise<void> { | ||
| const matrixUserId = userIdSchema.parse(`@${user.username}:${this.serverName}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Use the existing federated Matrix user ID when present; rebuilding it from the updated username can send updates for the wrong Matrix user after a rename. Prompt for AI agents |
||
|
|
||
| const subs = await Subscriptions.findJoinedByUserId<Pick<ISubscription, 'rid'>>(user._id, { projection: { rid: 1 } }).toArray(); | ||
|
|
||
| const rooms = await Rooms.findFederatedByIds<Pick<IRoomNativeFederated, '_id' | 'federation' | 'federated'>>( | ||
| subs.map(({ rid }) => rid), | ||
| { projection: { _id: 1, federation: 1, federated: 1 } }, | ||
| ).toArray(); | ||
|
|
||
| await Promise.all( | ||
| rooms.map(async ({ federation }) => { | ||
| try { | ||
| await federationSDK.updateRoomMembership({ | ||
| roomId: roomIdSchema.parse(federation.mrid), | ||
| userId: matrixUserId, | ||
| membership: 'join', | ||
| content: { | ||
| displayname: user.name || user.username, | ||
| }, | ||
| }); | ||
| } catch (err) { | ||
| this.logger.error({ msg: 'Failed to update username in Matrix for a room', roomId: federation.mrid, err }); | ||
| } | ||
| }), | ||
| ); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Fire-and-forget
updateUserNameshould still handle rejections; currently failures can become unhandled promise rejections.Prompt for AI agents