UNPKG

mattermost-redux

Version:

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

115 lines (114 loc) 3.89 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.deleteBookmark = deleteBookmark; exports.createBookmark = createBookmark; exports.editBookmark = editBookmark; exports.reorderBookmark = reorderBookmark; exports.fetchChannelBookmarks = fetchChannelBookmarks; const action_types_1 = require("mattermost-redux/action_types"); const client_1 = require("mattermost-redux/client"); const channel_bookmarks_1 = require("mattermost-redux/selectors/entities/channel_bookmarks"); const errors_1 = require("./errors"); const helpers_1 = require("./helpers"); function deleteBookmark(channelId, id, connectionId) { return async (dispatch, getState) => { const state = getState(); const bookmark = (0, channel_bookmarks_1.getChannelBookmark)(state, channelId, id); try { await client_1.Client4.deleteChannelBookmark(channelId, id, connectionId); dispatch({ type: action_types_1.ChannelBookmarkTypes.BOOKMARK_DELETED, data: bookmark, }); } catch (error) { return { data: false, error, }; } return { data: true }; }; } function createBookmark(channelId, bookmark, connectionId) { return async (dispatch) => { try { const createdBookmark = await client_1.Client4.createChannelBookmark(channelId, bookmark, connectionId); dispatch({ type: action_types_1.ChannelBookmarkTypes.RECEIVED_BOOKMARK, data: createdBookmark, }); } catch (error) { return { data: false, error, }; } return { data: true }; }; } function editBookmark(channelId, id, patch, connectionId) { return async (dispatch) => { try { const { updated, deleted } = await client_1.Client4.updateChannelBookmark(channelId, id, patch, connectionId); if (updated) { dispatch({ type: action_types_1.ChannelBookmarkTypes.RECEIVED_BOOKMARK, data: updated, }); } if (deleted) { dispatch({ type: action_types_1.ChannelBookmarkTypes.BOOKMARK_DELETED, data: deleted, }); } } catch (error) { return { data: false, error, }; } return { data: true }; }; } function reorderBookmark(channelId, id, newOrder, connectionId) { return async (dispatch) => { try { const bookmarks = await client_1.Client4.updateChannelBookmarkSortOrder(channelId, id, newOrder, connectionId); dispatch({ type: action_types_1.ChannelBookmarkTypes.RECEIVED_BOOKMARKS, data: { channelId, bookmarks }, }); } catch (error) { return { data: false, error, }; } return { data: true }; }; } function fetchChannelBookmarks(channelId) { return async (dispatch, getState) => { let bookmarks; try { bookmarks = await client_1.Client4.getChannelBookmarks(channelId); dispatch({ type: action_types_1.ChannelBookmarkTypes.RECEIVED_BOOKMARKS, data: { channelId, bookmarks }, }); } catch (error) { (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch((0, errors_1.logError)(error)); return { error }; } return { data: bookmarks }; }; }