This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
channel_utils.jsx
52 lines (42 loc) · 1.51 KB
/
channel_utils.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles';
import Permissions from 'mattermost-redux/constants/permissions';
import Constants from 'utils/constants';
import * as Utils from 'utils/utils.jsx';
export function canManageMembers(state, channel) {
if (channel.type === Constants.PRIVATE_CHANNEL) {
return haveIChannelPermission(
state,
{
channel: channel.id,
team: channel.team_id,
permission: Permissions.MANAGE_PRIVATE_CHANNEL_MEMBERS,
},
);
}
if (channel.type === Constants.OPEN_CHANNEL) {
return haveIChannelPermission(
state,
{
channel: channel.id,
team: channel.team_id,
permission: Permissions.MANAGE_PUBLIC_CHANNEL_MEMBERS,
},
);
}
return true;
}
export function findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, direction) {
const curIndex = allChannelIds.indexOf(curChannelId);
for (let i = 1; i < allChannelIds.length; i++) {
const index = Utils.mod(curIndex + (i * direction), allChannelIds.length);
if (unreadChannelIds.includes(allChannelIds[index])) {
return index;
}
}
return -1;
}
export function isArchivedChannel(channel) {
return Boolean(channel && channel.delete_at !== 0);
}