diff --git a/src/actions/compose.ts b/src/actions/compose.ts index 2339ff4ce2..d9e544768b 100644 --- a/src/actions/compose.ts +++ b/src/actions/compose.ts @@ -7,7 +7,7 @@ import api from 'soapbox/api'; import { isNativeEmoji } from 'soapbox/features/emoji'; import emojiSearch from 'soapbox/features/emoji/search'; import { normalizeTag } from 'soapbox/normalizers'; -import { selectAccount, selectOwnAccount } from 'soapbox/selectors'; +import { selectAccount, selectOwnAccount, makeGetAccount } from 'soapbox/selectors'; import { tagHistory } from 'soapbox/settings'; import toast from 'soapbox/toast'; import { isLoggedIn } from 'soapbox/utils/auth'; @@ -89,6 +89,8 @@ const COMPOSE_SET_STATUS = 'COMPOSE_SET_STATUS' as const; const COMPOSE_EDITOR_STATE_SET = 'COMPOSE_EDITOR_STATE_SET' as const; +const getAccount = makeGetAccount(); + const messages = defineMessages({ scheduleError: { id: 'compose.invalid_schedule', defaultMessage: 'You must schedule a post at least 5 minutes out.' }, success: { id: 'compose.submit_success', defaultMessage: 'Your post was sent!' }, @@ -279,11 +281,11 @@ const handleComposeSubmit = (dispatch: AppDispatch, getState: () => RootState, c const state = getState(); - const me = state.me as string; + const accountUrl = getAccount(state, state.me as string)!.url; const draftId = getState().compose.get(composeId)!.draft_id; dispatch(insertIntoTagHistory(composeId, data.tags || [], status)); - dispatch(submitComposeSuccess(composeId, { ...data }, me, draftId)); + dispatch(submitComposeSuccess(composeId, { ...data }, accountUrl, draftId)); toast.success(edit ? messages.editSuccess : messages.success, { actionLabel: messages.view, actionLink: `/@${data.account.acct}/posts/${data.id}`, @@ -391,11 +393,11 @@ const submitComposeRequest = (composeId: string) => ({ id: composeId, }); -const submitComposeSuccess = (composeId: string, status: APIEntity, accountId: string, draftId?: string | null) => ({ +const submitComposeSuccess = (composeId: string, status: APIEntity, accountUrl: string, draftId?: string | null) => ({ type: COMPOSE_SUBMIT_SUCCESS, id: composeId, status: status, - accountId, + accountUrl, draftId, }); diff --git a/src/actions/draft-statuses.ts b/src/actions/draft-statuses.ts index 6186dfb5a7..90d10c652c 100644 --- a/src/actions/draft-statuses.ts +++ b/src/actions/draft-statuses.ts @@ -1,5 +1,6 @@ import { v4 as uuid } from 'uuid'; +import { makeGetAccount } from 'soapbox/selectors'; import KVStore from 'soapbox/storage/kv-store'; import type { AppDispatch, RootState } from 'soapbox/store'; @@ -9,18 +10,25 @@ const DRAFT_STATUSES_FETCH_SUCCESS = 'DRAFT_STATUSES_FETCH_SUCCESS'; const PERSIST_DRAFT_STATUS = 'PERSIST_DRAFT_STATUS'; const CANCEL_DRAFT_STATUS = 'DELETE_DRAFT_STATUS'; +const getAccount = makeGetAccount(); + const fetchDraftStatuses = () => - (dispatch: AppDispatch, getState: () => RootState) => - KVStore.getItem(`drafts:${getState().me}`).then((statuses) => { + (dispatch: AppDispatch, getState: () => RootState) => { + const state = getState(); + const accountUrl = getAccount(state, state.me as string)!.url; + + return KVStore.getItem(`drafts:${accountUrl}`).then((statuses) => { dispatch({ type: DRAFT_STATUSES_FETCH_SUCCESS, statuses, }); }).catch(() => {}); + }; const saveDraftStatus = (composeId: string) => (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); + const accountUrl = getAccount(state, state.me as string)!.url; const compose = state.compose.get(composeId)!; @@ -32,17 +40,21 @@ const saveDraftStatus = (composeId: string) => dispatch({ type: PERSIST_DRAFT_STATUS, status: draft, - accountId: state.me, + accountUrl, }); }; const cancelDraftStatus = (id: string) => - (dispatch: AppDispatch, getState: () => RootState) => + (dispatch: AppDispatch, getState: () => RootState) => { + const state = getState(); + const accountUrl = getAccount(state, state.me as string)!.url; + dispatch({ type: CANCEL_DRAFT_STATUS, id, - accountId: getState().me, + accountUrl, }); + }; export { DRAFT_STATUSES_FETCH_SUCCESS, diff --git a/src/reducers/draft-statuses.ts b/src/reducers/draft-statuses.ts index ce3f940758..689d486f66 100644 --- a/src/reducers/draft-statuses.ts +++ b/src/reducers/draft-statuses.ts @@ -43,8 +43,8 @@ const deleteStatus = (state: State, id: string) => { return state; }; -const persistState = (state: State, accountId: string) => { - KVStore.setItem(`drafts:${accountId}`, state.toJS()); +const persistState = (state: State, accountUrl: string) => { + KVStore.setItem(`drafts:${accountUrl}`, state.toJS()); return state; }; @@ -53,11 +53,11 @@ export default function scheduled_statuses(state: State = initialState, action: case DRAFT_STATUSES_FETCH_SUCCESS: return importStatuses(state, action.statuses); case PERSIST_DRAFT_STATUS: - return persistState(importStatus(state, action.status), action.accountId); + return persistState(importStatus(state, action.status), action.accountUrl); case CANCEL_DRAFT_STATUS: - return persistState(deleteStatus(state, action.id), action.accountId); + return persistState(deleteStatus(state, action.id), action.accountUrl); case COMPOSE_SUBMIT_SUCCESS: - return persistState(deleteStatus(state, action.draftId), action.accountId); + return persistState(deleteStatus(state, action.draftId), action.accountUrl); default: return state; }