|
|
|
@ -3,18 +3,25 @@ import emojify from '../../features/emoji/emoji';
|
|
|
|
|
|
|
|
|
|
const domParser = new DOMParser();
|
|
|
|
|
|
|
|
|
|
const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => {
|
|
|
|
|
obj[`:${emoji.shortcode}:`] = emoji;
|
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
export function normalizeAccount(account) {
|
|
|
|
|
account = { ...account };
|
|
|
|
|
|
|
|
|
|
const emojiMap = makeEmojiMap(account);
|
|
|
|
|
const displayName = account.display_name.length === 0 ? account.username : account.display_name;
|
|
|
|
|
account.display_name_html = emojify(escapeTextContentForBrowser(displayName));
|
|
|
|
|
account.note_emojified = emojify(account.note);
|
|
|
|
|
|
|
|
|
|
account.display_name_html = emojify(escapeTextContentForBrowser(displayName), emojiMap);
|
|
|
|
|
account.note_emojified = emojify(account.note, emojiMap);
|
|
|
|
|
|
|
|
|
|
if (account.fields) {
|
|
|
|
|
account.fields = account.fields.map(pair => ({
|
|
|
|
|
...pair,
|
|
|
|
|
name_emojified: emojify(escapeTextContentForBrowser(pair.name)),
|
|
|
|
|
value_emojified: emojify(pair.value),
|
|
|
|
|
value_emojified: emojify(pair.value, emojiMap),
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -42,11 +49,7 @@ export function normalizeStatus(status, normalOldStatus) {
|
|
|
|
|
normalStatus.hidden = normalOldStatus.get('hidden');
|
|
|
|
|
} else {
|
|
|
|
|
const searchContent = [status.spoiler_text, status.content].join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
|
|
|
|
|
|
|
|
|
|
const emojiMap = normalStatus.emojis.reduce((obj, emoji) => {
|
|
|
|
|
obj[`:${emoji.shortcode}:`] = emoji;
|
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
|
|
|
|
const emojiMap = makeEmojiMap(normalStatus);
|
|
|
|
|
|
|
|
|
|
normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
|
|
|
|
|
normalStatus.contentHtml = emojify(normalStatus.content, emojiMap);
|
|
|
|
|