mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Start moving webapp to Redux * Fix localforage import * Updates per feedback * Feedback udpates and a few fixes * Minor updates * Fix statuses, config not loading properly, getMe sanitizing too much * Fix preferences * Fix user autocomplete * Fix sessions and audits * Fix error handling for all redux actions * Use new directory structure for components and containers * Refresh immediately on logout instead of after timeout * Add fetch polyfill
121 lines
3.2 KiB
JavaScript
121 lines
3.2 KiB
JavaScript
// 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);
|
|
}
|