2022-01-12 11:08:43 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import GuestUsers from '/imports/api/guest-users/';
|
|
|
|
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'UpdatePositionInWaitingQueueReqMsg';
|
|
|
|
|
2023-03-09 01:35:40 +08:00
|
|
|
export default async function updatePositionInWaitingQueue(meetingId) {
|
|
|
|
check(meetingId, String);
|
2022-01-12 11:08:43 +08:00
|
|
|
|
2023-03-09 01:35:40 +08:00
|
|
|
const guestUsers = await GuestUsers.find({
|
|
|
|
meetingId,
|
|
|
|
approved: false,
|
|
|
|
denied: false,
|
|
|
|
}).fetchAsync();
|
2022-01-12 11:08:43 +08:00
|
|
|
|
2023-03-09 01:35:40 +08:00
|
|
|
check(guestUsers, Array);
|
|
|
|
try {
|
|
|
|
const guests = guestUsers.map((guest) => ({
|
|
|
|
intId: guest.intId,
|
|
|
|
idx: String(guestUsers.indexOf(guest) + 1),
|
|
|
|
}));
|
|
|
|
check(guests, Array);
|
|
|
|
const payload = { guests };
|
2022-01-12 11:08:43 +08:00
|
|
|
|
2023-03-09 01:35:40 +08:00
|
|
|
Logger.info('The waiting positions of the guest users will be updated');
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, 'not-used', payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method updatePositionInWaitingQueue ${err.stack}`);
|
|
|
|
}
|
2022-01-12 11:08:43 +08:00
|
|
|
}
|