* [MM-31133]: participants screen component (#5116) * Fixed imports * Misc fixes * Added i18n string * Moved '(you)' after the name * [MM-30386][MM-30387] Client and redux changes for collapsed reply threads (#5175) * [MM-30386][MM-30387] Client and redux changes for collapsed reply threads * fix tests * add and use flat shim * use test helper function * use test helper function * revert crt changes to unused client and action functions * use toEqual * incorporate code review feedback * don't assume server success * batch actions * clearer code * WIP in changes, websockets and more redux changes * Added mark thread as read and mark all as read in a team * Added isCollapsedThreadEnabled entity * Fixed loading global screens on load if it's the last visited screen * Added root count and websocker and redux events related to threads * Fixed Message, Mention count root count on init and decrement actions * Moved old client to new client/rest * Misc fix * Misc fix * Misc. * Old redux test cases fix * Added polyfill back for array flat * Fixes mark as unread and pariticipants error in thread * Fixed initial load when CRT not enabled * Handling CRT preference change * Get threads fallsback to search in posts in case of unfollowed or unloaded threads * Gets threads on reconnect * DM, Channel counter fix * Added threads redux tests * Fixed channel dot issue when child post is arrived channel not active * Cleaning up threads on load, not letting posts included in threads getting deleted which can trigger many posts to be loaded at once * Fixed crash on team switch, partly fixed enable/disable from webapp * Fix when viewing a post from notification, to prevent from navigating back to global threads * Fixed when preferences are changed before app is launched * Fixed issue of NO THREADS appearing on reconnect * Excludes CRT handling for newly logged in users * Fixed unread dot showing even when all messages are read * Update app/mm-redux/selectors/entities/threads.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Not viewing threads action is pushed only when suer is in Global Threads * Fixed cleanup to exclude current team when cleanup starts on app going to background * Dispatch is not passed as param, misc code fixes * Preferences check and handling code refactored * added redux-mock-store * Preference change fix * Removed user login dispatch when handling crt change * Fixed fallback thread support * Return getThread * Added threads to sidebar, moved teamId logic to action * [MM-29106, MM-34847, MM-34843, MM-34846] Collapsed reply threads, Global Threads & In Channel experience UI implementation (#5376) * feat: global threads screen * Refactored global thread menu and misc design fixes * Added empty states for threads, unread. Removing markdown from thread messages. * Added friendly date, fixed long usernames & channel names in threads view. * Mark thread as read * Added intl, refactored code, seperated thread footer from thread item * Added intl to global threads, added global threads to android * Added Follow button to thread view * Added thread badges * In Channel experience .. WIP * Clean posts in channel incase CRT is enabled. * Added follow button, deleted messages doesnot have footer and design is now according to figma * Removed old post and post header * Added for follow/unfollow thread and fixed old one * MISC design & code fixes * Added options-follow/unfollow to the post's long press menu * Shows ORIGINAL MESSAGE DELETED in thread when root post gets deleted * Post list ts fix * Old testcases fix * Eslint fix * Added custom status emoji in at mention autocomplete * Fixed the width of the displayname and username * Changed the max width for the full name and username in the autocomplete item * Review fixes Changed the behaviour of ellipses for long names * Removed safearea bottom * Fixes Mark and unread and thread header theme * Fixes mark as unread and pariticipants error in thread * Unfollowing post fix and misc * Merge with master fix * Added fallback to get thread from posts in case of not following/unloaded threads * Refactored code and added tests for screens * Loads threads from global threads screen, marks thread as marked on new thread posts * Fixed tabs render on no threads, threads footer items styling and tests * Loads threads based on tab and items according to constant * Added infinite loading, unreads based on redux and not active thread list * Fixed the username cutting off after truncating display name issue * Changed avatars to touchableOpacity and added prop for parent component to style * Fixed infinite loading, tab switching scroll to top, misc styles, team switching, scroll indicator insets * Added follow button to DMs, moved follow button further right only on ios * Snapshot updated * Moved from useSelector to connect HOC * Scrolls to top on team change, changed thread constant from mm-redux * Fix merge issue * Test case fix * Fixed participants list * Update app/components/global_threads/global_threads.tsx Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/components/global_threads/thread_footer/thread_footer.tsx Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/components/sidebars/main/channels_list/channel_item/index.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/screens/thread/index.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Moved date numbers to constants * Fixed global threads component issues * Thread item display logic moved to redux * Misc fixes * Reverted to TouchableWithFeedback with opacity * Removed obselete snapshots * Removing currentTeamId as we aregetting it in action * Moved to connect component from useSelect for sidebar * Thread read issue fix * Removed react-native-navigation mock Co-authored-by: Anurag Shivarathri <anurag6713@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Manoj <manoj@brightscout.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Anurag Shivarathri <anurag6713@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Manoj <manoj@brightscout.com> Co-authored-by: Ashish Bhate <bhate.ashish@gmail.com> Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Manoj <manoj@brightscout.com>
323 lines
11 KiB
TypeScript
323 lines
11 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {ReactNode, useRef} from 'react';
|
|
import {Keyboard, StyleProp, View, ViewStyle} from 'react-native';
|
|
import {injectIntl, intlShape} from 'react-intl';
|
|
|
|
import {showModalOverCurrentContext} from '@actions/navigation';
|
|
import ThreadFooter from '@components/global_threads/thread_footer';
|
|
import SystemHeader from '@components/post_list/system_header';
|
|
import TouchableWithFeedback from '@components/touchable_with_feedback';
|
|
import SystemAvatar from '@components/post_list/system_avatar';
|
|
import * as Screens from '@constants/screen';
|
|
import {Posts} from '@mm-redux/constants';
|
|
import {UserProfile} from '@mm-redux/types/users';
|
|
import {UserThread} from '@mm-redux/types/threads';
|
|
import EventEmitter from '@mm-redux/utils/event_emitter';
|
|
import {fromAutoResponder, isPostEphemeral, isPostPendingOrFailed, isSystemMessage} from '@mm-redux/utils/post_utils';
|
|
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
|
|
import {preventDoubleTap} from '@utils/tap';
|
|
|
|
import type {Post as PostType} from '@mm-redux/types/posts';
|
|
import type {Theme} from '@mm-redux/types/preferences';
|
|
|
|
import Avatar from './avatar';
|
|
import Body from './body';
|
|
import Header from './header';
|
|
import PreHeader from './pre_header';
|
|
import SystemMessage from './system_message';
|
|
|
|
type PostProps = {
|
|
canDelete: boolean;
|
|
collapsedThreadsEnabled: boolean;
|
|
enablePostUsernameOverride: boolean;
|
|
highlight?: boolean;
|
|
highlightPinnedOrFlagged?: boolean;
|
|
intl: typeof intlShape;
|
|
isConsecutivePost?: boolean;
|
|
isFirstReply?: boolean;
|
|
isFlagged?: boolean;
|
|
isLastReply?: boolean;
|
|
location: string;
|
|
post?: PostType;
|
|
removePost: (post: PostType) => void;
|
|
rootPostAuthor?: string;
|
|
shouldRenderReplyButton?: boolean;
|
|
showAddReaction?: boolean;
|
|
showPermalink: (intl: typeof intlShape, teamName: string, postId: string) => null;
|
|
skipFlaggedHeader?: boolean;
|
|
skipPinnedHeader?: boolean;
|
|
style?: StyleProp<ViewStyle>;
|
|
teammateNameDisplay: string;
|
|
testID?: string;
|
|
theme: Theme
|
|
thread: UserThread;
|
|
threadStarter: UserProfile;
|
|
};
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
|
|
return {
|
|
consecutive: {marginTop: 0},
|
|
consecutivePostContainer: {
|
|
marginBottom: 10,
|
|
marginRight: 10,
|
|
marginLeft: 47,
|
|
marginTop: 10,
|
|
},
|
|
container: {flexDirection: 'row'},
|
|
highlight: {backgroundColor: changeOpacity(theme.mentionHighlightBg, 0.5)},
|
|
highlightBar: {
|
|
backgroundColor: theme.mentionHighlightBg,
|
|
opacity: 1,
|
|
},
|
|
highlightPinnedOrFlagged: {backgroundColor: changeOpacity(theme.mentionHighlightBg, 0.2)},
|
|
badgeContainer: {
|
|
position: 'absolute',
|
|
left: 28,
|
|
bottom: 9,
|
|
},
|
|
unreadDot: {
|
|
width: 8,
|
|
height: 8,
|
|
borderRadius: 4,
|
|
backgroundColor: theme.sidebarTextActiveBorder,
|
|
alignSelf: 'center',
|
|
top: -6,
|
|
left: 4,
|
|
},
|
|
pendingPost: {opacity: 0.5},
|
|
postStyle: {
|
|
overflow: 'hidden',
|
|
flex: 1,
|
|
},
|
|
replyBar: {
|
|
backgroundColor: theme.centerChannelColor,
|
|
opacity: 0.1,
|
|
marginLeft: 1,
|
|
marginRight: 7,
|
|
width: 3,
|
|
flexBasis: 3,
|
|
},
|
|
replyBarFirst: {paddingTop: 10},
|
|
replyBarLast: {paddingBottom: 10},
|
|
rightColumn: {
|
|
flex: 1,
|
|
flexDirection: 'column',
|
|
marginRight: 12,
|
|
},
|
|
rightColumnPadding: {paddingBottom: 3},
|
|
};
|
|
});
|
|
|
|
const Post = ({
|
|
canDelete, collapsedThreadsEnabled, enablePostUsernameOverride, highlight, highlightPinnedOrFlagged = true, intl, isConsecutivePost, isFirstReply, isFlagged, isLastReply,
|
|
location, post, removePost, rootPostAuthor, shouldRenderReplyButton, skipFlaggedHeader, skipPinnedHeader, showAddReaction = true, showPermalink, style,
|
|
teammateNameDisplay, testID, theme, thread, threadStarter,
|
|
}: PostProps) => {
|
|
const pressDetected = useRef(false);
|
|
const styles = getStyleSheet(theme);
|
|
|
|
const handlePress = preventDoubleTap(() => {
|
|
pressDetected.current = true;
|
|
|
|
if (post) {
|
|
if (location === Screens.THREAD) {
|
|
Keyboard.dismiss();
|
|
} else if (location === Screens.SEARCH) {
|
|
showPermalink(intl, '', post.id);
|
|
return;
|
|
}
|
|
|
|
const isValidSystemMessage = fromAutoResponder(post) || !isSystemMessage(post);
|
|
if (post.state !== Posts.POST_DELETED && isValidSystemMessage && !isPostPendingOrFailed(post)) {
|
|
if ([Screens.CHANNEL, Screens.PERMALINK].includes(location)) {
|
|
EventEmitter.emit('goToThread', post);
|
|
}
|
|
} else if ((isPostEphemeral(post) || post.state === Posts.POST_DELETED)) {
|
|
removePost(post);
|
|
}
|
|
|
|
const pressTimeout = setTimeout(() => {
|
|
pressDetected.current = false;
|
|
clearTimeout(pressTimeout);
|
|
}, 300);
|
|
}
|
|
});
|
|
|
|
const showPostOptions = () => {
|
|
if (!post) {
|
|
return;
|
|
}
|
|
|
|
const hasBeenDeleted = (post.delete_at !== 0 || post.state === Posts.POST_DELETED);
|
|
if (isSystemMessage(post) && (!canDelete || hasBeenDeleted)) {
|
|
return;
|
|
}
|
|
|
|
if (isPostPendingOrFailed(post) || isPostEphemeral(post)) {
|
|
return;
|
|
}
|
|
|
|
const screen = 'PostOptions';
|
|
const passProps = {
|
|
location,
|
|
post,
|
|
showAddReaction,
|
|
};
|
|
|
|
Keyboard.dismiss();
|
|
const postOptionsRequest = requestAnimationFrame(() => {
|
|
showModalOverCurrentContext(screen, passProps);
|
|
cancelAnimationFrame(postOptionsRequest);
|
|
});
|
|
};
|
|
|
|
if (!post) {
|
|
return null;
|
|
}
|
|
|
|
const highlightFlagged = isFlagged && !skipFlaggedHeader;
|
|
const hightlightPinned = post.is_pinned && !skipPinnedHeader;
|
|
const itemTestID = `${testID}.${post.id}`;
|
|
const rightColumnStyle = [styles.rightColumn, (post.root_id && isLastReply && styles.rightColumnPadding)];
|
|
const pendingPostStyle: StyleProp<ViewStyle> | undefined = isPostPendingOrFailed(post) ? styles.pendingPost : undefined;
|
|
const isAutoResponder = fromAutoResponder(post);
|
|
|
|
let highlightedStyle: StyleProp<ViewStyle>;
|
|
if (highlight) {
|
|
highlightedStyle = styles.highlight;
|
|
} else if ((highlightFlagged || hightlightPinned) && highlightPinnedOrFlagged) {
|
|
highlightedStyle = styles.highlightPinnedOrFlagged;
|
|
}
|
|
|
|
let header: ReactNode;
|
|
let postAvatar: ReactNode;
|
|
let consecutiveStyle: StyleProp<ViewStyle>;
|
|
if (isConsecutivePost) {
|
|
consecutiveStyle = styles.consective;
|
|
postAvatar = <View style={styles.consecutivePostContainer}/>;
|
|
} else {
|
|
postAvatar = isAutoResponder ? (
|
|
<SystemAvatar theme={theme}/>
|
|
) : (
|
|
<Avatar
|
|
pendingPostStyle={pendingPostStyle}
|
|
post={post}
|
|
theme={theme}
|
|
/>
|
|
);
|
|
|
|
if (isSystemMessage(post) && !isAutoResponder) {
|
|
header = (
|
|
<SystemHeader
|
|
createAt={post.create_at}
|
|
theme={theme}
|
|
/>
|
|
);
|
|
} else {
|
|
header = (
|
|
<Header
|
|
collapsedThreadsEnabled={collapsedThreadsEnabled}
|
|
enablePostUsernameOverride={enablePostUsernameOverride}
|
|
location={location}
|
|
post={post}
|
|
rootPostAuthor={rootPostAuthor}
|
|
shouldRenderReplyButton={shouldRenderReplyButton}
|
|
teammateNameDisplay={teammateNameDisplay}
|
|
theme={theme}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
let body;
|
|
if (isSystemMessage(post) && !isPostEphemeral(post) && !isAutoResponder) {
|
|
body = (
|
|
<SystemMessage
|
|
post={post}
|
|
theme={theme}
|
|
/>
|
|
);
|
|
} else {
|
|
body = (
|
|
<Body
|
|
highlight={Boolean(highlightedStyle)}
|
|
isFirstReply={isFirstReply}
|
|
isLastReply={isLastReply}
|
|
location={location}
|
|
post={post}
|
|
rootPostAuthor={rootPostAuthor}
|
|
showAddReaction={showAddReaction}
|
|
theme={theme}
|
|
/>
|
|
);
|
|
}
|
|
|
|
let footer;
|
|
if (
|
|
collapsedThreadsEnabled &&
|
|
Boolean(thread) &&
|
|
post.state !== Posts.POST_DELETED &&
|
|
thread?.participants?.length
|
|
) {
|
|
footer = (
|
|
<ThreadFooter
|
|
testID={`${itemTestID}.footer`}
|
|
theme={theme}
|
|
thread={thread}
|
|
threadStarter={threadStarter}
|
|
location={Screens.CHANNEL}
|
|
/>
|
|
);
|
|
}
|
|
|
|
let badge;
|
|
if (thread?.unread_mentions || thread?.unread_replies) {
|
|
if (thread.unread_replies && thread.unread_replies > 0) {
|
|
badge = (
|
|
<View style={styles.badgeContainer}>
|
|
<View style={styles.unreadDot}/>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<View
|
|
testID={testID}
|
|
style={[styles.postStyle, style, highlightedStyle]}
|
|
>
|
|
<TouchableWithFeedback
|
|
testID={itemTestID}
|
|
onPress={handlePress}
|
|
onLongPress={showPostOptions}
|
|
delayLongPress={200}
|
|
underlayColor={changeOpacity(theme.centerChannelColor, 0.1)}
|
|
cancelTouchOnPanning={true}
|
|
>
|
|
<>
|
|
<PreHeader
|
|
isConsecutivePost={isConsecutivePost}
|
|
isFlagged={isFlagged}
|
|
isPinned={post.is_pinned}
|
|
skipFlaggedHeader={skipFlaggedHeader}
|
|
skipPinnedHeader={skipPinnedHeader}
|
|
theme={theme}
|
|
/>
|
|
<View style={[styles.container, consecutiveStyle]}>
|
|
{postAvatar}
|
|
<View style={rightColumnStyle}>
|
|
{header}
|
|
{body}
|
|
{footer}
|
|
</View>
|
|
{badge}
|
|
</View>
|
|
</>
|
|
</TouchableWithFeedback>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default injectIntl(Post);
|