Handle admin notifications & unhandled ones

This commit is contained in:
Lim Chee Aun 2023-09-05 09:19:11 +08:00
parent 20dd843409
commit 4fede554e4
2 changed files with 16 additions and 2 deletions

View file

@ -95,6 +95,8 @@ export const ICONS = {
'arrow-down-circle': () => 'arrow-down-circle': () =>
import('@iconify-icons/mingcute/arrow-down-circle-line'), import('@iconify-icons/mingcute/arrow-down-circle-line'),
clipboard: () => import('@iconify-icons/mingcute/clipboard-line'), clipboard: () => import('@iconify-icons/mingcute/clipboard-line'),
'account-edit': () => import('@iconify-icons/mingcute/user-edit-line'),
'account-warning': () => import('@iconify-icons/mingcute/user-warning-line'),
}; };
function Icon({ function Icon({

View file

@ -18,6 +18,8 @@ const NOTIFICATION_ICONS = {
favourite: 'heart', favourite: 'heart',
poll: 'poll', poll: 'poll',
update: 'pencil', update: 'pencil',
'admin.signup': 'account-edit',
'admin.report': 'account-warning',
}; };
/* /*
@ -54,6 +56,8 @@ const contentText = {
'favourite+reblog+account': (count) => 'favourite+reblog+account': (count) =>
`boosted & favourited ${count} of your posts.`, `boosted & favourited ${count} of your posts.`,
'favourite+reblog_reply': 'boosted & favourited your reply.', 'favourite+reblog_reply': 'boosted & favourited your reply.',
'admin.signup': 'signed up.',
'admin.report': 'reported a post.',
}; };
function Notification({ notification, instance, reload, isStatic }) { function Notification({ notification, instance, reload, isStatic }) {
@ -102,9 +106,14 @@ function Notification({ notification, instance, reload, isStatic }) {
} else { } else {
text = contentText[type]; text = contentText[type];
} }
} else { } else if (contentText[type]) {
text = contentText[type]; text = contentText[type];
} else {
// Anticipate unhandled notification types, possibly from Mastodon forks or non-Mastodon instances
// This surfaces the error to the user, hoping that users will report it
text = `[Unknown notification type: ${type}]`;
} }
if (typeof text === 'function') { if (typeof text === 'function') {
text = text(_statuses?.length || _accounts?.length); text = text(_statuses?.length || _accounts?.length);
} }
@ -114,11 +123,14 @@ function Notification({ notification, instance, reload, isStatic }) {
return null; return null;
} }
const formattedCreatedAt =
notification.createdAt && new Date(notification.createdAt).toLocaleString();
return ( return (
<div class={`notification notification-${type}`} tabIndex="0"> <div class={`notification notification-${type}`} tabIndex="0">
<div <div
class={`notification-type notification-${type}`} class={`notification-type notification-${type}`}
title={new Date(notification.createdAt).toLocaleString()} title={formattedCreatedAt}
> >
{type === 'favourite+reblog' ? ( {type === 'favourite+reblog' ? (
<> <>