2021-10-09 14:56:03 -07:00
|
|
|
import { fromJS } from 'immutable';
|
2022-02-23 17:00:49 -08:00
|
|
|
import {
|
|
|
|
OrderedSet as ImmutableOrderedSet,
|
|
|
|
Map as ImmutableMap,
|
|
|
|
List as ImmutableList,
|
|
|
|
} from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-02-19 23:27:29 -08:00
|
|
|
import { normalizeStatus } from 'soapbox/normalizers/status';
|
2022-02-21 00:56:31 -08:00
|
|
|
import { calculateStatus } from 'soapbox/reducers/statuses';
|
2022-01-14 13:35:28 -08:00
|
|
|
import { makeGetAccount, makeGetStatus } from 'soapbox/selectors';
|
2021-10-09 14:56:03 -07:00
|
|
|
|
|
|
|
export const buildStatus = (state, pendingStatus, idempotencyKey) => {
|
|
|
|
const getAccount = makeGetAccount();
|
2022-01-14 13:35:28 -08:00
|
|
|
const getStatus = makeGetStatus();
|
2021-10-09 14:56:03 -07:00
|
|
|
|
|
|
|
const me = state.get('me');
|
|
|
|
const account = getAccount(state, me);
|
|
|
|
|
2022-01-15 05:29:32 -08:00
|
|
|
let mentions;
|
2022-01-14 13:35:28 -08:00
|
|
|
if (pendingStatus.get('in_reply_to_id')) {
|
|
|
|
const inReplyTo = getStatus(state, { id: pendingStatus.get('in_reply_to_id') });
|
|
|
|
|
2022-01-15 05:29:32 -08:00
|
|
|
if (inReplyTo.getIn(['account', 'id']) === me) {
|
2022-02-19 22:13:30 -08:00
|
|
|
mentions = ImmutableOrderedSet([account.get('acct')]).union(pendingStatus.get('to') || []);
|
2022-01-15 05:29:32 -08:00
|
|
|
} else {
|
|
|
|
mentions = pendingStatus.get('to', []);
|
|
|
|
}
|
|
|
|
|
2022-02-21 00:56:31 -08:00
|
|
|
mentions = mentions.toList().map(mention => ImmutableMap({
|
2022-01-15 05:29:32 -08:00
|
|
|
username: mention.split('@')[0],
|
2022-02-21 00:56:31 -08:00
|
|
|
acct: mention,
|
2022-01-15 05:29:32 -08:00
|
|
|
}));
|
2022-01-14 13:35:28 -08:00
|
|
|
}
|
|
|
|
|
2022-02-19 23:27:29 -08:00
|
|
|
const status = {
|
2021-10-09 14:56:03 -07:00
|
|
|
account,
|
2021-10-12 08:31:15 -07:00
|
|
|
content: pendingStatus.get('status', '').replace(new RegExp('\n', 'g'), '<br>'), /* eslint-disable-line no-control-regex */
|
2021-10-09 19:16:37 -07:00
|
|
|
id: `末pending-${idempotencyKey}`,
|
2021-10-09 14:56:03 -07:00
|
|
|
in_reply_to_id: pendingStatus.get('in_reply_to_id'),
|
2022-02-23 17:00:49 -08:00
|
|
|
media_attachments: pendingStatus.get('media_ids', ImmutableList()).map(id => ImmutableMap({ id })),
|
2022-01-15 05:29:32 -08:00
|
|
|
mentions,
|
2021-10-09 14:56:03 -07:00
|
|
|
poll: pendingStatus.get('poll', null),
|
2022-01-26 10:28:01 -08:00
|
|
|
quote: pendingStatus.get('quote_id', null),
|
2021-10-09 14:56:03 -07:00
|
|
|
sensitive: pendingStatus.get('sensitive', false),
|
|
|
|
visibility: pendingStatus.get('visibility', 'public'),
|
2022-02-19 23:27:29 -08:00
|
|
|
};
|
2021-10-09 14:56:03 -07:00
|
|
|
|
2022-02-21 00:56:31 -08:00
|
|
|
return calculateStatus(normalizeStatus(fromJS(status)));
|
2021-10-09 14:56:03 -07:00
|
|
|
};
|