2018-10-24 01:18:09 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
2018-10-26 23:16:29 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2018-10-24 01:18:09 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-06-07 21:49:50 +08:00
|
|
|
import fp from 'lodash/fp';
|
2018-10-24 01:18:09 +08:00
|
|
|
|
2019-08-22 20:05:06 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2018-10-30 03:36:45 +08:00
|
|
|
const findBreakouts = () => {
|
2018-11-02 01:55:35 +08:00
|
|
|
const BreakoutRooms = Breakouts.find({
|
|
|
|
parentMeetingId: Auth.meetingID,
|
|
|
|
}, {
|
|
|
|
sort: {
|
|
|
|
sequence: 1,
|
|
|
|
},
|
|
|
|
}).fetch();
|
2018-10-24 01:18:09 +08:00
|
|
|
|
|
|
|
return BreakoutRooms;
|
|
|
|
};
|
|
|
|
|
|
|
|
const breakoutRoomUser = (breakoutId) => {
|
2018-10-30 03:36:45 +08:00
|
|
|
const breakoutRooms = findBreakouts();
|
2018-10-24 01:18:09 +08:00
|
|
|
const breakoutRoom = breakoutRooms.filter(breakout => breakout.breakoutId === breakoutId).shift();
|
|
|
|
const breakoutUser = breakoutRoom.users.filter(user => user.userId === Auth.userID).shift();
|
|
|
|
return breakoutUser;
|
|
|
|
};
|
|
|
|
|
2020-06-20 13:46:10 +08:00
|
|
|
const closeBreakoutPanel = () => {
|
|
|
|
Session.set('openPanel', 'userlist');
|
|
|
|
window.dispatchEvent(new Event('panelChanged'));
|
|
|
|
};
|
2018-12-18 23:15:51 +08:00
|
|
|
|
2018-10-24 01:18:09 +08:00
|
|
|
const endAllBreakouts = () => {
|
|
|
|
makeCall('endAllBreakouts');
|
2018-11-20 07:29:48 +08:00
|
|
|
closeBreakoutPanel();
|
2018-10-24 01:18:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const requestJoinURL = (breakoutId) => {
|
|
|
|
makeCall('requestJoinURL', {
|
|
|
|
breakoutId,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const transferUserToMeeting = (fromMeetingId, toMeetingId) => makeCall('transferUser', fromMeetingId, toMeetingId);
|
|
|
|
|
2018-11-05 20:27:56 +08:00
|
|
|
const transferToBreakout = (breakoutId) => {
|
2018-10-30 03:36:45 +08:00
|
|
|
const breakoutRooms = findBreakouts();
|
2018-10-24 01:18:09 +08:00
|
|
|
const breakoutRoom = breakoutRooms.filter(breakout => breakout.breakoutId === breakoutId).shift();
|
|
|
|
const breakoutMeeting = Meetings.findOne({
|
|
|
|
$and: [
|
|
|
|
{ 'breakoutProps.sequence': breakoutRoom.sequence },
|
|
|
|
{ 'breakoutProps.parentId': breakoutRoom.parentMeetingId },
|
|
|
|
{ 'meetingProp.isBreakout': true },
|
|
|
|
],
|
2019-08-22 20:05:06 +08:00
|
|
|
}, { fields: { meetingId: 1 } });
|
2018-11-05 20:27:56 +08:00
|
|
|
transferUserToMeeting(Auth.meetingID, breakoutMeeting.meetingId);
|
2018-10-24 01:18:09 +08:00
|
|
|
};
|
|
|
|
|
2019-09-07 04:28:02 +08:00
|
|
|
const amIModerator = () => {
|
2019-08-22 20:05:06 +08:00
|
|
|
const User = Users.findOne({ intId: Auth.userID }, { fields: { role: 1 } });
|
|
|
|
return User.role === ROLE_MODERATOR;
|
2018-11-02 01:55:35 +08:00
|
|
|
};
|
|
|
|
|
2019-09-19 04:06:59 +08:00
|
|
|
const getBreakoutByUserId = userId => Breakouts.find(
|
|
|
|
{ 'users.userId': userId },
|
|
|
|
{ fields: { timeRemaining: 0 } },
|
|
|
|
).fetch();
|
2019-06-07 21:49:50 +08:00
|
|
|
|
2019-09-11 07:26:54 +08:00
|
|
|
const getBreakoutByUser = user => Breakouts.findOne({ users: user });
|
2019-06-07 21:49:50 +08:00
|
|
|
|
|
|
|
const getUsersFromBreakouts = breakoutsArray => breakoutsArray
|
|
|
|
.map(breakout => breakout.users)
|
|
|
|
.reduce((acc, usersArray) => [...acc, ...usersArray], []);
|
|
|
|
|
|
|
|
const filterUserURLs = userId => breakoutUsersArray => breakoutUsersArray
|
|
|
|
.filter(user => user.userId === userId);
|
|
|
|
|
|
|
|
const getLastURLInserted = breakoutURLArray => breakoutURLArray
|
|
|
|
.sort((a, b) => a.insertedTime - b.insertedTime).pop();
|
|
|
|
|
|
|
|
const getBreakoutUserByUserId = userId => fp.pipe(
|
|
|
|
getBreakoutByUserId,
|
|
|
|
getUsersFromBreakouts,
|
|
|
|
filterUserURLs(userId),
|
|
|
|
getLastURLInserted,
|
|
|
|
)(userId);
|
|
|
|
|
|
|
|
const getBreakouts = () => Breakouts.find({}, { sort: { sequence: 1 } }).fetch();
|
2019-09-19 04:06:59 +08:00
|
|
|
const getBreakoutsNoTime = () => Breakouts.find(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
sort: { sequence: 1 },
|
|
|
|
fields: { timeRemaining: 0 },
|
|
|
|
},
|
|
|
|
).fetch();
|
|
|
|
|
|
|
|
const getBreakoutUserIsIn = userId => Breakouts.findOne({ 'joinedUsers.userId': new RegExp(`^${userId}`) }, { fields: { sequence: 1 } });
|
2019-04-24 20:50:45 +08:00
|
|
|
|
2019-09-28 06:59:55 +08:00
|
|
|
const isUserInBreakoutRoom = (joinedUsers) => {
|
|
|
|
const userId = Auth.userID;
|
|
|
|
|
|
|
|
return !!joinedUsers.find(user => user.userId.startsWith(userId));
|
|
|
|
};
|
2019-09-19 02:55:06 +08:00
|
|
|
|
2018-10-24 01:18:09 +08:00
|
|
|
export default {
|
2018-10-30 03:36:45 +08:00
|
|
|
findBreakouts,
|
2018-10-24 01:18:09 +08:00
|
|
|
endAllBreakouts,
|
|
|
|
requestJoinURL,
|
|
|
|
breakoutRoomUser,
|
|
|
|
transferUserToMeeting,
|
|
|
|
transferToBreakout,
|
2018-11-05 20:27:56 +08:00
|
|
|
meetingId: () => Auth.meetingID,
|
2018-10-26 23:16:29 +08:00
|
|
|
closeBreakoutPanel,
|
2019-09-07 04:28:02 +08:00
|
|
|
amIModerator,
|
2019-06-07 21:49:50 +08:00
|
|
|
getBreakoutUserByUserId,
|
|
|
|
getBreakoutByUser,
|
|
|
|
getBreakouts,
|
2019-09-19 04:06:59 +08:00
|
|
|
getBreakoutsNoTime,
|
2019-06-07 21:49:50 +08:00
|
|
|
getBreakoutByUserId,
|
2019-09-19 04:06:59 +08:00
|
|
|
getBreakoutUserIsIn,
|
2019-09-19 02:55:06 +08:00
|
|
|
isUserInBreakoutRoom,
|
2018-10-24 01:18:09 +08:00
|
|
|
};
|