2019-10-29 07:20:54 +00:00
|
|
|
import BaseActionCableConnector from '../../shared/helpers/BaseActionCableConnector';
|
2021-10-18 13:09:04 +00:00
|
|
|
import { playNewMessageNotificationInWidget } from 'shared/helpers/AudioNotificationHelper';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
class ActionCableConnector extends BaseActionCableConnector {
|
|
|
|
constructor(app, pubsubToken) {
|
|
|
|
super(app, pubsubToken);
|
|
|
|
this.events = {
|
|
|
|
'message.created': this.onMessageCreated,
|
2020-04-17 15:45:20 +00:00
|
|
|
'message.updated': this.onMessageUpdated,
|
2020-05-04 17:37:56 +00:00
|
|
|
'conversation.typing_on': this.onTypingOn,
|
|
|
|
'conversation.typing_off': this.onTypingOff,
|
2021-04-28 15:23:23 +00:00
|
|
|
'conversation.status_changed': this.onStatusChange,
|
2020-07-04 06:12:47 +00:00
|
|
|
'presence.update': this.onPresenceUpdate,
|
2021-08-31 10:00:18 +00:00
|
|
|
'contact.merged': this.onContactMerge,
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-09 16:32:43 +00:00
|
|
|
onStatusChange = data => {
|
|
|
|
this.app.$store.dispatch('conversationAttributes/update', data);
|
|
|
|
};
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
onMessageCreated = data => {
|
2021-07-15 08:57:37 +00:00
|
|
|
this.app.$store
|
|
|
|
.dispatch('conversation/addOrUpdateMessage', data)
|
|
|
|
.then(() => {
|
2021-10-14 06:21:00 +00:00
|
|
|
window.bus.$emit('on-agent-message-received');
|
2021-07-15 08:57:37 +00:00
|
|
|
});
|
2021-10-18 13:09:04 +00:00
|
|
|
if (data.sender_type === 'User') {
|
|
|
|
playNewMessageNotificationInWidget();
|
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|
2020-04-17 15:45:20 +00:00
|
|
|
|
|
|
|
onMessageUpdated = data => {
|
2021-07-15 08:57:37 +00:00
|
|
|
this.app.$store.dispatch('conversation/addOrUpdateMessage', data);
|
2020-04-17 15:45:20 +00:00
|
|
|
};
|
2020-05-04 17:37:56 +00:00
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
onPresenceUpdate = data => {
|
|
|
|
this.app.$store.dispatch('agent/updatePresence', data.users);
|
|
|
|
};
|
|
|
|
|
2021-08-31 10:00:18 +00:00
|
|
|
onContactMerge = data => {
|
|
|
|
const { pubsub_token: pubsubToken } = data;
|
|
|
|
ActionCableConnector.refreshConnector(pubsubToken);
|
|
|
|
};
|
|
|
|
|
2021-11-01 08:20:07 +00:00
|
|
|
onTypingOn = data => {
|
|
|
|
if (data.is_private) {
|
2021-11-22 18:02:17 +00:00
|
|
|
return;
|
2021-11-01 08:20:07 +00:00
|
|
|
}
|
2020-05-04 17:37:56 +00:00
|
|
|
this.clearTimer();
|
|
|
|
this.app.$store.dispatch('conversation/toggleAgentTyping', {
|
|
|
|
status: 'on',
|
|
|
|
});
|
|
|
|
this.initTimer();
|
|
|
|
};
|
|
|
|
|
|
|
|
onTypingOff = () => {
|
|
|
|
this.clearTimer();
|
|
|
|
this.app.$store.dispatch('conversation/toggleAgentTyping', {
|
|
|
|
status: 'off',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
clearTimer = () => {
|
|
|
|
if (this.CancelTyping) {
|
|
|
|
clearTimeout(this.CancelTyping);
|
|
|
|
this.CancelTyping = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
initTimer = () => {
|
|
|
|
// Turn off typing automatically after 30 seconds
|
|
|
|
this.CancelTyping = setTimeout(() => {
|
|
|
|
this.onTypingOff();
|
|
|
|
}, 30000);
|
|
|
|
};
|
2019-10-29 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ActionCableConnector;
|