mattermost-mobile/app/components/post_list/post/header/index.ts
Miguel Alatzar 1d02d6e1e5
[Gekidou] app entry (#5609)
* Add channelEntry action

* Refactor appEntry

* Lint fix

* Some duplication removed

* Refactor app entry

* Refactor app entry and add prepareDestroyPermanentlyWithAssociations

* Handle team deletion

* Sync channels

* Lint fix

* Address review comments, take 1

* Address review comments, take 2

* Set initial channel ID to empty

* Fix types

* sort imports

* clean up app entry point

* Fix post header & highlight reply bar

* Style channel list text

* iOS Pods sync

* Rename goToChannel to goToHome

* Sync ios Gemfile.lock

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-09-29 12:38:05 -03:00

71 lines
3.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Q} from '@nozbe/watermelondb';
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
import withObservables from '@nozbe/with-observables';
import {of as of$} from 'rxjs';
import {switchMap} from 'rxjs/operators';
import {Preferences} from '@constants';
import {MM_TABLES, SYSTEM_IDENTIFIERS} from '@constants/database';
import {getPreferenceAsBool, getTeammateNameDisplaySetting} from '@helpers/api/preference';
import {isMinimumServerVersion} from '@utils/helpers';
import Header from './header';
import type {WithDatabaseArgs} from '@typings/database/database';
import type PostModel from '@typings/database/models/servers/post';
import type PreferenceModel from '@typings/database/models/servers/preference';
import type SystemModel from '@typings/database/models/servers/system';
type HeaderInputProps = {
config: ClientConfig;
differentThreadSequence: boolean;
license: ClientLicense;
preferences: PreferenceModel[];
post: PostModel;
};
const withBaseHeaderProps = withObservables([], ({database}: WithDatabaseArgs & {post: PostModel}) => ({
config: database.get(MM_TABLES.SERVER.SYSTEM).findAndObserve(SYSTEM_IDENTIFIERS.CONFIG).pipe(switchMap((cfg: SystemModel) => of$(cfg.value))),
license: database.get(MM_TABLES.SERVER.SYSTEM).findAndObserve(SYSTEM_IDENTIFIERS.LICENSE).pipe(switchMap((lcs: SystemModel) => of$(lcs.value))),
preferences: database.get(MM_TABLES.SERVER.PREFERENCE).query(Q.where('category', Preferences.CATEGORY_DISPLAY_SETTINGS)).observe(),
}));
const withHeaderProps = withObservables(
['preferences', 'post', 'differentThreadSequence'],
({config, post, license, database, preferences, differentThreadSequence}: WithDatabaseArgs & HeaderInputProps) => {
const author = post.author.observe();
const enablePostUsernameOverride = of$(config.EnablePostUsernameOverride === 'true');
const isTimezoneEnabled = of$(config.ExperimentalTimezone === 'true');
const isMilitaryTime = of$(getPreferenceAsBool(preferences, Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time', false));
const teammateNameDisplay = of$(getTeammateNameDisplaySetting(preferences, config, license));
const isCustomStatusEnabled = of$(config.EnableCustomUserStatuses === 'true' && isMinimumServerVersion(config.Version, 5, 36));
const commentCount = database.get(MM_TABLES.SERVER.POST).query(
Q.and(
Q.where('root_id', (post.rootId || post.id)),
Q.where('delete_at', Q.eq(0)),
),
).observeCount();
const rootPostAuthor = differentThreadSequence ? post.root.observe().pipe(switchMap((root) => {
if (root.length) {
return root[0].author.observe();
}
return of$(null);
})) : of$(null);
return {
author,
commentCount,
enablePostUsernameOverride,
isCustomStatusEnabled,
isMilitaryTime,
isTimezoneEnabled,
teammateNameDisplay,
rootPostAuthor,
};
});
export default withDatabase(withBaseHeaderProps(withHeaderProps(Header)));