UNPKG

mattermost-redux

Version:

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

108 lines (107 loc) 4.04 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.getTeamContentFlaggingStatus = getTeamContentFlaggingStatus; exports.getContentFlaggingConfig = getContentFlaggingConfig; exports.getPostContentFlaggingFields = getPostContentFlaggingFields; exports.loadPostContentFlaggingFields = loadPostContentFlaggingFields; exports.getPostContentFlaggingValues = getPostContentFlaggingValues; const action_types_1 = require("mattermost-redux/action_types"); const errors_1 = require("mattermost-redux/actions/errors"); const helpers_1 = require("mattermost-redux/actions/helpers"); const client_1 = require("mattermost-redux/client"); const data_loader_1 = require("mattermost-redux/utils/data_loader"); function getTeamContentFlaggingStatus(teamId) { return async (dispatch, getState) => { let response; try { response = await client_1.Client4.getTeamContentFlaggingStatus(teamId); dispatch({ type: action_types_1.TeamTypes.RECEIVED_CONTENT_FLAGGING_STATUS, data: { teamId, status: response.enabled, }, }); } catch (error) { (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch((0, errors_1.logError)(error)); return { error }; } return { data: response }; }; } function getContentFlaggingConfig(teamId) { return async (dispatch, getState) => { let response; try { response = await client_1.Client4.getContentFlaggingConfig(teamId); dispatch({ type: action_types_1.ContentFlaggingTypes.RECEIVED_CONTENT_FLAGGING_CONFIG, data: response, }); } catch (error) { (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch((0, errors_1.logError)(error)); return { error }; } return { data: response }; }; } function getPostContentFlaggingFields() { return async (dispatch, getState) => { let data; try { data = await client_1.Client4.getPostContentFlaggingFields(); } catch (error) { (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch((0, errors_1.logError)(error)); return { error }; } dispatch({ type: action_types_1.ContentFlaggingTypes.RECEIVED_POST_CONTENT_FLAGGING_FIELDS, data, }); return { data }; }; } function loadPostContentFlaggingFields() { // Use data loader and fetch data to manage multiple, simultaneous dispatches return async (dispatch, getState, { loaders }) => { if (!loaders.postContentFlaggingFieldsLoader) { loaders.postContentFlaggingFieldsLoader = new data_loader_1.DelayedDataLoader({ fetchBatch: () => dispatch(getPostContentFlaggingFields()), maxBatchSize: 1, wait: 200, }); } const loader = loaders.postContentFlaggingFieldsLoader; loader.queue([true]); return {}; }; } function getPostContentFlaggingValues(postId) { return async (dispatch, getState) => { let response; try { response = await client_1.Client4.getPostContentFlaggingValues(postId); dispatch({ type: action_types_1.ContentFlaggingTypes.RECEIVED_POST_CONTENT_FLAGGING_VALUES, data: { postId, values: response, }, }); } catch (error) { (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch((0, errors_1.logError)(error)); return { error }; } return { data: response }; }; }