forked from Ivasoft/mattermost-mobile
* added MENU_ITEM_HEIGHT to constant/view * fix user presence and your profile * added MENU_ITEM_HEIGHT to constant/view * fix user presence and your profile * UI Polish - Custom Status * UI Polish - Settings * UI Polish - logout * refactored styles * removed 'throws DataOperatorException' from './database/` * fix for copy link option * fix autoresponder 1. user should be allowed to enter paragraph 2. the OOO was not immediately being updated on the notification main screen. The fix is to cal fetchStatusInBatch after the updateMe operation * About Screen - code clean up * removed MenuItem component from common_post_options * removed MenuItem from Settings * refactored show_more and recent_item * removed menu_item component * Update setting_container.tsx * PR review correction * Update setting_container.tsx * Update recent_item.tsx
137 lines
4.5 KiB
TypeScript
137 lines
4.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {useManagedConfig} from '@mattermost/react-native-emm';
|
|
import React from 'react';
|
|
|
|
import {CopyPermalinkOption, FollowThreadOption, ReplyOption, SaveOption} from '@components/common_post_options';
|
|
import {ITEM_HEIGHT} from '@components/option_item';
|
|
import {Screens} from '@constants';
|
|
import useNavButtonPressed from '@hooks/navigation_button_pressed';
|
|
import BottomSheet from '@screens/bottom_sheet';
|
|
import {dismissModal} from '@screens/navigation';
|
|
import {isSystemMessage} from '@utils/post';
|
|
|
|
import CopyTextOption from './options/copy_text_option';
|
|
import DeletePostOption from './options/delete_post_option';
|
|
import EditOption from './options/edit_option';
|
|
import MarkAsUnreadOption from './options/mark_unread_option';
|
|
import PinChannelOption from './options/pin_channel_option';
|
|
import ReactionBar from './reaction_bar';
|
|
|
|
import type PostModel from '@typings/database/models/servers/post';
|
|
import type ThreadModel from '@typings/database/models/servers/thread';
|
|
|
|
const POST_OPTIONS_BUTTON = 'close-post-options';
|
|
|
|
type PostOptionsProps = {
|
|
canAddReaction: boolean;
|
|
canDelete: boolean;
|
|
canEdit: boolean;
|
|
canMarkAsUnread: boolean;
|
|
canPin: boolean;
|
|
canReply: boolean;
|
|
combinedPost?: Post | PostModel;
|
|
isSaved: boolean;
|
|
sourceScreen: typeof Screens[keyof typeof Screens];
|
|
post: PostModel;
|
|
thread?: ThreadModel;
|
|
componentId: string;
|
|
};
|
|
const PostOptions = ({
|
|
canAddReaction, canDelete, canEdit,
|
|
canMarkAsUnread, canPin, canReply,
|
|
combinedPost, componentId, isSaved,
|
|
sourceScreen, post, thread,
|
|
}: PostOptionsProps) => {
|
|
const managedConfig = useManagedConfig<ManagedConfig>();
|
|
|
|
const close = () => {
|
|
dismissModal({componentId});
|
|
};
|
|
|
|
useNavButtonPressed(POST_OPTIONS_BUTTON, componentId, close, []);
|
|
|
|
const isSystemPost = isSystemMessage(post);
|
|
|
|
const canCopyPermalink = !isSystemPost && managedConfig?.copyAndPasteProtection !== 'true';
|
|
const canCopyText = canCopyPermalink && post.message;
|
|
|
|
const shouldRenderFollow = !(sourceScreen !== Screens.CHANNEL || !thread);
|
|
|
|
const snapPoints = [
|
|
canAddReaction, canCopyPermalink, canCopyText,
|
|
canDelete, canEdit, shouldRenderFollow,
|
|
canMarkAsUnread, canPin, canReply, !isSystemPost,
|
|
].reduce((acc, v) => {
|
|
return v ? acc + 1 : acc;
|
|
}, 0);
|
|
|
|
const renderContent = () => {
|
|
return (
|
|
<>
|
|
{canAddReaction && <ReactionBar postId={post.id}/>}
|
|
{canReply && sourceScreen !== Screens.THREAD && <ReplyOption post={post}/>}
|
|
{shouldRenderFollow &&
|
|
<FollowThreadOption thread={thread}/>
|
|
}
|
|
{canMarkAsUnread && !isSystemPost &&
|
|
<MarkAsUnreadOption
|
|
post={post}
|
|
sourceScreen={sourceScreen}
|
|
/>
|
|
}
|
|
{canCopyPermalink &&
|
|
<CopyPermalinkOption
|
|
post={post}
|
|
sourceScreen={sourceScreen}
|
|
/>
|
|
}
|
|
{!isSystemPost &&
|
|
<SaveOption
|
|
isSaved={isSaved}
|
|
postId={post.id}
|
|
/>
|
|
}
|
|
{Boolean(canCopyText && post.message) &&
|
|
<CopyTextOption
|
|
postMessage={post.message}
|
|
sourceScreen={sourceScreen}
|
|
/>}
|
|
{canPin &&
|
|
<PinChannelOption
|
|
isPostPinned={post.isPinned}
|
|
postId={post.id}
|
|
/>
|
|
}
|
|
{canEdit &&
|
|
<EditOption
|
|
post={post}
|
|
canDelete={canDelete}
|
|
/>
|
|
}
|
|
{canDelete &&
|
|
<DeletePostOption
|
|
combinedPost={combinedPost}
|
|
post={post}
|
|
/>}
|
|
</>
|
|
);
|
|
};
|
|
|
|
const additionalSnapPoints = 2;
|
|
|
|
return (
|
|
<BottomSheet
|
|
renderContent={renderContent}
|
|
closeButtonId={POST_OPTIONS_BUTTON}
|
|
componentId={Screens.POST_OPTIONS}
|
|
initialSnapIndex={0}
|
|
snapPoints={[((snapPoints + additionalSnapPoints) * ITEM_HEIGHT), 10]}
|
|
testID='post_options'
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default PostOptions;
|