From c4c89a8f055128515fb5f62cf5defc8ce7536d68 Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Fri, 22 Jul 2022 17:44:39 +0530 Subject: [PATCH] [Gekidou MM-40096] Permalink view for replies when CRT is enabled (#6494) * Permalink for CRT * typo * Condition refactor --- app/actions/remote/post.ts | 11 ++-- app/components/post_list/post/body/index.tsx | 5 +- app/components/post_list/post/post.tsx | 10 +-- app/components/post_list/post_list.tsx | 1 + app/screens/permalink/index.ts | 3 + app/screens/permalink/permalink.tsx | 64 ++++++++++++++++---- 6 files changed, 73 insertions(+), 21 deletions(-) diff --git a/app/actions/remote/post.ts b/app/actions/remote/post.ts index 734c43519..973ef0cd6 100644 --- a/app/actions/remote/post.ts +++ b/app/actions/remote/post.ts @@ -570,7 +570,7 @@ export const fetchPostAuthors = async (serverUrl: string, posts: Post[], fetchOn } }; -export async function fetchPostThread(serverUrl: string, postId: string, fetchOnly = false): Promise { +export async function fetchPostThread(serverUrl: string, postId: string, fetchOnly = false) { const operator = DatabaseManager.serverDatabases[serverUrl]?.operator; if (!operator) { return {error: `${serverUrl} database not found`}; @@ -587,12 +587,15 @@ export async function fetchPostThread(serverUrl: string, postId: string, fetchOn const isCRTEnabled = await getIsCRTEnabled(operator.database); const data = await client.getPostThread(postId, isCRTEnabled, isCRTEnabled); const result = processPostsFetched(data); + let posts: Model[] = []; if (!fetchOnly) { - const models = await operator.handlePosts({ + const models: Model[] = []; + posts = await operator.handlePosts({ ...result, actionType: ActionType.POSTS.RECEIVED_IN_THREAD, prepareRecordsOnly: true, }); + models.push(...posts); const {authors} = await fetchPostAuthors(serverUrl, result.posts, true); if (authors?.length) { @@ -611,7 +614,7 @@ export async function fetchPostThread(serverUrl: string, postId: string, fetchOn } await operator.batchRecords(models); } - return result; + return {posts: extractRecordsForTable(posts, MM_TABLES.SERVER.POST)}; } catch (error) { forceLogoutIfNecessary(serverUrl, error as ClientErrorProps); return {error}; @@ -641,7 +644,7 @@ export async function fetchPostsAround(serverUrl: string, channelId: string, pos const preData: PostResponse = { posts: { ...filterPostsInOrderedArray(after.posts, after.order), - postId: post.posts![postId], + [postId]: post.posts![postId], ...filterPostsInOrderedArray(before.posts, before.order), }, order: [], diff --git a/app/components/post_list/post/body/index.tsx b/app/components/post_list/post/body/index.tsx index 97c61bbd5..b01e25237 100644 --- a/app/components/post_list/post/body/index.tsx +++ b/app/components/post_list/post/body/index.tsx @@ -27,6 +27,7 @@ type BodyProps = { hasReactions: boolean; highlight: boolean; highlightReplyBar: boolean; + isCRTEnabled?: boolean; isEphemeral: boolean; isFirstReply?: boolean; isJumboEmoji: boolean; @@ -75,7 +76,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { const Body = ({ appsEnabled, hasFiles, hasReactions, highlight, highlightReplyBar, - isEphemeral, isFirstReply, isJumboEmoji, isLastReply, isPendingOrFailed, isPostAddChannelMember, + isCRTEnabled, isEphemeral, isFirstReply, isJumboEmoji, isLastReply, isPendingOrFailed, isPostAddChannelMember, location, post, searchPatterns, showAddReaction, theme, }: BodyProps) => { const style = getStyleSheet(theme); @@ -90,7 +91,7 @@ const Body = ({ const hasContent = (post.metadata?.embeds?.length || (appsEnabled && post.props?.app_bindings?.length)) || post.props?.attachments?.length; const replyBarStyle = useCallback((): StyleProp|undefined => { - if (!isReplyPost) { + if (!isReplyPost || (isCRTEnabled && location === Screens.PERMALINK)) { return undefined; } diff --git a/app/components/post_list/post/post.tsx b/app/components/post_list/post/post.tsx index 7ca41201f..89e6ba11b 100644 --- a/app/components/post_list/post/post.tsx +++ b/app/components/post_list/post/post.tsx @@ -53,6 +53,7 @@ type PostProps = { isPostAddChannelMember: boolean; location: string; post: PostModel; + rootId?: string; previousPost?: PostModel; hasReactions: boolean; searchPatterns?: SearchPattern[]; @@ -105,7 +106,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { const Post = ({ appsEnabled, canDelete, currentUser, differentThreadSequence, hasFiles, hasReplies, highlight, highlightPinnedOrSaved = true, highlightReplyBar, isCRTEnabled, isConsecutivePost, isEphemeral, isFirstReply, isSaved, isJumboEmoji, isLastReply, isPostAddChannelMember, - location, post, hasReactions, searchPatterns, shouldRenderReplyButton, skipSavedHeader, skipPinnedHeader, showAddReaction = true, style, + location, post, rootId, hasReactions, searchPatterns, shouldRenderReplyButton, skipSavedHeader, skipPinnedHeader, showAddReaction = true, style, testID, thread, previousPost, }: PostProps) => { const pressDetected = useRef(false); @@ -140,8 +141,8 @@ const Post = ({ const isValidSystemMessage = isAutoResponder || !isSystemPost; if (post.deleteAt === 0 && isValidSystemMessage && !isPendingOrFailed) { if ([Screens.CHANNEL, Screens.PERMALINK].includes(location)) { - const rootId = post.rootId || post.id; - fetchAndSwitchToThread(serverUrl, rootId); + const postRootId = post.rootId || post.id; + fetchAndSwitchToThread(serverUrl, postRootId); } } else if ((isEphemeral || post.deleteAt > 0)) { removePost(serverUrl, post); @@ -278,6 +279,7 @@ const Post = ({ hasReactions={hasReactions} highlight={Boolean(highlightedStyle)} highlightReplyBar={highlightReplyBar} + isCRTEnabled={isCRTEnabled} isEphemeral={isEphemeral} isFirstReply={isFirstReply} isJumboEmoji={isJumboEmoji} @@ -295,7 +297,7 @@ const Post = ({ let unreadDot; let footer; - if (isCRTEnabled && thread && location !== Screens.THREAD) { + if (isCRTEnabled && thread && location !== Screens.THREAD && !(rootId && location === Screens.PERMALINK)) { if (thread.replyCount > 0 || thread.isFollowing) { footer = (