From 8167b72762051c9a38553d8a4bcd435ab7891471 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 16 Mar 2022 21:33:09 -0500 Subject: [PATCH] Call fromJS in all normalizers --- .../normalizers/__tests__/account-test.js | 38 +++++++++---------- .../normalizers/__tests__/attachment-test.js | 6 +-- .../normalizers/__tests__/card-test.js | 4 +- .../normalizers/__tests__/instance-test.js | 16 ++++---- .../normalizers/__tests__/mention-test.js | 6 +-- .../__tests__/notification-test.js | 4 +- .../normalizers/__tests__/poll-test.js | 8 ++-- .../normalizers/__tests__/status-test.js | 28 +++++++------- app/soapbox/normalizers/account.ts | 5 ++- app/soapbox/normalizers/attachment.ts | 13 +++++-- app/soapbox/normalizers/card.ts | 8 ++-- app/soapbox/normalizers/emoji.ts | 8 ++-- app/soapbox/normalizers/instance.ts | 11 +++--- app/soapbox/normalizers/mention.ts | 7 +--- app/soapbox/normalizers/notification.ts | 7 +++- app/soapbox/normalizers/poll.ts | 5 ++- app/soapbox/normalizers/status.ts | 5 ++- 17 files changed, 97 insertions(+), 82 deletions(-) diff --git a/app/soapbox/normalizers/__tests__/account-test.js b/app/soapbox/normalizers/__tests__/account-test.js index 9211a1cf8..538e2eb6b 100644 --- a/app/soapbox/normalizers/__tests__/account-test.js +++ b/app/soapbox/normalizers/__tests__/account-test.js @@ -6,7 +6,7 @@ const AVATAR_MISSING = require('images/avatar-missing.png'); describe('normalizeAccount()', () => { it('adds base fields', () => { - const account = fromJS({}); + const account = {}; const result = normalizeAccount(account); expect(ImmutableRecord.isRecord(result)).toBe(true); @@ -16,12 +16,12 @@ describe('normalizeAccount()', () => { }); it('normalizes a mention', () => { - const mention = fromJS({ + const mention = { acct: 'NEETzsche@iddqd.social', id: '9v5bw7hEGBPc9nrpzc', url: 'https://iddqd.social/users/NEETzsche', username: 'NEETzsche', - }); + }; const result = normalizeAccount(mention); expect(result.emojis).toEqual(fromJS([])); @@ -32,21 +32,21 @@ describe('normalizeAccount()', () => { }); it('normalizes Fedibird birthday', () => { - const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json')); + const account = require('soapbox/__fixtures__/fedibird-account.json'); const result = normalizeAccount(account); expect(result.birthday).toEqual('1993-07-03'); }); it('normalizes Pleroma birthday', () => { - const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); + const account = require('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.birthday).toEqual('1993-07-03'); }); it('normalizes Pleroma legacy fields', () => { - const account = fromJS(require('soapbox/__fixtures__/pleroma-2.2.2-account.json')); + const account = require('soapbox/__fixtures__/pleroma-2.2.2-account.json'); const result = normalizeAccount(account); expect(result.getIn(['pleroma', 'is_active'])).toBe(true); @@ -57,7 +57,7 @@ describe('normalizeAccount()', () => { }); it('prefers new Pleroma fields', () => { - const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); + const account = require('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.getIn(['pleroma', 'is_active'])).toBe(true); @@ -66,76 +66,76 @@ describe('normalizeAccount()', () => { }); it('normalizes a verified Pleroma user', () => { - const account = fromJS(require('soapbox/__fixtures__/mk.json')); + const account = require('soapbox/__fixtures__/mk.json'); const result = normalizeAccount(account); expect(result.verified).toBe(true); }); it('normalizes an unverified Pleroma user', () => { - const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); + const account = require('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.verified).toBe(false); }); it('normalizes a verified Truth Social user', () => { - const account = fromJS(require('soapbox/__fixtures__/realDonaldTrump.json')); + const account = require('soapbox/__fixtures__/realDonaldTrump.json'); const result = normalizeAccount(account); expect(result.verified).toBe(true); }); it('normalizes Fedibird location', () => { - const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json')); + const account = require('soapbox/__fixtures__/fedibird-account.json'); const result = normalizeAccount(account); expect(result.location).toBe('Texas, USA'); }); it('normalizes Truth Social location', () => { - const account = fromJS(require('soapbox/__fixtures__/truthsocial-account.json')); + const account = require('soapbox/__fixtures__/truthsocial-account.json'); const result = normalizeAccount(account); expect(result.location).toBe('Texas'); }); it('sets display_name from username', () => { - const account = fromJS({ username: 'alex' }); + const account = { username: 'alex' }; const result = normalizeAccount(account); expect(result.display_name).toBe('alex'); }); it('sets display_name from acct', () => { - const account = fromJS({ acct: 'alex@gleasonator.com' }); + const account = { acct: 'alex@gleasonator.com' }; const result = normalizeAccount(account); expect(result.display_name).toBe('alex'); }); it('overrides a whitespace display_name', () => { - const account = fromJS({ username: 'alex', display_name: ' ' }); + const account = { username: 'alex', display_name: ' ' }; const result = normalizeAccount(account); expect(result.display_name).toBe('alex'); }); it('emojifies display name as `display_name_html`', () => { - const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); + const account = require('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); const expected = 'Alex Gleason 😂 :soapbox: :ablobcatrainbow:'; expect(result.display_name_html).toBe(expected); }); it('emojifies note as `note_emojified`', () => { - const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); + const account = require('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); const expected = 'I create Fediverse software that empowers people online. :soapbox:

I'm vegan btw

Note: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.'; expect(result.note_emojified).toBe(expected); }); it('unescapes HTML note as `note_plain`', () => { - const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); + const account = require('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); const expected = 'I create Fediverse software that empowers people online. :soapbox:\n\nI\'m vegan btw\n\nNote: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.'; expect(result.note_plain).toBe(expected); }); it('emojifies custom profile field', () => { - const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); + const account = require('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); const field = result.fields.get(1); diff --git a/app/soapbox/normalizers/__tests__/attachment-test.js b/app/soapbox/normalizers/__tests__/attachment-test.js index ecf3813e7..9647a55fa 100644 --- a/app/soapbox/normalizers/__tests__/attachment-test.js +++ b/app/soapbox/normalizers/__tests__/attachment-test.js @@ -1,10 +1,10 @@ -import { Record as ImmutableRecord, fromJS } from 'immutable'; +import { Record as ImmutableRecord } from 'immutable'; import { normalizeAttachment } from '../attachment'; describe('normalizeAttachment()', () => { it('adds base fields', () => { - const attachment = fromJS({}); + const attachment = {}; const result = normalizeAttachment(attachment); expect(ImmutableRecord.isRecord(result)).toBe(true); @@ -13,7 +13,7 @@ describe('normalizeAttachment()', () => { }); it('infers preview_url from url', () => { - const attachment = fromJS({ url: 'https://site.fedi/123.png' }); + const attachment = { url: 'https://site.fedi/123.png' }; const result = normalizeAttachment(attachment); expect(result.preview_url).toEqual('https://site.fedi/123.png'); diff --git a/app/soapbox/normalizers/__tests__/card-test.js b/app/soapbox/normalizers/__tests__/card-test.js index e8ac120b0..fc8d06221 100644 --- a/app/soapbox/normalizers/__tests__/card-test.js +++ b/app/soapbox/normalizers/__tests__/card-test.js @@ -1,10 +1,10 @@ -import { Record as ImmutableRecord, fromJS } from 'immutable'; +import { Record as ImmutableRecord } from 'immutable'; import { normalizeCard } from '../card'; describe('normalizeCard()', () => { it('adds base fields', () => { - const card = fromJS({}); + const card = {}; const result = normalizeCard(card); expect(ImmutableRecord.isRecord(result)).toBe(true); diff --git a/app/soapbox/normalizers/__tests__/instance-test.js b/app/soapbox/normalizers/__tests__/instance-test.js index 597fbbeee..2df36734f 100644 --- a/app/soapbox/normalizers/__tests__/instance-test.js +++ b/app/soapbox/normalizers/__tests__/instance-test.js @@ -59,7 +59,7 @@ describe('normalizeInstance()', () => { }); it('normalizes Pleroma instance with Mastodon configuration format', () => { - const instance = fromJS(require('soapbox/__fixtures__/pleroma-instance.json')); + const instance = require('soapbox/__fixtures__/pleroma-instance.json'); const expected = { configuration: { @@ -81,7 +81,7 @@ describe('normalizeInstance()', () => { }); it('normalizes Mastodon instance with retained configuration', () => { - const instance = fromJS(require('soapbox/__fixtures__/mastodon-instance.json')); + const instance = require('soapbox/__fixtures__/mastodon-instance.json'); const expected = { configuration: { @@ -111,7 +111,7 @@ describe('normalizeInstance()', () => { }); it('normalizes Mastodon 3.0.0 instance with default configuration', () => { - const instance = fromJS(require('soapbox/__fixtures__/mastodon-3.0.0-instance.json')); + const instance = require('soapbox/__fixtures__/mastodon-3.0.0-instance.json'); const expected = { configuration: { @@ -133,18 +133,18 @@ describe('normalizeInstance()', () => { }); it('normalizes Fedibird instance', () => { - const instance = fromJS(require('soapbox/__fixtures__/fedibird-instance.json')); + const instance = require('soapbox/__fixtures__/fedibird-instance.json'); const result = normalizeInstance(instance); // Sets description_limit expect(result.description_limit).toEqual(1500); // Preserves fedibird_capabilities - expect(result.fedibird_capabilities).toEqual(instance.get('fedibird_capabilities')); + expect(result.fedibird_capabilities).toEqual(fromJS(instance.fedibird_capabilities)); }); it('normalizes Mitra instance', () => { - const instance = fromJS(require('soapbox/__fixtures__/mitra-instance.json')); + const instance = require('soapbox/__fixtures__/mitra-instance.json'); const result = normalizeInstance(instance); // Adds configuration and description_limit @@ -153,7 +153,7 @@ describe('normalizeInstance()', () => { }); it('normalizes GoToSocial instance', () => { - const instance = fromJS(require('soapbox/__fixtures__/gotosocial-instance.json')); + const instance = require('soapbox/__fixtures__/gotosocial-instance.json'); const result = normalizeInstance(instance); // Normalizes max_toot_chars @@ -166,7 +166,7 @@ describe('normalizeInstance()', () => { }); it('normalizes Friendica instance', () => { - const instance = fromJS(require('soapbox/__fixtures__/friendica-instance.json')); + const instance = require('soapbox/__fixtures__/friendica-instance.json'); const result = normalizeInstance(instance); // Normalizes max_toot_chars diff --git a/app/soapbox/normalizers/__tests__/mention-test.js b/app/soapbox/normalizers/__tests__/mention-test.js index e429a03b1..03d712175 100644 --- a/app/soapbox/normalizers/__tests__/mention-test.js +++ b/app/soapbox/normalizers/__tests__/mention-test.js @@ -1,10 +1,10 @@ -import { Record as ImmutableRecord, fromJS } from 'immutable'; +import { Record as ImmutableRecord } from 'immutable'; import { normalizeMention } from '../mention'; describe('normalizeMention()', () => { it('adds base fields', () => { - const account = fromJS({}); + const account = {}; const result = normalizeMention(account); expect(ImmutableRecord.isRecord(result)).toBe(true); @@ -15,7 +15,7 @@ describe('normalizeMention()', () => { }); it('infers username from acct', () => { - const account = fromJS({ acct: 'alex@gleasonator.com' }); + const account = { acct: 'alex@gleasonator.com' }; const result = normalizeMention(account); expect(result.username).toEqual('alex'); diff --git a/app/soapbox/normalizers/__tests__/notification-test.js b/app/soapbox/normalizers/__tests__/notification-test.js index c90b5451e..b72f0d9aa 100644 --- a/app/soapbox/normalizers/__tests__/notification-test.js +++ b/app/soapbox/normalizers/__tests__/notification-test.js @@ -1,10 +1,10 @@ -import { Record as ImmutableRecord, fromJS } from 'immutable'; +import { Record as ImmutableRecord } from 'immutable'; import { normalizeNotification } from '../notification'; describe('normalizeNotification()', () => { it('normalizes an empty map', () => { - const notification = fromJS({}); + const notification = {}; const result = normalizeNotification(notification); expect(ImmutableRecord.isRecord(result)).toBe(true); diff --git a/app/soapbox/normalizers/__tests__/poll-test.js b/app/soapbox/normalizers/__tests__/poll-test.js index 4cc9dbbbc..31691f484 100644 --- a/app/soapbox/normalizers/__tests__/poll-test.js +++ b/app/soapbox/normalizers/__tests__/poll-test.js @@ -1,10 +1,10 @@ -import { Record as ImmutableRecord, fromJS } from 'immutable'; +import { Record as ImmutableRecord } from 'immutable'; import { normalizePoll } from '../poll'; describe('normalizePoll()', () => { it('adds base fields', () => { - const poll = fromJS({ options: [{ title: 'Apples' }] }); + const poll = { options: [{ title: 'Apples' }] }; const result = normalizePoll(poll); const expected = { @@ -25,7 +25,7 @@ describe('normalizePoll()', () => { }); it('normalizes a Pleroma logged-out poll', () => { - const poll = fromJS(require('soapbox/__fixtures__/pleroma-status-with-poll.json')).get('poll'); + const { poll } = require('soapbox/__fixtures__/pleroma-status-with-poll.json'); const result = normalizePoll(poll); // Adds logged-in fields @@ -34,7 +34,7 @@ describe('normalizePoll()', () => { }); it('normalizes poll with emojis', () => { - const poll = fromJS(require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json')).get('poll'); + const { poll } = require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); const result = normalizePoll(poll); // Emojifies poll options diff --git a/app/soapbox/normalizers/__tests__/status-test.js b/app/soapbox/normalizers/__tests__/status-test.js index 2824615cc..ebfcb3eee 100644 --- a/app/soapbox/normalizers/__tests__/status-test.js +++ b/app/soapbox/normalizers/__tests__/status-test.js @@ -4,7 +4,7 @@ import { normalizeStatus } from '../status'; describe('normalizeStatus()', () => { it('adds base fields', () => { - const status = fromJS({}); + const status = {}; const result = normalizeStatus(status); expect(ImmutableRecord.isRecord(result)).toBe(true); @@ -17,7 +17,7 @@ describe('normalizeStatus()', () => { }); it('fixes the order of mentions', () => { - const status = fromJS(require('soapbox/__fixtures__/status-unordered-mentions.json')); + const status = require('soapbox/__fixtures__/status-unordered-mentions.json'); const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden']; @@ -30,7 +30,7 @@ describe('normalizeStatus()', () => { }); it('adds mention to self in self-reply on Mastodon', () => { - const status = fromJS(require('soapbox/__fixtures__/mastodon-reply-to-self.json')); + const status = require('soapbox/__fixtures__/mastodon-reply-to-self.json'); const expected = { id: '106801667066418367', @@ -48,7 +48,7 @@ describe('normalizeStatus()', () => { }); it('normalizes mentions with only acct', () => { - const status = fromJS({ mentions: [{ acct: 'alex@gleasonator.com' }] }); + const status = { mentions: [{ acct: 'alex@gleasonator.com' }] }; const expected = [{ id: '', @@ -63,7 +63,7 @@ describe('normalizeStatus()', () => { }); it('normalizes Mitra attachments', () => { - const status = fromJS(require('soapbox/__fixtures__/mitra-status-with-attachments.json')); + const status = require('soapbox/__fixtures__/mitra-status-with-attachments.json'); const expected = [{ id: '017eeb0e-e5df-30a4-77a7-a929145cb836', @@ -97,7 +97,7 @@ describe('normalizeStatus()', () => { }); it('leaves Pleroma attachments alone', () => { - const status = fromJS(require('soapbox/__fixtures__/pleroma-status-with-attachments.json')); + const status = require('soapbox/__fixtures__/pleroma-status-with-attachments.json'); const result = normalizeStatus(status).media_attachments; expect(result.size).toBe(4); @@ -108,15 +108,15 @@ describe('normalizeStatus()', () => { }); it('normalizes Pleroma quote post', () => { - const status = fromJS(require('soapbox/__fixtures__/pleroma-quote-post.json')); + const status = require('soapbox/__fixtures__/pleroma-quote-post.json'); const result = normalizeStatus(status); - expect(result.quote).toEqual(status.getIn(['pleroma', 'quote'])); + expect(result.quote).toEqual(fromJS(status.pleroma.quote)); expect(result.pleroma.get('quote')).toBe(undefined); }); it('normalizes GoToSocial status', () => { - const status = fromJS(require('soapbox/__fixtures__/gotosocial-status.json')); + const status = require('soapbox/__fixtures__/gotosocial-status.json'); const result = normalizeStatus(status); // Adds missing fields @@ -132,7 +132,7 @@ describe('normalizeStatus()', () => { }); it('normalizes Friendica status', () => { - const status = fromJS(require('soapbox/__fixtures__/friendica-status.json')); + const status = require('soapbox/__fixtures__/friendica-status.json'); const result = normalizeStatus(status); // Adds missing fields @@ -145,7 +145,7 @@ describe('normalizeStatus()', () => { }); it('normalizes poll and poll options', () => { - const status = fromJS({ poll: { options: [{ title: 'Apples' }] } }); + const status = { poll: { options: [{ title: 'Apples' }] } }; const result = normalizeStatus(status); const expected = { @@ -166,7 +166,7 @@ describe('normalizeStatus()', () => { }); it('normalizes a Pleroma logged-out poll', () => { - const status = fromJS(require('soapbox/__fixtures__/pleroma-status-with-poll.json')); + const status = require('soapbox/__fixtures__/pleroma-status-with-poll.json'); const result = normalizeStatus(status); // Adds logged-in fields @@ -175,7 +175,7 @@ describe('normalizeStatus()', () => { }); it('normalizes poll with emojis', () => { - const status = fromJS(require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json')); + const status = require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); const result = normalizeStatus(status); // Emojifies poll options @@ -188,7 +188,7 @@ describe('normalizeStatus()', () => { }); it('normalizes a card', () => { - const status = fromJS(require('soapbox/__fixtures__/status-with-card.json')); + const status = require('soapbox/__fixtures__/status-with-card.json'); const result = normalizeStatus(status); expect(ImmutableRecord.isRecord(result.card)).toBe(true); diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index 2a8a1748b..feb443f59 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -8,6 +8,7 @@ import { Map as ImmutableMap, List as ImmutableList, Record as ImmutableRecord, + fromJS, } from 'immutable'; import emojify from 'soapbox/features/emoji/emoji'; @@ -181,9 +182,9 @@ const addInternalFields = (account: ImmutableMap) => { }); }; -export const normalizeAccount = (account: ImmutableMap): IAccount => { +export const normalizeAccount = (account: Record): IAccount => { return AccountRecord( - account.withMutations(account => { + ImmutableMap(fromJS(account)).withMutations(account => { normalizePleromaLegacyFields(account); normalizeEmojis(account); normalizeAvatar(account); diff --git a/app/soapbox/normalizers/attachment.ts b/app/soapbox/normalizers/attachment.ts index f25f09581..adb596dd0 100644 --- a/app/soapbox/normalizers/attachment.ts +++ b/app/soapbox/normalizers/attachment.ts @@ -6,6 +6,7 @@ import { Map as ImmutableMap, Record as ImmutableRecord, + fromJS, } from 'immutable'; import { mergeDefined } from 'soapbox/utils/normalizers'; @@ -28,8 +29,7 @@ export const AttachmentRecord = ImmutableRecord({ status: null, }); -// Ensure attachments have required fields -export const normalizeAttachment = (attachment: ImmutableMap) => { +const normalizeUrls = (attachment: ImmutableMap) => { const url = [ attachment.get('url'), attachment.get('preview_url'), @@ -41,5 +41,12 @@ export const normalizeAttachment = (attachment: ImmutableMap) => { preview_url: url, }); - return AttachmentRecord(attachment.mergeWith(mergeDefined, base)); + return attachment.mergeWith(mergeDefined, base); +}; + +// Ensure attachments have required fields +export const normalizeAttachment = (attachment: Record) => { + return AttachmentRecord( + normalizeUrls(ImmutableMap(fromJS(attachment))), + ); }; diff --git a/app/soapbox/normalizers/card.ts b/app/soapbox/normalizers/card.ts index 0ae1f0b0f..169492647 100644 --- a/app/soapbox/normalizers/card.ts +++ b/app/soapbox/normalizers/card.ts @@ -3,7 +3,7 @@ * Converts API cards into our internal format. * @see {@link https://docs.joinmastodon.org/entities/card/} */ -import { Record as ImmutableRecord, Map as ImmutableMap } from 'immutable'; +import { Record as ImmutableRecord, Map as ImmutableMap, fromJS } from 'immutable'; // https://docs.joinmastodon.org/entities/card/ export const CardRecord = ImmutableRecord({ @@ -23,6 +23,8 @@ export const CardRecord = ImmutableRecord({ width: 0, }); -export const normalizeCard = (card: ImmutableMap) => { - return CardRecord(card); +export const normalizeCard = (card: Record) => { + return CardRecord( + ImmutableMap(fromJS(card)), + ); }; diff --git a/app/soapbox/normalizers/emoji.ts b/app/soapbox/normalizers/emoji.ts index 133d294d1..8d973b175 100644 --- a/app/soapbox/normalizers/emoji.ts +++ b/app/soapbox/normalizers/emoji.ts @@ -3,7 +3,7 @@ * Converts API emojis into our internal format. * @see {@link https://docs.joinmastodon.org/entities/emoji/} */ -import { Record as ImmutableRecord, Map as ImmutableMap } from 'immutable'; +import { Record as ImmutableRecord, Map as ImmutableMap, fromJS } from 'immutable'; // https://docs.joinmastodon.org/entities/emoji/ export const EmojiRecord = ImmutableRecord({ @@ -14,6 +14,8 @@ export const EmojiRecord = ImmutableRecord({ visible_in_picker: true, }); -export const normalizeEmoji = (emoji: ImmutableMap) => { - return EmojiRecord(emoji); +export const normalizeEmoji = (emoji: Record) => { + return EmojiRecord( + ImmutableMap(fromJS(emoji)), + ); }; diff --git a/app/soapbox/normalizers/instance.ts b/app/soapbox/normalizers/instance.ts index aded8075d..6e2c0b4f9 100644 --- a/app/soapbox/normalizers/instance.ts +++ b/app/soapbox/normalizers/instance.ts @@ -7,6 +7,7 @@ import { Map as ImmutableMap, List as ImmutableList, Record as ImmutableRecord, + fromJS, } from 'immutable'; import { parseVersion, PLEROMA } from 'soapbox/utils/features'; @@ -84,12 +85,12 @@ const pleromaToMastodonConfig = (instance: ImmutableMap) => { const getAttachmentLimit = (software: string) => software === PLEROMA ? Infinity : 4; // Normalize instance (Pleroma, Mastodon, etc.) to Mastodon's format -export const normalizeInstance = (instance: ImmutableMap) => { - const { software } = parseVersion(instance.get('version')); - const mastodonConfig = pleromaToMastodonConfig(instance); - +export const normalizeInstance = (instance: Record) => { return InstanceRecord( - instance.withMutations(instance => { + ImmutableMap(fromJS(instance)).withMutations((instance: ImmutableMap) => { + const { software } = parseVersion(instance.get('version')); + const mastodonConfig = pleromaToMastodonConfig(instance); + // Merge configuration instance.update('configuration', ImmutableMap(), configuration => ( configuration.mergeDeepWith(mergeDefined, mastodonConfig) diff --git a/app/soapbox/normalizers/mention.ts b/app/soapbox/normalizers/mention.ts index 266f22dc6..5ff35ce16 100644 --- a/app/soapbox/normalizers/mention.ts +++ b/app/soapbox/normalizers/mention.ts @@ -3,10 +3,7 @@ * Converts API mentions into our internal format. * @see {@link https://docs.joinmastodon.org/entities/mention/} */ -import { - Map as ImmutableMap, - Record as ImmutableRecord, -} from 'immutable'; +import { Record as ImmutableRecord } from 'immutable'; import { normalizeAccount } from 'soapbox/normalizers/account'; @@ -18,7 +15,7 @@ export const MentionRecord = ImmutableRecord({ url: '', }); -export const normalizeMention = (mention: ImmutableMap) => { +export const normalizeMention = (mention: Record) => { // Simply normalize it as an account then cast it as a mention ¯\_(ツ)_/¯ return MentionRecord(normalizeAccount(mention)); }; diff --git a/app/soapbox/normalizers/notification.ts b/app/soapbox/normalizers/notification.ts index b05b50148..defd51215 100644 --- a/app/soapbox/normalizers/notification.ts +++ b/app/soapbox/normalizers/notification.ts @@ -6,6 +6,7 @@ import { Map as ImmutableMap, Record as ImmutableRecord, + fromJS, } from 'immutable'; // https://docs.joinmastodon.org/entities/notification/ @@ -20,6 +21,8 @@ export const NotificationRecord = ImmutableRecord({ type: '', }); -export const normalizeNotification = (notification: ImmutableMap) => { - return NotificationRecord(notification); +export const normalizeNotification = (notification: Record) => { + return NotificationRecord( + ImmutableMap(fromJS(notification)), + ); }; diff --git a/app/soapbox/normalizers/poll.ts b/app/soapbox/normalizers/poll.ts index 30fc7ff4e..592f9aa65 100644 --- a/app/soapbox/normalizers/poll.ts +++ b/app/soapbox/normalizers/poll.ts @@ -8,6 +8,7 @@ import { Map as ImmutableMap, List as ImmutableList, Record as ImmutableRecord, + fromJS, } from 'immutable'; import emojify from 'soapbox/features/emoji/emoji'; @@ -76,9 +77,9 @@ const normalizePollVoted = (poll: ImmutableMap) => { }); }; -export const normalizePoll = (poll: ImmutableMap) => { +export const normalizePoll = (poll: Record) => { return PollRecord( - poll.withMutations((poll: ImmutableMap) => { + ImmutableMap(fromJS(poll)).withMutations((poll: ImmutableMap) => { normalizeEmojis(poll); normalizePollOptions(poll); normalizePollOwnVotes(poll); diff --git a/app/soapbox/normalizers/status.ts b/app/soapbox/normalizers/status.ts index 3257c112b..8db44ba39 100644 --- a/app/soapbox/normalizers/status.ts +++ b/app/soapbox/normalizers/status.ts @@ -7,6 +7,7 @@ import { Map as ImmutableMap, List as ImmutableList, Record as ImmutableRecord, + fromJS, } from 'immutable'; import { normalizeAttachment } from 'soapbox/normalizers/attachment'; @@ -135,9 +136,9 @@ const fixQuote = (status: ImmutableMap) => { }); }; -export const normalizeStatus = (status: ImmutableMap): IStatus => { +export const normalizeStatus = (status: Record): IStatus => { return StatusRecord( - status.withMutations(status => { + ImmutableMap(fromJS(status)).withMutations(status => { normalizeAttachments(status); normalizeMentions(status); normalizeEmojis(status);