UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

47 lines (46 loc) 2.2 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchAppBindings = fetchAppBindings; exports.fetchRHSAppsBindings = fetchRHSAppsBindings; const action_types_1 = require("mattermost-redux/action_types"); const client_1 = require("mattermost-redux/client"); const channels_1 = require("mattermost-redux/selectors/entities/channels"); const teams_1 = require("mattermost-redux/selectors/entities/teams"); const helpers_1 = require("./helpers"); function fetchAppBindings(channelID) { return async (dispatch, getState) => { if (!channelID) { return { data: true }; } const state = getState(); const channel = (0, channels_1.getChannel)(state, channelID); const teamID = channel?.team_id || (0, teams_1.getCurrentTeamId)(state); return dispatch((0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.getAppsBindings(channelID, teamID), onSuccess: action_types_1.AppsTypes.RECEIVED_APP_BINDINGS, onFailure: action_types_1.AppsTypes.FAILED_TO_FETCH_APP_BINDINGS, })); }; } function fetchRHSAppsBindings(channelID) { return async (dispatch, getState) => { const state = getState(); const currentChannelID = (0, channels_1.getCurrentChannelId)(state); const channel = (0, channels_1.getChannel)(state, channelID); const teamID = channel?.team_id || (0, teams_1.getCurrentTeamId)(state); if (channelID === currentChannelID) { const bindings = JSON.parse(JSON.stringify(state.entities.apps.main.bindings)); return dispatch({ data: bindings, type: action_types_1.AppsTypes.RECEIVED_APP_RHS_BINDINGS, }); } return dispatch((0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.getAppsBindings(channelID, teamID), onSuccess: action_types_1.AppsTypes.RECEIVED_APP_RHS_BINDINGS, onFailure: action_types_1.AppsTypes.FAILED_TO_FETCH_APP_BINDINGS, })); }; }