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

35 lines
1.2 KiB

import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { sdk } from '../../app/utils/client/lib/SDKClient';
import { onLoggedIn } from '../lib/loggedIn';
import { getUserId } from '../lib/user';
import { Messages } from '../stores';
Meteor.startup(() => {
onLoggedIn(() => {
// Only event I found triggers this is from ephemeral messages
// Other types of messages come from another stream
return sdk.stream('notify-user', [`${getUserId()}/message`], (msg: IMessage) => {
msg.u = msg.u || { username: 'rocket.cat' };
msg.private = true;
return Messages.state.store(msg);
});
});
onLoggedIn(() => {
return sdk.stream('notify-user', [`${getUserId()}/subscriptions-changed`], (_action, sub) => {
Messages.state.update(
(record) => record.rid === sub.rid && ('ignored' in sub && sub.ignored ? !sub.ignored.includes(record.u._id) : 'ignored' in record),
({ ignored: _, ...record }) => record,
);
if ('ignored' in sub && sub.ignored) {
Messages.state.update(
(record) => record.rid === sub.rid && record.t !== 'command' && (sub.ignored?.includes(record.u._id) ?? false),
(record) => ({ ...record, ignored: true }),
);
}
});
});
});