bigbluebutton-Github/bigbluebutton-html5/imports/api/user-reaction/server/helpers.js
Arthurk12 196d2c1e0a feat(reactions): sync expiration with akka
Currently, the reactions are cleared on mongo based on the expire time.
So to sync its state with akka, an observer is atattched to the user
reactions collection and whenever a reaction is removed because of the
expiration time, akka is notified with message 'UserReactionTimeExpiredCmdMsg'.
2023-05-25 17:32:27 -03:00

47 lines
1.4 KiB
JavaScript

import RedisPubSub from '/imports/startup/server/redis';
import UserReactions from '/imports/api/user-reaction';
import Logger from '/imports/startup/server/logger';
const expireSeconds = Meteor.settings.public.userReaction.expire;
const expireMilliseconds = expireSeconds * 1000
const addUserReactionsObserver = (meetingId) => {
const meetingUserReactions = UserReactions.find({ meetingId });
return meetingUserReactions.observe({
removed(document) {
const isExpirationTriggeredRemoval = (Date.now() - Date.parse(document.creationDate)) >= expireMilliseconds
if (isExpirationTriggeredRemoval) {
notifyExpiredReaction(meetingId, document.userId);
}
}
})
}
const notifyExpiredReaction = (meetingId, userId) => {
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'UserReactionTimeExpiredCmdMsg';
const NODE_USER = 'nodeJSapp';
const emoji = 'none';
check(meetingId, String);
const payload = {
emoji,
userId,
};
Logger.verbose('User emoji status updated due to expiration time', {
emoji, NODE_USER, meetingId,
});
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, NODE_USER, payload);
} catch (err) {
Logger.error(`Exception while invoking method resetUserReaction ${err.stack}`);
}
}
export {
addUserReactionsObserver,
};