fix: Notification from unknown actor causes app crash

This commit is contained in:
Tom Moor
2023-05-22 09:31:18 -04:00
parent d587360f4b
commit 3c5dc10446
4 changed files with 43 additions and 39 deletions

View File

@@ -46,7 +46,7 @@ function NotificationListItem({ notification, onNavigate }: Props) {
<Flex column>
<Text as="div" size="small">
<Text as="span" weight="bold">
{notification.actor.name}
{notification.actor?.name ?? t("Unknown")}
</Text>{" "}
{notification.eventText(t)}{" "}
<Text as="span" weight="bold">

View File

@@ -12,6 +12,7 @@ import useStores from "~/hooks/useStores";
import { hover } from "~/styles";
import Desktop from "~/utils/Desktop";
import Empty from "../Empty";
import ErrorBoundary from "../ErrorBoundary";
import Flex from "../Flex";
import NudeButton from "../NudeButton";
import PaginatedList from "../PaginatedList";
@@ -47,45 +48,47 @@ function Notifications(
}, [notifications.approximateUnreadCount]);
return (
<Flex style={{ width: "100%" }} column>
<Header justify="space-between">
<Text weight="bold" as="span">
{t("Notifications")}
</Text>
<Text color="textSecondary" as={Flex} gap={8}>
{notifications.approximateUnreadCount > 0 && (
<Tooltip delay={500} tooltip={t("Mark all as read")}>
<Button action={markNotificationsAsRead} context={context}>
<MarkAsReadIcon />
<ErrorBoundary>
<Flex style={{ width: "100%" }} column>
<Header justify="space-between">
<Text weight="bold" as="span">
{t("Notifications")}
</Text>
<Text color="textSecondary" as={Flex} gap={8}>
{notifications.approximateUnreadCount > 0 && (
<Tooltip delay={500} tooltip={t("Mark all as read")}>
<Button action={markNotificationsAsRead} context={context}>
<MarkAsReadIcon />
</Button>
</Tooltip>
)}
<Tooltip delay={500} tooltip={t("Settings")}>
<Button action={navigateToNotificationSettings} context={context}>
<SettingsIcon />
</Button>
</Tooltip>
)}
<Tooltip delay={500} tooltip={t("Settings")}>
<Button action={navigateToNotificationSettings} context={context}>
<SettingsIcon />
</Button>
</Tooltip>
</Text>
</Header>
<React.Suspense fallback={null}>
<Scrollable ref={ref} flex topShadow>
<PaginatedList
fetch={notifications.fetchPage}
items={notifications.orderedData}
renderItem={(item: Notification) => (
<NotificationListItem
key={item.id}
notification={item}
onNavigate={onRequestClose}
/>
)}
/>
</Scrollable>
</React.Suspense>
{isEmpty && (
<EmptyNotifications>{t("No notifications yet")}.</EmptyNotifications>
)}
</Flex>
</Text>
</Header>
<React.Suspense fallback={null}>
<Scrollable ref={ref} flex topShadow>
<PaginatedList
fetch={notifications.fetchPage}
items={notifications.orderedData}
renderItem={(item: Notification) => (
<NotificationListItem
key={item.id}
notification={item}
onNavigate={onRequestClose}
/>
)}
/>
</Scrollable>
</React.Suspense>
{isEmpty && (
<EmptyNotifications>{t("No notifications yet")}.</EmptyNotifications>
)}
</Flex>
</ErrorBoundary>
);
}

View File

@@ -25,7 +25,7 @@ class Notification extends BaseModel {
@observable
archivedAt: Date | null;
actor: User;
actor?: User;
documentId?: string;

View File

@@ -205,6 +205,7 @@
"Sorry, an error occurred.": "Sorry, an error occurred.",
"Click to retry": "Click to retry",
"Back": "Back",
"Unknown": "Unknown",
"Mark all as read": "Mark all as read",
"No notifications yet": "No notifications yet",
"Documents": "Documents",