|
|
|
|
@ -2,6 +2,7 @@ import crypto from 'crypto'; |
|
|
|
|
|
|
|
|
|
import { MeteorService, Presence, ServiceClass } from '@rocket.chat/core-services'; |
|
|
|
|
import { InstanceStatus } from '@rocket.chat/instance-status'; |
|
|
|
|
import { Users } from '@rocket.chat/models'; |
|
|
|
|
import polka from 'polka'; |
|
|
|
|
import { throttle } from 'underscore'; |
|
|
|
|
import WebSocket from 'ws'; |
|
|
|
|
@ -123,12 +124,34 @@ export class DDPStreamer extends ServiceClass { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
server.on(DDP_EVENTS.LOGGED, (info) => { |
|
|
|
|
async function sendUserData(client: Client, userId: string) { |
|
|
|
|
// TODO figure out what fields to send. maybe to to export function getBaseUserFields to a package
|
|
|
|
|
const loggedUser = await Users.findOneById(userId, { |
|
|
|
|
projection: { name: 1, username: 1, settings: 1, roles: 1, active: 1, statusLivechat: 1, statusDefault: 1, status: 1 }, |
|
|
|
|
}); |
|
|
|
|
if (!loggedUser) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// using setImmediate here so login's method result is sent before we send the user data
|
|
|
|
|
setImmediate(async () => server.added(client, 'users', userId, loggedUser)); |
|
|
|
|
} |
|
|
|
|
server.on(DDP_EVENTS.LOGGED, async (info: Client) => { |
|
|
|
|
const { userId, connection } = info; |
|
|
|
|
|
|
|
|
|
Presence.newConnection(userId, connection.id, nodeID); |
|
|
|
|
if (!userId) { |
|
|
|
|
throw new Error('User not logged in'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await Presence.newConnection(userId, connection.id, nodeID); |
|
|
|
|
|
|
|
|
|
this.updateConnections(); |
|
|
|
|
|
|
|
|
|
// mimic Meteor's default publication that sends user data after login
|
|
|
|
|
await sendUserData(info, userId); |
|
|
|
|
|
|
|
|
|
server.emit('presence', { userId, connection }); |
|
|
|
|
|
|
|
|
|
this.api?.broadcast('accounts.login', { userId, connection }); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|