2019-10-24 20:07:01 +00:00
|
|
|
import AuthAPI from '../api/auth';
|
2019-10-29 07:20:54 +00:00
|
|
|
import BaseActionCableConnector from '../../shared/helpers/BaseActionCableConnector';
|
2019-10-24 20:07:01 +00:00
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
class ActionCableConnector extends BaseActionCableConnector {
|
2019-10-24 20:07:01 +00:00
|
|
|
constructor(app, pubsubToken) {
|
2019-10-29 07:20:54 +00:00
|
|
|
super(app, pubsubToken);
|
2019-10-24 20:07:01 +00:00
|
|
|
this.events = {
|
|
|
|
'message.created': this.onMessageCreated,
|
2020-04-17 15:45:20 +00:00
|
|
|
'message.updated': this.onMessageUpdated,
|
2019-10-24 20:07:01 +00:00
|
|
|
'conversation.created': this.onConversationCreated,
|
|
|
|
'status_change:conversation': this.onStatusChange,
|
|
|
|
'user:logout': this.onLogout,
|
|
|
|
'page:reload': this.onReload,
|
|
|
|
'assignee.changed': this.onAssigneeChanged,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:45:20 +00:00
|
|
|
onMessageUpdated = data => {
|
|
|
|
this.app.$store.dispatch('updateMessage', data);
|
|
|
|
};
|
|
|
|
|
2019-10-24 20:07:01 +00:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
};
|