2020-06-30 10:43:20 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { toast } from 'react-toastify';
|
2022-02-15 22:51:51 +08:00
|
|
|
import Icon from '/imports/ui/components/common/icon/component';
|
2020-06-30 10:43:20 +08:00
|
|
|
import { ENTER } from '/imports/utils/keyCodes';
|
2021-11-09 03:54:19 +08:00
|
|
|
import Styled from './styles';
|
2023-06-08 09:10:07 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2022-02-25 01:00:27 +08:00
|
|
|
import TooltipContainer from '/imports/ui/components/common/tooltip/container';
|
2022-01-08 03:41:22 +08:00
|
|
|
|
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
2020-06-30 10:43:20 +08:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
lowerHandsLabel: {
|
|
|
|
id: 'app.statusNotifier.lowerHands',
|
|
|
|
description: 'text displayed to clear all raised hands',
|
|
|
|
},
|
2022-02-25 01:00:27 +08:00
|
|
|
lowerHandDescOneUser: {
|
|
|
|
id: 'app.statusNotifier.lowerHandDescOneUser',
|
|
|
|
description: 'text displayed to clear a single user raised hands',
|
|
|
|
},
|
2020-06-30 10:43:20 +08:00
|
|
|
raisedHandsTitle: {
|
|
|
|
id: 'app.statusNotifier.raisedHandsTitle',
|
|
|
|
description: 'heading for raised hands toast',
|
|
|
|
},
|
2020-07-01 02:53:30 +08:00
|
|
|
raisedHandDesc: {
|
|
|
|
id: 'app.statusNotifier.raisedHandDesc',
|
2021-04-22 18:08:25 +08:00
|
|
|
description: 'label for multiple users with raised hands',
|
|
|
|
},
|
|
|
|
raisedHandDescOneUser: {
|
|
|
|
id: 'app.statusNotifier.raisedHandDescOneUser',
|
|
|
|
description: 'label for a single user with raised hand',
|
2020-07-01 02:53:30 +08:00
|
|
|
},
|
2020-06-30 10:43:20 +08:00
|
|
|
and: {
|
|
|
|
id: 'app.statusNotifier.and',
|
|
|
|
description: 'used as conjunction word',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const MAX_AVATAR_COUNT = 3;
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
class RaiseHandNotifier extends Component {
|
2020-06-30 10:43:20 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.statusNotifierId = null;
|
|
|
|
|
2020-12-01 00:09:35 +08:00
|
|
|
this.audio = new Audio(`${Meteor.settings.public.app.cdn + Meteor.settings.public.app.basename + Meteor.settings.public.app.instanceId}/resources/sounds/bbb-handRaise.mp3`);
|
2020-06-30 10:43:20 +08:00
|
|
|
|
|
|
|
this.renderRaisedHands = this.renderRaisedHands.bind(this);
|
|
|
|
this.getRaisedHandNames = this.getRaisedHandNames.bind(this);
|
|
|
|
this.raisedHandAvatars = this.raisedHandAvatars.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const {
|
2023-06-08 09:10:07 +08:00
|
|
|
raiseHandUsers, raiseHandAudioAlert, raiseHandPushAlert, isViewer, isPresenter,
|
2020-06-30 10:43:20 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2021-09-27 19:29:49 +08:00
|
|
|
if (isViewer && !isPresenter) {
|
2020-07-06 20:56:19 +08:00
|
|
|
if (this.statusNotifierId) toast.dismiss(this.statusNotifierId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
if (raiseHandUsers.length === 0) {
|
|
|
|
return this.statusNotifierId ? toast.dismiss(this.statusNotifierId) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (raiseHandAudioAlert && raiseHandUsers.length > prevProps.raiseHandUsers.length) {
|
|
|
|
this.audio.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (raiseHandPushAlert) {
|
|
|
|
if (this.statusNotifierId) {
|
|
|
|
return toast.update(this.statusNotifierId, {
|
|
|
|
render: this.renderRaisedHands(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusNotifierId = toast(this.renderRaisedHands(), {
|
|
|
|
onClose: () => { this.statusNotifierId = null; },
|
|
|
|
autoClose: false,
|
|
|
|
closeOnClick: false,
|
|
|
|
closeButton: false,
|
|
|
|
className: 'raiseHandToast',
|
|
|
|
});
|
2020-06-30 10:43:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRaisedHandNames() {
|
2023-06-08 09:10:07 +08:00
|
|
|
const { raiseHandUsers, intl } = this.props;
|
|
|
|
if (raiseHandUsers.length === 0) return '';
|
2020-06-30 10:43:20 +08:00
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
const _names = raiseHandUsers.map((u) => u.name);
|
2020-06-30 10:43:20 +08:00
|
|
|
const { length } = _names;
|
|
|
|
const and = intl.formatMessage(messages.and);
|
|
|
|
let formattedNames = '';
|
|
|
|
|
|
|
|
switch (length) {
|
|
|
|
case 1:
|
|
|
|
formattedNames = _names;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
formattedNames = _names.join(` ${and} `);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
formattedNames = _names.slice(0, length - 1).join(', ');
|
|
|
|
formattedNames += ` ${and} ${_names.slice(length - 1)}`;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
formattedNames = _names.slice(0, MAX_AVATAR_COUNT).join(', ');
|
2020-07-01 02:53:30 +08:00
|
|
|
formattedNames += ` ${and} ${length - MAX_AVATAR_COUNT}+ `;
|
2020-06-30 10:43:20 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
const raisedHandMessageString = length === 1
|
|
|
|
? messages.raisedHandDescOneUser : messages.raisedHandDesc;
|
2021-04-22 18:08:25 +08:00
|
|
|
return intl.formatMessage(raisedHandMessageString, { 0: formattedNames });
|
2020-06-30 10:43:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
raisedHandAvatars() {
|
2023-06-08 09:10:07 +08:00
|
|
|
const { raiseHandUsers, clearUserStatus, intl } = this.props;
|
|
|
|
let users = raiseHandUsers;
|
|
|
|
if (raiseHandUsers.length > MAX_AVATAR_COUNT) users = users.slice(0, MAX_AVATAR_COUNT);
|
2020-06-30 10:43:20 +08:00
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
const avatars = users.map((u) => (
|
2022-02-25 01:00:27 +08:00
|
|
|
<TooltipContainer
|
2020-06-30 10:43:20 +08:00
|
|
|
key={`statusToastAvatar-${u.userId}`}
|
2023-06-08 09:10:07 +08:00
|
|
|
title={intl.formatMessage(messages.lowerHandDescOneUser, { 0: u.name })}
|
|
|
|
>
|
2022-02-25 01:00:27 +08:00
|
|
|
<Styled.Avatar
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
style={{ backgroundColor: `${u.color}` }}
|
2023-10-20 00:18:10 +08:00
|
|
|
onClick={() => lowerUserHands(u.userId)}
|
2023-06-08 09:10:07 +08:00
|
|
|
onKeyDown={(e) => (e.keyCode === ENTER ? clearUserStatus(u.userId) : null)}
|
2022-02-25 01:00:27 +08:00
|
|
|
data-test="avatarsWrapperAvatar"
|
2022-01-08 03:41:22 +08:00
|
|
|
moderator={u.role === ROLE_MODERATOR}
|
|
|
|
avatar={u.avatar}
|
2022-02-25 01:00:27 +08:00
|
|
|
>
|
|
|
|
{u.name.slice(0, 2)}
|
|
|
|
</Styled.Avatar>
|
|
|
|
</TooltipContainer>
|
2020-06-30 10:43:20 +08:00
|
|
|
));
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
if (raiseHandUsers.length > MAX_AVATAR_COUNT) {
|
2020-06-30 10:43:20 +08:00
|
|
|
avatars.push(
|
2023-06-08 09:10:07 +08:00
|
|
|
<Styled.AvatarsExtra key={`statusToastAvatar-${raiseHandUsers.length}`}>
|
|
|
|
{raiseHandUsers.length}
|
2021-11-09 03:54:19 +08:00
|
|
|
</Styled.AvatarsExtra>,
|
2020-06-30 10:43:20 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return avatars;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderRaisedHands() {
|
2023-06-08 09:10:07 +08:00
|
|
|
const { raiseHandUsers, intl, lowerUserHands } = this.props;
|
2020-06-30 10:43:20 +08:00
|
|
|
const formattedRaisedHands = this.getRaisedHandNames();
|
|
|
|
return (
|
|
|
|
<div>
|
2021-11-09 03:54:19 +08:00
|
|
|
<Styled.ToastIcon>
|
|
|
|
<Styled.IconWrapper>
|
2020-06-30 10:43:20 +08:00
|
|
|
<Icon iconName="hand" />
|
2021-11-09 03:54:19 +08:00
|
|
|
</Styled.IconWrapper>
|
|
|
|
</Styled.ToastIcon>
|
|
|
|
<Styled.AvatarsWrapper data-test="avatarsWrapper">
|
2020-06-30 10:43:20 +08:00
|
|
|
{this.raisedHandAvatars()}
|
2021-11-09 03:54:19 +08:00
|
|
|
</Styled.AvatarsWrapper>
|
|
|
|
<Styled.ToastMessage>
|
2020-06-30 10:43:20 +08:00
|
|
|
<div>{intl.formatMessage(messages.raisedHandsTitle)}</div>
|
|
|
|
{formattedRaisedHands}
|
2021-11-09 03:54:19 +08:00
|
|
|
</Styled.ToastMessage>
|
2021-11-11 19:47:39 +08:00
|
|
|
<Styled.ToastSeparator />
|
2021-11-09 03:54:19 +08:00
|
|
|
<Styled.ClearButton
|
2020-06-30 10:43:20 +08:00
|
|
|
label={intl.formatMessage(messages.lowerHandsLabel)}
|
|
|
|
color="default"
|
|
|
|
size="md"
|
|
|
|
onClick={() => {
|
2023-06-08 09:10:07 +08:00
|
|
|
raiseHandUsers.map((u) => lowerUserHands(u.userId));
|
2020-06-30 10:43:20 +08:00
|
|
|
}}
|
2023-02-04 04:04:45 +08:00
|
|
|
data-test="raiseHandRejection"
|
2020-06-30 10:43:20 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() { return null; }
|
|
|
|
}
|
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
export default injectIntl(RaiseHandNotifier);
|
2020-06-30 10:43:20 +08:00
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
RaiseHandNotifier.propTypes = {
|
2020-06-30 10:43:20 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2023-06-08 09:10:07 +08:00
|
|
|
lowerUserHands: PropTypes.func.isRequired,
|
|
|
|
raiseHandUsers: PropTypes.instanceOf(Array).isRequired,
|
2020-06-30 10:43:20 +08:00
|
|
|
raiseHandAudioAlert: PropTypes.bool.isRequired,
|
|
|
|
raiseHandPushAlert: PropTypes.bool.isRequired,
|
|
|
|
};
|