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
/
integration_actions.jsx
141 lines (120 loc) · 4.23 KB
/
integration_actions.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import request from 'superagent';
import * as IntegrationActions from 'mattermost-redux/actions/integrations';
import {getProfilesByIds} from 'mattermost-redux/actions/users';
import {getUser} from 'mattermost-redux/selectors/entities/users';
const DEFAULT_PAGE_SIZE = 100;
export function loadIncomingHooksAndProfilesForTeam(teamId, page = 0, perPage = DEFAULT_PAGE_SIZE) {
return async (dispatch) => {
const {data} = await dispatch(IntegrationActions.getIncomingHooks(teamId, page, perPage));
if (data) {
dispatch(loadProfilesForIncomingHooks(data));
}
};
}
export function loadProfilesForIncomingHooks(hooks) {
return async (dispatch, getState) => {
const state = getState();
const profilesToLoad = {};
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (!getUser(state, hook.user_id)) {
profilesToLoad[hook.user_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
dispatch(getProfilesByIds(list));
};
}
export function loadOutgoingHooksAndProfilesForTeam(teamId, page = 0, perPage = DEFAULT_PAGE_SIZE) {
return async (dispatch) => {
const {data} = await dispatch(IntegrationActions.getOutgoingHooks('', teamId, page, perPage));
if (data) {
dispatch(loadProfilesForOutgoingHooks(data));
}
};
}
export function loadProfilesForOutgoingHooks(hooks) {
return async (dispatch, getState) => {
const state = getState();
const profilesToLoad = {};
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (!getUser(state, hook.creator_id)) {
profilesToLoad[hook.creator_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
dispatch(getProfilesByIds(list));
};
}
export function loadCommandsAndProfilesForTeam(teamId) {
return async (dispatch) => {
const {data} = await dispatch(IntegrationActions.getCustomTeamCommands(teamId));
if (data) {
dispatch(loadProfilesForCommands(data));
}
};
}
export function loadProfilesForCommands(commands) {
return async (dispatch, getState) => {
const state = getState();
const profilesToLoad = {};
for (let i = 0; i < commands.length; i++) {
const command = commands[i];
if (!getUser(state, command.creator_id)) {
profilesToLoad[command.creator_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
dispatch(getProfilesByIds(list));
};
}
export function loadOAuthAppsAndProfiles(page = 0, perPage = DEFAULT_PAGE_SIZE) {
return async (dispatch) => {
const {data} = await dispatch(IntegrationActions.getOAuthApps(page, perPage));
if (data) {
dispatch(loadProfilesForOAuthApps(data));
}
};
}
export function loadProfilesForOAuthApps(apps) {
return async (dispatch, getState) => {
const state = getState();
const profilesToLoad = {};
for (let i = 0; i < apps.length; i++) {
const app = apps[i];
if (!getUser(state, app.creator_id)) {
profilesToLoad[app.creator_id] = true;
}
}
const list = Object.keys(profilesToLoad);
if (list.length === 0) {
return;
}
dispatch(getProfilesByIds(list));
};
}
export function getYoutubeVideoInfo(googleKey, videoId, success, error) {
request.get('https://www.googleapis.com/youtube/v3/videos').
query({part: 'snippet', id: videoId, key: googleKey}).
end((err, res) => {
if (err) {
return error(err);
}
if (!res.body) {
console.error('Missing response body for getYoutubeVideoInfo'); // eslint-disable-line no-console
}
return success(res.body);
});
}