2017-08-01 21:10:12 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2017-10-12 10:00:28 +08:00
|
|
|
import VoiceUsers from '/imports/api/voice-users';
|
2017-08-01 21:10:12 +08:00
|
|
|
|
|
|
|
const USER_CONFIG = Meteor.settings.public.user;
|
|
|
|
const ROLE_MODERATOR = USER_CONFIG.role_moderator;
|
|
|
|
|
2017-10-04 03:22:26 +08:00
|
|
|
const getVoiceUser = userId => VoiceUsers.findOne({ intId: userId });
|
|
|
|
|
2017-08-01 21:10:12 +08:00
|
|
|
const mapUser = (user) => {
|
|
|
|
const userId = Auth.userID;
|
2017-10-04 03:22:26 +08:00
|
|
|
const voiceUser = getVoiceUser(user.userId);
|
2017-08-01 21:10:12 +08:00
|
|
|
|
2017-08-01 21:41:24 +08:00
|
|
|
const mappedUser = {
|
2017-08-02 22:29:33 +08:00
|
|
|
id: user.userId,
|
2017-08-01 21:10:12 +08:00
|
|
|
name: user.name,
|
2017-08-03 20:36:26 +08:00
|
|
|
color: user.color,
|
|
|
|
avatar: user.avatar,
|
2017-08-01 21:10:12 +08:00
|
|
|
emoji: {
|
|
|
|
status: user.emoji,
|
2017-08-02 22:29:33 +08:00
|
|
|
changedAt: user.emojiTime,
|
2017-08-01 21:10:12 +08:00
|
|
|
},
|
|
|
|
isPresenter: user.presenter,
|
|
|
|
isModerator: user.role === ROLE_MODERATOR,
|
2017-08-02 22:29:33 +08:00
|
|
|
isCurrent: user.userId === userId,
|
2017-10-12 22:49:50 +08:00
|
|
|
isVoiceUser: voiceUser ? voiceUser.joined : false,
|
2017-10-04 03:22:26 +08:00
|
|
|
isMuted: voiceUser ? voiceUser.muted : false,
|
2018-04-09 22:39:27 +08:00
|
|
|
isTalking: voiceUser ? voiceUser.talking && !voiceUser.muted : false,
|
2017-10-04 03:22:26 +08:00
|
|
|
isListenOnly: voiceUser ? voiceUser.listenOnly : false,
|
2018-04-03 19:40:33 +08:00
|
|
|
isSharingWebcam: user.has_stream,
|
2017-08-01 21:10:12 +08:00
|
|
|
isPhoneUser: user.phone_user,
|
2017-08-02 22:29:33 +08:00
|
|
|
isOnline: user.connectionStatus === 'online',
|
2017-08-01 21:10:12 +08:00
|
|
|
};
|
|
|
|
|
2018-01-29 19:52:07 +08:00
|
|
|
mappedUser.isLocked = user.locked && !(mappedUser.isPresenter || mappedUser.isModerator);
|
|
|
|
|
2017-08-01 21:41:24 +08:00
|
|
|
return mappedUser;
|
2017-08-01 21:10:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default mapUser;
|