Skip to content

Commit

Permalink
MM-29986 Don't show archived channels with unread filter enabled (mat…
Browse files Browse the repository at this point in the history
…termost#6956)

Automatic Merge
  • Loading branch information
hmhealey committed Oct 29, 2020
1 parent 10c63e9 commit 6e8e6c7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
52 changes: 48 additions & 4 deletions selectors/views/channel_sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ describe('isCategoryCollapsed', () => {
});

describe('getUnreadChannels', () => {
const currentChanenl = {id: 'currentChanenl', total_msg_count: 0, last_post_at: 0};
const readChannel = {id: 'readChannel', total_msg_count: 10, last_post_at: 300};
const unreadChannel1 = {id: 'unreadChannel1', total_msg_count: 10, last_post_at: 100};
const unreadChannel2 = {id: 'unreadChannel2', total_msg_count: 10, last_post_at: 200};
const currentChanenl = {id: 'currentChanenl', delete_at: 0, total_msg_count: 0, last_post_at: 0};
const readChannel = {id: 'readChannel', delete_at: 0, total_msg_count: 10, last_post_at: 300};
const unreadChannel1 = {id: 'unreadChannel1', delete_at: 0, total_msg_count: 10, last_post_at: 100};
const unreadChannel2 = {id: 'unreadChannel2', delete_at: 0, total_msg_count: 10, last_post_at: 200};

const baseState = {
entities: {
Expand Down Expand Up @@ -212,4 +212,48 @@ describe('getUnreadChannels', () => {
// unreadChannel2 is muted and has a mention
expect(Selectors.getUnreadChannels(state)).toEqual([unreadChannel1, currentChanenl, unreadChannel2]);
});

test('should not show archived channels unless they are the current channel', () => {
const archivedChannel = {id: 'archivedChannel', delete_at: 1, total_msg_count: 10, last_post_at: 400};

let state = {
...baseState,
entities: {
...baseState.entities,
channels: {
...baseState.entities.channels,
channels: {
...baseState.entities.channels.channels,
archivedChannel,
},
channelsInTeam: {
...baseState.entities.channels.channelsInTeam,
team1: [
...baseState.entities.channels.channelsInTeam.team1,
'archivedChannel',
],
},
myMembers: {
...baseState.entities.channels.myMembers,
archivedChannel: {notify_props: {}, mention_count: 0, msg_count: 0},
},
},
},
};

expect(Selectors.getUnreadChannels(state)).toEqual([unreadChannel2, unreadChannel1, currentChanenl]);

state = {
...state,
entities: {
...state.entities,
channels: {
...state.entities.channels,
currentChannelId: 'archivedChannel',
},
},
};

expect(Selectors.getUnreadChannels(state)).toEqual([archivedChannel, unreadChannel2, unreadChannel1]);
});
});
14 changes: 12 additions & 2 deletions selectors/views/channel_sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,19 @@ export const getUnreadChannels = (() => {
(state: GlobalState) => getUnreadChannelIds(state),
getCurrentChannelId,
(allChannels, unreadChannelIds, currentChannelId) => {
const unreadChannels = unreadChannelIds.map((channelId) => allChannels[channelId]);
const unreadChannels = [];
for (const channelId of unreadChannelIds) {
const channel = allChannels[channelId];

if (unreadChannelIds.indexOf(currentChannelId) === -1) {
// Only include an archived channel if it's the current channel
if (channel.delete_at > 0 && channel.id !== currentChannelId) {
continue;
}

unreadChannels.push(channel);
}

if (unreadChannels.findIndex((channel) => channel.id === currentChannelId) === -1) {
unreadChannels.push(allChannels[currentChannelId]);
}

Expand Down

0 comments on commit 6e8e6c7

Please sign in to comment.