From 834c81fd2741858abde56c1460e7e8d81102a48b Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 3 Jun 2022 08:49:13 -0400 Subject: [PATCH] Show permalink view with CRT enabled (#6343) --- app/actions/remote/post.ts | 9 ++++----- app/screens/permalink/index.ts | 2 ++ app/screens/permalink/permalink.tsx | 8 +++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/actions/remote/post.ts b/app/actions/remote/post.ts index 4b1097512c..e091db6754 100644 --- a/app/actions/remote/post.ts +++ b/app/actions/remote/post.ts @@ -631,7 +631,7 @@ export async function fetchPostThread(serverUrl: string, postId: string, fetchOn } } -export async function fetchPostsAround(serverUrl: string, channelId: string, postId: string, perPage = General.POST_AROUND_CHUNK_SIZE) { +export async function fetchPostsAround(serverUrl: string, channelId: string, postId: string, perPage = General.POST_AROUND_CHUNK_SIZE, isCRTEnabled = false) { const operator = DatabaseManager.serverDatabases[serverUrl]?.operator; if (!operator) { return {error: `${serverUrl} database not found`}; @@ -646,9 +646,9 @@ export async function fetchPostsAround(serverUrl: string, channelId: string, pos try { const [after, post, before] = await Promise.all([ - client.getPostsAfter(channelId, postId, 0, perPage), - client.getPostThread(postId), - client.getPostsBefore(channelId, postId, 0, perPage), + client.getPostsAfter(channelId, postId, 0, perPage, isCRTEnabled, isCRTEnabled), + client.getPostThread(postId, isCRTEnabled, isCRTEnabled), + client.getPostsBefore(channelId, postId, 0, perPage, isCRTEnabled, isCRTEnabled), ]); const preData: PostResponse = { @@ -687,7 +687,6 @@ export async function fetchPostsAround(serverUrl: string, channelId: string, pos models.push(...posts); - const isCRTEnabled = await getIsCRTEnabled(operator.database); if (isCRTEnabled) { const threadModels = await prepareThreadsFromReceivedPosts(operator, data.posts); if (threadModels?.length) { diff --git a/app/screens/permalink/index.ts b/app/screens/permalink/index.ts index 29ff8a4f12..f49c6d8b3a 100644 --- a/app/screens/permalink/index.ts +++ b/app/screens/permalink/index.ts @@ -7,6 +7,7 @@ import {of as of$} from 'rxjs'; import {switchMap} from 'rxjs/operators'; import {observePost} from '@queries/servers/post'; +import {observeIsCRTEnabled} from '@queries/servers/thread'; import {WithDatabaseArgs} from '@typings/database/database'; import PostModel from '@typings/database/models/servers/post'; @@ -21,6 +22,7 @@ const enhance = withObservables([], ({database, postId}: OwnProps) => { channel: post.pipe( switchMap((p) => (p ? p.channel.observe() : of$(undefined))), ), + isCRTEnabled: observeIsCRTEnabled(database), }; }); diff --git a/app/screens/permalink/permalink.tsx b/app/screens/permalink/permalink.tsx index c052729735..206d55fc4f 100644 --- a/app/screens/permalink/permalink.tsx +++ b/app/screens/permalink/permalink.tsx @@ -25,8 +25,9 @@ import type ChannelModel from '@typings/database/models/servers/channel'; import type PostModel from '@typings/database/models/servers/post'; type Props = { - postId: PostModel['id']; channel?: ChannelModel; + isCRTEnabled: boolean; + postId: PostModel['id']; } const edges: Edge[] = ['left', 'right', 'top']; @@ -118,7 +119,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({ }, })); -function Permalink({channel, postId}: Props) { +function Permalink({channel, isCRTEnabled, postId}: Props) { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const theme = useTheme(); @@ -133,7 +134,7 @@ function Permalink({channel, postId}: Props) { useEffect(() => { (async () => { if (channel?.id) { - const data = await fetchPostsAround(serverUrl, channel.id, postId, 5); + const data = await fetchPostsAround(serverUrl, channel.id, postId, 5, isCRTEnabled); if (data?.posts) { setLoading(false); setPosts(data.posts); @@ -209,6 +210,7 @@ function Permalink({channel, postId}: Props) {