From 8a3502bfa18c349861b088dfb87b91aa39c38121 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 29 Jan 2024 23:51:01 +0530 Subject: [PATCH] fix: mark all as read and mark comment as read --- crm/api/notifications.py | 56 ++++++++++++++++------- frontend/src/components/Notifications.vue | 16 +++---- frontend/src/stores/notifications.js | 33 ++++++------- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/crm/api/notifications.py b/crm/api/notifications.py index 61a6c02b..b20b75bf 100644 --- a/crm/api/notifications.py +++ b/crm/api/notifications.py @@ -1,6 +1,7 @@ import frappe from frappe.query_builder import Order + @frappe.whitelist() def get_notifications(): if frappe.session.user == "Guest": @@ -17,22 +18,43 @@ def get_notifications(): _notifications = [] for notification in notifications: - reference_doc = frappe.get_value("Comment", notification.comment, ['reference_doctype', 'reference_name']) - _notifications.append({ - "creation": notification.creation, - "from_user": { - "name": notification.from_user, - "full_name": frappe.get_value( - "User", notification.from_user, "full_name" - ), - }, - "type": notification.type, - "to_user": notification.to_user, - "read": notification.read, - "comment": notification.comment, - "reference_doctype": "deal" if reference_doc[0] == "CRM Deal" else "lead", - "reference_name": reference_doc[1], - "route_name": "Deal" if reference_doc[0] == "CRM Deal" else "Lead", - }) + reference_doc = frappe.get_value( + "Comment", notification.comment, ["reference_doctype", "reference_name"] + ) + _notifications.append( + { + "creation": notification.creation, + "from_user": { + "name": notification.from_user, + "full_name": frappe.get_value( + "User", notification.from_user, "full_name" + ), + }, + "type": notification.type, + "to_user": notification.to_user, + "read": notification.read, + "comment": notification.comment, + "reference_doctype": "deal" + if reference_doc[0] == "CRM Deal" + else "lead", + "reference_name": reference_doc[1], + "route_name": "Deal" if reference_doc[0] == "CRM Deal" else "Lead", + } + ) return _notifications + + +@frappe.whitelist() +def mark_as_read(user=None, comment=None): + if frappe.session.user == "Guest": + frappe.throw("Authentication failed", exc=frappe.AuthenticationError) + + user = user or frappe.session.user + filters = {"to_user": user, "read": False} + if comment: + filters["comment"] = comment + for n in frappe.get_all("CRM Notification", filters=filters): + d = frappe.get_doc("CRM Notification", n.name) + d.read = True + d.save() diff --git a/frontend/src/components/Notifications.vue b/frontend/src/components/Notifications.vue index ccb4bc7a..bed8e880 100644 --- a/frontend/src/components/Notifications.vue +++ b/frontend/src/components/Notifications.vue @@ -18,7 +18,7 @@