Chatwoot/app/javascript/dashboard/helper/actionCable.js
Pranav Raj S 16fe912fbd
[Feature] Website live chat (#187)
Co-authored-by: Nithin David Thomas <webofnithin@gmail.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
2019-10-29 12:50:54 +05:30

53 lines
1.3 KiB
JavaScript

import AuthAPI from '../api/auth';
import BaseActionCableConnector from '../../shared/helpers/BaseActionCableConnector';
class ActionCableConnector extends BaseActionCableConnector {
constructor(app, pubsubToken) {
super(app, pubsubToken);
this.events = {
'message.created': this.onMessageCreated,
'conversation.created': this.onConversationCreated,
'status_change:conversation': this.onStatusChange,
'user:logout': this.onLogout,
'page:reload': this.onReload,
'assignee.changed': this.onAssigneeChanged,
};
}
onAssigneeChanged = payload => {
const { meta = {}, id } = payload;
const { assignee } = meta || {};
if (id) {
this.app.$store.dispatch('updateAssignee', { id, assignee });
}
};
onConversationCreated = data => {
this.app.$store.dispatch('addConversation', data);
};
onLogout = () => AuthAPI.logout();
onMessageCreated = data => {
this.app.$store.dispatch('addMessage', data);
};
onReload = () => window.location.reload();
onStatusChange = data => {
this.app.$store.dispatch('addConversation', data);
};
}
export default {
init() {
if (AuthAPI.isLoggedIn()) {
const actionCable = new ActionCableConnector(
window.WOOT,
AuthAPI.getPubSubToken()
);
return actionCable;
}
return null;
},
};