From 1760b75dbf29216f05e9d8733c4ab7640e56e879 Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Thu, 5 May 2022 21:03:09 +0530 Subject: [PATCH] [Gekidou] [MM-43973] Thread footer for recent mentions (#6225) * Displaying thread footer * Participants can be empty * Update thread.ts --- app/actions/remote/search.ts | 6 +++++ app/actions/websocket/posts.ts | 8 +++++-- .../post_with_channel_info/index.ts | 23 ++++++++++++++++++ .../{index.tsx => post_with_channel_info.tsx} | 4 +++- .../server_data_operator/handlers/thread.ts | 24 ++++++++----------- app/screens/post_options/post_options.tsx | 3 +-- types/database/database.d.ts | 2 +- 7 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 app/components/post_with_channel_info/index.ts rename app/components/post_with_channel_info/{index.tsx => post_with_channel_info.tsx} (89%) diff --git a/app/actions/remote/search.ts b/app/actions/remote/search.ts index 2a3c9e3648..34715c21a2 100644 --- a/app/actions/remote/search.ts +++ b/app/actions/remote/search.ts @@ -5,6 +5,7 @@ import {SYSTEM_IDENTIFIERS} from '@constants/database'; import DatabaseManager from '@database/manager'; import NetworkManager from '@managers/network_manager'; import {prepareMissingChannelsForAllTeams} from '@queries/servers/channel'; +import {getIsCRTEnabled, prepareThreadsFromReceivedPosts} from '@queries/servers/thread'; import {getCurrentUser} from '@queries/servers/user'; import {processPostsFetched} from '@utils/post'; @@ -66,6 +67,11 @@ export async function fetchRecentMentions(serverUrl: string): Promise { + return { + isCRTEnabled: observeIsCRTEnabled(database), + }; +}); + +export default compose( + withDatabase, + enhance, +)(PostWithChannelInfo); diff --git a/app/components/post_with_channel_info/index.tsx b/app/components/post_with_channel_info/post_with_channel_info.tsx similarity index 89% rename from app/components/post_with_channel_info/index.tsx rename to app/components/post_with_channel_info/post_with_channel_info.tsx index f3c1689386..d77683c3da 100644 --- a/app/components/post_with_channel_info/index.tsx +++ b/app/components/post_with_channel_info/post_with_channel_info.tsx @@ -11,6 +11,7 @@ import ChannelInfo from './channel_info'; import type PostModel from '@typings/database/models/servers/post'; type Props = { + isCRTEnabled: boolean; post: PostModel; location: string; } @@ -26,12 +27,13 @@ const styles = StyleSheet.create({ }, }); -function PostWithChannelInfo({post, location}: Props) { +function PostWithChannelInfo({isCRTEnabled, post, location}: Props) { return ( class extends superclass { // Let's process the thread data for (const thread of uniqueThreads) { - threadsParticipants.push({ - thread_id: thread.id, - participants: (thread.participants || []).map((participant) => ({ - id: participant.id, + // Avoid participants field set as "null" from overriding the existing ones + if (Array.isArray(thread.participants)) { + threadsParticipants.push({ thread_id: thread.id, - })), - }); + participants: thread.participants.map((participant) => ({ + id: participant.id, + thread_id: thread.id, + })), + }); + } } // Get thread models to be created and updated @@ -106,14 +109,7 @@ const ThreadHandler = (superclass: any) => class extends superclass { handleThreadParticipants = async ({threadsParticipants, prepareRecordsOnly, skipSync = false}: HandleThreadParticipantsArgs): Promise => { const batchRecords: ThreadParticipantModel[] = []; - if (!threadsParticipants?.length) { - // eslint-disable-next-line no-console - console.warn( - 'An empty or undefined "threadParticipants" array has been passed to the handleThreadParticipants method', - ); - return []; - } - + // NOTE: Participants list can also be an empty array for await (const threadParticipant of threadsParticipants) { const {thread_id, participants} = threadParticipant; const rawValues = getUniqueRawsBy({raws: participants, key: 'id'}) as ThreadParticipant[]; diff --git a/app/screens/post_options/post_options.tsx b/app/screens/post_options/post_options.tsx index be5f04d74f..ef03f2caee 100644 --- a/app/screens/post_options/post_options.tsx +++ b/app/screens/post_options/post_options.tsx @@ -129,8 +129,7 @@ const PostOptions = ({ ); }; - // This fixes opening "post options modal" on top of "thread modal" - const additionalSnapPoints = sourceScreen === Screens.THREAD ? 3 : 2; + const additionalSnapPoints = 2; return (