fix: only toast unread notifications, not archived ones

This commit is contained in:
Pujit Mehrotra
2025-02-03 13:06:27 -05:00
committed by Eli Bosley
parent ad32cffd75
commit 8251c6f2d3
2 changed files with 18 additions and 8 deletions

View File

@@ -103,10 +103,12 @@ export class NotificationsService {
const notification = await this.loadNotificationFile(path, NotificationType[type]);
this.increment(notification.importance, NotificationsService.overview[type.toLowerCase()]);
this.publishOverview();
pubsub.publish(PUBSUB_CHANNEL.NOTIFICATION_ADDED, {
notificationAdded: notification,
});
if (type === NotificationType.UNREAD) {
this.publishOverview();
pubsub.publish(PUBSUB_CHANNEL.NOTIFICATION_ADDED, {
notificationAdded: notification,
});
}
}
/**

View File

@@ -42,6 +42,12 @@ const { onResult: onNotificationAdded } = useSubscription(notificationAddedSubsc
onNotificationAdded(({ data }) => {
if (!data) return;
const notif = useFragment(NOTIFICATION_FRAGMENT, data.notificationAdded);
if (notif.type !== NotificationType.Unread) return;
// probably smart to leave this log outside the if-block for the initial release
console.log('incoming notification', notif);
if (!globalThis.toast) {
return;
}
const funcMapping: Record<Importance, (typeof globalThis)['toast']['info' | 'error' | 'warning']> = {
[Importance.Alert]: globalThis.toast.error,
@@ -51,10 +57,12 @@ onNotificationAdded(({ data }) => {
const toast = funcMapping[notif.importance];
const createOpener = () => ({ label: 'Open', onClick: () => location.assign(notif.link as string) });
toast(notif.title, {
description: notif.subject,
action: notif.link ? createOpener() : undefined,
});
requestAnimationFrame(() =>
toast(notif.title, {
description: notif.subject,
action: notif.link ? createOpener() : undefined,
})
);
});
const overview = computed(() => {