Merge branch 'compose' into 'develop'

Allow multiple compose forms

See merge request soapbox-pub/soapbox!1786
This commit is contained in:
marcin mikołajczak
2022-09-17 21:00:29 +00:00
64 changed files with 1598 additions and 1804 deletions

View File

@@ -2,6 +2,7 @@ import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutabl
import { mockStore, rootState } from 'soapbox/jest/test-helpers';
import { InstanceRecord } from 'soapbox/normalizers';
import { ReducerCompose } from 'soapbox/reducers/compose';
import { uploadCompose, submitCompose } from '../compose';
import { STATUS_CREATE_REQUEST } from '../statuses';
@@ -26,7 +27,8 @@ describe('uploadCompose()', () => {
const state = rootState
.set('me', '1234')
.set('instance', instance);
.set('instance', instance)
.setIn(['compose', 'home'], ReducerCompose());
store = mockStore(state);
files = [{
@@ -43,7 +45,7 @@ describe('uploadCompose()', () => {
} as unknown as IntlShape;
const expectedActions = [
{ type: 'COMPOSE_UPLOAD_REQUEST', skipLoading: true },
{ type: 'COMPOSE_UPLOAD_REQUEST', id: 'home', skipLoading: true },
{
type: 'ALERT_SHOW',
message: 'Image exceeds the current file size limit (10 Bytes)',
@@ -51,10 +53,10 @@ describe('uploadCompose()', () => {
actionLink: undefined,
severity: 'error',
},
{ type: 'COMPOSE_UPLOAD_FAIL', error: true, skipLoading: true },
{ type: 'COMPOSE_UPLOAD_FAIL', id: 'home', error: true, skipLoading: true },
];
await store.dispatch(uploadCompose(files, mockIntl));
await store.dispatch(uploadCompose('home', files, mockIntl));
const actions = store.getActions();
expect(actions).toEqual(expectedActions);
@@ -78,7 +80,8 @@ describe('uploadCompose()', () => {
const state = rootState
.set('me', '1234')
.set('instance', instance);
.set('instance', instance)
.setIn(['compose', 'home'], ReducerCompose());
store = mockStore(state);
files = [{
@@ -95,7 +98,7 @@ describe('uploadCompose()', () => {
} as unknown as IntlShape;
const expectedActions = [
{ type: 'COMPOSE_UPLOAD_REQUEST', skipLoading: true },
{ type: 'COMPOSE_UPLOAD_REQUEST', id: 'home', skipLoading: true },
{
type: 'ALERT_SHOW',
message: 'Video exceeds the current file size limit (10 Bytes)',
@@ -103,10 +106,10 @@ describe('uploadCompose()', () => {
actionLink: undefined,
severity: 'error',
},
{ type: 'COMPOSE_UPLOAD_FAIL', error: true, skipLoading: true },
{ type: 'COMPOSE_UPLOAD_FAIL', id: 'home', error: true, skipLoading: true },
];
await store.dispatch(uploadCompose(files, mockIntl));
await store.dispatch(uploadCompose('home', files, mockIntl));
const actions = store.getActions();
expect(actions).toEqual(expectedActions);
@@ -118,10 +121,10 @@ describe('submitCompose()', () => {
it('inserts mentions from text', async() => {
const state = rootState
.set('me', '123')
.setIn(['compose', 'text'], '@alex hello @mkljczk@pl.fediverse.pl @gg@汉语/漢語.com alex@alexgleason.me');
.setIn(['compose', 'home'], ReducerCompose({ text: '@alex hello @mkljczk@pl.fediverse.pl @gg@汉语/漢語.com alex@alexgleason.me' }));
const store = mockStore(state);
await store.dispatch(submitCompose());
await store.dispatch(submitCompose('home'));
const actions = store.getActions();
const statusCreateRequest = actions.find(action => action.type === STATUS_CREATE_REQUEST);

View File

@@ -121,6 +121,7 @@ describe('deleteStatus()', () => {
version: '0.0.0',
},
withRedraft: true,
id: 'compose-modal',
},
{ type: 'MODAL_OPEN', modalType: 'COMPOSE', modalProps: undefined },
];

View File

@@ -54,9 +54,6 @@ const COMPOSE_SUGGESTION_TAGS_UPDATE = 'COMPOSE_SUGGESTION_TAGS_UPDATE';
const COMPOSE_TAG_HISTORY_UPDATE = 'COMPOSE_TAG_HISTORY_UPDATE';
const COMPOSE_MOUNT = 'COMPOSE_MOUNT';
const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT';
const COMPOSE_SENSITIVITY_CHANGE = 'COMPOSE_SENSITIVITY_CHANGE';
const COMPOSE_SPOILERNESS_CHANGE = 'COMPOSE_SPOILERNESS_CHANGE';
const COMPOSE_TYPE_CHANGE = 'COMPOSE_TYPE_CHANGE';
@@ -101,14 +98,6 @@ const messages = defineMessages({
replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
});
const COMPOSE_PANEL_BREAKPOINT = 600 + (285 * 1) + (10 * 1);
const ensureComposeIsVisible = (getState: () => RootState, routerHistory: History) => {
if (!getState().compose.mounted && window.innerWidth < COMPOSE_PANEL_BREAKPOINT) {
routerHistory.push('/posts/new');
}
};
const setComposeToStatus = (status: Status, rawText: string, spoilerText?: string, contentType?: string | false, withRedraft?: boolean) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const { instance } = getState();
@@ -116,6 +105,7 @@ const setComposeToStatus = (status: Status, rawText: string, spoilerText?: strin
dispatch({
type: COMPOSE_SET_STATUS,
id: 'compose-modal',
status,
rawText,
explicitAddressing,
@@ -126,8 +116,9 @@ const setComposeToStatus = (status: Status, rawText: string, spoilerText?: strin
});
};
const changeCompose = (text: string) => ({
const changeCompose = (composeId: string, text: string) => ({
type: COMPOSE_CHANGE,
id: composeId,
text: text,
});
@@ -139,6 +130,7 @@ const replyCompose = (status: Status) =>
dispatch({
type: COMPOSE_REPLY,
id: 'compose-modal',
status: status,
account: state.accounts.get(state.me),
explicitAddressing,
@@ -147,22 +139,9 @@ const replyCompose = (status: Status) =>
dispatch(openModal('COMPOSE'));
};
const replyComposeWithConfirmation = (status: Status, intl: IntlShape) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
if (state.compose.text.trim().length !== 0) {
dispatch(openModal('CONFIRM', {
message: intl.formatMessage(messages.replyMessage),
confirm: intl.formatMessage(messages.replyConfirm),
onConfirm: () => dispatch(replyCompose(status)),
}));
} else {
dispatch(replyCompose(status));
}
};
const cancelReplyCompose = () => ({
type: COMPOSE_REPLY_CANCEL,
id: 'compose-modal',
});
const quoteCompose = (status: Status) =>
@@ -173,6 +152,7 @@ const quoteCompose = (status: Status) =>
dispatch({
type: COMPOSE_QUOTE,
id: 'compose-modal',
status: status,
account: state.accounts.get(state.me),
explicitAddressing,
@@ -183,16 +163,19 @@ const quoteCompose = (status: Status) =>
const cancelQuoteCompose = () => ({
type: COMPOSE_QUOTE_CANCEL,
id: 'compose-modal',
});
const resetCompose = () => ({
const resetCompose = (composeId = 'compose-modal') => ({
type: COMPOSE_RESET,
id: composeId,
});
const mentionCompose = (account: Account) =>
(dispatch: AppDispatch) => {
dispatch({
type: COMPOSE_MENTION,
id: 'compose-modal',
account: account,
});
@@ -203,6 +186,7 @@ const directCompose = (account: Account) =>
(dispatch: AppDispatch) => {
dispatch({
type: COMPOSE_DIRECT,
id: 'compose-modal',
account: account,
});
@@ -215,22 +199,23 @@ const directComposeById = (accountId: string) =>
dispatch({
type: COMPOSE_DIRECT,
id: 'compose-modal',
account: account,
});
dispatch(openModal('COMPOSE'));
};
const handleComposeSubmit = (dispatch: AppDispatch, getState: () => RootState, data: APIEntity, status: string, edit?: boolean) => {
const handleComposeSubmit = (dispatch: AppDispatch, getState: () => RootState, composeId: string, data: APIEntity, status: string, edit?: boolean) => {
if (!dispatch || !getState) return;
dispatch(insertIntoTagHistory(data.tags || [], status));
dispatch(submitComposeSuccess({ ...data }));
dispatch(insertIntoTagHistory(composeId, data.tags || [], status));
dispatch(submitComposeSuccess(composeId, { ...data }));
dispatch(snackbar.success(edit ? messages.editSuccess : messages.success, messages.view, `/@${data.account.acct}/posts/${data.id}`));
};
const needsDescriptions = (state: RootState) => {
const media = state.compose.media_attachments;
const needsDescriptions = (state: RootState, composeId: string) => {
const media = state.compose.get(composeId)!.media_attachments;
const missingDescriptionModal = getSettings(state).get('missingDescriptionModal');
const hasMissing = media.filter(item => !item.description).size > 0;
@@ -238,8 +223,8 @@ const needsDescriptions = (state: RootState) => {
return missingDescriptionModal && hasMissing;
};
const validateSchedule = (state: RootState) => {
const schedule = state.compose.schedule;
const validateSchedule = (state: RootState, composeId: string) => {
const schedule = state.compose.get(composeId)?.schedule;
if (!schedule) return true;
const fiveMinutesFromNow = new Date(new Date().getTime() + 300000);
@@ -247,17 +232,19 @@ const validateSchedule = (state: RootState) => {
return schedule.getTime() > fiveMinutesFromNow.getTime();
};
const submitCompose = (routerHistory?: History, force = false) =>
const submitCompose = (composeId: string, routerHistory?: History, force = false) =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
const state = getState();
const status = state.compose.text;
const media = state.compose.media_attachments;
const statusId = state.compose.id;
let to = state.compose.to;
const compose = state.compose.get(composeId)!;
if (!validateSchedule(state)) {
const status = compose.text;
const media = compose.media_attachments;
const statusId = compose.id;
let to = compose.to;
if (!validateSchedule(state, composeId)) {
dispatch(snackbar.error(messages.scheduleError));
return;
}
@@ -266,11 +253,11 @@ const submitCompose = (routerHistory?: History, force = false) =>
return;
}
if (!force && needsDescriptions(state)) {
if (!force && needsDescriptions(state, composeId)) {
dispatch(openModal('MISSING_DESCRIPTION', {
onContinue: () => {
dispatch(closeModal('MISSING_DESCRIPTION'));
dispatch(submitCompose(routerHistory, true));
dispatch(submitCompose(composeId, routerHistory, true));
},
}));
return;
@@ -282,22 +269,22 @@ const submitCompose = (routerHistory?: History, force = false) =>
to = to.union(mentions.map(mention => mention.trim().slice(1)));
}
dispatch(submitComposeRequest());
dispatch(submitComposeRequest(composeId));
dispatch(closeModal());
const idempotencyKey = state.compose.idempotencyKey;
const idempotencyKey = compose.idempotencyKey;
const params = {
status,
in_reply_to_id: state.compose.in_reply_to,
quote_id: state.compose.quote,
in_reply_to_id: compose.in_reply_to,
quote_id: compose.quote,
media_ids: media.map(item => item.id),
sensitive: state.compose.sensitive,
spoiler_text: state.compose.spoiler_text,
visibility: state.compose.privacy,
content_type: state.compose.content_type,
poll: state.compose.poll,
scheduled_at: state.compose.schedule,
sensitive: compose.sensitive,
spoiler_text: compose.spoiler_text,
visibility: compose.privacy,
content_type: compose.content_type,
poll: compose.poll,
scheduled_at: compose.schedule,
to,
};
@@ -305,27 +292,30 @@ const submitCompose = (routerHistory?: History, force = false) =>
if (!statusId && data.visibility === 'direct' && getState().conversations.mounted <= 0 && routerHistory) {
routerHistory.push('/messages');
}
handleComposeSubmit(dispatch, getState, data, status, !!statusId);
handleComposeSubmit(dispatch, getState, composeId, data, status, !!statusId);
}).catch(function(error) {
dispatch(submitComposeFail(error));
dispatch(submitComposeFail(composeId, error));
});
};
const submitComposeRequest = () => ({
const submitComposeRequest = (composeId: string) => ({
type: COMPOSE_SUBMIT_REQUEST,
id: composeId,
});
const submitComposeSuccess = (status: APIEntity) => ({
const submitComposeSuccess = (composeId: string, status: APIEntity) => ({
type: COMPOSE_SUBMIT_SUCCESS,
id: composeId,
status: status,
});
const submitComposeFail = (error: AxiosError) => ({
const submitComposeFail = (composeId: string, error: AxiosError) => ({
type: COMPOSE_SUBMIT_FAIL,
id: composeId,
error: error,
});
const uploadCompose = (files: FileList, intl: IntlShape) =>
const uploadCompose = (composeId: string, files: FileList, intl: IntlShape) =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
const attachmentLimit = getState().instance.configuration.getIn(['statuses', 'max_media_attachments']) as number;
@@ -333,19 +323,21 @@ const uploadCompose = (files: FileList, intl: IntlShape) =>
const maxVideoSize = getState().instance.configuration.getIn(['media_attachments', 'video_size_limit']) as number | undefined;
const maxVideoDuration = getState().instance.configuration.getIn(['media_attachments', 'video_duration_limit']) as number | undefined;
const media = getState().compose.media_attachments;
const media = getState().compose.get(composeId)?.media_attachments;
const progress = new Array(files.length).fill(0);
let total = Array.from(files).reduce((a, v) => a + v.size, 0);
if (files.length + media.size > attachmentLimit) {
const mediaCount = media ? media.size : 0;
if (files.length + mediaCount > attachmentLimit) {
dispatch(showAlert(undefined, messages.uploadErrorLimit, 'error'));
return;
}
dispatch(uploadComposeRequest());
dispatch(uploadComposeRequest(composeId));
Array.from(files).forEach(async(f, i) => {
if (media.size + i > attachmentLimit - 1) return;
if (mediaCount + i > attachmentLimit - 1) return;
const isImage = f.type.match(/image.*/);
const isVideo = f.type.match(/video.*/);
@@ -355,18 +347,18 @@ const uploadCompose = (files: FileList, intl: IntlShape) =>
const limit = formatBytes(maxImageSize);
const message = intl.formatMessage(messages.exceededImageSizeLimit, { limit });
dispatch(snackbar.error(message));
dispatch(uploadComposeFail(true));
dispatch(uploadComposeFail(composeId, true));
return;
} else if (isVideo && maxVideoSize && (f.size > maxVideoSize)) {
const limit = formatBytes(maxVideoSize);
const message = intl.formatMessage(messages.exceededVideoSizeLimit, { limit });
dispatch(snackbar.error(message));
dispatch(uploadComposeFail(true));
dispatch(uploadComposeFail(composeId, true));
return;
} else if (isVideo && maxVideoDuration && (videoDurationInSeconds > maxVideoDuration)) {
const message = intl.formatMessage(messages.exceededVideoDurationLimit, { limit: maxVideoDuration });
dispatch(snackbar.error(message));
dispatch(uploadComposeFail(true));
dispatch(uploadComposeFail(composeId, true));
return;
}
@@ -380,7 +372,7 @@ const uploadCompose = (files: FileList, intl: IntlShape) =>
const onUploadProgress = ({ loaded }: any) => {
progress[i] = loaded;
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
dispatch(uploadComposeProgress(composeId, progress.reduce((a, v) => a + v, 0), total));
};
return dispatch(uploadMedia(data, onUploadProgress))
@@ -388,98 +380,107 @@ const uploadCompose = (files: FileList, intl: IntlShape) =>
// If server-side processing of the media attachment has not completed yet,
// poll the server until it is, before showing the media attachment as uploaded
if (status === 200) {
dispatch(uploadComposeSuccess(data, f));
dispatch(uploadComposeSuccess(composeId, data, f));
} else if (status === 202) {
const poll = () => {
dispatch(fetchMedia(data.id)).then(({ status, data }) => {
if (status === 200) {
dispatch(uploadComposeSuccess(data, f));
dispatch(uploadComposeSuccess(composeId, data, f));
} else if (status === 206) {
setTimeout(() => poll(), 1000);
}
}).catch(error => dispatch(uploadComposeFail(error)));
}).catch(error => dispatch(uploadComposeFail(composeId, error)));
};
poll();
}
});
}).catch(error => dispatch(uploadComposeFail(error)));
}).catch(error => dispatch(uploadComposeFail(composeId, error)));
/* eslint-enable no-loop-func */
});
};
const changeUploadCompose = (id: string, params: Record<string, any>) =>
const changeUploadCompose = (composeId: string, id: string, params: Record<string, any>) =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
dispatch(changeUploadComposeRequest());
dispatch(changeUploadComposeRequest(composeId));
dispatch(updateMedia(id, params)).then(response => {
dispatch(changeUploadComposeSuccess(response.data));
dispatch(changeUploadComposeSuccess(composeId, response.data));
}).catch(error => {
dispatch(changeUploadComposeFail(id, error));
dispatch(changeUploadComposeFail(composeId, id, error));
});
};
const changeUploadComposeRequest = () => ({
const changeUploadComposeRequest = (composeId: string) => ({
type: COMPOSE_UPLOAD_CHANGE_REQUEST,
id: composeId,
skipLoading: true,
});
const changeUploadComposeSuccess = (media: APIEntity) => ({
const changeUploadComposeSuccess = (composeId: string, media: APIEntity) => ({
type: COMPOSE_UPLOAD_CHANGE_SUCCESS,
id: composeId,
media: media,
skipLoading: true,
});
const changeUploadComposeFail = (id: string, error: AxiosError) => ({
const changeUploadComposeFail = (composeId: string, id: string, error: AxiosError) => ({
type: COMPOSE_UPLOAD_CHANGE_FAIL,
composeId,
id,
error: error,
skipLoading: true,
});
const uploadComposeRequest = () => ({
const uploadComposeRequest = (composeId: string) => ({
type: COMPOSE_UPLOAD_REQUEST,
id: composeId,
skipLoading: true,
});
const uploadComposeProgress = (loaded: number, total: number) => ({
const uploadComposeProgress = (composeId: string, loaded: number, total: number) => ({
type: COMPOSE_UPLOAD_PROGRESS,
id: composeId,
loaded: loaded,
total: total,
});
const uploadComposeSuccess = (media: APIEntity, file: File) => ({
const uploadComposeSuccess = (composeId: string, media: APIEntity, file: File) => ({
type: COMPOSE_UPLOAD_SUCCESS,
id: composeId,
media: media,
file,
skipLoading: true,
});
const uploadComposeFail = (error: AxiosError | true) => ({
const uploadComposeFail = (composeId: string, error: AxiosError | true) => ({
type: COMPOSE_UPLOAD_FAIL,
id: composeId,
error: error,
skipLoading: true,
});
const undoUploadCompose = (media_id: string) => ({
const undoUploadCompose = (composeId: string, media_id: string) => ({
type: COMPOSE_UPLOAD_UNDO,
id: composeId,
media_id: media_id,
});
const clearComposeSuggestions = () => {
const clearComposeSuggestions = (composeId: string) => {
if (cancelFetchComposeSuggestionsAccounts) {
cancelFetchComposeSuggestionsAccounts();
}
return {
type: COMPOSE_SUGGESTIONS_CLEAR,
id: composeId,
};
};
const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) => {
const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, composeId, token) => {
if (cancelFetchComposeSuggestionsAccounts) {
cancelFetchComposeSuggestionsAccounts();
cancelFetchComposeSuggestionsAccounts(composeId);
}
api(getState).get('/api/v1/accounts/search', {
cancelToken: new CancelToken(cancel => {
@@ -492,7 +493,7 @@ const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) =>
},
}).then(response => {
dispatch(importFetchedAccounts(response.data));
dispatch(readyComposeSuggestionsAccounts(token, response.data));
dispatch(readyComposeSuggestionsAccounts(composeId, token, response.data));
}).catch(error => {
if (!isCancel(error)) {
dispatch(showAlertForError(error));
@@ -500,46 +501,48 @@ const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) =>
});
}, 200, { leading: true, trailing: true });
const fetchComposeSuggestionsEmojis = (dispatch: AppDispatch, getState: () => RootState, token: string) => {
const fetchComposeSuggestionsEmojis = (dispatch: AppDispatch, getState: () => RootState, composeId: string, token: string) => {
const results = emojiSearch(token.replace(':', ''), { maxResults: 5 } as any);
dispatch(readyComposeSuggestionsEmojis(token, results));
dispatch(readyComposeSuggestionsEmojis(composeId, token, results));
};
const fetchComposeSuggestionsTags = (dispatch: AppDispatch, getState: () => RootState, token: string) => {
const fetchComposeSuggestionsTags = (dispatch: AppDispatch, getState: () => RootState, composeId: string, token: string) => {
const state = getState();
const currentTrends = state.trends.items;
dispatch(updateSuggestionTags(token, currentTrends));
dispatch(updateSuggestionTags(composeId, token, currentTrends));
};
const fetchComposeSuggestions = (token: string) =>
const fetchComposeSuggestions = (composeId: string, token: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
switch (token[0]) {
case ':':
fetchComposeSuggestionsEmojis(dispatch, getState, token);
fetchComposeSuggestionsEmojis(dispatch, getState, composeId, token);
break;
case '#':
fetchComposeSuggestionsTags(dispatch, getState, token);
fetchComposeSuggestionsTags(dispatch, getState, composeId, token);
break;
default:
fetchComposeSuggestionsAccounts(dispatch, getState, token);
fetchComposeSuggestionsAccounts(dispatch, getState, composeId, token);
break;
}
};
const readyComposeSuggestionsEmojis = (token: string, emojis: Emoji[]) => ({
const readyComposeSuggestionsEmojis = (composeId: string, token: string, emojis: Emoji[]) => ({
type: COMPOSE_SUGGESTIONS_READY,
id: composeId,
token,
emojis,
});
const readyComposeSuggestionsAccounts = (token: string, accounts: APIEntity[]) => ({
const readyComposeSuggestionsAccounts = (composeId: string, token: string, accounts: APIEntity[]) => ({
type: COMPOSE_SUGGESTIONS_READY,
id: composeId,
token,
accounts,
});
const selectComposeSuggestion = (position: number, token: string | null, suggestion: AutoSuggestion, path: Array<string | number>) =>
const selectComposeSuggestion = (composeId: string, position: number, token: string | null, suggestion: AutoSuggestion, path: Array<string | number>) =>
(dispatch: AppDispatch, getState: () => RootState) => {
let completion, startPosition;
@@ -558,6 +561,7 @@ const selectComposeSuggestion = (position: number, token: string | null, suggest
dispatch({
type: COMPOSE_SUGGESTION_SELECT,
id: composeId,
position: startPosition,
token,
completion,
@@ -565,21 +569,23 @@ const selectComposeSuggestion = (position: number, token: string | null, suggest
});
};
const updateSuggestionTags = (token: string, currentTrends: ImmutableList<Tag>) => ({
const updateSuggestionTags = (composeId: string, token: string, currentTrends: ImmutableList<Tag>) => ({
type: COMPOSE_SUGGESTION_TAGS_UPDATE,
id: composeId,
token,
currentTrends,
});
const updateTagHistory = (tags: string[]) => ({
const updateTagHistory = (composeId: string, tags: string[]) => ({
type: COMPOSE_TAG_HISTORY_UPDATE,
id: composeId,
tags,
});
const insertIntoTagHistory = (recognizedTags: APIEntity[], text: string) =>
const insertIntoTagHistory = (composeId: string, recognizedTags: APIEntity[], text: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const oldHistory = state.compose.tagHistory;
const oldHistory = state.compose.get(composeId)!.tagHistory;
const me = state.me;
const names = recognizedTags
.filter(tag => text.match(new RegExp(`#${tag.name}`, 'i')))
@@ -591,120 +597,124 @@ const insertIntoTagHistory = (recognizedTags: APIEntity[], text: string) =>
const newHistory = names.slice(0, 1000);
tagHistory.set(me as string, newHistory);
dispatch(updateTagHistory(newHistory));
dispatch(updateTagHistory(composeId, newHistory));
};
const mountCompose = () => ({
type: COMPOSE_MOUNT,
});
const unmountCompose = () => ({
type: COMPOSE_UNMOUNT,
});
const changeComposeSensitivity = () => ({
const changeComposeSensitivity = (composeId: string) => ({
type: COMPOSE_SENSITIVITY_CHANGE,
id: composeId,
});
const changeComposeSpoilerness = () => ({
const changeComposeSpoilerness = (composeId: string) => ({
type: COMPOSE_SPOILERNESS_CHANGE,
id: composeId,
});
const changeComposeContentType = (value: string) => ({
const changeComposeContentType = (composeId: string, value: string) => ({
type: COMPOSE_TYPE_CHANGE,
id: composeId,
value,
});
const changeComposeSpoilerText = (text: string) => ({
const changeComposeSpoilerText = (composeId: string, text: string) => ({
type: COMPOSE_SPOILER_TEXT_CHANGE,
id: composeId,
text,
});
const changeComposeVisibility = (value: string) => ({
const changeComposeVisibility = (composeId: string, value: string) => ({
type: COMPOSE_VISIBILITY_CHANGE,
id: composeId,
value,
});
const insertEmojiCompose = (position: number, emoji: string, needsSpace: boolean) => ({
const insertEmojiCompose = (composeId: string, position: number, emoji: Emoji, needsSpace: boolean) => ({
type: COMPOSE_EMOJI_INSERT,
id: composeId,
position,
emoji,
needsSpace,
});
const changeComposing = (value: string) => ({
type: COMPOSE_COMPOSING_CHANGE,
value,
});
const addPoll = () => ({
const addPoll = (composeId: string) => ({
type: COMPOSE_POLL_ADD,
id: composeId,
});
const removePoll = () => ({
const removePoll = (composeId: string) => ({
type: COMPOSE_POLL_REMOVE,
id: composeId,
});
const addSchedule = () => ({
const addSchedule = (composeId: string) => ({
type: COMPOSE_SCHEDULE_ADD,
id: composeId,
});
const setSchedule = (date: Date) => ({
const setSchedule = (composeId: string, date: Date) => ({
type: COMPOSE_SCHEDULE_SET,
id: composeId,
date: date,
});
const removeSchedule = () => ({
const removeSchedule = (composeId: string) => ({
type: COMPOSE_SCHEDULE_REMOVE,
id: composeId,
});
const addPollOption = (title: string) => ({
const addPollOption = (composeId: string, title: string) => ({
type: COMPOSE_POLL_OPTION_ADD,
id: composeId,
title,
});
const changePollOption = (index: number, title: string) => ({
const changePollOption = (composeId: string, index: number, title: string) => ({
type: COMPOSE_POLL_OPTION_CHANGE,
id: composeId,
index,
title,
});
const removePollOption = (index: number) => ({
const removePollOption = (composeId: string, index: number) => ({
type: COMPOSE_POLL_OPTION_REMOVE,
id: composeId,
index,
});
const changePollSettings = (expiresIn?: string | number, isMultiple?: boolean) => ({
const changePollSettings = (composeId: string, expiresIn?: string | number, isMultiple?: boolean) => ({
type: COMPOSE_POLL_SETTINGS_CHANGE,
id: composeId,
expiresIn,
isMultiple,
});
const openComposeWithText = (text = '') =>
const openComposeWithText = (composeId: string, text = '') =>
(dispatch: AppDispatch) => {
dispatch(resetCompose());
dispatch(resetCompose(composeId));
dispatch(openModal('COMPOSE'));
dispatch(changeCompose(text));
dispatch(changeCompose(composeId, text));
};
const addToMentions = (accountId: string) =>
const addToMentions = (composeId: string, accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const acct = state.accounts.get(accountId)!.acct;
return dispatch({
type: COMPOSE_ADD_TO_MENTIONS,
id: composeId,
account: acct,
});
};
const removeFromMentions = (accountId: string) =>
const removeFromMentions = (composeId: string, accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const acct = state.accounts.get(accountId)!.acct;
return dispatch({
type: COMPOSE_REMOVE_FROM_MENTIONS,
id: composeId,
account: acct,
});
};
@@ -731,8 +741,6 @@ export {
COMPOSE_SUGGESTION_SELECT,
COMPOSE_SUGGESTION_TAGS_UPDATE,
COMPOSE_TAG_HISTORY_UPDATE,
COMPOSE_MOUNT,
COMPOSE_UNMOUNT,
COMPOSE_SENSITIVITY_CHANGE,
COMPOSE_SPOILERNESS_CHANGE,
COMPOSE_TYPE_CHANGE,
@@ -756,11 +764,9 @@ export {
COMPOSE_ADD_TO_MENTIONS,
COMPOSE_REMOVE_FROM_MENTIONS,
COMPOSE_SET_STATUS,
ensureComposeIsVisible,
setComposeToStatus,
changeCompose,
replyCompose,
replyComposeWithConfirmation,
cancelReplyCompose,
quoteCompose,
cancelQuoteCompose,
@@ -790,15 +796,12 @@ export {
selectComposeSuggestion,
updateSuggestionTags,
updateTagHistory,
mountCompose,
unmountCompose,
changeComposeSensitivity,
changeComposeSpoilerness,
changeComposeContentType,
changeComposeSpoilerText,
changeComposeVisibility,
insertEmojiCompose,
changeComposing,
addPoll,
removePoll,
addSchedule,

View File

@@ -177,7 +177,6 @@ const toggleFavourite = (status: StatusEntity) =>
}
};
const favouriteRequest = (status: StatusEntity) => ({
type: FAVOURITE_REQUEST,
status: status,