diff --git a/app/javascript/flavours/glitch/actions/notification_groups.ts b/app/javascript/flavours/glitch/actions/notification_groups.ts index 3f6d14a978..e034792275 100644 --- a/app/javascript/flavours/glitch/actions/notification_groups.ts +++ b/app/javascript/flavours/glitch/actions/notification_groups.ts @@ -38,10 +38,6 @@ function dispatchAssociatedRecords( const fetchedStatuses: ApiStatusJSON[] = []; notifications.forEach((notification) => { - if ('sample_accounts' in notification) { - fetchedAccounts.push(...notification.sample_accounts); - } - if (notification.type === 'admin.report') { fetchedAccounts.push(notification.report.target_account); } @@ -75,7 +71,9 @@ export const fetchNotifications = createDataLoadingThunk( : excludeAllTypesExcept(activeFilter), }); }, - ({ notifications }, { dispatch }) => { + ({ notifications, accounts, statuses }, { dispatch }) => { + dispatch(importFetchedAccounts(accounts)); + dispatch(importFetchedStatuses(statuses)); dispatchAssociatedRecords(dispatch, notifications); const payload: (ApiNotificationGroupJSON | NotificationGap)[] = notifications; @@ -95,7 +93,9 @@ export const fetchNotificationsGap = createDataLoadingThunk( async (params: { gap: NotificationGap }) => apiFetchNotifications({ max_id: params.gap.maxId }), - ({ notifications }, { dispatch }) => { + ({ notifications, accounts, statuses }, { dispatch }) => { + dispatch(importFetchedAccounts(accounts)); + dispatch(importFetchedStatuses(statuses)); dispatchAssociatedRecords(dispatch, notifications); return { notifications }; diff --git a/app/javascript/flavours/glitch/api/notifications.ts b/app/javascript/flavours/glitch/api/notifications.ts index fe71878822..781f4b1dde 100644 --- a/app/javascript/flavours/glitch/api/notifications.ts +++ b/app/javascript/flavours/glitch/api/notifications.ts @@ -1,17 +1,24 @@ import api, { apiRequest, getLinks } from 'flavours/glitch/api'; -import type { ApiNotificationGroupJSON } from 'flavours/glitch/api_types/notifications'; +import type { ApiNotificationGroupsResultJSON } from 'flavours/glitch/api_types/notifications'; export const apiFetchNotifications = async (params?: { exclude_types?: string[]; max_id?: string; }) => { - const response = await api().request({ + const response = await api().request({ method: 'GET', url: '/api/v2_alpha/notifications', params, }); - return { notifications: response.data, links: getLinks(response) }; + const { statuses, accounts, notification_groups } = response.data; + + return { + statuses, + accounts, + notifications: notification_groups, + links: getLinks(response), + }; }; export const apiClearNotifications = () => diff --git a/app/javascript/flavours/glitch/api_types/notifications.ts b/app/javascript/flavours/glitch/api_types/notifications.ts index ea37556d8d..3e0d43bb23 100644 --- a/app/javascript/flavours/glitch/api_types/notifications.ts +++ b/app/javascript/flavours/glitch/api_types/notifications.ts @@ -51,7 +51,7 @@ export interface BaseNotificationGroupJSON { group_key: string; notifications_count: number; type: NotificationType; - sample_accounts: ApiAccountJSON[]; + sample_account_ids: string[]; latest_page_notification_at: string; // FIXME: This will only be present if the notification group is returned in a paginated list, not requested directly most_recent_notification_id: string; page_min_id?: string; @@ -143,3 +143,9 @@ export type ApiNotificationGroupJSON = | AccountRelationshipSeveranceNotificationGroupJSON | NotificationGroupWithStatusJSON | ModerationWarningNotificationGroupJSON; + +export interface ApiNotificationGroupsResultJSON { + accounts: ApiAccountJSON[]; + statuses: ApiStatusJSON[]; + notification_groups: ApiNotificationGroupJSON[]; +} diff --git a/app/javascript/flavours/glitch/models/notification_group.ts b/app/javascript/flavours/glitch/models/notification_group.ts index 6c8b8eb6e3..448487915d 100644 --- a/app/javascript/flavours/glitch/models/notification_group.ts +++ b/app/javascript/flavours/glitch/models/notification_group.ts @@ -14,7 +14,7 @@ import type { ApiReportJSON } from 'flavours/glitch/api_types/reports'; export const NOTIFICATIONS_GROUP_MAX_AVATARS = 8; interface BaseNotificationGroup - extends Omit { + extends Omit { sampleAccountIds: string[]; } @@ -115,8 +115,7 @@ function createAccountRelationshipSeveranceEventFromJSON( export function createNotificationGroupFromJSON( groupJson: ApiNotificationGroupJSON, ): NotificationGroup { - const { sample_accounts, ...group } = groupJson; - const sampleAccountIds = sample_accounts.map((account) => account.id); + const { sample_account_ids: sampleAccountIds, ...group } = groupJson; switch (group.type) { case 'favourite':