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': () =>
import('@iconify-icons/mingcute/arrow-down-circle-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({

View file

@ -18,6 +18,8 @@ const NOTIFICATION_ICONS = {
favourite: 'heart',
poll: 'poll',
update: 'pencil',
'admin.signup': 'account-edit',
'admin.report': 'account-warning',
};
/*
@ -54,6 +56,8 @@ const contentText = {
'favourite+reblog+account': (count) =>
`boosted & favourited ${count} of your posts.`,
'favourite+reblog_reply': 'boosted & favourited your reply.',
'admin.signup': 'signed up.',
'admin.report': 'reported a post.',
};
function Notification({ notification, instance, reload, isStatic }) {
@ -102,9 +106,14 @@ function Notification({ notification, instance, reload, isStatic }) {
} else {
text = contentText[type];
}
} else {
} else if (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') {
text = text(_statuses?.length || _accounts?.length);
}
@ -114,11 +123,14 @@ function Notification({ notification, instance, reload, isStatic }) {
return null;
}
const formattedCreatedAt =
notification.createdAt && new Date(notification.createdAt).toLocaleString();
return (
<div class={`notification notification-${type}`} tabIndex="0">
<div
class={`notification-type notification-${type}`}
title={new Date(notification.createdAt).toLocaleString()}
title={formattedCreatedAt}
>
{type === 'favourite+reblog' ? (
<>