summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorChristian Schmidt <github@chsc.dk>2023-07-25 20:29:31 +0200
committerGitHub <noreply@github.com>2023-07-25 20:29:31 +0200
commit6781dc6462b0511a2d3e6e08c965b7006ffd3331 (patch)
tree63824aad179acb40e874f1173c598d3df3d122ec /app
parentce1f35d7e213327549b960bb64f63c67a141ea40 (diff)
Preserve translation on status re-import (#26168)
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/actions/importer/index.js6
-rw-r--r--app/javascript/mastodon/actions/importer/normalizer.js33
2 files changed, 30 insertions, 9 deletions
diff --git a/app/javascript/mastodon/actions/importer/index.js b/app/javascript/mastodon/actions/importer/index.js
index 9c69be601ed..369be6b8fbc 100644
--- a/app/javascript/mastodon/actions/importer/index.js
+++ b/app/javascript/mastodon/actions/importer/index.js
@@ -81,7 +81,7 @@ export function importFetchedStatuses(statuses) {
}
if (status.poll && status.poll.id) {
- pushUnique(polls, normalizePoll(status.poll));
+ pushUnique(polls, normalizePoll(status.poll, getState().getIn(['polls', status.poll.id])));
}
}
@@ -95,7 +95,7 @@ export function importFetchedStatuses(statuses) {
}
export function importFetchedPoll(poll) {
- return dispatch => {
- dispatch(importPolls([normalizePoll(poll)]));
+ return (dispatch, getState) => {
+ dispatch(importPolls([normalizePoll(poll, getState().getIn(['polls', poll.id]))]));
};
}
diff --git a/app/javascript/mastodon/actions/importer/normalizer.js b/app/javascript/mastodon/actions/importer/normalizer.js
index 9ed6b583b5f..67368abb249 100644
--- a/app/javascript/mastodon/actions/importer/normalizer.js
+++ b/app/javascript/mastodon/actions/importer/normalizer.js
@@ -76,6 +76,7 @@ export function normalizeStatus(status, normalOldStatus) {
normalStatus.spoilerHtml = normalOldStatus.get('spoilerHtml');
normalStatus.spoiler_text = normalOldStatus.get('spoiler_text');
normalStatus.hidden = normalOldStatus.get('hidden');
+ normalStatus.translation = normalOldStatus.get('translation');
} else {
// If the status has a CW but no contents, treat the CW as if it were the
// status' contents, to avoid having a CW toggle with seemingly no effect.
@@ -94,6 +95,18 @@ export function normalizeStatus(status, normalOldStatus) {
normalStatus.hidden = expandSpoilers ? false : spoilerText.length > 0 || normalStatus.sensitive;
}
+ if (normalOldStatus) {
+ const list = normalOldStatus.get('media_attachments');
+ if (normalStatus.media_attachments && list) {
+ normalStatus.media_attachments.forEach(item => {
+ const oldItem = list.find(i => i.get('id') === item.id);
+ if (oldItem && oldItem.get('description') === item.description) {
+ item.translation = oldItem.get('translation')
+ }
+ });
+ }
+ }
+
return normalStatus;
}
@@ -112,15 +125,23 @@ export function normalizeStatusTranslation(translation, status) {
return normalTranslation;
}
-export function normalizePoll(poll) {
+export function normalizePoll(poll, normalOldPoll) {
const normalPoll = { ...poll };
const emojiMap = makeEmojiMap(poll.emojis);
- normalPoll.options = poll.options.map((option, index) => ({
- ...option,
- voted: poll.own_votes && poll.own_votes.includes(index),
- titleHtml: emojify(escapeTextContentForBrowser(option.title), emojiMap),
- }));
+ normalPoll.options = poll.options.map((option, index) => {
+ const normalOption = {
+ ...option,
+ voted: poll.own_votes && poll.own_votes.includes(index),
+ titleHtml: emojify(escapeTextContentForBrowser(option.title), emojiMap),
+ }
+
+ if (normalOldPoll && normalOldPoll.getIn(['options', index, 'title']) === option.title) {
+ normalOption.translation = normalOldPoll.getIn(['options', index, 'translation']);
+ }
+
+ return normalOption
+ });
return normalPoll;
}