2017-08-05 04:05:18 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-10-31 02:27:17 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import VoiceUsers from '/imports/api/voice-users';
|
2020-06-27 02:51:01 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-03-17 00:15:41 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-08-05 04:05:18 +08:00
|
|
|
|
2023-03-17 02:37:24 +08:00
|
|
|
export default async function muteToggle(uId, toggle) {
|
2021-05-06 02:05:59 +08:00
|
|
|
try {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'MuteUserCmdMsg';
|
2017-08-05 04:05:18 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2021-03-17 00:15:41 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2021-03-17 00:15:41 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
const userToMute = uId || requesterUserId;
|
2017-08-05 04:05:18 +08:00
|
|
|
|
2023-03-17 02:37:24 +08:00
|
|
|
const requester = await Users.findOneAsync({
|
2021-05-06 02:05:59 +08:00
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
});
|
2017-10-31 02:27:17 +08:00
|
|
|
|
2023-03-17 02:37:24 +08:00
|
|
|
const voiceUser = await VoiceUsers.findOneAsync({
|
2021-05-06 02:05:59 +08:00
|
|
|
intId: userToMute,
|
|
|
|
meetingId,
|
|
|
|
});
|
2017-10-31 02:27:17 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
if (!requester || !voiceUser) return;
|
2017-11-03 03:23:27 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
const { listenOnly, muted } = voiceUser;
|
|
|
|
if (listenOnly) return;
|
2017-11-03 03:23:27 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
// if allowModsToUnmuteUsers is false, users will be kicked out for attempting to unmute others
|
|
|
|
if (requesterUserId !== userToMute && muted) {
|
2023-03-17 02:37:24 +08:00
|
|
|
const meeting = await Meetings.findOneAsync({ meetingId },
|
2021-05-06 02:05:59 +08:00
|
|
|
{ fields: { 'usersProp.allowModsToUnmuteUsers': 1 } });
|
|
|
|
if (meeting.usersProp && !meeting.usersProp.allowModsToUnmuteUsers) {
|
|
|
|
Logger.warn(`Attempted unmuting by another user meetingId:${meetingId} requester: ${requesterUserId} userId: ${userToMute}`);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-27 02:51:01 +08:00
|
|
|
}
|
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
let _muted;
|
2021-02-12 10:55:34 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
if ((toggle === undefined) || (toggle === null)) {
|
|
|
|
_muted = !muted;
|
|
|
|
} else {
|
|
|
|
_muted = !!toggle;
|
|
|
|
}
|
2021-02-12 10:55:34 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
const payload = {
|
|
|
|
userId: userToMute,
|
|
|
|
mutedBy: requesterUserId,
|
|
|
|
mute: _muted,
|
|
|
|
};
|
2017-11-25 06:02:14 +08:00
|
|
|
|
2021-05-06 02:05:59 +08:00
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method muteToggle ${err.stack}`);
|
|
|
|
}
|
2017-09-08 00:47:20 +08:00
|
|
|
}
|