2020-05-09 16:32:43 +00:00
|
|
|
import {
|
|
|
|
SET_CONVERSATION_ATTRIBUTES,
|
|
|
|
UPDATE_CONVERSATION_ATTRIBUTES,
|
2021-06-30 15:39:44 +00:00
|
|
|
CLEAR_CONVERSATION_ATTRIBUTES,
|
2020-05-09 16:32:43 +00:00
|
|
|
} from '../types';
|
|
|
|
import { getConversationAPI } from '../../api/conversation';
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
id: '',
|
|
|
|
status: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getters = {
|
|
|
|
getConversationParams: $state => $state,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
2021-06-30 15:39:44 +00:00
|
|
|
getAttributes: async ({ commit }) => {
|
2020-05-09 16:32:43 +00:00
|
|
|
try {
|
|
|
|
const { data } = await getConversationAPI();
|
2020-09-10 13:49:15 +00:00
|
|
|
const { contact_last_seen_at: lastSeen } = data;
|
2020-05-09 16:32:43 +00:00
|
|
|
commit(SET_CONVERSATION_ATTRIBUTES, data);
|
2020-07-07 18:34:44 +00:00
|
|
|
commit('conversation/setMetaUserLastSeenAt', lastSeen, { root: true });
|
2020-05-09 16:32:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
// Ignore error
|
|
|
|
}
|
|
|
|
},
|
|
|
|
update({ commit }, data) {
|
|
|
|
commit(UPDATE_CONVERSATION_ATTRIBUTES, data);
|
|
|
|
},
|
2021-06-30 15:39:44 +00:00
|
|
|
clearConversationAttributes: ({ commit }) => {
|
|
|
|
commit('CLEAR_CONVERSATION_ATTRIBUTES');
|
|
|
|
},
|
2020-05-09 16:32:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[SET_CONVERSATION_ATTRIBUTES]($state, data) {
|
|
|
|
$state.id = data.id;
|
|
|
|
$state.status = data.status;
|
|
|
|
},
|
|
|
|
[UPDATE_CONVERSATION_ATTRIBUTES]($state, data) {
|
|
|
|
if (data.id === $state.id) {
|
|
|
|
$state.id = data.id;
|
|
|
|
$state.status = data.status;
|
|
|
|
}
|
|
|
|
},
|
2021-06-30 15:39:44 +00:00
|
|
|
[CLEAR_CONVERSATION_ATTRIBUTES]($state) {
|
|
|
|
$state.id = '';
|
|
|
|
$state.status = '';
|
|
|
|
},
|
2020-05-09 16:32:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|