2018-03-10 02:42:14 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2018-07-26 22:56:26 +08:00
|
|
|
import { CHAT_ACCESS_PUBLIC, CHAT_ACCESS_PRIVATE } from '/imports/api/group-chat'
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-07-26 22:56:26 +08:00
|
|
|
|
|
|
|
export default function createGroupChat(credentials, receiver) {
|
2018-03-10 02:42:14 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
2018-07-26 22:56:26 +08:00
|
|
|
const EVENT_NAME = 'CreateGroupChatReqMsg';
|
|
|
|
|
2018-03-10 02:42:14 +08:00
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
2018-07-26 22:56:26 +08:00
|
|
|
check(receiver, Object);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-07-26 22:56:26 +08:00
|
|
|
let payload = {
|
|
|
|
correlationId: `${requesterUserId}-${Date.now()}`,
|
|
|
|
msg: [],
|
|
|
|
users: [receiver.id],
|
|
|
|
access: CHAT_ACCESS_PRIVATE,
|
|
|
|
name: receiver.name
|
2018-03-10 02:42:14 +08:00
|
|
|
};
|
|
|
|
|
2018-07-26 22:56:26 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|