* Revert front-end changes for #25715 * Fix lint * Fix again --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b02d634916
Коммит
7bae6c57f9
@@ -5,7 +5,7 @@ import {Client4} from 'mattermost-redux/client';
|
||||
import {Posts, Preferences} from 'mattermost-redux/constants';
|
||||
import {getPreferenceKey} from 'mattermost-redux/utils/preference_utils';
|
||||
|
||||
import {removeGlobalItem, setGlobalItem} from 'actions/storage';
|
||||
import {setGlobalItem} from 'actions/storage';
|
||||
|
||||
import mockStore from 'tests/test_store';
|
||||
import {StoragePrefixes} from 'utils/constants';
|
||||
@@ -164,19 +164,6 @@ describe('draft actions', () => {
|
||||
|
||||
describe('removeDraft', () => {
|
||||
it('calls setGlobalItem action correctly', async () => {
|
||||
store = mockStore({
|
||||
...initialState,
|
||||
entities: {
|
||||
...initialState.entities,
|
||||
general: {
|
||||
...initialState.entities.general,
|
||||
config: {
|
||||
...initialState.entities.general.config,
|
||||
AllowSyncedDrafts: 'false',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
await store.dispatch(removeDraft(key, channelId));
|
||||
|
||||
const testStore = mockStore(initialState);
|
||||
@@ -187,8 +174,6 @@ describe('draft actions', () => {
|
||||
uploadsInProgress: [],
|
||||
}));
|
||||
|
||||
testStore.dispatch(removeGlobalItem(StoragePrefixes.DRAFT + channelId));
|
||||
|
||||
expect(store.getActions()).toEqual(testStore.getActions());
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import type {PostMetadata, PostPriorityMetadata} from '@mattermost/types/posts';
|
||||
import type {PreferenceType} from '@mattermost/types/preferences';
|
||||
import type {UserProfile} from '@mattermost/types/users';
|
||||
|
||||
import {getPost} from 'mattermost-redux/actions/posts';
|
||||
import {savePreferences} from 'mattermost-redux/actions/preferences';
|
||||
import {Client4} from 'mattermost-redux/client';
|
||||
import Preferences from 'mattermost-redux/constants/preferences';
|
||||
@@ -17,7 +16,7 @@ import {syncedDraftsAreAllowedAndEnabled} from 'mattermost-redux/selectors/entit
|
||||
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
|
||||
import type {ActionFunc, ActionFuncAsync} from 'mattermost-redux/types/actions';
|
||||
|
||||
import {removeGlobalItem, setGlobalItem} from 'actions/storage';
|
||||
import {setGlobalItem} from 'actions/storage';
|
||||
import {makeGetDrafts} from 'selectors/drafts';
|
||||
import {getConnectionId} from 'selectors/general';
|
||||
import {getGlobalItem} from 'selectors/storage';
|
||||
@@ -45,40 +44,13 @@ export function getDrafts(teamId: string): ActionFuncAsync<boolean, GlobalState>
|
||||
|
||||
let serverDrafts: Draft[] = [];
|
||||
try {
|
||||
const response = await Client4.getUserDrafts(teamId);
|
||||
|
||||
// check if response is an array
|
||||
if (Array.isArray(response)) {
|
||||
serverDrafts = response.map((draft) => transformServerDraft(draft));
|
||||
}
|
||||
serverDrafts = (await Client4.getUserDrafts(teamId)).map((draft) => transformServerDraft(draft));
|
||||
} catch (error) {
|
||||
return {data: false, error};
|
||||
}
|
||||
|
||||
const drafts = [...serverDrafts];
|
||||
const localDrafts = getLocalDrafts(state);
|
||||
|
||||
// drafts that are not on server, but on local storage
|
||||
const localOnlyDrafts = localDrafts.filter((localDraft) => {
|
||||
return !serverDrafts.find((serverDraft) => serverDraft.key === localDraft.key);
|
||||
});
|
||||
|
||||
// check if drafts are still valid
|
||||
await Promise.all(localOnlyDrafts.map(async (draft) => {
|
||||
if (draft.value.rootId) {
|
||||
// get post from server to check if it exists
|
||||
const {error} = await dispatch(getPost(draft.value.rootId));
|
||||
|
||||
// remove locally stored draft if post does not exist
|
||||
if (error.status_code === 404) {
|
||||
await dispatch(setGlobalItem(draft.key, {message: '', fileInfos: [], uploadsInProgress: []}));
|
||||
await dispatch(removeGlobalItem(draft.key));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
drafts.push(draft);
|
||||
}));
|
||||
const drafts = [...serverDrafts, ...localDrafts];
|
||||
|
||||
// Reconcile drafts and only keep the latest version of a draft.
|
||||
const draftsMap = new Map(drafts.map((draft) => [draft.key, draft]));
|
||||
@@ -102,12 +74,10 @@ export function removeDraft(key: string, channelId: string, rootId = ''): Action
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
||||
// set draft to empty to re-render the component
|
||||
await dispatch(setGlobalItem(key, {message: '', fileInfos: [], uploadsInProgress: []}));
|
||||
dispatch(setGlobalItem(key, {message: '', fileInfos: [], uploadsInProgress: []}));
|
||||
|
||||
if (syncedDraftsAreAllowedAndEnabled(state)) {
|
||||
const connectionId = getConnectionId(getState());
|
||||
|
||||
try {
|
||||
await Client4.deleteDraft(channelId, rootId, connectionId);
|
||||
} catch (error) {
|
||||
@@ -116,9 +86,6 @@ export function removeDraft(key: string, channelId: string, rootId = ''): Action
|
||||
error,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// only remove draft from storage for local drafts
|
||||
await dispatch(removeGlobalItem(key));
|
||||
}
|
||||
return {data: true};
|
||||
};
|
||||
|
||||
@@ -100,7 +100,7 @@ import {redirectUserToDefaultTeam} from 'actions/global_actions';
|
||||
import {sendDesktopNotification} from 'actions/notification_actions.jsx';
|
||||
import {handleNewPost} from 'actions/post_actions';
|
||||
import * as StatusActions from 'actions/status_actions';
|
||||
import {removeGlobalItem, setGlobalItem} from 'actions/storage';
|
||||
import {setGlobalItem} from 'actions/storage';
|
||||
import {loadProfilesForDM, loadProfilesForGM} from 'actions/user_actions';
|
||||
import {syncPostsInChannel} from 'actions/views/channel';
|
||||
import {setGlobalDraft, transformServerDraft} from 'actions/views/drafts';
|
||||
@@ -118,7 +118,7 @@ import RemovedFromChannelModal from 'components/removed_from_channel_modal';
|
||||
import WebSocketClient from 'client/web_websocket_client';
|
||||
import {loadPlugin, loadPluginsIfNecessary, removePlugin} from 'plugins';
|
||||
import {getHistory} from 'utils/browser_history';
|
||||
import {ActionTypes, Constants, AnnouncementBarMessages, SocketEvents, UserStatuses, ModalIdentifiers, PageLoadContext, StoragePrefixes} from 'utils/constants';
|
||||
import {ActionTypes, Constants, AnnouncementBarMessages, SocketEvents, UserStatuses, ModalIdentifiers, PageLoadContext} from 'utils/constants';
|
||||
import {getSiteURL} from 'utils/url';
|
||||
|
||||
import {temporarilySetPageLoadContext} from './telemetry_actions';
|
||||
@@ -778,19 +778,6 @@ async function handlePostDeleteEvent(msg) {
|
||||
|
||||
dispatch(postDeleted(post));
|
||||
|
||||
// remove draft associated with this post from store
|
||||
const draftKey = `${StoragePrefixes.COMMENT_DRAFT}${post.id}`;
|
||||
|
||||
// update the draft first to re-render
|
||||
await dispatch(setGlobalItem(draftKey, {
|
||||
message: '',
|
||||
fileInfos: [],
|
||||
uploadsInProgress: [],
|
||||
}));
|
||||
|
||||
// then remove it
|
||||
await dispatch(removeGlobalItem(draftKey));
|
||||
|
||||
// update thread when a comment is deleted and CRT is on
|
||||
if (post.root_id && collapsedThreads) {
|
||||
const thread = getThread(state, post.root_id);
|
||||
@@ -1738,15 +1725,11 @@ function handleDeleteDraftEvent(msg) {
|
||||
const draft = JSON.parse(msg.data.draft);
|
||||
const {key} = transformServerDraft(draft);
|
||||
|
||||
// update the draft first to re-render
|
||||
await doDispatch(setGlobalItem(key, {
|
||||
doDispatch(setGlobalItem(key, {
|
||||
message: '',
|
||||
fileInfos: [],
|
||||
uploadsInProgress: [],
|
||||
}));
|
||||
|
||||
// then remove it
|
||||
await doDispatch(removeGlobalItem(key));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user