(cherry picked from commit 0a78b1d804)
Co-authored-by: Daniel Espino García <larkox@gmail.com>
This commit is contained in:
parent
4e400a69fc
commit
3d92a61f32
3 changed files with 10 additions and 11 deletions
|
|
@ -9,11 +9,9 @@ import {addPostAcknowledgement, removePost, removePostAcknowledgement, storePost
|
|||
import {addRecentReaction} from '@actions/local/reactions';
|
||||
import {createThreadFromNewPost} from '@actions/local/thread';
|
||||
import {ActionType, General, Post, ServerErrors} from '@constants';
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import DatabaseManager from '@database/manager';
|
||||
import {filterPostsInOrderedArray} from '@helpers/api/post';
|
||||
import {getNeededAtMentionedUsernames} from '@helpers/api/user';
|
||||
import {extractRecordsForTable} from '@helpers/database';
|
||||
import NetworkManager from '@managers/network_manager';
|
||||
import {getMyChannel, prepareMissingChannelsForAllTeams, queryAllMyChannel} from '@queries/servers/channel';
|
||||
import {queryAllCustomEmojis} from '@queries/servers/custom_emoji';
|
||||
|
|
@ -600,7 +598,7 @@ export async function fetchPostThread(serverUrl: string, postId: string, options
|
|||
await operator.batchRecords(models, 'fetchPostThread');
|
||||
}
|
||||
setFetchingThreadState(postId, false);
|
||||
return {posts: extractRecordsForTable<PostModel>(posts, MM_TABLES.SERVER.POST)};
|
||||
return {posts: result.posts};
|
||||
} catch (error) {
|
||||
logDebug('error on fetchPostThread', getFullErrorMessage(error));
|
||||
forceLogoutIfNecessary(serverUrl, error);
|
||||
|
|
@ -668,7 +666,7 @@ export async function fetchPostsAround(serverUrl: string, channelId: string, pos
|
|||
await operator.batchRecords(models, 'fetchPostsAround');
|
||||
}
|
||||
|
||||
return {posts: extractRecordsForTable<PostModel>(posts, MM_TABLES.SERVER.POST)};
|
||||
return {posts: data.posts};
|
||||
} catch (error) {
|
||||
logDebug('error on fetchPostsAround', getFullErrorMessage(error));
|
||||
forceLogoutIfNecessary(serverUrl, error);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import xRegExp from 'xregexp';
|
|||
|
||||
import {General} from '@constants';
|
||||
|
||||
import type Model from '@nozbe/watermelondb/Model';
|
||||
import type ChannelModel from '@typings/database/models/servers/channel';
|
||||
import type MyChannelModel from '@typings/database/models/servers/my_channel';
|
||||
|
||||
|
|
@ -26,11 +25,6 @@ type NotifyProps = {
|
|||
NotifyProps,
|
||||
]
|
||||
|
||||
export const extractRecordsForTable = <T>(records: Model[], tableName: string): T[] => {
|
||||
// @ts-expect-error constructor.table not exposed in type definition
|
||||
return records.filter((r) => r.constructor.table === tableName) as T[];
|
||||
};
|
||||
|
||||
export function extractChannelDisplayName(raw: Pick<Channel, 'type' | 'display_name' | 'fake'>, record?: ChannelModel) {
|
||||
let displayName = '';
|
||||
switch (raw.type) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {Alert, Text, TouchableOpacity, View} from 'react-native';
|
|||
import Animated from 'react-native-reanimated';
|
||||
import {type Edge, SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
|
||||
|
||||
import {getPosts} from '@actions/local/post';
|
||||
import {fetchChannelById, joinChannel, switchToChannelById} from '@actions/remote/channel';
|
||||
import {fetchPostById, fetchPostsAround, fetchPostThread} from '@actions/remote/post';
|
||||
import {addCurrentUserToTeam, fetchTeamByName, removeCurrentUserFromTeam} from '@actions/remote/team';
|
||||
|
|
@ -122,6 +123,10 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
|
|||
|
||||
const POSTS_LIMIT = 5;
|
||||
|
||||
const idExtractor = (item: Post) => {
|
||||
return item.id;
|
||||
};
|
||||
|
||||
function Permalink({
|
||||
channel,
|
||||
rootId,
|
||||
|
|
@ -163,7 +168,9 @@ function Permalink({
|
|||
setError({unreachable: true});
|
||||
}
|
||||
if (data.posts) {
|
||||
setPosts(loadThreadPosts ? processThreadPosts(data.posts, postId) : data.posts);
|
||||
const ids = data.posts.map(idExtractor);
|
||||
const postsModels = await getPosts(serverUrl, ids, 'desc');
|
||||
setPosts(loadThreadPosts ? processThreadPosts(postsModels, postId) : postsModels);
|
||||
}
|
||||
setLoading(false);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue