2021-03-05 06:26:25 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import { getMultiUser } from '/imports/api/whiteboard-multi-user/server/helpers';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2021-05-06 02:53:13 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2023-03-09 01:36:40 +08:00
|
|
|
export default async function removeIndividualAccess(whiteboardId, userId) {
|
2021-05-06 02:53:13 +08:00
|
|
|
try {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'ModifyWhiteboardAccessPubMsg';
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2021-05-06 02:53:13 +08:00
|
|
|
check(whiteboardId, String);
|
|
|
|
check(userId, String);
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2021-05-06 02:53:13 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2021-05-06 02:53:13 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2023-03-09 01:36:40 +08:00
|
|
|
const multiUser = await getMultiUser(meetingId, whiteboardId);
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2021-05-06 02:53:13 +08:00
|
|
|
if (multiUser.includes(userId)) {
|
|
|
|
const payload = {
|
|
|
|
multiUser: multiUser.filter(id => id !== userId),
|
|
|
|
whiteboardId,
|
|
|
|
};
|
2021-03-05 06:26:25 +08:00
|
|
|
|
2021-05-06 02:53:13 +08:00
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method removeIndividualAccess ${err.stack}`);
|
2021-03-05 06:26:25 +08:00
|
|
|
}
|
|
|
|
}
|