UNPKG

mattermost-redux

Version:

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

64 lines (63 loc) 2.1 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.receivedFiles = receivedFiles; exports.getMissingFilesByPosts = getMissingFilesByPosts; exports.getFilesForPost = getFilesForPost; exports.getFilePublicLink = getFilePublicLink; const action_types_1 = require("mattermost-redux/action_types"); const client_1 = require("mattermost-redux/client"); const errors_1 = require("./errors"); const helpers_1 = require("./helpers"); function receivedFiles(files) { return { type: action_types_1.FileTypes.RECEIVED_FILES_FOR_SEARCH, data: files, }; } function getMissingFilesByPosts(posts) { return async (dispatch, getState) => { const { files } = getState().entities.files; const postIds = posts.reduce((curr, post) => { const { file_ids: fileIds } = post; if (!fileIds || fileIds.every((id) => files[id])) { return curr; } curr.push(post.id); return curr; }, []); for (const id of postIds) { dispatch(getFilesForPost(id)); } return { data: true }; }; } function getFilesForPost(postId) { return async (dispatch, getState) => { let files; try { files = await client_1.Client4.getFileInfosForPost(postId); } catch (error) { (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch((0, errors_1.logError)(error)); return { error }; } dispatch({ type: action_types_1.FileTypes.RECEIVED_FILES_FOR_POST, data: files, postId, }); return { data: true }; }; } function getFilePublicLink(fileId) { return (0, helpers_1.bindClientFunc)({ clientFunc: client_1.Client4.getFilePublicLink, onSuccess: action_types_1.FileTypes.RECEIVED_FILE_PUBLIC_LINK, params: [ fileId, ], }); }