2021-07-16 02:43:38 +08:00
|
|
|
import UserReaction from '/imports/api/user-reaction';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
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
|
|
|
|
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,
|
2023-06-08 09:10:07 +08:00
|
|
|
creationDate: 1,
|
2021-07-16 02:43:38 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!reaction) {
|
|
|
|
return {
|
|
|
|
reaction: 'none',
|
2023-06-08 09:10:07 +08:00
|
|
|
reactionTime: 0,
|
2021-07-16 02:43:38 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
return { reaction: reaction.reaction, reactionTime: reaction.creationDate.getTime() };
|
2021-07-16 02:43:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getUserReaction,
|
2022-09-29 04:20:31 +08:00
|
|
|
getUsersIdFromUserReaction,
|
2021-07-16 02:43:38 +08:00
|
|
|
isEnabled,
|
|
|
|
};
|