UNPKG

mattermost-redux

Version:

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

59 lines (58 loc) 3.25 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.isScheduledPostsEnabled = void 0; exports.makeGetScheduledPostsByTeam = makeGetScheduledPostsByTeam; exports.getScheduledPostsByTeamCount = getScheduledPostsByTeamCount; exports.hasScheduledPostError = hasScheduledPostError; exports.showChannelOrThreadScheduledPostIndicator = showChannelOrThreadScheduledPostIndicator; const create_selector_1 = require("mattermost-redux/selectors/create_selector"); const general_1 = require("mattermost-redux/selectors/entities/general"); const emptyList = []; function makeGetScheduledPostsByTeam() { return (0, create_selector_1.createSelector)('makeGetScheduledPostsByTeam', (state) => state.entities.scheduledPosts.byId, (state, teamId, includeDirectChannels) => includeDirectChannels, (state, teamId) => state.entities.scheduledPosts.byTeamId[teamId] || emptyList, (state) => state.entities.scheduledPosts.byTeamId.directChannels || emptyList, (scheduledPostsById, includeDirectChannels, teamScheduledPostsIDs, directChannelScheduledPostsIDs) => { const scheduledPosts = []; const extractor = (scheduledPostId) => { const scheduledPost = scheduledPostsById[scheduledPostId]; if (scheduledPost) { scheduledPosts.push(scheduledPost); } }; teamScheduledPostsIDs.forEach(extractor); if (includeDirectChannels) { directChannelScheduledPostsIDs.forEach(extractor); } // Most recently upcoming post shows up first. scheduledPosts.sort((a, b) => a.scheduled_at - b.scheduled_at || a.create_at - b.create_at); return scheduledPosts; }); } function getScheduledPostsByTeamCount(state, teamId, includeDirectChannels) { let count = state.entities.scheduledPosts.byTeamId[teamId]?.length || 0; if (includeDirectChannels) { count += (state.entities.scheduledPosts.byTeamId.directChannels?.length || 0); } return count; } function hasScheduledPostError(state, teamId) { return state.entities.scheduledPosts.errorsByTeamId[teamId]?.length > 0 || state.entities.scheduledPosts.errorsByTeamId.directChannels?.length > 0; } function showChannelOrThreadScheduledPostIndicator(state, channelOrThreadId) { const allChannelScheduledPosts = state.entities.scheduledPosts.byChannelOrThreadId[channelOrThreadId] || emptyList; const eligibleScheduledPosts = allChannelScheduledPosts.filter((scheduledPostId) => { const scheduledPost = state.entities.scheduledPosts.byId[scheduledPostId]; return !scheduledPost?.error_code; }); const data = { count: eligibleScheduledPosts.length, }; if (data.count === 1) { const scheduledPostId = eligibleScheduledPosts[0]; data.scheduledPost = state.entities.scheduledPosts.byId[scheduledPostId]; } return data; } exports.isScheduledPostsEnabled = (0, create_selector_1.createSelector)('isScheduledPostsEnabled', general_1.getConfig, general_1.getLicense, (config, license) => { return config.ScheduledPosts === 'true' && license.IsLicensed === 'true'; });