2023-04-27 21:14:50 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2021-07-16 02:43:38 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-04-27 21:14:50 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-07-16 02:43:38 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
|
2024-04-27 03:52:28 +08:00
|
|
|
const ALLOWED_REACTIONS = Meteor.settings.public.userReaction.reactions;
|
|
|
|
const nativeEmojis = ALLOWED_REACTIONS.map((reaction) => reaction.native);
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
export default function setUserReaction(reactionEmoji, userId = undefined) {
|
2023-04-27 21:14:50 +08:00
|
|
|
try {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
2023-06-08 09:10:07 +08:00
|
|
|
const EVENT_NAME = 'ChangeUserReactionEmojiReqMsg';
|
2021-07-16 02:43:38 +08:00
|
|
|
|
2023-04-27 21:14:50 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2021-07-16 02:43:38 +08:00
|
|
|
|
2023-04-27 21:14:50 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2023-06-08 09:10:07 +08:00
|
|
|
check(reactionEmoji, String);
|
2024-04-27 03:52:28 +08:00
|
|
|
if (!nativeEmojis.includes(reactionEmoji) && reactionEmoji !== 'none') return;
|
2023-04-27 21:14:50 +08:00
|
|
|
|
|
|
|
const payload = {
|
2023-06-08 09:10:07 +08:00
|
|
|
reactionEmoji,
|
|
|
|
userId: userId || requesterUserId,
|
2023-04-27 21:14:50 +08:00
|
|
|
};
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
Logger.verbose('User reactionEmoji status updated', {
|
|
|
|
reactionEmoji, requesterUserId, meetingId,
|
2023-04-27 21:14:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method setUserReaction ${err.stack}`);
|
|
|
|
}
|
2021-07-16 02:43:38 +08:00
|
|
|
}
|