bigbluebutton-Github/bigbluebutton-html5/imports/api/group-chat-msg/server/methods/chatMessageBeforeJoinCounter.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-03-10 04:52:20 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import GroupChat from '/imports/api/group-chat';
import { GroupChatMsg } from '/imports/api/group-chat-msg';
import Users from '/imports/api/users';
import { extractCredentials } from '/imports/api/common/server/helpers';
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
export default function chatMessageBeforeJoinCounter() {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
2021-03-10 04:52:20 +08:00
const groupChats = GroupChat.find({
$or: [
{ meetingId, access: PUBLIC_CHAT_TYPE },
{ meetingId, users: { $all: [requesterUserId] } },
],
}).fetch();
const User = Users.findOne({ userId: requesterUserId, meetingId });
const chatIdWithCounter = groupChats.map((groupChat) => {
2021-04-27 22:57:53 +08:00
const msgCount = GroupChatMsg.find({
meetingId,
chatId: groupChat.chatId,
timestamp: { $lt: User.authTokenValidatedTime },
}).count();
2021-03-10 04:52:20 +08:00
return {
chatId: groupChat.chatId,
count: msgCount,
};
2021-04-27 22:57:53 +08:00
}).filter((chat) => chat.count);
2021-03-10 04:52:20 +08:00
return chatIdWithCounter;
}