Keep routine events out of notifications
This commit is contained in:
1 parent
79c508be2b
commit
3bb1dda6bb
2 files changed
+41
-68
No files matched your search
@@ -89,16 +89,7 @@ export function notificationForEvent(event: DashboardEvent): NotificationDraft |
|
||||
href: `/conversations/${encodeURIComponent(event.payload.conversationId)}`,
|
||||
};
|
||||
case 'message.sent':
|
||||
return {
|
||||
id: event.id,
|
||||
occurredAt: event.occurredAt,
|
||||
title: `Message sent to u/${event.payload.recipient}`,
|
||||
message: 'The message was delivered successfully.',
|
||||
tone: 'success',
|
||||
href: event.payload.conversationId
|
||||
? `/conversations/${encodeURIComponent(event.payload.conversationId)}`
|
||||
: '/conversations',
|
||||
};
|
||||
return null;
|
||||
case 'message.failed':
|
||||
return {
|
||||
id: event.id,
|
||||
@@ -111,23 +102,17 @@ export function notificationForEvent(event: DashboardEvent): NotificationDraft |
|
||||
: '/operations',
|
||||
};
|
||||
case 'bot.status.changed':
|
||||
if (event.payload.status !== 'stopped') return null;
|
||||
return {
|
||||
id: event.id,
|
||||
occurredAt: event.occurredAt,
|
||||
title: `Bot ${event.payload.status}`,
|
||||
message: event.payload.reason ?? `The bot is now ${event.payload.status}.`,
|
||||
tone: event.payload.status === 'running' ? 'success' : event.payload.status === 'stopped' ? 'warning' : 'info',
|
||||
tone: 'warning',
|
||||
href: '/operations',
|
||||
};
|
||||
case 'sync.completed':
|
||||
return {
|
||||
id: event.id,
|
||||
occurredAt: event.occurredAt,
|
||||
title: `${titleCase(event.payload.kind)} sync complete`,
|
||||
message: `${event.payload.processed.toLocaleString()} items processed.`,
|
||||
tone: 'success',
|
||||
href: '/operations',
|
||||
};
|
||||
return null;
|
||||
case 'sync.failed':
|
||||
return {
|
||||
id: event.id,
|
||||
@@ -138,26 +123,25 @@ export function notificationForEvent(event: DashboardEvent): NotificationDraft |
|
||||
href: '/operations',
|
||||
};
|
||||
case 'rate-limit.changed':
|
||||
if (!event.payload.limited) return null;
|
||||
return {
|
||||
id: event.id,
|
||||
occurredAt: event.occurredAt,
|
||||
title: event.payload.limited ? 'Rate limit reached' : 'Rate limit cleared',
|
||||
message: event.payload.reason ?? (event.payload.limited
|
||||
? 'Sending will resume when the limit resets.'
|
||||
: 'The bot can send messages again.'),
|
||||
tone: event.payload.limited ? 'warning' : 'success',
|
||||
title: 'Rate limit reached',
|
||||
message: event.payload.reason ?? 'Sending will resume when the limit resets.',
|
||||
tone: 'warning',
|
||||
href: '/operations',
|
||||
};
|
||||
case 'reddit.session.changed':
|
||||
if (!['authenticated', 'expired', 'logged-out', 'error'].includes(event.payload.status)) return null;
|
||||
if (!['expired', 'logged-out', 'error'].includes(event.payload.status)) return null;
|
||||
return {
|
||||
id: event.id,
|
||||
occurredAt: event.occurredAt,
|
||||
title: event.payload.status === 'authenticated' ? 'Reddit account connected' : 'Reddit account needs attention',
|
||||
title: 'Reddit account needs attention',
|
||||
message: event.payload.reason ?? (event.payload.username
|
||||
? `Signed in as u/${event.payload.username}.`
|
||||
? `The session for u/${event.payload.username} changed to ${event.payload.status}.`
|
||||
: `Session status changed to ${event.payload.status}.`),
|
||||
tone: event.payload.status === 'authenticated' ? 'success' : 'error',
|
||||
tone: 'error',
|
||||
href: '/accounts',
|
||||
};
|
||||
case 'conversation.updated':
|
||||
@@ -168,34 +152,6 @@ export function notificationForEvent(event: DashboardEvent): NotificationDraft |
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toasts interrupt the operator, so reserve them for inbound activity and
|
||||
* states that need attention. Routine lifecycle and successful sync events
|
||||
* remain available in the notification centre without producing a pop-up.
|
||||
*/
|
||||
export function shouldToastForEvent(event: DashboardEvent): boolean {
|
||||
switch (event.type) {
|
||||
case 'reply.received':
|
||||
case 'media.received':
|
||||
case 'message.failed':
|
||||
case 'sync.failed':
|
||||
return true;
|
||||
case 'bot.status.changed':
|
||||
return event.payload.status === 'stopped';
|
||||
case 'rate-limit.changed':
|
||||
return event.payload.limited;
|
||||
case 'reddit.session.changed':
|
||||
return ['expired', 'logged-out', 'error'].includes(event.payload.status);
|
||||
case 'message.sent':
|
||||
case 'conversation.updated':
|
||||
case 'sync.started':
|
||||
case 'sync.progress':
|
||||
case 'sync.completed':
|
||||
case 'log.created':
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadNotifications(): NotificationItem[] {
|
||||
const storage = notificationStorage();
|
||||
if (!storage) return [];
|
||||
@@ -249,11 +205,9 @@ export function NotificationProvider({ children, realtime: realtimeOverride }: N
|
||||
setNotifications((current) => current.some((entry) => entry.id === item.id)
|
||||
? current
|
||||
: [item, ...current].slice(0, MAX_NOTIFICATIONS));
|
||||
if (shouldToastForEvent(event)) {
|
||||
setToasts((current) => current.some((entry) => entry.id === item.id)
|
||||
? current
|
||||
: [...current, item]);
|
||||
}
|
||||
setToasts((current) => current.some((entry) => entry.id === item.id)
|
||||
? current
|
||||
: [...current, item]);
|
||||
}), [realtime]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -359,7 +313,7 @@ export function NotificationViewport() {
|
||||
<div className="notification-empty">
|
||||
<span aria-hidden="true"><BellIcon /></span>
|
||||
<strong>All quiet</strong>
|
||||
<p>Replies, delivery updates, syncs, and account alerts will appear here.</p>
|
||||
<p>New replies, received images, and important account alerts will appear here.</p>
|
||||
</div>
|
||||
)}
|
||||
</aside>
|
||||
|
||||
Reference in new issue
Block a user