feat: Split reconnect logic PR (store) (#9520)
# Pull Request Template ## Description This PR includes store filter parts split from this [Reconnect PR](https://github.com/chatwoot/chatwoot/pull/9453)
This commit is contained in:
@@ -159,4 +159,11 @@ export const actions = {
|
||||
clear({ commit }) {
|
||||
commit(types.CLEAR_NOTIFICATIONS);
|
||||
},
|
||||
|
||||
setNotificationFilters: ({ commit }, filters) => {
|
||||
commit(types.SET_NOTIFICATION_FILTERS, filters);
|
||||
},
|
||||
updateNotificationFilters: ({ commit }, filters) => {
|
||||
commit(types.UPDATE_NOTIFICATION_FILTERS, filters);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -24,4 +24,7 @@ export const getters = {
|
||||
getMeta: $state => {
|
||||
return $state.meta;
|
||||
},
|
||||
getNotificationFilters($state) {
|
||||
return $state.notificationFilters;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ const state = {
|
||||
isUpdatingUnreadCount: false,
|
||||
isAllNotificationsLoaded: false,
|
||||
},
|
||||
notificationFilters: {},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -28,6 +28,16 @@ export const mutations = {
|
||||
},
|
||||
[types.SET_NOTIFICATIONS]: ($state, data) => {
|
||||
data.forEach(notification => {
|
||||
// Find existing notification with same primary_actor_id (primary_actor_id is unique)
|
||||
const existingNotification = Object.values($state.records).find(
|
||||
record => record.primary_actor_id === notification.primary_actor_id
|
||||
);
|
||||
// This is to handle the case where the same notification is received multiple times
|
||||
// On reconnect, if there is existing notification with same primary_actor_id,
|
||||
// it will be deleted and the new one will be added. So it will solve with duplicate notification
|
||||
if (existingNotification) {
|
||||
Vue.delete($state.records, existingNotification.id);
|
||||
}
|
||||
Vue.set($state.records, notification.id, {
|
||||
...($state.records[notification.id] || {}),
|
||||
...notification,
|
||||
@@ -85,4 +95,14 @@ export const mutations = {
|
||||
[types.SNOOZE_NOTIFICATION]: ($state, { id, snoozed_until }) => {
|
||||
Vue.set($state.records[id], 'snoozed_until', snoozed_until);
|
||||
},
|
||||
|
||||
[types.SET_NOTIFICATION_FILTERS]: ($state, filters) => {
|
||||
Vue.set($state, 'notificationFilters', filters);
|
||||
},
|
||||
[types.UPDATE_NOTIFICATION_FILTERS]: ($state, filters) => {
|
||||
Vue.set($state, 'notificationFilters', {
|
||||
...$state.notificationFilters,
|
||||
...filters,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user