mattermost-mobile/app/components/post_draft/index.js
Elias Nahum 48f1875cf1
MM-23090 MM-26078 && MM-26876 Refactor post draft component (#4621)
* Refactor post draft component
Re-styled ReadOnly channels
Remove filename from upload error

* Update canSubmit based on file attachment changes

* Fix error message for max file size

* Fix select autocomplete values on iOS

* Style readonly and refactor accessory view for iOS

* Make PostDraft scrollViewNativeID prop not required

* Update ReadOnly to have a background with 0.40 opacity

* Update max file size error message

* Fix shift+enter with HW keyboard
2020-08-06 19:39:25 -04:00

57 lines
2 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 {getCurrentChannel, getChannel, isCurrentChannelReadOnly} from '@mm-redux/selectors/entities/channels';
import {haveIChannelPermission} from '@mm-redux/selectors/entities/roles';
import {getTheme} from '@mm-redux/selectors/entities/preferences';
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';
import {getChannelMembersForDm} from '@selectors/channel';
import PostDraft from './post_draft';
export function mapStateToProps(state, ownProps) {
const channel = ownProps.rootId ? getChannel(state) : getCurrentChannel(state);
const currentUserId = getCurrentUserId(state);
const channelId = ownProps.channelId || (channel ? channel.id : '');
let canPost = true;
let deactivatedChannel = false;
if (channel && channel.type === General.DM_CHANNEL) {
const teammate = getChannelMembersForDm(state, channel);
if (teammate.length && teammate[0].delete_at) {
deactivatedChannel = true;
}
}
if (channel && isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)) {
canPost = haveIChannelPermission(
state,
{
channel: channel.id,
team: channel.team_id,
permission: Permissions.CREATE_POST,
default: true,
},
);
}
let channelIsReadOnly = false;
if (currentUserId && channelId) {
channelIsReadOnly = isCurrentChannelReadOnly(state) || false;
}
return {
canPost,
channelId,
channelIsArchived: ownProps.channelIsArchived || (channel ? channel.delete_at !== 0 : false),
channelIsReadOnly,
deactivatedChannel,
theme: getTheme(state),
};
}
export default connect(mapStateToProps, null, null, {forwardRef: true})(PostDraft);