Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-hornets-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue where a federated user's display name would be overwritten by its username
18 changes: 17 additions & 1 deletion apps/meteor/server/services/federation/domain/FederatedUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,23 @@ export class FederatedUser {
}

public shouldUpdateDisplayName(displayName: string): boolean {
return this.internalReference.name !== displayName;
// If there is no change, then we don't need to update
if (this.internalReference.name === displayName) {
return false;
}

// If we don't have a name yet, then use whatever we're receiving
if (!this.internalReference.name) {
return true;
}

// If the displayName received is based on the username, then ignore it and keep the existing name instead
if (this.internalReference.username?.includes(displayName) || this.externalId.includes(displayName)) {
return false;
}

// It's a new value and an actual display name
return true;
}

public getInternalId(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('Federation - Application - FederationUserServiceSender', () => {
existsOnlyOnProxyServer: false,
}),
);
bridge.getUserProfileInformation.resolves({ displayname: 'normalizedInviterId' });
bridge.getUserProfileInformation.resolves({ displayName: 'normalizedInviterId' });
await service.afterUserRealNameChanged('id', 'name');

expect(bridge.setUserDisplayName.called).to.be.false;
Expand All @@ -252,7 +252,7 @@ describe('Federation - Application - FederationUserServiceSender', () => {
_id: '_id',
}),
);
bridge.getUserProfileInformation.resolves({ displayname: 'different' });
bridge.getUserProfileInformation.resolves({ displayName: 'different' });
await service.afterUserRealNameChanged('id', 'name');

expect(bridge.setUserDisplayName.calledWith('externalInviterId', 'name')).to.be.true;
Expand Down
Loading