Call fromJS in all normalizers
This commit is contained in:
parent
6b8e79d898
commit
8167b72762
17 changed files with 42 additions and 27 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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<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,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<string, any>) => {
|
||||
const normalizeUrls = (attachment: ImmutableMap<string, any>) => {
|
||||
const url = [
|
||||
attachment.get('url'),
|
||||
attachment.get('preview_url'),
|
||||
|
@ -41,5 +41,12 @@ export const normalizeAttachment = (attachment: ImmutableMap<string, any>) => {
|
|||
preview_url: url,
|
||||
});
|
||||
|
||||
return AttachmentRecord(attachment.mergeWith(mergeDefined, base));
|
||||
return attachment.mergeWith(mergeDefined, base);
|
||||
};
|
||||
|
||||
// Ensure attachments have required fields
|
||||
export const normalizeAttachment = (attachment: Record<string, any>) => {
|
||||
return AttachmentRecord(
|
||||
normalizeUrls(ImmutableMap(fromJS(attachment))),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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<string, any>) => {
|
||||
return CardRecord(card);
|
||||
export const normalizeCard = (card: Record<string, any>) => {
|
||||
return CardRecord(
|
||||
ImmutableMap(fromJS(card)),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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<string, any>) => {
|
||||
return EmojiRecord(emoji);
|
||||
export const normalizeEmoji = (emoji: Record<string, any>) => {
|
||||
return EmojiRecord(
|
||||
ImmutableMap(fromJS(emoji)),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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<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,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<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,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<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';
|
||||
|
@ -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';
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue