UNPKG

mattermost-redux

Version:

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

69 lines (68 loc) 3.37 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.getAutocompleteCommandsList = exports.getAllCommands = exports.getOutgoingHooksInCurrentTeam = exports.getAppsBotIDs = exports.getAppsOAuthAppIDs = exports.getFilteredIncomingHooks = void 0; exports.getIncomingHooks = getIncomingHooks; exports.getIncomingHooksTotalCount = getIncomingHooksTotalCount; exports.getOutgoingHooks = getOutgoingHooks; exports.getCommands = getCommands; exports.getOAuthApps = getOAuthApps; exports.getOutgoingOAuthConnections = getOutgoingOAuthConnections; exports.getDialogArguments = getDialogArguments; exports.getSystemCommands = getSystemCommands; const create_selector_1 = require("mattermost-redux/selectors/create_selector"); const teams_1 = require("mattermost-redux/selectors/entities/teams"); const apps_1 = require("./apps"); function getIncomingHooks(state) { return state.entities.integrations.incomingHooks; } function getIncomingHooksTotalCount(state) { return state.entities.integrations.incomingHooksTotalCount; } function getOutgoingHooks(state) { return state.entities.integrations.outgoingHooks; } function getCommands(state) { return state.entities.integrations.commands; } function getOAuthApps(state) { return state.entities.integrations.oauthApps; } function getOutgoingOAuthConnections(state) { return state.entities.integrations.outgoingOAuthConnections; } function getDialogArguments(state) { return state.entities.integrations.dialogArguments; } exports.getFilteredIncomingHooks = (0, create_selector_1.createSelector)('getFilteredIncomingHooks', teams_1.getCurrentTeamId, getIncomingHooks, (teamId, hooks) => { return Object.keys(hooks). map((key) => hooks[key]). filter((incomingHook) => incomingHook.team_id === teamId); }); exports.getAppsOAuthAppIDs = (0, create_selector_1.createSelector)('getAppsOAuthAppIDs', apps_1.appsEnabled, (state) => state.entities.integrations.appsOAuthAppIDs, (apps, ids) => { return apps ? ids : []; }); exports.getAppsBotIDs = (0, create_selector_1.createSelector)('getAppsBotIDs', apps_1.appsEnabled, (state) => state.entities.integrations.appsBotIDs, (apps, ids) => { return apps ? ids : []; }); function getSystemCommands(state) { return state.entities.integrations.systemCommands; } /** * get outgoing hooks in current team */ exports.getOutgoingHooksInCurrentTeam = (0, create_selector_1.createSelector)('getOutgoingHooksInCurrentTeam', teams_1.getCurrentTeamId, getOutgoingHooks, (teamId, hooks) => { return Object.values(hooks).filter((o) => o.team_id === teamId); }); exports.getAllCommands = (0, create_selector_1.createSelector)('getAllCommands', getCommands, getSystemCommands, (commands, systemCommands) => { return { ...commands, ...systemCommands, }; }); exports.getAutocompleteCommandsList = (0, create_selector_1.createSelector)('getAutocompleteCommandsList', exports.getAllCommands, teams_1.getCurrentTeamId, (commands, currentTeamId) => { return Object.values(commands).filter((command) => { return command && (!command.team_id || command.team_id === currentTeamId) && command.auto_complete; }).sort((a, b) => a.display_name.localeCompare(b.display_name)); });