* Show Confirmation Dialogue WIP First Commit Show Confirmation Dialogue WIP Second Commit refactoring according to comments refactor code according to comments Fix linting problems add i18n strings Update regex pattern add test and make fixes fix message not submitting Fix linting fix index.js fix conflicts address PR comments address PR comments single dispatch Address PR comments add test * Show Confirmation Dialogue WIP First Commit Show Confirmation Dialogue WIP Second Commit refactoring according to comments refactor code according to comments Fix linting problems add i18n strings Update regex pattern add test and make fixes fix message not submitting Fix linting fix index.js fix conflicts address PR comments address PR comments single dispatch Address PR comments add test * make some changes * fix test failures * Address PR comments * Update app/mm-redux/types/channels.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/mm-redux/selectors/entities/channels.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/mm-redux/selectors/entities/channels.test.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/constants/autocomplete.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Address PR comments * make group mention mapping its own function * Address PR comments * Update app/components/post_draft/post_draft.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Merge branch 'master' of https://github.com/mattermost/mattermost-mobile into MM-23785-ShowConfirmationDialogue-2 * Merge branch 'master' into MM-23785-ShowConfirmationDialogue-2 * Address MM-26987 * Retrieve group information on mount RN: Group Mention confirmation prompt not shown on default channel load * Update Regex to fix MM-26976 Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
137 lines
5.6 KiB
JavaScript
137 lines
5.6 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {connect} from 'react-redux';
|
|
|
|
import {isMinimumServerVersion} from '@mm-redux/utils/helpers';
|
|
import {General, Permissions} from '@mm-redux/constants';
|
|
import {createPost} from '@mm-redux/actions/posts';
|
|
import {setStatus} from '@mm-redux/actions/users';
|
|
import {getCurrentChannel, isCurrentChannelReadOnly, getCurrentChannelStats, getChannelMemberCountsByGroup as selectChannelMemberCountsByGroup} from '@mm-redux/selectors/entities/channels';
|
|
import {haveIChannelPermission} from '@mm-redux/selectors/entities/roles';
|
|
import {getConfig, getLicense} from '@mm-redux/selectors/entities/general';
|
|
import {getTheme} from '@mm-redux/selectors/entities/preferences';
|
|
import {getCurrentUserId, getStatusForUserId} from '@mm-redux/selectors/entities/users';
|
|
import {getChannelTimezones, getChannelMemberCountsByGroup} from '@mm-redux/actions/channels';
|
|
import {getAssociatedGroupsForReferenceMap} from '@mm-redux/selectors/entities/groups';
|
|
|
|
import {executeCommand} from '@actions/views/command';
|
|
import {addReactionToLatestPost} from '@actions/views/emoji';
|
|
import {handleClearFiles, handleClearFailedFiles, initUploadFiles} from '@actions/views/file_upload';
|
|
import {MAX_MESSAGE_LENGTH_FALLBACK} from '@constants/post_draft';
|
|
import {getCurrentChannelDraft, getThreadDraft} from '@selectors/views';
|
|
import {getChannelMembersForDm} from '@selectors/channel';
|
|
import {getAllowedServerMaxFileSize} from '@utils/file';
|
|
import {isLandscape} from '@selectors/device';
|
|
|
|
import PostDraft from './post_draft';
|
|
|
|
export function mapStateToProps(state, ownProps) {
|
|
const currentDraft = ownProps.rootId ? getThreadDraft(state, ownProps.rootId) : getCurrentChannelDraft(state);
|
|
const config = getConfig(state);
|
|
const currentChannel = getCurrentChannel(state);
|
|
const currentUserId = getCurrentUserId(state);
|
|
const status = getStatusForUserId(state, currentUserId);
|
|
const userIsOutOfOffice = status === General.OUT_OF_OFFICE;
|
|
const enableConfirmNotificationsToChannel = config?.EnableConfirmNotificationsToChannel === 'true';
|
|
const currentChannelStats = getCurrentChannelStats(state);
|
|
const membersCount = currentChannelStats?.member_count || 0; // eslint-disable-line camelcase
|
|
const isTimezoneEnabled = config?.ExperimentalTimezone === 'true';
|
|
const channelId = ownProps.channelId || (currentChannel ? currentChannel.id : '');
|
|
const channelTeamId = currentChannel ? currentChannel.team_id : '';
|
|
const license = getLicense(state);
|
|
let canPost = true;
|
|
let useChannelMentions = true;
|
|
let deactivatedChannel = false;
|
|
let useGroupMentions = false;
|
|
const channelMemberCountsByGroup = selectChannelMemberCountsByGroup(state, channelId);
|
|
let groupsWithAllowReference = new Map();
|
|
|
|
if (currentChannel && currentChannel.type === General.DM_CHANNEL) {
|
|
const teammate = getChannelMembersForDm(state, currentChannel);
|
|
if (teammate.length && teammate[0].delete_at) {
|
|
deactivatedChannel = true;
|
|
}
|
|
}
|
|
|
|
if (currentChannel && isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)) {
|
|
canPost = haveIChannelPermission(
|
|
state,
|
|
{
|
|
channel: currentChannel.id,
|
|
team: currentChannel.team_id,
|
|
permission: Permissions.CREATE_POST,
|
|
default: true,
|
|
},
|
|
);
|
|
|
|
useChannelMentions = haveIChannelPermission(
|
|
state,
|
|
{
|
|
channel: currentChannel.id,
|
|
permission: Permissions.USE_CHANNEL_MENTIONS,
|
|
default: true,
|
|
},
|
|
);
|
|
}
|
|
|
|
if (isMinimumServerVersion(state.entities.general.serverVersion, 5, 24) && license && license.IsLicensed === 'true') {
|
|
useGroupMentions = haveIChannelPermission(
|
|
state,
|
|
{
|
|
channel: currentChannel.id,
|
|
team: currentChannel.team_id,
|
|
permission: Permissions.USE_GROUP_MENTIONS,
|
|
},
|
|
);
|
|
|
|
if (useGroupMentions) {
|
|
groupsWithAllowReference = getAssociatedGroupsForReferenceMap(state, channelTeamId, channelId);
|
|
}
|
|
}
|
|
|
|
let channelIsReadOnly = false;
|
|
if (currentUserId && channelId) {
|
|
channelIsReadOnly = isCurrentChannelReadOnly(state) || false;
|
|
}
|
|
|
|
return {
|
|
canPost,
|
|
currentChannel,
|
|
channelId,
|
|
channelTeamId,
|
|
channelDisplayName: state.views.channel.displayName || (currentChannel ? currentChannel.display_name : ''),
|
|
channelIsArchived: ownProps.channelIsArchived || (currentChannel ? currentChannel.delete_at !== 0 : false),
|
|
channelIsReadOnly,
|
|
currentUserId,
|
|
deactivatedChannel,
|
|
enableConfirmNotificationsToChannel,
|
|
files: currentDraft.files,
|
|
isLandscape: isLandscape(state),
|
|
isTimezoneEnabled,
|
|
maxMessageLength: (config && parseInt(config.MaxPostSize || 0, 10)) || MAX_MESSAGE_LENGTH_FALLBACK,
|
|
maxFileSize: getAllowedServerMaxFileSize(config),
|
|
membersCount,
|
|
theme: getTheme(state),
|
|
useChannelMentions,
|
|
userIsOutOfOffice,
|
|
value: currentDraft.draft,
|
|
groupsWithAllowReference,
|
|
useGroupMentions,
|
|
channelMemberCountsByGroup,
|
|
};
|
|
}
|
|
|
|
const mapDispatchToProps = {
|
|
addReactionToLatestPost,
|
|
createPost,
|
|
executeCommand,
|
|
getChannelTimezones,
|
|
handleClearFiles,
|
|
handleClearFailedFiles,
|
|
initUploadFiles,
|
|
setStatus,
|
|
getChannelMemberCountsByGroup,
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps, null, {forwardRef: true})(PostDraft);
|