forked from Ivasoft/mattermost-mobile
Show permalink view with CRT enabled (#6343)
This commit is contained in:
@@ -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<PostsObjectsRequest>([
|
||||
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) {
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -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<PostModel[]>([]);
|
||||
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) {
|
||||
<View style={style.postList}>
|
||||
<PostList
|
||||
highlightedId={postId}
|
||||
isCRTEnabled={isCRTEnabled}
|
||||
posts={posts}
|
||||
location={Screens.PERMALINK}
|
||||
lastViewedAt={0}
|
||||
|
||||
Reference in New Issue
Block a user