2018-12-17 19:48:34 +08:00
|
|
|
import React, { PureComponent } 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-10-17 01:48:27 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2017-10-28 03:29:48 +08:00
|
|
|
|
2018-08-15 10:35:58 +08:00
|
|
|
const ALERT_INTERVAL = 2000; // 2 seconds
|
|
|
|
const ALERT_LIFETIME = 4000; // 4 seconds
|
2018-06-15 22:22:56 +08:00
|
|
|
|
2017-10-28 03:29:48 +08:00
|
|
|
const propTypes = {
|
|
|
|
notify: PropTypes.func.isRequired,
|
|
|
|
onOpen: PropTypes.func.isRequired,
|
2018-10-25 23:20:37 +08:00
|
|
|
chatId: PropTypes.string.isRequired,
|
|
|
|
message: PropTypes.node.isRequired,
|
|
|
|
content: PropTypes.node.isRequired,
|
2017-10-28 03:29:48 +08:00
|
|
|
};
|
2017-10-27 01:14:50 +08:00
|
|
|
|
2018-12-17 19:48:34 +08:00
|
|
|
class ChatPushAlert extends PureComponent {
|
2018-06-13 01:21:31 +08:00
|
|
|
static link(message, chatId) {
|
2018-10-17 01:48:27 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role="button"
|
2018-10-25 23:20:37 +08:00
|
|
|
aria-label={message}
|
|
|
|
tabIndex={0}
|
2018-10-17 01:48:27 +08:00
|
|
|
onClick={() => {
|
2018-12-18 23:15:51 +08:00
|
|
|
Session.set('openPanel', 'chat');
|
|
|
|
Session.set('idChatOpen', chatId);
|
|
|
|
}}
|
2018-10-17 01:48:27 +08:00
|
|
|
>
|
|
|
|
{ message }
|
|
|
|
</div>
|
|
|
|
);
|
2018-06-13 01:21:31 +08:00
|
|
|
}
|
|
|
|
|
2017-10-27 01:14:50 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-08-15 10:35:58 +08:00
|
|
|
this.showNotify = _.debounce(this.showNotify.bind(this), ALERT_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:37:57 +08:00
|
|
|
return notify(
|
2018-08-15 10:35:58 +08:00
|
|
|
ChatPushAlert.link(message, chatId),
|
2018-06-15 22:37:57 +08:00
|
|
|
'info',
|
|
|
|
'chat',
|
2018-08-15 10:35:58 +08:00
|
|
|
{ onOpen, autoClose: ALERT_LIFETIME },
|
|
|
|
ChatPushAlert.link(content, chatId),
|
2018-06-15 22:37:57 +08:00
|
|
|
true,
|
|
|
|
);
|
2017-10-27 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2018-08-15 10:35:58 +08:00
|
|
|
ChatPushAlert.propTypes = propTypes;
|
2017-10-27 01:14:50 +08:00
|
|
|
|
2018-08-15 10:35:58 +08:00
|
|
|
export default injectNotify(ChatPushAlert);
|