diff --git a/app/soapbox/normalizers/status.ts b/app/soapbox/normalizers/status.ts index e200370991..fae88470a1 100644 --- a/app/soapbox/normalizers/status.ts +++ b/app/soapbox/normalizers/status.ts @@ -13,7 +13,7 @@ import { import { normalizeAttachment } from 'soapbox/normalizers/attachment'; import { normalizeEmoji } from 'soapbox/normalizers/emoji'; import { normalizeMention } from 'soapbox/normalizers/mention'; -import { accountSchema, cardSchema, pollSchema, tombstoneSchema } from 'soapbox/schemas'; +import { accountSchema, cardSchema, groupSchema, pollSchema, tombstoneSchema } from 'soapbox/schemas'; import type { Account, Attachment, Card, Emoji, Group, Mention, Poll, EmbeddedEntity } from 'soapbox/types/entities'; @@ -55,7 +55,7 @@ export const StatusRecord = ImmutableRecord({ favourited: false, favourites_count: 0, filtered: ImmutableList(), - group: null as EmbeddedEntity, + group: null as Group | null, in_reply_to_account_id: null as string | null, in_reply_to_id: null as string | null, id: '', @@ -252,6 +252,15 @@ const parseAccount = (status: ImmutableMap) => { } }; +const parseGroup = (status: ImmutableMap) => { + try { + const group = groupSchema.parse(status.get('group').toJS()); + return status.set('group', group); + } catch (_e) { + return status.set('group', null); + } +}; + export const normalizeStatus = (status: Record) => { return StatusRecord( ImmutableMap(fromJS(status)).withMutations(status => { @@ -270,6 +279,7 @@ export const normalizeStatus = (status: Record) => { normalizeDislikes(status); normalizeTombstone(status); parseAccount(status); + parseGroup(status); }), ); }; diff --git a/app/soapbox/reducers/statuses.ts b/app/soapbox/reducers/statuses.ts index 62b0ad01b8..8d8a7d35d1 100644 --- a/app/soapbox/reducers/statuses.ts +++ b/app/soapbox/reducers/statuses.ts @@ -59,7 +59,6 @@ export interface ReducerStatus extends StatusRecord { reblog: string | null poll: string | null quote: string | null - group: string | null } const minifyStatus = (status: StatusRecord): ReducerStatus => { @@ -67,7 +66,6 @@ const minifyStatus = (status: StatusRecord): ReducerStatus => { reblog: normalizeId(status.getIn(['reblog', 'id'])), poll: normalizeId(status.getIn(['poll', 'id'])), quote: normalizeId(status.getIn(['quote', 'id'])), - group: normalizeId(status.getIn(['group', 'id'])), }) as ReducerStatus; }; diff --git a/app/soapbox/selectors/index.ts b/app/soapbox/selectors/index.ts index 2d3c3ddc80..e0e605335c 100644 --- a/app/soapbox/selectors/index.ts +++ b/app/soapbox/selectors/index.ts @@ -7,7 +7,6 @@ import { import { createSelector } from 'reselect'; import { getSettings } from 'soapbox/actions/settings'; -import { Entities } from 'soapbox/entity-store/entities'; import { getDomain } from 'soapbox/utils/accounts'; import { validId } from 'soapbox/utils/auth'; import ConfigDB from 'soapbox/utils/config-db'; @@ -17,7 +16,7 @@ import { shouldFilter } from 'soapbox/utils/timelines'; import type { ContextType } from 'soapbox/normalizers/filter'; import type { ReducerChat } from 'soapbox/reducers/chats'; import type { RootState } from 'soapbox/store'; -import type { Filter as FilterEntity, Notification, Status, Group } from 'soapbox/types/entities'; +import type { Filter as FilterEntity, Notification, Status } from 'soapbox/types/entities'; const normalizeId = (id: any): string => typeof id === 'string' ? id : ''; @@ -113,31 +112,26 @@ export const makeGetStatus = () => { [ (state: RootState, { id }: APIStatus) => state.statuses.get(id) as Status | undefined, (state: RootState, { id }: APIStatus) => state.statuses.get(state.statuses.get(id)?.reblog || '') as Status | undefined, - (state: RootState, { id }: APIStatus) => state.entities[Entities.GROUPS]?.store[state.statuses.get(id)?.group || ''] as Group | undefined, (_state: RootState, { username }: APIStatus) => username, getFilters, (state: RootState) => state.me, (state: RootState) => getFeatures(state.instance), ], - (statusBase, statusReblog, group, username, filters, me, features) => { + (statusBase, statusReblog, username, filters, me, features) => { if (!statusBase) return null; - const accountBase = statusBase.account; + const { account } = statusBase; + const accountUsername = account.acct; - const accountUsername = accountBase.acct; - //Must be owner of status if username exists + // Must be owner of status if username exists. if (accountUsername !== username && username !== undefined) { return null; } return statusBase.withMutations((map: Status) => { map.set('reblog', statusReblog || null); - // @ts-ignore :( - map.set('account', accountBase || null); - // @ts-ignore - map.set('group', group || null); - if ((features.filters) && accountBase.id !== me) { + if ((features.filters) && account.id !== me) { const filtered = checkFiltered(statusReblog?.search_index || statusBase.search_index, filters); map.set('filtered', filtered);