mirror of
https://github.com/kikobar/mastodon.git
synced 2024-12-29 09:14:15 +00:00
Preserve translation on status re-import (#26168)
This commit is contained in:
parent
ce1f35d7e2
commit
6781dc6462
|
@ -81,7 +81,7 @@ export function importFetchedStatuses(statuses) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.poll && status.poll.id) {
|
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) {
|
export function importFetchedPoll(poll) {
|
||||||
return dispatch => {
|
return (dispatch, getState) => {
|
||||||
dispatch(importPolls([normalizePoll(poll)]));
|
dispatch(importPolls([normalizePoll(poll, getState().getIn(['polls', poll.id]))]));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ export function normalizeStatus(status, normalOldStatus) {
|
||||||
normalStatus.spoilerHtml = normalOldStatus.get('spoilerHtml');
|
normalStatus.spoilerHtml = normalOldStatus.get('spoilerHtml');
|
||||||
normalStatus.spoiler_text = normalOldStatus.get('spoiler_text');
|
normalStatus.spoiler_text = normalOldStatus.get('spoiler_text');
|
||||||
normalStatus.hidden = normalOldStatus.get('hidden');
|
normalStatus.hidden = normalOldStatus.get('hidden');
|
||||||
|
normalStatus.translation = normalOldStatus.get('translation');
|
||||||
} else {
|
} else {
|
||||||
// If the status has a CW but no contents, treat the CW as if it were the
|
// 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.
|
// 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;
|
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;
|
return normalStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,15 +125,23 @@ export function normalizeStatusTranslation(translation, status) {
|
||||||
return normalTranslation;
|
return normalTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizePoll(poll) {
|
export function normalizePoll(poll, normalOldPoll) {
|
||||||
const normalPoll = { ...poll };
|
const normalPoll = { ...poll };
|
||||||
const emojiMap = makeEmojiMap(poll.emojis);
|
const emojiMap = makeEmojiMap(poll.emojis);
|
||||||
|
|
||||||
normalPoll.options = poll.options.map((option, index) => ({
|
normalPoll.options = poll.options.map((option, index) => {
|
||||||
...option,
|
const normalOption = {
|
||||||
voted: poll.own_votes && poll.own_votes.includes(index),
|
...option,
|
||||||
titleHtml: emojify(escapeTextContentForBrowser(option.title), emojiMap),
|
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;
|
return normalPoll;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue