* Extract common observers to queries * Separate also queries and more agressive refactoring * Use query to avoid throws from findAndObserve * Fix minor error * Address feedback * Address feedback * Address feedback * Fix model types * Address feedback
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
|
|
import withObservables from '@nozbe/with-observables';
|
|
import {of as of$} from 'rxjs';
|
|
import {switchMap} from 'rxjs/operators';
|
|
|
|
import {observeConfig} from '@queries/servers/system';
|
|
import {observeCurrentUser} from '@queries/servers/user';
|
|
import {WithDatabaseArgs} from '@typings/database/database';
|
|
|
|
import EditProfile from './edit_profile';
|
|
|
|
const enhanced = withObservables([], ({database}: WithDatabaseArgs) => {
|
|
const config = observeConfig(database);
|
|
|
|
return {
|
|
currentUser: observeCurrentUser(database),
|
|
lockedFirstName: config.pipe(
|
|
switchMap(
|
|
(cfg) => of$(cfg?.LdapFirstNameAttributeSet === 'true' || cfg?.SamlFirstNameAttributeSet === 'true'),
|
|
),
|
|
),
|
|
lockedLastName: config.pipe(
|
|
switchMap(
|
|
(cfg) => of$(cfg?.LdapLastNameAttributeSet === 'true' || cfg?.SamlLastNameAttributeSet === 'true'),
|
|
),
|
|
),
|
|
lockedNickname: config.pipe(
|
|
switchMap(
|
|
(cfg) => of$(cfg?.LdapNicknameAttributeSet === 'true' || cfg?.SamlNicknameAttributeSet === 'true'),
|
|
),
|
|
),
|
|
lockedPosition: config.pipe(
|
|
switchMap(
|
|
(cfg) => of$(cfg?.LdapPositionAttributeSet === 'true' || cfg?.SamlPositionAttributeSet === 'true'),
|
|
),
|
|
),
|
|
lockedPicture: config.pipe(
|
|
switchMap(
|
|
(cfg) => of$(cfg?.LdapPictureAttributeSet === 'true'),
|
|
),
|
|
),
|
|
};
|
|
});
|
|
|
|
export default withDatabase(enhanced(EditProfile));
|