fix: realtime notifications

This commit is contained in:
Shariq Ansari 2024-04-25 18:29:39 +05:30
parent a0260bfb41
commit 16d6f3d976
3 changed files with 20 additions and 3 deletions

View File

@ -1,9 +1,10 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
import frappe
from frappe.model.document import Document
class CRMNotification(Document):
pass
def on_update(self):
frappe.publish_realtime("crm_notification")

View File

@ -98,10 +98,13 @@ import MarkAsDoneIcon from '@/components/Icons/MarkAsDoneIcon.vue'
import NotificationsIcon from '@/components/Icons/NotificationsIcon.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import { notificationsStore } from '@/stores/notifications'
import { globalStore } from '@/stores/global'
import { timeAgo } from '@/utils'
import { onClickOutside } from '@vueuse/core'
import { Tooltip } from 'frappe-ui'
import { ref } from 'vue'
import { ref, onMounted, onBeforeUnmount } from 'vue'
const { $socket } = globalStore()
const target = ref(null)
onClickOutside(
@ -124,6 +127,16 @@ function mark_as_read(doc) {
notificationsStore().mark_doc_as_read(doc)
}
onBeforeUnmount(() => {
$socket.off('crm_notification')
})
onMounted(() => {
$socket.on('crm_notification', () => {
notificationsStore().notifications.reload()
})
})
function getRoute(notification) {
let params = {
leadId: notification.reference_name,
@ -139,4 +152,6 @@ function getRoute(notification) {
hash: '#' + notification.comment || notification.notification_type_doc,
}
}
onMounted(() => {})
</script>

View File

@ -36,6 +36,7 @@ export const notificationsStore = defineStore('crm-notifications', () => {
}
return {
notifications,
visible,
allNotifications,
unreadNotificationsCount,