Merge branch 'normalizer-exports' into 'develop'
Normalizer exports, use fromJS in all normalizers See merge request soapbox-pub/soapbox-fe!1105
This commit is contained in:
commit
c413d94459
|
@ -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 <img draggable="false" class="emojione" alt="😂" title=":joy:" src="/packs/emoji/1f602.svg" /> <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" /> <img draggable="false" class="emojione" alt=":ablobcatrainbow:" title=":ablobcatrainbow:" src="https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png" />';
|
||||
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. <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" /><br/><br/>I'm vegan btw<br/><br/>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);
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
Map as ImmutableMap,
|
||||
List as ImmutableList,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
import emojify from 'soapbox/features/emoji/emoji';
|
||||
|
@ -17,7 +18,7 @@ import { unescapeHTML } from 'soapbox/utils/html';
|
|||
import { mergeDefined, makeEmojiMap } from 'soapbox/utils/normalizers';
|
||||
|
||||
// https://docs.joinmastodon.org/entities/account/
|
||||
const AccountRecord = ImmutableRecord({
|
||||
export const AccountRecord = ImmutableRecord({
|
||||
acct: '',
|
||||
avatar: '',
|
||||
avatar_static: '',
|
||||
|
@ -56,7 +57,7 @@ const AccountRecord = ImmutableRecord({
|
|||
});
|
||||
|
||||
// https://docs.joinmastodon.org/entities/field/
|
||||
const FieldRecord = ImmutableRecord({
|
||||
export const FieldRecord = ImmutableRecord({
|
||||
name: '',
|
||||
value: '',
|
||||
verified_at: null,
|
||||
|
@ -181,9 +182,9 @@ const addInternalFields = (account: ImmutableMap<string, any>) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const normalizeAccount = (account: ImmutableMap<string, any>): IAccount => {
|
||||
export const normalizeAccount = (account: Record<string, any>): IAccount => {
|
||||
return AccountRecord(
|
||||
account.withMutations(account => {
|
||||
ImmutableMap(fromJS(account)).withMutations(account => {
|
||||
normalizePleromaLegacyFields(account);
|
||||
normalizeEmojis(account);
|
||||
normalizeAvatar(account);
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
import {
|
||||
Map as ImmutableMap,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
import { mergeDefined } from 'soapbox/utils/normalizers';
|
||||
|
||||
// https://docs.joinmastodon.org/entities/attachment/
|
||||
const AttachmentRecord = ImmutableRecord({
|
||||
export const AttachmentRecord = ImmutableRecord({
|
||||
blurhash: undefined,
|
||||
description: '',
|
||||
id: '',
|
||||
|
@ -29,7 +30,7 @@ const AttachmentRecord = ImmutableRecord({
|
|||
});
|
||||
|
||||
// Ensure attachments have required fields
|
||||
export const normalizeAttachment = (attachment: ImmutableMap<string, any>) => {
|
||||
const normalizeUrls = (attachment: ImmutableMap<string, any>) => {
|
||||
const url = [
|
||||
attachment.get('url'),
|
||||
attachment.get('preview_url'),
|
||||
|
@ -41,5 +42,11 @@ export const normalizeAttachment = (attachment: ImmutableMap<string, any>) => {
|
|||
preview_url: url,
|
||||
});
|
||||
|
||||
return AttachmentRecord(attachment.mergeWith(mergeDefined, base));
|
||||
return attachment.mergeWith(mergeDefined, base);
|
||||
};
|
||||
|
||||
export const normalizeAttachment = (attachment: Record<string, any>) => {
|
||||
return AttachmentRecord(
|
||||
normalizeUrls(ImmutableMap(fromJS(attachment))),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
* 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/
|
||||
const CardRecord = ImmutableRecord({
|
||||
export const CardRecord = ImmutableRecord({
|
||||
author_name: '',
|
||||
author_url: '',
|
||||
blurhash: null,
|
||||
|
@ -23,6 +23,8 @@ const CardRecord = ImmutableRecord({
|
|||
width: 0,
|
||||
});
|
||||
|
||||
export const normalizeCard = (card: ImmutableMap<string, any>) => {
|
||||
return CardRecord(card);
|
||||
export const normalizeCard = (card: Record<string, any>) => {
|
||||
return CardRecord(
|
||||
ImmutableMap(fromJS(card)),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
* 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/
|
||||
const EmojiRecord = ImmutableRecord({
|
||||
export const EmojiRecord = ImmutableRecord({
|
||||
category: '',
|
||||
shortcode: '',
|
||||
static_url: '',
|
||||
|
@ -14,6 +14,8 @@ const EmojiRecord = ImmutableRecord({
|
|||
visible_in_picker: true,
|
||||
});
|
||||
|
||||
export const normalizeEmoji = (emoji: ImmutableMap<string, any>) => {
|
||||
return EmojiRecord(emoji);
|
||||
export const normalizeEmoji = (emoji: Record<string, any>) => {
|
||||
return EmojiRecord(
|
||||
ImmutableMap(fromJS(emoji)),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
export { AccountRecord, FieldRecord, normalizeAccount } from './account';
|
||||
export { AttachmentRecord, normalizeAttachment } from './attachment';
|
||||
export { CardRecord, normalizeCard } from './card';
|
||||
export { EmojiRecord, normalizeEmoji } from './emoji';
|
||||
export { InstanceRecord, normalizeInstance } from './instance';
|
||||
export { MentionRecord, normalizeMention } from './mention';
|
||||
export { NotificationRecord, normalizeNotification } from './notification';
|
||||
export { PollRecord, PollOptionRecord, normalizePoll } from './poll';
|
||||
export { StatusRecord, normalizeStatus } from './status';
|
|
@ -7,6 +7,7 @@ import {
|
|||
Map as ImmutableMap,
|
||||
List as ImmutableList,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
import { parseVersion, PLEROMA } from 'soapbox/utils/features';
|
||||
|
@ -15,7 +16,7 @@ import { isNumber } from 'soapbox/utils/numbers';
|
|||
|
||||
// Use Mastodon defaults
|
||||
// https://docs.joinmastodon.org/entities/instance/
|
||||
const InstanceRecord = ImmutableRecord({
|
||||
export const InstanceRecord = ImmutableRecord({
|
||||
approval_required: false,
|
||||
contact_account: ImmutableMap(),
|
||||
configuration: ImmutableMap({
|
||||
|
@ -84,12 +85,12 @@ const pleromaToMastodonConfig = (instance: ImmutableMap<string, any>) => {
|
|||
const getAttachmentLimit = (software: string) => software === PLEROMA ? Infinity : 4;
|
||||
|
||||
// Normalize instance (Pleroma, Mastodon, etc.) to Mastodon's format
|
||||
export const normalizeInstance = (instance: ImmutableMap<string, any>) => {
|
||||
export const normalizeInstance = (instance: Record<string, any>) => {
|
||||
return InstanceRecord(
|
||||
ImmutableMap(fromJS(instance)).withMutations((instance: ImmutableMap<string, any>) => {
|
||||
const { software } = parseVersion(instance.get('version'));
|
||||
const mastodonConfig = pleromaToMastodonConfig(instance);
|
||||
|
||||
return InstanceRecord(
|
||||
instance.withMutations(instance => {
|
||||
// Merge configuration
|
||||
instance.update('configuration', ImmutableMap(), configuration => (
|
||||
configuration.mergeDeepWith(mergeDefined, mastodonConfig)
|
||||
|
|
|
@ -3,22 +3,19 @@
|
|||
* 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';
|
||||
|
||||
// https://docs.joinmastodon.org/entities/mention/
|
||||
const MentionRecord = ImmutableRecord({
|
||||
export const MentionRecord = ImmutableRecord({
|
||||
id: '',
|
||||
acct: '',
|
||||
username: '',
|
||||
url: '',
|
||||
});
|
||||
|
||||
export const normalizeMention = (mention: ImmutableMap<string, any>) => {
|
||||
export const normalizeMention = (mention: Record<string, any>) => {
|
||||
// Simply normalize it as an account then cast it as a mention ¯\_(ツ)_/¯
|
||||
return MentionRecord(normalizeAccount(mention));
|
||||
};
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
import {
|
||||
Map as ImmutableMap,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
// https://docs.joinmastodon.org/entities/notification/
|
||||
const NotificationRecord = ImmutableRecord({
|
||||
export const NotificationRecord = ImmutableRecord({
|
||||
account: null,
|
||||
chat_message: null, // pleroma:chat_mention
|
||||
created_at: new Date(),
|
||||
|
@ -20,6 +21,8 @@ const NotificationRecord = ImmutableRecord({
|
|||
type: '',
|
||||
});
|
||||
|
||||
export const normalizeNotification = (notification: ImmutableMap<string, any>) => {
|
||||
return NotificationRecord(notification);
|
||||
export const normalizeNotification = (notification: Record<string, any>) => {
|
||||
return NotificationRecord(
|
||||
ImmutableMap(fromJS(notification)),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
Map as ImmutableMap,
|
||||
List as ImmutableList,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
import emojify from 'soapbox/features/emoji/emoji';
|
||||
|
@ -15,7 +16,7 @@ import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
|||
import { makeEmojiMap } from 'soapbox/utils/normalizers';
|
||||
|
||||
// https://docs.joinmastodon.org/entities/poll/
|
||||
const PollRecord = ImmutableRecord({
|
||||
export const PollRecord = ImmutableRecord({
|
||||
emojis: ImmutableList(),
|
||||
expired: false,
|
||||
expires_at: new Date(),
|
||||
|
@ -29,7 +30,7 @@ const PollRecord = ImmutableRecord({
|
|||
});
|
||||
|
||||
// Sub-entity of Poll
|
||||
const PollOptionRecord = ImmutableRecord({
|
||||
export const PollOptionRecord = ImmutableRecord({
|
||||
title: '',
|
||||
votes_count: 0,
|
||||
|
||||
|
@ -76,9 +77,9 @@ const normalizePollVoted = (poll: ImmutableMap<string, any>) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const normalizePoll = (poll: ImmutableMap<string, any>) => {
|
||||
export const normalizePoll = (poll: Record<string, any>) => {
|
||||
return PollRecord(
|
||||
poll.withMutations((poll: ImmutableMap<string, any>) => {
|
||||
ImmutableMap(fromJS(poll)).withMutations((poll: ImmutableMap<string, any>) => {
|
||||
normalizeEmojis(poll);
|
||||
normalizePollOptions(poll);
|
||||
normalizePollOwnVotes(poll);
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
Map as ImmutableMap,
|
||||
List as ImmutableList,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
import { normalizeAttachment } from 'soapbox/normalizers/attachment';
|
||||
|
@ -17,7 +18,7 @@ import { normalizePoll } from 'soapbox/normalizers/poll';
|
|||
import { IStatus } from 'soapbox/types';
|
||||
|
||||
// https://docs.joinmastodon.org/entities/status/
|
||||
const StatusRecord = ImmutableRecord({
|
||||
export const StatusRecord = ImmutableRecord({
|
||||
account: null,
|
||||
application: null,
|
||||
bookmarked: false,
|
||||
|
@ -135,9 +136,9 @@ const fixQuote = (status: ImmutableMap<string, any>) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const normalizeStatus = (status: ImmutableMap<string, any>): IStatus => {
|
||||
export const normalizeStatus = (status: Record<string, any>): IStatus => {
|
||||
return StatusRecord(
|
||||
status.withMutations(status => {
|
||||
ImmutableMap(fromJS(status)).withMutations(status => {
|
||||
normalizeAttachments(status);
|
||||
normalizeMentions(status);
|
||||
normalizeEmojis(status);
|
||||
|
|
|
@ -46,7 +46,7 @@ const minifyAccount = account => {
|
|||
};
|
||||
|
||||
const fixAccount = (state, account) => {
|
||||
const normalized = minifyAccount(normalizeAccount(fromJS(account)));
|
||||
const normalized = minifyAccount(normalizeAccount(account));
|
||||
return state.set(account.id, normalized);
|
||||
};
|
||||
|
||||
|
@ -119,7 +119,7 @@ const removePermission = (state, accountIds, permissionGroup) => {
|
|||
});
|
||||
};
|
||||
|
||||
const buildAccount = adminUser => normalizeAccount(fromJS({
|
||||
const buildAccount = adminUser => normalizeAccount({
|
||||
id: adminUser.get('id'),
|
||||
username: adminUser.get('nickname').split('@')[0],
|
||||
acct: adminUser.get('nickname'),
|
||||
|
@ -142,7 +142,7 @@ const buildAccount = adminUser => normalizeAccount(fromJS({
|
|||
},
|
||||
},
|
||||
should_refetch: true,
|
||||
}));
|
||||
});
|
||||
|
||||
const mergeAdminUser = (account, adminUser) => {
|
||||
return account.withMutations(account => {
|
||||
|
|
|
@ -116,7 +116,7 @@ const reducers = {
|
|||
};
|
||||
|
||||
// Build a default state from all reducers: it has the key and `undefined`
|
||||
const StateRecord = ImmutableRecord(
|
||||
export const StateRecord = ImmutableRecord(
|
||||
Object.keys(reducers).reduce((params, reducer) => {
|
||||
params[reducer] = undefined;
|
||||
return params;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import { POLLS_IMPORT } from 'soapbox/actions/importer';
|
||||
import { normalizeStatus } from 'soapbox/normalizers/status';
|
||||
|
@ -6,7 +6,7 @@ import { normalizeStatus } from 'soapbox/normalizers/status';
|
|||
// HOTFIX: Convert the poll into a fake status to normalize it...
|
||||
// TODO: get rid of POLLS_IMPORT and use STATUS_IMPORT here.
|
||||
const normalizePoll = poll => {
|
||||
const status = fromJS({ poll });
|
||||
const status = { poll };
|
||||
return normalizeStatus(status).poll;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue