Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-39073: fixes threads unread tab #9047

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/threading/global_threads/global_threads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const GlobalThreads = () => {
}, [currentUserId, currentTeamId, filter]);

useEffect(() => {
if ((!selectedThread || !selectedPost) && !isLoading) {
if (!selectedThread && !selectedPost && !isLoading) {
clear();
}
}, [currentTeamId, selectedThread, selectedPost, isLoading, counts, filter]);
Expand Down
14 changes: 13 additions & 1 deletion packages/mattermost-redux/src/actions/threads.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Actions.Threads', () => {

const currentTeamId = 'currentTeamId'.padEnd(26, ID_PAD);
const currentUserId = 'currentUserId'.padEnd(26, ID_PAD);
const channel = TestHelper.fakeChannelWithId(currentTeamId);

beforeEach(() => {
store = configureStore({
Expand All @@ -89,6 +90,17 @@ describe('Actions.Threads', () => {
users: {
currentUserId,
},
channels: {
channelsInTeam: {
[currentTeamId]: [channel.id],
},
channels: {
[channel.id]: channel,
},
myMembers: {
[channel.id]: {},
},
},
},
});
});
Expand All @@ -98,7 +110,7 @@ describe('Actions.Threads', () => {
});

test('getThread', async () => {
const [mockThread, {threadId}] = mockUserThread();
const [mockThread, {threadId}] = mockUserThread({channelId: channel.id});

nock(Client4.getBaseRoute()).
get((uri) => uri.includes(`/users/${currentUserId}/teams/${currentTeamId}/threads/${threadId}`)).
Expand Down
18 changes: 12 additions & 6 deletions packages/mattermost-redux/src/selectors/entities/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import {createSelector} from 'reselect';

import {getMyChannels} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {GlobalState} from 'mattermost-redux/types/store';
import {Team} from 'mattermost-redux/types/teams';
Expand Down Expand Up @@ -66,15 +67,20 @@ export function getThreads(state: GlobalState): IDMappedObjects<UserThread> {
return state.entities.threads.threads;
}

export function getThread(state: GlobalState, threadId: $ID<UserThread> | undefined): UserThread | null {
if (
!threadId ||
!(getThreadsInCurrentTeam(state)?.includes(threadId) || getUnreadThreadsInCurrentTeam(state)?.includes(threadId))
) {
export function getThread(state: GlobalState, threadId?: $ID<UserThread>) {
const threads = getThreads(state);
const myChannels = getMyChannels(state).map((c) => c.id);

if (!threadId) {
return null;
}

const thread = threads[threadId];
if (!thread || (thread.post && myChannels.indexOf(thread.post.channel_id) === -1)) {
return null;
}

return getThreads(state)[threadId];
return thread;
}

export function getThreadOrSynthetic(state: GlobalState, rootPost: Post): UserThread | UserThreadSynthetic {
Expand Down