From 825fefdeb1b9b813cb34bcc66e2313da2a998113 Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Thu, 1 Jan 2026 23:36:13 -0600 Subject: [PATCH] refactor(notification): streamline notification handling by updating API endpoints, improving unread count logic, and enhancing notification click behavior --- .../frontend/components/NotificationBell.vue | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/meshchatx/src/frontend/components/NotificationBell.vue b/meshchatx/src/frontend/components/NotificationBell.vue index 71ec613..2c69f55 100644 --- a/meshchatx/src/frontend/components/NotificationBell.vue +++ b/meshchatx/src/frontend/components/NotificationBell.vue @@ -94,17 +94,9 @@
- {{ - notification.latest_message_preview ?? - notification.latest_message_title ?? - "No message preview" - }} + {{ notification.latest_message_preview ?? notification.content ?? "No preview" }}
@@ -145,14 +137,11 @@ export default { isDropdownOpen: false, isLoading: false, notifications: [], + unreadCount: 0, reloadInterval: null, }; }, - computed: { - unreadCount() { - return this.notifications.length; - }, - }, + computed: {}, beforeUnmount() { if (this.reloadInterval) { clearInterval(this.reloadInterval); @@ -182,15 +171,16 @@ export default { async loadNotifications() { this.isLoading = true; try { - const response = await window.axios.get(`/api/v1/lxmf/conversations`, { + const response = await window.axios.get(`/api/v1/notifications`, { params: { - filter_unread: true, + unread: true, limit: 10, }, }); - const newNotifications = response.data.conversations || []; + const newNotifications = response.data.notifications || []; this.notifications = newNotifications; + this.unreadCount = response.data.unread_count || 0; } catch (e) { console.error("Failed to load notifications", e); this.notifications = []; @@ -203,9 +193,14 @@ export default { return; } try { - const destination_hashes = this.notifications.map((n) => n.destination_hash); + const destination_hashes = this.notifications + .filter((n) => n.type === "lxmf_message") + .map((n) => n.destination_hash); + const notification_ids = this.notifications.filter((n) => n.type !== "lxmf_message").map((n) => n.id); + await window.axios.post("/api/v1/notifications/mark-as-viewed", { destination_hashes: destination_hashes, + notification_ids: notification_ids, }); } catch (e) { console.error("Failed to mark notifications as viewed", e); @@ -213,10 +208,17 @@ export default { }, onNotificationClick(notification) { this.closeDropdown(); - this.$router.push({ - name: "messages", - params: { destinationHash: notification.destination_hash }, - }); + if (notification.type === "lxmf_message") { + this.$router.push({ + name: "messages", + params: { destinationHash: notification.destination_hash }, + }); + } else if (notification.type === "telephone_missed_call") { + this.$router.push({ + name: "call", + query: { tab: "history" }, + }); + } }, formatTimeAgo(datetimeString) { return Utils.formatTimeAgo(datetimeString);