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';
|
2021-03-17 00:15:41 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-01-14 00:19:52 +08:00
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
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
|
2021-05-06 00:47:43 +08:00
|
|
|
try {
|
|
|
|
// so we don't update the db in a method
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2019-05-18 03:39:05 +08:00
|
|
|
|
2021-05-06 00:47:43 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2021-03-17 00:15:41 +08:00
|
|
|
|
2021-05-06 00:47:43 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
};
|
2019-05-18 03:39:05 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
const numberAffected = Users.update(selector, { $set: { loggedOut: true } });
|
|
|
|
|
|
|
|
if (numberAffected) {
|
2023-01-14 00:19:52 +08:00
|
|
|
UsersPersistentData.update(selector, { $set: { loggedOut: true } });
|
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) {
|
2021-05-06 00:47:43 +08:00
|
|
|
Logger.error(`Exception while invoking method userLeftMeeting ${err.stack}`);
|
2020-11-23 21:13:46 +08:00
|
|
|
}
|
2019-05-18 03:39:05 +08:00
|
|
|
}
|