MM-52513: fixes deleting a reply (#23177)

* MM-52513: fixes deleting a reply

Currently when we receive a WS event for a reply being deleted we might
accidentally push it to a wrong team's store. This might happen if the
thread is already loaded in store and we are viewing another team.
In that case we were fetching the thread from the API using the team id
of the current team. The API returns the thread, even though the team id
is not the one which the thread belongs to.

This commit is fixing the above issue by getting the team id in which
the thread belongs to, or current team id in the case of DM/GM messages,
and using that to fetch the thread from the API.

PS: the fetching is needed since we don't send a thread_update WS event
upon deleting a reply, and we need to get the new participants list.

* Fixes team id on another occasion

* Refactors a bit

* Reverts returning empty string as team id

* Refactor a bit to pass the post as argument

---------

Co-authored-by: Kyriakos Ziakoulis <koox00@Kyriakoss-MacBook-Pro.local>
Co-authored-by: Kyriakos Ziakoulis <koox00@192.168.2.3>
Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Этот коммит содержится в:
Kyriakos Z
2023-05-30 22:33:19 +03:00
коммит произвёл GitHub
родитель 281f8cf9ea
Коммит 14fcc8a22e
2 изменённых файлов: 24 добавлений и 5 удалений

Просмотреть файл

@@ -82,7 +82,7 @@ import {
getCurrentChannelId,
getRedirectChannelNameForTeam,
} from 'mattermost-redux/selectors/entities/channels';
import {getPost, getMostRecentPostIdInChannel} from 'mattermost-redux/selectors/entities/posts';
import {getPost, getMostRecentPostIdInChannel, getTeamIdFromPost} from 'mattermost-redux/selectors/entities/posts';
import {haveISystemPermission, haveITeamPermission} from 'mattermost-redux/selectors/entities/roles';
import {appsFeatureFlagEnabled} from 'mattermost-redux/selectors/entities/apps';
import {getStandardAnalytics} from 'mattermost-redux/actions/admin';
@@ -774,8 +774,10 @@ async function handlePostDeleteEvent(msg) {
const thread = getThread(state, post.root_id);
if (thread) {
const userId = getCurrentUserId(state);
const teamId = getCurrentTeamId(state);
dispatch(fetchThread(userId, teamId, post.root_id, true));
const teamId = getTeamIdFromPost(state, post);
if (teamId) {
dispatch(fetchThread(userId, teamId, post.root_id, true));
}
} else {
const res = await dispatch(getPostThread(post.root_id));
const {order, posts} = res.data;
@@ -1679,7 +1681,7 @@ function handleThreadFollowChanged(msg) {
const state = doGetState();
const thread = getThread(state, msg.data.thread_id);
if (!thread && msg.data.state && msg.data.reply_count) {
await doDispatch(fetchThread(getCurrentUserId(state), getCurrentTeamId(state), msg.data.thread_id, true));
await doDispatch(fetchThread(getCurrentUserId(state), msg.broadcast.team_id, msg.data.thread_id, true));
}
handleFollowChanged(doDispatch, msg.data.thread_id, msg.broadcast.team_id, msg.data.state);
};

Просмотреть файл

@@ -1,13 +1,15 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Posts, Preferences} from 'mattermost-redux/constants';
import {General, Posts, Preferences} from 'mattermost-redux/constants';
import {createSelector} from 'mattermost-redux/selectors/create_selector';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/common';
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
import {getUsers, getCurrentUserId, getUserStatuses} from 'mattermost-redux/selectors/entities/users';
import {getConfig, getFeatureFlagValue} from 'mattermost-redux/selectors/entities/general';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {createIdsSelector} from 'mattermost-redux/utils/helpers';
@@ -36,6 +38,7 @@ import {
import {Reaction} from '@mattermost/types/reactions';
import {GlobalState} from '@mattermost/types/store';
import {UserProfile} from '@mattermost/types/users';
import type {Team} from '@mattermost/types/teams';
import {
IDMappedObjects,
RelationOneToOne,
@@ -830,3 +833,17 @@ export function makeGetPostAcknowledgementsWithProfiles(): (state: GlobalState,
},
);
}
export function getTeamIdFromPost(state: GlobalState, post: Post): Team['id'] | undefined {
const channel = getChannel(state, post.channel_id);
if (!channel) {
return undefined;
}
if (channel.type === General.DM_CHANNEL || channel.type === General.GM_CHANNEL) {
return getCurrentTeamId(state);
}
return channel.team_id;
}