From d8c4b105117f03685304e6b35003efddaf1542f5 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 8 Jan 2024 13:28:58 +0530 Subject: [PATCH] feat: Show subscribed notifications --- .../dashboard/components/layout/Sidebar.vue | 1 + .../store/modules/notifications/getters.js | 40 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/javascript/dashboard/components/layout/Sidebar.vue b/app/javascript/dashboard/components/layout/Sidebar.vue index 1290ea602..793a84e46 100644 --- a/app/javascript/dashboard/components/layout/Sidebar.vue +++ b/app/javascript/dashboard/components/layout/Sidebar.vue @@ -158,6 +158,7 @@ export default { this.$store.dispatch('notifications/unReadCount'); this.$store.dispatch('teams/get'); this.$store.dispatch('attributes/get'); + this.$store.dispatch('userNotificationSettings/get'); this.fetchCustomViews(); }, diff --git a/app/javascript/dashboard/store/modules/notifications/getters.js b/app/javascript/dashboard/store/modules/notifications/getters.js index 6e9464697..99f9cd1b3 100644 --- a/app/javascript/dashboard/store/modules/notifications/getters.js +++ b/app/javascript/dashboard/store/modules/notifications/getters.js @@ -1,14 +1,46 @@ +const NOTIFICATION_TYPES = { + conversation_creation: 1, + conversation_assignment: 2, + assigned_conversation_new_message: 3, + conversation_mention: 4, + participating_conversation_new_message: 5, +}; + +function getSubscribedNotificationTypes(pushFlags, emailFlags) { + return Object.keys(NOTIFICATION_TYPES).filter(notificationType => { + const emailFlag = `email_${notificationType}`; + const pushFlag = `push_${notificationType}`; + return pushFlags.includes(pushFlag) || emailFlags.includes(emailFlag); + }); +} + export const getters = { - getNotifications($state) { - return Object.values($state.records).sort((n1, n2) => n2.id - n1.id); + getNotifications($state, __, rootState) { + const notificationSettings = + rootState.userNotificationSettings.record || {}; + const pushFlags = notificationSettings.selected_push_flags || {}; + const emailFlags = notificationSettings.selected_email_flags || {}; + + const subscribedNotificationTypes = getSubscribedNotificationTypes( + pushFlags, + emailFlags + ); + + return Object.values($state.records) + .filter(notification => + subscribedNotificationTypes.includes(notification.notification_type) + ) + .sort((n1, n2) => n2.id - n1.id); }, + getUIFlags($state) { return $state.uiFlags; }, + getNotification: $state => id => { - const notification = $state.records[id]; - return notification || {}; + return $state.records[id] || {}; }, + getMeta: $state => { return $state.meta; },