diff --git a/app/soapbox/actions/importer/index.js b/app/soapbox/actions/importer/index.js
index 3a019e636..8599e7dbc 100644
--- a/app/soapbox/actions/importer/index.js
+++ b/app/soapbox/actions/importer/index.js
@@ -1,8 +1,5 @@
-import { getSettings } from '../settings';
-
import {
normalizeAccount,
- normalizeStatus,
normalizePoll,
} from './normalizer';
@@ -60,11 +57,6 @@ export function importFetchedStatus(status, idempotencyKey) {
// Skip broken statuses
if (isBroken(status)) return;
- const normalOldStatus = getState().getIn(['statuses', status.id]);
- const expandSpoilers = getSettings(getState()).get('expandSpoilers');
-
- const normalizedStatus = normalizeStatus(status, normalOldStatus, expandSpoilers);
-
if (status.reblog?.id) {
dispatch(importFetchedStatus(status.reblog));
}
@@ -83,7 +75,7 @@ export function importFetchedStatus(status, idempotencyKey) {
}
dispatch(importFetchedAccount(status.account));
- dispatch(importStatus(normalizedStatus, idempotencyKey));
+ dispatch(importStatus(status, idempotencyKey));
};
}
@@ -106,17 +98,12 @@ const isBroken = status => {
export function importFetchedStatuses(statuses) {
return (dispatch, getState) => {
const accounts = [];
- const normalStatuses = [];
const polls = [];
function processStatus(status) {
// Skip broken statuses
if (isBroken(status)) return;
- const normalOldStatus = getState().getIn(['statuses', status.id]);
- const expandSpoilers = getSettings(getState()).get('expandSpoilers');
-
- normalStatuses.push(normalizeStatus(status, normalOldStatus, expandSpoilers));
accounts.push(status.account);
if (status.reblog?.id) {
@@ -141,7 +128,7 @@ export function importFetchedStatuses(statuses) {
dispatch(importPolls(polls));
dispatch(importFetchedAccounts(accounts));
- dispatch(importStatuses(normalStatuses));
+ dispatch(importStatuses(statuses));
};
}
diff --git a/app/soapbox/actions/importer/normalizer.js b/app/soapbox/actions/importer/normalizer.js
index 7d40357f0..4de148c0b 100644
--- a/app/soapbox/actions/importer/normalizer.js
+++ b/app/soapbox/actions/importer/normalizer.js
@@ -1,12 +1,8 @@
import escapeTextContentForBrowser from 'escape-html';
-import { stripCompatibilityFeatures } from 'soapbox/utils/html';
-
import emojify from '../../features/emoji/emoji';
import { unescapeHTML } from '../../utils/html';
-const domParser = new DOMParser();
-
const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => {
obj[`:${emoji.shortcode}:`] = emoji;
return obj;
@@ -45,61 +41,6 @@ export function normalizeAccount(account) {
return account;
}
-export function normalizeStatus(status, normalOldStatus, expandSpoilers) {
- const normalStatus = { ...status };
-
- // Some backends can return null, or omit these required fields
- if (!normalStatus.emojis) normalStatus.emojis = [];
- if (!normalStatus.spoiler_text) normalStatus.spoiler_text = '';
-
- // Copy the pleroma object too, so we can modify our copy
- if (status.pleroma) {
- normalStatus.pleroma = { ...status.pleroma };
- }
-
- normalStatus.account = status.account.id;
-
- if (status.reblog?.id) {
- normalStatus.reblog = status.reblog.id;
- }
-
- if (status.poll?.id) {
- normalStatus.poll = status.poll.id;
- }
-
- if (status.pleroma?.quote?.id) {
- // Normalize quote to the top-level, so delete the original for performance
- normalStatus.quote = status.pleroma.quote.id;
- delete normalStatus.pleroma.quote;
- } else if (status.quote?.id) {
- // Fedibird compatibility, because why not
- normalStatus.quote = status.quote.id;
- } else if (status.quote_id) {
- // Fedibird: fall back to quote_id
- normalStatus.quote = status.quote_id;
- }
-
- // Only calculate these values when status first encountered
- // Otherwise keep the ones already in the reducer
- if (normalOldStatus) {
- normalStatus.search_index = normalOldStatus.get('search_index');
- normalStatus.contentHtml = normalOldStatus.get('contentHtml');
- normalStatus.spoilerHtml = normalOldStatus.get('spoilerHtml');
- normalStatus.hidden = normalOldStatus.get('hidden');
- } else {
- const spoilerText = normalStatus.spoiler_text || '';
- const searchContent = ([spoilerText, status.content].concat((status.poll?.options) ? status.poll.options.map(option => option.title) : [])).join('\n\n').replace(/
/g, '\n').replace(/<\/p>
/g, '\n\n'); - const emojiMap = makeEmojiMap(normalStatus); - - normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent; - normalStatus.contentHtml = stripCompatibilityFeatures(emojify(normalStatus.content, emojiMap)); - normalStatus.spoilerHtml = emojify(escapeTextContentForBrowser(spoilerText), emojiMap); - normalStatus.hidden = expandSpoilers ? false : spoilerText.length > 0 || normalStatus.sensitive; - } - - return normalStatus; -} - export function normalizePoll(poll) { const normalPoll = { ...poll }; diff --git a/app/soapbox/components/status_reply_mentions.js b/app/soapbox/components/status_reply_mentions.js index 11664bb31..51c684841 100644 --- a/app/soapbox/components/status_reply_mentions.js +++ b/app/soapbox/components/status_reply_mentions.js @@ -43,39 +43,18 @@ class StatusReplyMentions extends ImmutablePureComponent { const to = status.get('mentions', []); // The post is a reply, but it has no mentions. + // Rare, but it can happen. if (to.size === 0) { - // The author is replying to themself. - if (status.get('in_reply_to_account_id') === status.getIn(['account', 'id'])) { - return ( -
/g, '\n\n'); + const emojiMap = makeEmojiMap(status); + + return status.merge({ + search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent, + contentHtml: stripCompatibilityFeatures(emojify(status.get('content'), emojiMap)), + spoilerHtml: emojify(escapeTextContentForBrowser(spoilerText), emojiMap), + hidden: spoilerText.length > 0 || status.get('sensitive'), + }); + } +}; + const isQuote = status => { return Boolean(status.get('quote_id') || status.getIn(['pleroma', 'quote_url'])); }; @@ -45,9 +88,13 @@ const fixQuote = (state, status) => { }; const fixStatus = (state, status) => { + const oldStatus = state.get(status.get('id')); + return status.withMutations(status => { normalizeStatus(status); fixQuote(state, status); + calculateStatus(status, oldStatus); + minifyStatus(status); }); };