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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
import {ActionTypes} from 'utils/constants.jsx';
// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {getProfilesByIds} from 'mattermost-redux/actions/users';
export function loadIncomingHooks() {
Client.listIncomingHooks(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_INCOMING_WEBHOOKS,
teamId: TeamStore.getCurrentId(),
incomingWebhooks: data
});
loadProfilesForIncomingHooks(data);
},
(err) => {
AsyncClient.dispatchError(err, 'listIncomingHooks');
}
);
}
function loadProfilesForIncomingHooks(hooks) {
const profilesToLoad = {};
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (!UserStore.hasProfile(hook.user_id)) {
profilesToLoad[hook.user_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
getProfilesByIds(list)(dispatch, getState);
}
export function loadOutgoingHooks() {
Client.listOutgoingHooks(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_OUTGOING_WEBHOOKS,
teamId: TeamStore.getCurrentId(),
outgoingWebhooks: data
});
loadProfilesForOutgoingHooks(data);
},
(err) => {
AsyncClient.dispatchError(err, 'listOutgoingHooks');
}
);
}
function loadProfilesForOutgoingHooks(hooks) {
const profilesToLoad = {};
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (!UserStore.hasProfile(hook.creator_id)) {
profilesToLoad[hook.creator_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
getProfilesByIds(list)(dispatch, getState);
}
export function loadTeamCommands() {
Client.listTeamCommands(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_COMMANDS,
teamId: Client.teamId,
commands: data
});
loadProfilesForCommands(data);
},
(err) => {
AsyncClient.dispatchError(err, 'loadTeamCommands');
}
);
}
function loadProfilesForCommands(commands) {
const profilesToLoad = {};
for (let i = 0; i < commands.length; i++) {
const command = commands[i];
if (!UserStore.hasProfile(command.creator_id)) {
profilesToLoad[command.creator_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
getProfilesByIds(list)(dispatch, getState);
}
|