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/incomingMessages.ts

41 lines
1.1 KiB

import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { ChatMessage } from '../../app/models/client';
import { Notifications } from '../../app/notifications/client';
import { CachedCollectionManager } from '../../app/ui-cached-collection/client';
Meteor.startup(() => {
Tracker.autorun(() => {
if (!Meteor.userId()) {
return;
}
Notifications.onUser('message', (msg: IMessage) => {
msg.u = msg.u || { username: 'rocket.cat' };
msg.private = true;
return ChatMessage.upsert({ _id: msg._id }, msg);
});
});
CachedCollectionManager.onLogin(() => {
Notifications.onUser('subscriptions-changed', (_action, sub) => {
ChatMessage.update(
{
rid: sub.rid,
...('ignored' in sub && sub.ignored ? { 'u._id': { $nin: sub.ignored } } : { ignored: { $exists: true } }),
},
{ $unset: { ignored: true } },
{ multi: true },
);
if ('ignored' in sub && sub.ignored) {
ChatMessage.update(
{ 'rid': sub.rid, 't': { $ne: 'command' }, 'u._id': { $in: sub.ignored } },
{ $set: { ignored: true } },
{ multi: true },
);
}
});
});
});