forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_utils.jsx
54 lines (44 loc) · 1.72 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
53
54
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles';
import {getRedirectChannelNameForTeam as getRedirectChannelNameForTeamRedux} from 'mattermost-redux/selectors/entities/channels';
import Permissions from 'mattermost-redux/constants/permissions';
import store from 'stores/redux_store.jsx';
import Constants from 'utils/constants';
import * as Utils from 'utils/utils.jsx';
export function canManageMembers(channel) {
if (channel.type === Constants.PRIVATE_CHANNEL) {
return haveIChannelPermission(
store.getState(),
{
channel: channel.id,
team: channel.team_id,
permission: Permissions.MANAGE_PRIVATE_CHANNEL_MEMBERS,
}
);
}
if (channel.type === Constants.OPEN_CHANNEL) {
return haveIChannelPermission(
store.getState(),
{
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 getRedirectChannelNameForTeam(teamId) {
return getRedirectChannelNameForTeamRedux(store.getState(), teamId);
}