mattermost-mobile/app/queries/servers/post.ts
Avinash Lingaloo e8ce78f39d
MM-36721 - [GEKIDOU] Porting Markdown components (#5586)
* Started with Channel Post List

* Added markdown hashtag

* Added TouchableWithFeedback component

* Added utils/bottom_sheet

* Removed BottomSheet in favor of future SlideUpPanel

* Added markdown_block_quote

* Added markdown_list_item

* Added markdown_list

* Added MarkDownTableCell component

* Markdown_table - in progress - need to verify TS

* Added markdown_table

* Update Podfile.lock

* Added deep_linking constant

* Added utils/draft

* Update config to include ExperimentalNormalizeMarkdownLinks

* Added markdown_link

* Added markdown_table_row

* Added ProgressiveImage and RetriableImage components and images utils

* Converted Retriable component to functional component

* Added type definition for commonmark

* Continuing with markdown TS

* Markdown - Typing props [ in progress ]

* Fix boolean flag with mardown block quote

* Adding observable config to markdown_link

* TS Fixes [ in progress ]

* TS fixes

* TS fixes - TextStyles

* Update markdown.tsx

* TS fixes on markdown

* TS Fixes - AtMention component

* AtMention [ IN PROGRESS ]

* Add markdown support

* Fix emoji and jumboEmoji on iOS

* Fix handleMyTeam operator

* Fix navigation style based on theme

* Fix iOS MattermostManaged deleteDatabse return error type

* wrap setNavigationStackStyles under a requestAnimationFrame

* Add preventDoubleTap to channel mention

* Increase double tap to 750ms

* Fix handleReceivedPostsInChannel chunk query

* Set initial navigation theme

* Swizzle FastImage on iOS

* fix preventDoubleTap test

Co-authored-by: Avinash Lingaloo <>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-08-02 20:30:17 +04:00

50 lines
1.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Database, Q} from '@nozbe/watermelondb';
import {MM_TABLES} from '@constants/database';
import type PostModel from '@typings/database/models/servers/post';
import type PostInChannelModel from '@typings/database/models/servers/posts_in_channel';
const {SERVER: {POST, POSTS_IN_CHANNEL}} = MM_TABLES;
export const queryPostsInChannel = (database: Database, channelId: string): Promise<PostInChannelModel[]> => {
try {
return database.get(POSTS_IN_CHANNEL).query(
Q.where('id', channelId),
Q.experimentalSortBy('latest', Q.desc),
).fetch() as Promise<PostInChannelModel[]>;
} catch {
return Promise.resolve([] as PostInChannelModel[]);
}
};
export const queryPostsChunk = (database: Database, channelId: string, earliest: number, latest: number): Promise<PostModel[]> => {
try {
return database.get(POST).query(
Q.and(
Q.where('channel_id', channelId),
Q.where('create_at', Q.between(earliest, latest)),
Q.where('delete_at', Q.eq(0)),
),
Q.experimentalSortBy('create_at', Q.desc),
).fetch() as Promise<PostModel[]>;
} catch {
return Promise.resolve([] as PostModel[]);
}
};
export const queryRecentPostsInChannel = async (database: Database, channelId: string): Promise<PostModel[]> => {
try {
const chunks = await queryPostsInChannel(database, channelId);
if (chunks.length) {
const recent = chunks[0];
return queryPostsChunk(database, channelId, recent.earliest, recent.latest);
}
return Promise.resolve([] as PostModel[]);
} catch {
return Promise.resolve([] as PostModel[]);
}
};