Skip to content

Commit

Permalink
Experiment use markers for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Sep 10, 2023
1 parent fcfc61c commit 671c68b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/background-service.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/pages/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/pages/notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 671c68b

Please sign in to comment.