2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2018-12-12 20:28:08 +08:00
|
|
|
import PresentationPods from '/imports/api/presentation-pods';
|
2019-06-29 04:52:19 +08:00
|
|
|
import changePresenter from '/imports/api/users/server/modifiers/changePresenter';
|
2020-04-29 20:00:32 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
|
|
|
|
function setPresenterInPodReqMsg(credentials) { // TODO-- switch to meetingId, etc
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'SetPresenterInPodReqMsg';
|
|
|
|
|
|
|
|
const { meetingId, requesterUserId, presenterId } = credentials;
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
podId: 'DEFAULT_PRESENTATION_POD',
|
|
|
|
nextPresenterId: presenterId,
|
|
|
|
};
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
}
|
2017-10-12 09:02:23 +08:00
|
|
|
|
2018-12-07 03:07:51 +08:00
|
|
|
export default function handlePresenterAssigned({ body }, meetingId) {
|
2017-10-26 01:29:03 +08:00
|
|
|
const { presenterId, assignedBy } = body;
|
2017-10-12 09:02:23 +08:00
|
|
|
|
2019-06-29 04:52:19 +08:00
|
|
|
changePresenter(true, presenterId, meetingId, assignedBy);
|
2017-02-23 02:59:47 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2017-10-26 01:29:03 +08:00
|
|
|
userId: { $ne: presenterId },
|
|
|
|
presenter: true,
|
2017-02-23 02:59:47 +08:00
|
|
|
};
|
|
|
|
|
2017-10-26 01:29:03 +08:00
|
|
|
const prevPresenter = Users.findOne(selector);
|
2018-02-08 07:10:15 +08:00
|
|
|
|
|
|
|
// no previous presenters
|
2018-12-12 20:28:08 +08:00
|
|
|
// The below code is responsible for set Meeting presenter to be default pod presenter as well.
|
|
|
|
// It's been handled here because right now akka-apps don't handle all cases scenarios.
|
2018-02-08 07:10:15 +08:00
|
|
|
if (!prevPresenter) {
|
2018-12-12 20:28:08 +08:00
|
|
|
const setPresenterPayload = {
|
|
|
|
meetingId,
|
|
|
|
requesterUserId: assignedBy,
|
|
|
|
presenterId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultPodSelector = {
|
2018-12-14 01:45:46 +08:00
|
|
|
meetingId,
|
2018-12-12 20:28:08 +08:00
|
|
|
podId: 'DEFAULT_PRESENTATION_POD',
|
|
|
|
};
|
|
|
|
const currentDefaultPodPresenter = PresentationPods.findOne(defaultPodSelector);
|
|
|
|
const { currentPresenterId } = currentDefaultPodPresenter;
|
|
|
|
|
|
|
|
if (currentPresenterId === '') {
|
|
|
|
return setPresenterInPodReqMsg(setPresenterPayload);
|
|
|
|
}
|
|
|
|
|
2020-08-20 00:22:43 +08:00
|
|
|
const oldPresenter = Users.findOne({ meetingId, userId: currentPresenterId });
|
2018-12-12 20:28:08 +08:00
|
|
|
|
2020-08-20 00:22:43 +08:00
|
|
|
if (oldPresenter?.userId !== currentPresenterId) {
|
2018-12-12 20:28:08 +08:00
|
|
|
return setPresenterInPodReqMsg(setPresenterPayload);
|
|
|
|
}
|
|
|
|
|
2018-12-01 03:34:00 +08:00
|
|
|
return true;
|
2018-02-08 07:10:15 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
changePresenter(false, prevPresenter.userId, meetingId, assignedBy);
|
2017-10-12 09:02:23 +08:00
|
|
|
}
|