mattermost-mobile/app/screens/post_options/index.js
Elias Nahum 9f238d5ef4
Post List & post components refactored (#5409)
* Update transform to make Android's post list scroll smooth

* set start since metric when appStarted is false

* Refactor Formatted components

* Downgrade RNN to 7.13.0 & patch XCDYouTube to allow video playback

* Refactor Post list and all related components

* review suggestion rename hour12 to isMilitaryTime

* feedback review use aliases

* feedback review deconstruct actions in markdown_link

* feedback review simplify if/else statement in combined_used_activity

* Simplify if statement for consecutive posts

* Specify npm version to build iOS on CI

* Refactor network_indicator

* render Icon in file gallery with transparent background

* Increase timeout to scroll to bottom when posting a new message

* fix: scroll when tapping on the new messages bar

* fix: dismiss all modals

* fix navigation tests

* Handle dismissAllModals for iOS to prevent blank screens

* Prevent modal from dismissing when showing the thread screen in the stack

* Update app/components/image_viewport.tsx

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Update app/utils/post.ts

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* fix: rename selector and prop

* Fix XCDYouTube patch

* Fix posting from a thread in the right channel

* do not render reply bar on the thread screen

* close previous permalink before showing a new one

* move XCDYouTube patch to ios/patches folder

* closePermalink directly instead of using an onClose prop

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
Co-authored-by: Miguel Alatzar <this.migbot@gmail.com>
2021-06-03 11:12:15 -07:00

166 lines
5.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {addReaction} from '@actions/views/emoji';
import {MAX_ALLOWED_REACTIONS} from '@constants/emoji';
import {THREAD} from '@constants/screen';
import {
deletePost,
flagPost,
pinPost,
unflagPost,
unpinPost,
removePost,
setUnreadPost,
} from '@mm-redux/actions/posts';
import {General, Permissions, Posts} from '@mm-redux/constants';
import {makeGetReactionsForPost} from '@mm-redux/selectors/entities/posts';
import {isChannelReadOnlyById, getChannel, getCurrentChannelId} from '@mm-redux/selectors/entities/channels';
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';
import {getConfig, getLicense} from '@mm-redux/selectors/entities/general';
import {getMyPreferences, getTheme} from '@mm-redux/selectors/entities/preferences';
import {haveIChannelPermission} from '@mm-redux/selectors/entities/roles';
import {getCurrentTeamId, getCurrentTeamUrl} from '@mm-redux/selectors/entities/teams';
import {canEditPost, isPostFlagged, isSystemMessage} from '@mm-redux/utils/post_utils';
import {getDimensions} from '@selectors/device';
import {canDeletePost} from '@selectors/permissions';
import {selectEmojisCountFromReactions} from '@selectors/emojis';
import mattermostManaged from 'app/mattermost_managed';
import PostOptions from './post_options';
export function makeMapStateToProps() {
const getReactionsForPostSelector = makeGetReactionsForPost();
return (state, ownProps) => {
const managedConfig = mattermostManaged.getCachedConfig();
const post = ownProps.post;
const channel = getChannel(state, post.channel_id);
const config = getConfig(state);
const license = getLicense(state);
const currentUserId = getCurrentUserId(state);
const currentTeamId = getCurrentTeamId(state);
const currentChannelId = getCurrentChannelId(state);
const reactions = getReactionsForPostSelector(state, post.id);
const channelIsReadOnly = isChannelReadOnlyById(state, post.channel_id);
const myPreferences = getMyPreferences(state);
const channelIsArchived = channel.delete_at !== 0;
const isSystemPost = isSystemMessage(post);
const hasBeenDeleted = (post.delete_at !== 0 || post.state === Posts.POST_DELETED);
let canMarkAsUnread = true;
let canReply = true;
let canCopyPermalink = true;
let canCopyText = false;
let canEdit = false;
let canEditUntil = -1;
let canFlag = true;
let canPin = true;
const canPost = haveIChannelPermission(
state,
{
channel: post.channel_id,
team: channel.team_id || currentTeamId,
permission: Permissions.CREATE_POST,
default: true,
},
);
let canAddReaction = haveIChannelPermission(state, {
team: currentTeamId,
channel: post.channel_id,
permission: Permissions.ADD_REACTION,
default: true,
});
let canDelete = false;
if (post && channel?.delete_at === 0) {
canDelete = canDeletePost(state, channel?.team_id || currentTeamId, post?.channel_id, post, false);
}
if (ownProps.location === THREAD) {
canReply = false;
}
if (channelIsArchived || channelIsReadOnly) {
canAddReaction = false;
canReply = false;
canDelete = false;
canPin = false;
} else {
canEdit = canEditPost(state, config, license, currentTeamId, currentChannelId, currentUserId, post);
if (canEdit && license.IsLicensed === 'true' &&
(config.AllowEditPost === General.ALLOW_EDIT_POST_TIME_LIMIT || (config.PostEditTimeLimit !== -1 && config.PostEditTimeLimit !== '-1'))
) {
canEditUntil = post.create_at + (config.PostEditTimeLimit * 1000);
}
}
if (!canPost) {
canReply = false;
}
if (isSystemPost) {
canAddReaction = false;
canReply = false;
canCopyPermalink = false;
canEdit = false;
canPin = false;
canFlag = false;
}
if (hasBeenDeleted) {
canDelete = false;
}
if (!ownProps.showAddReaction) {
canAddReaction = false;
}
if (!isSystemPost && managedConfig?.copyAndPasteProtection !== 'true' && post.message) {
canCopyText = true;
}
if (channelIsArchived) {
canMarkAsUnread = false;
}
return {
...getDimensions(state),
canAddReaction: canAddReaction && selectEmojisCountFromReactions(reactions) < MAX_ALLOWED_REACTIONS,
canReply,
canCopyPermalink,
canCopyText,
canEdit,
canEditUntil,
canDelete,
canFlag,
canPin,
canMarkAsUnread,
currentTeamUrl: getCurrentTeamUrl(state),
currentUserId,
isFlagged: isPostFlagged(post.id, myPreferences),
theme: getTheme(state),
};
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
addReaction,
deletePost,
flagPost,
pinPost,
removePost,
unflagPost,
unpinPost,
setUnreadPost,
}, dispatch),
};
}
export default connect(makeMapStateToProps, mapDispatchToProps)(PostOptions);