2021-07-16 02:43:38 +08:00
|
|
|
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';
|
2023-05-26 05:05:50 +08:00
|
|
|
import { isReactionsEnabled } from '/imports/ui/services/features/index';
|
2021-07-16 02:43:38 +08:00
|
|
|
|
|
|
|
const ENABLED = Meteor.settings.public.userReaction.enabled;
|
|
|
|
|
2023-05-26 05:05:50 +08:00
|
|
|
const isEnabled = () => isReactionsEnabled() && getFromUserSettings('enable-user-reaction', ENABLED);
|
2021-07-16 02:43:38 +08:00
|
|
|
|
|
|
|
const setUserReaction = (reaction) => {
|
|
|
|
if (isEnabled()) {
|
|
|
|
makeCall('setUserReaction', reaction);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-29 04:20:31 +08:00
|
|
|
const getUsersIdFromUserReaction = () => UserReaction.find(
|
|
|
|
{ meetingId: Auth.meetingID },
|
|
|
|
{ fields: { userId: 1 } },
|
|
|
|
).fetch().map((user) => user.userId);
|
|
|
|
|
2021-07-16 02:43:38 +08:00
|
|
|
const getUserReaction = (userId) => {
|
|
|
|
const reaction = UserReaction.findOne(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields:
|
|
|
|
{
|
|
|
|
reaction: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!reaction) {
|
|
|
|
return {
|
|
|
|
reaction: 'none',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-29 04:20:31 +08:00
|
|
|
return reaction.reaction;
|
2021-07-16 02:43:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getUserReaction,
|
|
|
|
setUserReaction,
|
2022-09-29 04:20:31 +08:00
|
|
|
getUsersIdFromUserReaction,
|
2021-07-16 02:43:38 +08:00
|
|
|
isEnabled,
|
|
|
|
};
|