|
|
@ -6,7 +6,7 @@ import emojify from 'soapbox/features/emoji/emoji';
|
|
|
|
import { normalizeStatus } from 'soapbox/normalizers';
|
|
|
|
import { normalizeStatus } from 'soapbox/normalizers';
|
|
|
|
import { simulateEmojiReact, simulateUnEmojiReact } from 'soapbox/utils/emoji_reacts';
|
|
|
|
import { simulateEmojiReact, simulateUnEmojiReact } from 'soapbox/utils/emoji_reacts';
|
|
|
|
import { stripCompatibilityFeatures, unescapeHTML } from 'soapbox/utils/html';
|
|
|
|
import { stripCompatibilityFeatures, unescapeHTML } from 'soapbox/utils/html';
|
|
|
|
import { makeEmojiMap } from 'soapbox/utils/normalizers';
|
|
|
|
import { makeEmojiMap, normalizeId } from 'soapbox/utils/normalizers';
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
EMOJI_REACT_REQUEST,
|
|
|
|
EMOJI_REACT_REQUEST,
|
|
|
@ -42,16 +42,20 @@ type State = ImmutableMap<string, StatusRecord>;
|
|
|
|
|
|
|
|
|
|
|
|
const minifyStatus = (status: StatusRecord): StatusRecord => {
|
|
|
|
const minifyStatus = (status: StatusRecord): StatusRecord => {
|
|
|
|
return status.mergeWith((o, n) => n || o, {
|
|
|
|
return status.mergeWith((o, n) => n || o, {
|
|
|
|
account: status.getIn(['account', 'id']),
|
|
|
|
account: normalizeId(status.getIn(['account', 'id'])),
|
|
|
|
reblog: status.getIn(['reblog', 'id']),
|
|
|
|
reblog: normalizeId(status.getIn(['reblog', 'id'])),
|
|
|
|
poll: status.getIn(['poll', 'id']),
|
|
|
|
poll: normalizeId(status.getIn(['poll', 'id'])),
|
|
|
|
quote: status.getIn(['quote', 'id']),
|
|
|
|
quote: normalizeId(status.getIn(['quote', 'id'])),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Gets titles of poll options from status
|
|
|
|
// Gets titles of poll options from status
|
|
|
|
const getPollOptionTitles = (status: StatusRecord): Array<string> => {
|
|
|
|
const getPollOptionTitles = ({ poll }: StatusRecord): ImmutableList<string> => {
|
|
|
|
return status.poll?.options.map(({ title }: { title: string }) => title);
|
|
|
|
if (poll && typeof poll === 'object') {
|
|
|
|
|
|
|
|
return poll.options.map(({ title }) => title);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return ImmutableList();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Creates search text from the status
|
|
|
|
// Creates search text from the status
|
|
|
@ -63,14 +67,14 @@ const buildSearchContent = (status: StatusRecord): string => {
|
|
|
|
status.content,
|
|
|
|
status.content,
|
|
|
|
]).concat(pollOptionTitles);
|
|
|
|
]).concat(pollOptionTitles);
|
|
|
|
|
|
|
|
|
|
|
|
return unescapeHTML(fields.join('\n\n'));
|
|
|
|
return unescapeHTML(fields.join('\n\n')) || '';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Only calculate these values when status first encountered
|
|
|
|
// Only calculate these values when status first encountered
|
|
|
|
// Otherwise keep the ones already in the reducer
|
|
|
|
// Otherwise keep the ones already in the reducer
|
|
|
|
export const calculateStatus = (
|
|
|
|
export const calculateStatus = (
|
|
|
|
status: StatusRecord,
|
|
|
|
status: StatusRecord,
|
|
|
|
oldStatus: StatusRecord,
|
|
|
|
oldStatus?: StatusRecord,
|
|
|
|
expandSpoilers: boolean = false,
|
|
|
|
expandSpoilers: boolean = false,
|
|
|
|
): StatusRecord => {
|
|
|
|
): StatusRecord => {
|
|
|
|
if (oldStatus) {
|
|
|
|
if (oldStatus) {
|
|
|
@ -86,7 +90,7 @@ export const calculateStatus = (
|
|
|
|
const emojiMap = makeEmojiMap(status.emojis);
|
|
|
|
const emojiMap = makeEmojiMap(status.emojis);
|
|
|
|
|
|
|
|
|
|
|
|
return status.merge({
|
|
|
|
return status.merge({
|
|
|
|
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent || undefined,
|
|
|
|
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent || '',
|
|
|
|
contentHtml: stripCompatibilityFeatures(emojify(status.content, emojiMap)),
|
|
|
|
contentHtml: stripCompatibilityFeatures(emojify(status.content, emojiMap)),
|
|
|
|
spoilerHtml: emojify(escapeTextContentForBrowser(spoilerText), emojiMap),
|
|
|
|
spoilerHtml: emojify(escapeTextContentForBrowser(spoilerText), emojiMap),
|
|
|
|
hidden: expandSpoilers ? false : spoilerText.length > 0 || status.sensitive,
|
|
|
|
hidden: expandSpoilers ? false : spoilerText.length > 0 || status.sensitive,
|
|
|
@ -100,7 +104,7 @@ const isQuote = (status: StatusRecord) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Preserve quote if an existing status already has it
|
|
|
|
// Preserve quote if an existing status already has it
|
|
|
|
const fixQuote = (status: StatusRecord, oldStatus: StatusRecord): StatusRecord => {
|
|
|
|
const fixQuote = (status: StatusRecord, oldStatus?: StatusRecord): StatusRecord => {
|
|
|
|
if (oldStatus && !status.quote && isQuote(status)) {
|
|
|
|
if (oldStatus && !status.quote && isQuote(status)) {
|
|
|
|
return status
|
|
|
|
return status
|
|
|
|
.set('quote', oldStatus.quote)
|
|
|
|
.set('quote', oldStatus.quote)
|
|
|
@ -111,7 +115,7 @@ const fixQuote = (status: StatusRecord, oldStatus: StatusRecord): StatusRecord =
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const fixStatus = (state: State, status: APIEntity, expandSpoilers: boolean): StatusRecord => {
|
|
|
|
const fixStatus = (state: State, status: APIEntity, expandSpoilers: boolean): StatusRecord => {
|
|
|
|
const oldStatus: StatusRecord = state.get(status.id);
|
|
|
|
const oldStatus = state.get(status.id);
|
|
|
|
|
|
|
|
|
|
|
|
return normalizeStatus(status).withMutations(status => {
|
|
|
|
return normalizeStatus(status).withMutations(status => {
|
|
|
|
fixQuote(status, oldStatus);
|
|
|
|
fixQuote(status, oldStatus);
|
|
|
@ -154,6 +158,25 @@ const deletePendingStatus = (state: State, { in_reply_to_id }: APIEntity) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Simulate favourite/unfavourite of status for optimistic interactions */
|
|
|
|
|
|
|
|
const simulateFavourite = (
|
|
|
|
|
|
|
|
state: State,
|
|
|
|
|
|
|
|
statusId: string,
|
|
|
|
|
|
|
|
favourited: boolean,
|
|
|
|
|
|
|
|
): State => {
|
|
|
|
|
|
|
|
const status = state.get(statusId);
|
|
|
|
|
|
|
|
if (!status) return state;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const delta = favourited ? +1 : -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updatedStatus = status.merge({
|
|
|
|
|
|
|
|
favourited,
|
|
|
|
|
|
|
|
favourites_count: Math.max(0, status.favourites_count + delta),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return state.set(statusId, updatedStatus);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const initialState: State = ImmutableMap();
|
|
|
|
const initialState: State = ImmutableMap();
|
|
|
|
|
|
|
|
|
|
|
|
export default function statuses(state = initialState, action: AnyAction): State {
|
|
|
|
export default function statuses(state = initialState, action: AnyAction): State {
|
|
|
@ -167,15 +190,9 @@ export default function statuses(state = initialState, action: AnyAction): State
|
|
|
|
case STATUS_CREATE_FAIL:
|
|
|
|
case STATUS_CREATE_FAIL:
|
|
|
|
return deletePendingStatus(state, action.params);
|
|
|
|
return deletePendingStatus(state, action.params);
|
|
|
|
case FAVOURITE_REQUEST:
|
|
|
|
case FAVOURITE_REQUEST:
|
|
|
|
return state.update(action.status.get('id'), status =>
|
|
|
|
return simulateFavourite(state, action.status.id, true);
|
|
|
|
status
|
|
|
|
|
|
|
|
.set('favourited', true)
|
|
|
|
|
|
|
|
.update('favourites_count', count => count + 1));
|
|
|
|
|
|
|
|
case UNFAVOURITE_REQUEST:
|
|
|
|
case UNFAVOURITE_REQUEST:
|
|
|
|
return state.update(action.status.get('id'), status =>
|
|
|
|
return simulateFavourite(state, action.status.id, false);
|
|
|
|
status
|
|
|
|
|
|
|
|
.set('favourited', false)
|
|
|
|
|
|
|
|
.update('favourites_count', count => Math.max(0, count - 1)));
|
|
|
|
|
|
|
|
case EMOJI_REACT_REQUEST:
|
|
|
|
case EMOJI_REACT_REQUEST:
|
|
|
|
return state
|
|
|
|
return state
|
|
|
|
.updateIn(
|
|
|
|
.updateIn(
|
|
|
|