bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/user-reaction/service.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

import UserReaction from '/imports/api/user-reaction';
import Auth from '/imports/ui/services/auth';
import { makeCall } from '/imports/ui/services/api';
2023-04-28 05:31:11 +08:00
import getFromUserSettings from '/imports/ui/services/users-settings';
import { isReactionsEnabled } from '/imports/ui/services/features/index';
const ENABLED = Meteor.settings.public.userReaction.enabled;
const isEnabled = () => isReactionsEnabled() && getFromUserSettings('enable-user-reaction', ENABLED);
const setUserReaction = (reaction) => {
if (isEnabled()) {
makeCall('setUserReaction', reaction);
}
};
const getUsersIdFromUserReaction = () => UserReaction.find(
{ meetingId: Auth.meetingID },
{ fields: { userId: 1 } },
).fetch().map((user) => user.userId);
const getUserReaction = (userId) => {
const reaction = UserReaction.findOne(
{
meetingId: Auth.meetingID,
userId,
},
{
fields:
{
reaction: 1,
},
},
);
if (!reaction) {
return {
reaction: 'none',
};
}
return reaction.reaction;
};
export default {
getUserReaction,
setUserReaction,
getUsersIdFromUserReaction,
isEnabled,
};