bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/notification/push-notification/component.jsx
2018-05-18 08:54:26 -03:00

62 lines
1.6 KiB
JavaScript
Executable File

import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import injectNotify from '/imports/ui/components/toast/inject-notify/component';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import { Link } from 'react-router';
import { styles } from '../../styles.scss';
const propTypes = {
intl: intlShape.isRequired,
count: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
notify: PropTypes.func.isRequired,
onOpen: PropTypes.func.isRequired,
};
const intlMessages = defineMessages({
appToastChatSigular: {
id: 'app.toast.chat.singular',
description: 'when entry a message',
},
appToastChatPlural: {
id: 'app.toast.chat.plural',
description: 'when entry various message',
},
});
class ChatPushNotification extends React.Component {
constructor(props) {
super(props);
this.showNotify = _.debounce(this.showNotify.bind(this), 1000);
this.componentDidMount = this.showNotify;
this.componentDidUpdate = this.showNotify;
}
showNotify() {
const {
intl,
count,
name,
notify,
onOpen,
userId,
} = this.props;
const message = intl.formatMessage(count > 1 ?
intlMessages.appToastChatPlural :
intlMessages.appToastChatSigular, {
0: count,
1: name,
});
return notify((<Link className={styles.link} to={`/users/chat/${userId}`}>{message}</Link>), 'info', 'chat', { onOpen });
}
render() {
return null;
}
}
ChatPushNotification.propTypes = propTypes;
export default injectIntl(injectNotify(ChatPushNotification));