From 1c36d1b91cb8b0d19520c01cbaad4b3483f66189 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 8 Mar 2022 22:02:02 -0600 Subject: [PATCH] Store statuses as StatusRecord --- app/soapbox/normalizers/status.js | 36 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/soapbox/normalizers/status.js b/app/soapbox/normalizers/status.js index ab6ce6312..fc790d846 100644 --- a/app/soapbox/normalizers/status.js +++ b/app/soapbox/normalizers/status.js @@ -1,10 +1,10 @@ -import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; +import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable'; import { accountToMention } from 'soapbox/utils/accounts'; import { mergeDefined } from 'soapbox/utils/normalizers'; -// Some backends can return null, or omit these required fields -const baseStatus = ImmutableMap({ +const StatusRecord = Record({ + account: ImmutableMap(), application: null, bookmarked: false, card: null, @@ -14,14 +14,20 @@ const baseStatus = ImmutableMap({ favourites_count: 0, in_reply_to_account_id: null, in_reply_to_id: null, + id: '', language: null, + media_attachments: ImmutableList(), mentions: ImmutableList(), muted: false, pinned: false, + pleroma: ImmutableMap(), + poll: null, + quote: null, reblog: null, reblogged: false, reblogs_count: 0, replies_count: 0, + sensitive: false, spoiler_text: '', tags: ImmutableList(), uri: '', @@ -41,11 +47,6 @@ const basePoll = ImmutableMap({ votes_count: 0, }); -// Merge base status -const mergeBase = status => { - return status.mergeDeepWith(mergeDefined, baseStatus); -}; - // Ensure attachments have required fields // https://docs.joinmastodon.org/entities/attachment/ const normalizeAttachment = attachment => { @@ -147,13 +148,14 @@ const fixQuote = status => { }; export const normalizeStatus = status => { - return status.withMutations(status => { - mergeBase(status); - normalizeAttachments(status); - normalizeMentions(status); - normalizePoll(status); - fixMentionsOrder(status); - addSelfMention(status); - fixQuote(status); - }); + return StatusRecord( + status.withMutations(status => { + normalizeAttachments(status); + normalizeMentions(status); + normalizePoll(status); + fixMentionsOrder(status); + addSelfMention(status); + fixQuote(status); + }), + ); };