The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/startup/notifications/usersNameChanged.ts

55 lines
905 B

import type { IUser } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { Messages, Subscriptions } from '../../../app/models/client';
import { Notifications } from '../../../app/notifications/client';
type UsersNameChangedEvent = Partial<IUser>;
Meteor.startup(() => {
Notifications.onLogged('Users:NameChanged', ({ _id, name, username }: UsersNameChangedEvent) => {
Messages.update(
{
'u._id': _id,
},
{
$set: {
'u.username': username,
'u.name': name,
},
},
{
multi: true,
},
);
Messages.update(
{
mentions: {
$elemMatch: { _id },
},
},
{
$set: {
'mentions.$.username': username,
'mentions.$.name': name,
},
},
{
multi: true,
},
);
Subscriptions.update(
{
name: username,
t: 'd',
},
{
$set: {
fname: name,
},
},
);
});
});