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

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-03 02:18:33 +08:00
import { GroupChatMsg, UsersTyping } from '/imports/api/group-chat-msg';
import { Meteor } from 'meteor/meteor';
import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
function groupChatMsg(chatsIds) {
if (!this.userId) {
return GroupChatMsg.find({ meetingId: '' });
}
const { meetingId, requesterUserId } = extractCredentials(this.userId);
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_GROUP_CHAT_ID = CHAT_CONFIG.public_group_id;
Logger.debug(`Publishing group-chat-msg for ${meetingId} ${requesterUserId}`);
return GroupChatMsg.find({
$or: [
{ meetingId, chatId: { $eq: PUBLIC_GROUP_CHAT_ID } },
{ chatId: { $in: chatsIds } },
],
});
}
function publish(...args) {
const boundGroupChat = groupChatMsg.bind(this);
return boundGroupChat(...args);
}
Meteor.publish('group-chat-msg', publish);
2019-08-03 02:18:33 +08:00
function usersTyping() {
if (!this.userId) {
return UsersTyping.find({ meetingId: '' });
}
2019-08-03 02:18:33 +08:00
const { meetingId, requesterUserId } = extractCredentials(this.userId);
Logger.debug(`Publishing users-typing for ${meetingId} ${requesterUserId}`);
2019-08-03 02:18:33 +08:00
return UsersTyping.find({ meetingId });
}
function pubishUsersTyping(...args) {
const boundUsersTyping = usersTyping.bind(this);
return boundUsersTyping(...args);
}
Meteor.publish('users-typing', pubishUsersTyping);