2018-07-27 21:44:21 +08:00
|
|
|
import GroupChat from '/imports/api/group-chat';
|
2018-03-10 02:42:14 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2023-03-16 21:03:29 +08:00
|
|
|
async function groupChat() {
|
|
|
|
const tokenValidation = await AuthTokenValidation
|
|
|
|
.findOneAsync({ connectionId: this.connection.id });
|
2020-09-02 00:31:11 +08:00
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
|
|
|
Logger.warn(`Publishing GroupChat was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return GroupChat.find({ meetingId: '' });
|
|
|
|
}
|
2020-09-02 00:31:11 +08:00
|
|
|
|
|
|
|
const { meetingId, userId } = tokenValidation;
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-08-01 01:13:36 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
|
|
|
|
|
2020-11-24 23:13:09 +08:00
|
|
|
Logger.debug('Publishing group-chat', { meetingId, userId });
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-07-27 21:44:21 +08:00
|
|
|
return GroupChat.find({
|
|
|
|
$or: [
|
2018-08-01 01:13:36 +08:00
|
|
|
{ meetingId, access: PUBLIC_CHAT_TYPE },
|
2020-09-02 00:31:11 +08:00
|
|
|
{ meetingId, users: { $all: [userId] } },
|
2018-07-27 21:44:21 +08:00
|
|
|
],
|
|
|
|
|
|
|
|
});
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundGroupChat = groupChat.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundGroupChat(...args);
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('group-chat', publish);
|