[Glitch] Fix notification screen crashing in rare cases where the status no longer exists

Port 0d85a79f19 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
pull/2813/head
Renaud Chaput 2024-08-14 08:47:15 +02:00 committed by Claire
parent cf96857038
commit 524fc8563b
5 changed files with 15 additions and 9 deletions

View File

@ -47,7 +47,7 @@ function dispatchAssociatedRecords(
fetchedAccounts.push(notification.moderation_warning.target_account); fetchedAccounts.push(notification.moderation_warning.target_account);
} }
if ('status' in notification) { if ('status' in notification && notification.status) {
fetchedStatuses.push(notification.status); fetchedStatuses.push(notification.status);
} }
}); });
@ -119,7 +119,7 @@ export const processNewNotificationForGroups = createAppAsyncThunk(
if ( if (
(notification.type === 'mention' || notification.type === 'update') && (notification.type === 'mention' || notification.type === 'update') &&
notification.status.filtered notification.status?.filtered
) { ) {
const filters = notification.status.filtered.filter((result) => const filters = notification.status.filtered.filter((result) =>
result.filter.context.includes('notifications'), result.filter.context.includes('notifications'),

View File

@ -60,12 +60,12 @@ export interface BaseNotificationGroupJSON {
interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON { interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON {
type: NotificationWithStatusType; type: NotificationWithStatusType;
status_id: string; status_id: string | null;
} }
interface NotificationWithStatusJSON extends BaseNotificationJSON { interface NotificationWithStatusJSON extends BaseNotificationJSON {
type: NotificationWithStatusType; type: NotificationWithStatusType;
status: ApiStatusJSON; status: ApiStatusJSON | null;
} }
interface ReportNotificationGroupJSON extends BaseNotificationGroupJSON { interface ReportNotificationGroupJSON extends BaseNotificationGroupJSON {

View File

@ -37,7 +37,11 @@ export const NotificationMention: React.FC<{
unread: boolean; unread: boolean;
}> = ({ notification, unread }) => { }> = ({ notification, unread }) => {
const [isDirect, isReply] = useAppSelector((state) => { const [isDirect, isReply] = useAppSelector((state) => {
const status = state.statuses.get(notification.statusId) as Status; const status = state.statuses.get(notification.statusId) as
| Status
| undefined;
if (!status) return [false, false] as const;
return [ return [
status.get('visibility') === 'direct', status.get('visibility') === 'direct',

View File

@ -26,7 +26,7 @@ export const NotificationWithStatus: React.FC<{
icon: IconProp; icon: IconProp;
iconId: string; iconId: string;
accountIds: string[]; accountIds: string[];
statusId: string; statusId: string | undefined;
count: number; count: number;
labelRenderer: LabelRenderer; labelRenderer: LabelRenderer;
unread: boolean; unread: boolean;
@ -80,6 +80,8 @@ export const NotificationWithStatus: React.FC<{
[dispatch, statusId], [dispatch, statusId],
); );
if (!statusId) return null;
return ( return (
<HotKeys handlers={handlers}> <HotKeys handlers={handlers}>
<div <div

View File

@ -21,7 +21,7 @@ interface BaseNotificationGroup
interface BaseNotificationWithStatus<Type extends NotificationWithStatusType> interface BaseNotificationWithStatus<Type extends NotificationWithStatusType>
extends BaseNotificationGroup { extends BaseNotificationGroup {
type: Type; type: Type;
statusId: string; statusId: string | undefined;
} }
interface BaseNotification<Type extends NotificationType> interface BaseNotification<Type extends NotificationType>
@ -126,7 +126,7 @@ export function createNotificationGroupFromJSON(
case 'update': { case 'update': {
const { status_id: statusId, ...groupWithoutStatus } = group; const { status_id: statusId, ...groupWithoutStatus } = group;
return { return {
statusId, statusId: statusId ?? undefined,
sampleAccountIds, sampleAccountIds,
...groupWithoutStatus, ...groupWithoutStatus,
}; };
@ -183,7 +183,7 @@ export function createNotificationGroupFromNotificationJSON(
case 'mention': case 'mention':
case 'poll': case 'poll':
case 'update': case 'update':
return { ...group, statusId: notification.status.id }; return { ...group, statusId: notification.status?.id };
case 'admin.report': case 'admin.report':
return { ...group, report: createReportFromJSON(notification.report) }; return { ...group, report: createReportFromJSON(notification.report) };
case 'severed_relationships': case 'severed_relationships':