* Initial commit post input * Fix message posting, add create direct channel and minor fixes * Fix "is typing" and "react to last post" behaviour * Some reordering, better handling of upload error, properly clear draft on send message, and fix minor progress bar misbehavior * Add keyboard listener for shift-enter, add selection between video or photo while attaching, add alert when trying to attach more than you are allowed, add paste functionality, minor fixes and reordering * Add library patch * Fix lint * Address feedback * Address feedback * Add missing negation * Check for group name and fix typo on draft comparisons * Address feedback * Address feedback * Address feedback * Address feedback * Fix several bugs * Remove @app imports * Address feedback * fix post list & post draft layout on iOS * Fix post draft cursor position * Fix file upload route * Allow to pick multiple images using the image picker * accurately get the channel member count * remove android cursor workaround * Remove local const INPUT_LINE_HEIGHT * move getPlaceHolder out of the component * use substring instead of legacy substr for hardward keyboard * Move onAppStateChange above the effects * Fix camera action bottom sheet * no need to memo SendButton * properly use memberCount in sender handler * Refactor how to get memberCount * Fix queryRecentPostsInThread * Remove unused isDirectChannelVisible && isGroupChannelVisible util functions * rename errorBadUser to errorUnkownUser * extract localized strings * use ClientErrorProps instead of ClientError * Minor improvements Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
68 lines
2.4 KiB
TypeScript
68 lines
2.4 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 {combineLatest, of as of$} from 'rxjs';
|
|
import {switchMap} from 'rxjs/operators';
|
|
|
|
import {MM_TABLES, SYSTEM_IDENTIFIERS} from '@constants/database';
|
|
import {DEFAULT_SERVER_MAX_FILE_SIZE} from '@constants/post_draft';
|
|
import {isMinimumServerVersion} from '@utils/helpers';
|
|
|
|
import DraftHandler from './draft_handler';
|
|
|
|
import type {WithDatabaseArgs} from '@typings/database/database';
|
|
import type DraftModel from '@typings/database/models/servers/draft';
|
|
import type SystemModel from '@typings/database/models/servers/system';
|
|
|
|
const {SERVER: {SYSTEM, DRAFT}} = MM_TABLES;
|
|
|
|
type OwnProps = {
|
|
channelId: string;
|
|
rootId?: string;
|
|
}
|
|
const enhanced = withObservables([], ({database, channelId, rootId = ''}: WithDatabaseArgs & OwnProps) => {
|
|
const draft = database.get<DraftModel>(DRAFT).query(
|
|
Q.where('channel_id', channelId),
|
|
Q.where('root_id', rootId),
|
|
).observeWithColumns(['message', 'files']).pipe(switchMap((v) => of$(v[0])));
|
|
|
|
const files = draft.pipe(switchMap((d) => of$(d?.files)));
|
|
const message = draft.pipe(switchMap((d) => of$(d?.message)));
|
|
|
|
const config = database.get<SystemModel>(SYSTEM).findAndObserve(SYSTEM_IDENTIFIERS.CONFIG).pipe(
|
|
switchMap(({value}) => of$(value as ClientConfig)),
|
|
);
|
|
|
|
const license = database.get<SystemModel>(SYSTEM).findAndObserve(SYSTEM_IDENTIFIERS.LICENSE).pipe(
|
|
switchMap(({value}) => of$(value as ClientLicense)),
|
|
);
|
|
|
|
const canUploadFiles = combineLatest([config, license]).pipe(
|
|
switchMap(([c, l]) => of$(
|
|
c.EnableFileAttachments !== 'false' &&
|
|
(l.IsLicensed === 'false' || l.Compliance === 'false' || c.EnableMobileFileUpload !== 'false'),
|
|
),
|
|
),
|
|
);
|
|
|
|
const maxFileSize = config.pipe(
|
|
switchMap((cfg) => of$(parseInt(cfg.MaxFileSize || '0', 10) || DEFAULT_SERVER_MAX_FILE_SIZE)),
|
|
);
|
|
|
|
const maxFileCount = config.pipe(
|
|
switchMap((cfg) => of$(isMinimumServerVersion(cfg.Version, 6, 0) ? 10 : 5)),
|
|
);
|
|
|
|
return {
|
|
files,
|
|
message,
|
|
maxFileSize,
|
|
maxFileCount,
|
|
canUploadFiles,
|
|
};
|
|
});
|
|
|
|
export default withDatabase(enhanced(DraftHandler));
|