Break Mention normalizer into its own module (with tests)
This commit is contained in:
parent
b100068b95
commit
08f219ab64
5 changed files with 25 additions and 14 deletions
Binary file not shown.
BIN
app/soapbox/normalizers/__tests__/mention-test.js
Normal file
BIN
app/soapbox/normalizers/__tests__/mention-test.js
Normal file
Binary file not shown.
Binary file not shown.
24
app/soapbox/normalizers/mention.ts
Normal file
24
app/soapbox/normalizers/mention.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
* Mention normalizer:
|
||||||
|
* 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 { normalizeAccount } from 'soapbox/normalizers/account';
|
||||||
|
|
||||||
|
// https://docs.joinmastodon.org/entities/mention/
|
||||||
|
const MentionRecord = ImmutableRecord({
|
||||||
|
id: '',
|
||||||
|
acct: '',
|
||||||
|
username: '',
|
||||||
|
url: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
export const normalizeMention = (mention: ImmutableMap<string, any>) => {
|
||||||
|
// Simply normalize it as an account then cast it as a mention ¯\_(ツ)_/¯
|
||||||
|
return MentionRecord(normalizeAccount(mention));
|
||||||
|
};
|
|
@ -11,8 +11,8 @@ import {
|
||||||
} from 'immutable';
|
} from 'immutable';
|
||||||
|
|
||||||
import emojify from 'soapbox/features/emoji/emoji';
|
import emojify from 'soapbox/features/emoji/emoji';
|
||||||
import { normalizeAccount } from 'soapbox/normalizers/account';
|
|
||||||
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
||||||
|
import { normalizeMention } from 'soapbox/normalizers/mention';
|
||||||
import { IStatus } from 'soapbox/types';
|
import { IStatus } from 'soapbox/types';
|
||||||
import { mergeDefined, makeEmojiMap } from 'soapbox/utils/normalizers';
|
import { mergeDefined, makeEmojiMap } from 'soapbox/utils/normalizers';
|
||||||
|
|
||||||
|
@ -73,14 +73,6 @@ const AttachmentRecord = ImmutableRecord({
|
||||||
status: null,
|
status: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://docs.joinmastodon.org/entities/mention/
|
|
||||||
const MentionRecord = ImmutableRecord({
|
|
||||||
id: '',
|
|
||||||
acct: '',
|
|
||||||
username: '',
|
|
||||||
url: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
// https://docs.joinmastodon.org/entities/poll/
|
// https://docs.joinmastodon.org/entities/poll/
|
||||||
const PollRecord = ImmutableRecord({
|
const PollRecord = ImmutableRecord({
|
||||||
emojis: ImmutableList(),
|
emojis: ImmutableList(),
|
||||||
|
@ -126,11 +118,6 @@ const normalizeAttachments = (status: ImmutableMap<string, any>) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize mentions
|
|
||||||
const normalizeMention = (mention: ImmutableMap<string, any>) => {
|
|
||||||
return MentionRecord(normalizeAccount(mention));
|
|
||||||
};
|
|
||||||
|
|
||||||
const normalizeMentions = (status: ImmutableMap<string, any>) => {
|
const normalizeMentions = (status: ImmutableMap<string, any>) => {
|
||||||
return status.update('mentions', ImmutableList(), mentions => {
|
return status.update('mentions', ImmutableList(), mentions => {
|
||||||
return mentions.map(normalizeMention);
|
return mentions.map(normalizeMention);
|
||||||
|
|
Loading…
Reference in a new issue