2017-02-07 23:29:27 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-02-07 21:08:06 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
2017-02-07 23:29:27 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-02-07 21:08:06 +08:00
|
|
|
|
2017-02-07 23:29:27 +08:00
|
|
|
import setConnectionStatus from '../modifiers/setConnectionStatus';
|
2017-02-10 20:24:14 +08:00
|
|
|
import listenOnlyToggle from './listenOnlyToggle';
|
2017-02-07 21:08:06 +08:00
|
|
|
|
2017-02-24 04:16:10 +08:00
|
|
|
const OFFLINE_CONNECTION_STATUS = 'offline';
|
|
|
|
|
2017-02-07 21:08:06 +08:00
|
|
|
export default function userLeaving(credentials, userId) {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.redis;
|
2017-02-24 04:16:10 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.users;
|
2017-02-07 21:08:06 +08:00
|
|
|
const EVENT_NAME = 'user_leaving_request';
|
|
|
|
|
|
|
|
const { meetingId, requesterUserId } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(userId, String);
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
const selector = {
|
2017-02-07 21:08:06 +08:00
|
|
|
meetingId,
|
2017-02-24 04:16:10 +08:00
|
|
|
userId,
|
2017-03-11 02:33:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const User = Users.findOne(selector);
|
2017-02-07 21:08:06 +08:00
|
|
|
if (!User) {
|
2017-05-18 03:17:27 +08:00
|
|
|
throw new Meteor.Error(
|
|
|
|
'user-not-found', `Could not find ${userId} in ${meetingId}: cannot complete userLeaving`);
|
2017-02-07 21:08:06 +08:00
|
|
|
}
|
|
|
|
|
2017-02-24 04:16:10 +08:00
|
|
|
if (User.user.connection_status === OFFLINE_CONNECTION_STATUS) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2017-02-07 21:08:06 +08:00
|
|
|
if (User.user.listenOnly) {
|
2017-02-10 20:24:14 +08:00
|
|
|
listenOnlyToggle(credentials, false);
|
2017-02-07 21:08:06 +08:00
|
|
|
}
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
if (User.validated) {
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
2017-04-18 01:14:31 +08:00
|
|
|
validated: null,
|
2017-03-11 02:33:46 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Invalidating user: ${err}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
|
|
|
return Logger.info(`Invalidate user=${userId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-07 01:06:03 +08:00
|
|
|
Users.update(selector, modifier, cb);
|
2017-03-11 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 21:08:06 +08:00
|
|
|
let payload = {
|
|
|
|
meeting_id: meetingId,
|
|
|
|
userid: userId,
|
|
|
|
};
|
2017-04-18 01:20:09 +08:00
|
|
|
|
2017-02-24 01:59:56 +08:00
|
|
|
Logger.verbose(`User '${requesterUserId}' left meeting '${meetingId}'`);
|
2017-02-07 21:08:06 +08:00
|
|
|
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
|
|
|
|
};
|