From 671c68b8f8436e982a094679cb25979c5343bb1b Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 10 Sep 2023 19:22:14 +0800 Subject: [PATCH] Experiment use markers for notifications --- src/components/background-service.jsx | 15 ++++++++++++++- src/pages/home.jsx | 9 +++++++++ src/pages/notifications.jsx | 9 +++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/background-service.jsx b/src/components/background-service.jsx index ecaad095..52a514a3 100644 --- a/src/components/background-service.jsx +++ b/src/components/background-service.jsx @@ -24,7 +24,20 @@ export default memo(function BackgroundService({ isLoggedIn }) { }); const { value: notifications } = await notificationsIterator.next(); if (notifications?.length) { - states.notificationsShowNew = true; + let lastReadId; + try { + const markers = await masto.v1.markers.fetch({ + timeline: 'notifications', + }); + lastReadId = markers?.notifications?.lastReadId; + } catch (e) {} + if (lastReadId) { + if (notifications[0].id !== lastReadId) { + states.notificationsShowNew = true; + } + } else { + states.notificationsShowNew = true; + } } } diff --git a/src/pages/home.jsx b/src/pages/home.jsx index c1bc8d43..5ab7458d 100644 --- a/src/pages/home.jsx +++ b/src/pages/home.jsx @@ -128,6 +128,15 @@ function NotificationsMenu({ anchorRef, state, onClose }) { states.notificationsLast = notifications[0]; states.notifications = groupedNotifications; + + // Update last read marker + masto.v1.markers + .create({ + notifications: { + lastReadId: notifications[0].id, + }, + }) + .catch(() => {}); } states.notificationsShowNew = false; diff --git a/src/pages/notifications.jsx b/src/pages/notifications.jsx index d60e7ef5..0788b557 100644 --- a/src/pages/notifications.jsx +++ b/src/pages/notifications.jsx @@ -73,6 +73,15 @@ function Notifications({ columnMode }) { if (firstLoad) { states.notificationsLast = notifications[0]; states.notifications = groupedNotifications; + + // Update last read marker + masto.v1.markers + .create({ + notifications: { + lastReadId: notifications[0].id, + }, + }) + .catch(() => {}); } else { states.notifications.push(...groupedNotifications); }