2017-10-27 01:14:50 +08:00
|
|
|
import React from 'react';
|
2017-10-28 03:29:48 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-27 01:14:50 +08:00
|
|
|
import _ from 'lodash';
|
|
|
|
import injectNotify from '/imports/ui/components/toast/inject-notify/component';
|
2018-05-18 19:54:26 +08:00
|
|
|
import { Link } from 'react-router';
|
2018-06-13 01:21:31 +08:00
|
|
|
import cx from 'classnames';
|
2018-05-18 19:54:26 +08:00
|
|
|
import { styles } from '../../styles.scss';
|
2017-10-28 03:29:48 +08:00
|
|
|
|
2018-06-15 22:22:56 +08:00
|
|
|
const NOTIFICATION_INTERVAL = 2000;
|
|
|
|
const NOTIFICATION_LIFETIME = 4000;
|
|
|
|
|
2017-10-28 03:29:48 +08:00
|
|
|
const propTypes = {
|
|
|
|
notify: PropTypes.func.isRequired,
|
|
|
|
onOpen: PropTypes.func.isRequired,
|
|
|
|
};
|
2017-10-27 01:14:50 +08:00
|
|
|
|
|
|
|
class ChatPushNotification extends React.Component {
|
2018-06-13 01:21:31 +08:00
|
|
|
static link(message, chatId) {
|
|
|
|
return (
|
|
|
|
<Link className={styles.link} to={`/users/chat/${chatId}`}>
|
|
|
|
{message}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-27 01:14:50 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-06-15 22:22:56 +08:00
|
|
|
this.showNotify = _.debounce(this.showNotify.bind(this), NOTIFICATION_INTERVAL);
|
2017-10-27 01:14:50 +08:00
|
|
|
|
|
|
|
this.componentDidMount = this.showNotify;
|
|
|
|
this.componentDidUpdate = this.showNotify;
|
|
|
|
}
|
|
|
|
|
|
|
|
showNotify() {
|
|
|
|
const {
|
|
|
|
notify,
|
|
|
|
onOpen,
|
2018-05-30 00:43:11 +08:00
|
|
|
chatId,
|
|
|
|
message,
|
|
|
|
content,
|
2017-10-27 01:14:50 +08:00
|
|
|
} = this.props;
|
2018-05-30 00:43:11 +08:00
|
|
|
|
2018-06-15 22:22:56 +08:00
|
|
|
return notify(ChatPushNotification.link(message, chatId), 'info', 'chat', { onOpen, autoClose: NOTIFICATION_LIFETIME }, ChatPushNotification.link(content, chatId), true);
|
2017-10-27 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-10-28 03:29:48 +08:00
|
|
|
ChatPushNotification.propTypes = propTypes;
|
2017-10-27 01:14:50 +08:00
|
|
|
|
2018-05-30 00:43:11 +08:00
|
|
|
export default injectNotify(ChatPushNotification);
|