2020-05-04 17:37:56 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import * as types from '../mutation-types';
|
2020-06-14 08:37:52 +00:00
|
|
|
import ConversationAPI from '../../api/inbox/conversation';
|
2020-05-04 17:37:56 +00:00
|
|
|
const state = {
|
|
|
|
records: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getters = {
|
|
|
|
getUserList: $state => id => {
|
|
|
|
return $state.records[Number(id)] || [];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
2021-11-01 08:20:07 +00:00
|
|
|
toggleTyping: async (_, { status, conversationId, isPrivate }) => {
|
2020-06-14 08:37:52 +00:00
|
|
|
try {
|
2021-11-01 08:20:07 +00:00
|
|
|
await ConversationAPI.toggleTyping({ status, conversationId, isPrivate });
|
2020-06-14 08:37:52 +00:00
|
|
|
} catch (error) {
|
|
|
|
// Handle error
|
|
|
|
}
|
|
|
|
},
|
2020-05-04 17:37:56 +00:00
|
|
|
create: ({ commit }, { conversationId, user }) => {
|
|
|
|
commit(types.default.ADD_USER_TYPING_TO_CONVERSATION, {
|
|
|
|
conversationId,
|
|
|
|
user,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
destroy: ({ commit }, { conversationId, user }) => {
|
|
|
|
commit(types.default.REMOVE_USER_TYPING_FROM_CONVERSATION, {
|
|
|
|
conversationId,
|
|
|
|
user,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[types.default.ADD_USER_TYPING_TO_CONVERSATION]: (
|
|
|
|
$state,
|
|
|
|
{ conversationId, user }
|
|
|
|
) => {
|
|
|
|
const records = $state.records[conversationId] || [];
|
|
|
|
const hasUserRecordAlready = !!records.filter(
|
|
|
|
record => record.id === user.id && record.type === user.type
|
|
|
|
).length;
|
|
|
|
if (!hasUserRecordAlready) {
|
|
|
|
Vue.set($state.records, conversationId, [...records, user]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[types.default.REMOVE_USER_TYPING_FROM_CONVERSATION]: (
|
|
|
|
$state,
|
|
|
|
{ conversationId, user }
|
|
|
|
) => {
|
|
|
|
const records = $state.records[conversationId] || [];
|
|
|
|
const updatedRecords = records.filter(
|
|
|
|
record => record.id !== user.id || record.type !== user.type
|
|
|
|
);
|
|
|
|
Vue.set($state.records, conversationId, updatedRecords);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|