2019-05-18 03:39:05 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import Users from '/imports/api/users';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2020-09-01 20:07:56 +08:00
|
|
|
import ClientConnections from '/imports/startup/server/ClientConnections';
|
2019-05-18 03:39:05 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
export default function userLeftMeeting() { // TODO-- spread the code to method/modifier/handler
|
|
|
|
// so we don't update the db in a method
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2019-05-18 03:39:05 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
|
|
|
const numberAffected = Users.update(selector, { $set: { loggedOut: true } });
|
|
|
|
|
|
|
|
if (numberAffected) {
|
2019-05-18 03:39:05 +08:00
|
|
|
Logger.info(`user left id=${requesterUserId} meeting=${meetingId}`);
|
2021-01-30 04:29:07 +08:00
|
|
|
ClientConnections.removeClientConnection(this.userId, this.connection.id);
|
2019-05-18 03:39:05 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`leaving dummy user to collection: ${err}`);
|
|
|
|
}
|
2019-05-18 03:39:05 +08:00
|
|
|
}
|