forked from Ivasoft/mattermost-mobile
* 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
36 lines
1.1 KiB
TypeScript
36 lines
1.1 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 {observeCurrentUserId} from '@queries/servers/system';
|
|
import {observeUser} from '@queries/servers/user';
|
|
import {getUserIdFromChannelName} from '@utils/user';
|
|
|
|
import DmAvatar from './dm_avatar';
|
|
|
|
import type {WithDatabaseArgs} from '@typings/database/database';
|
|
|
|
const enhance = withObservables(['channelName'], ({channelName, database}: {channelName: string} & WithDatabaseArgs) => {
|
|
const currentUserId = observeCurrentUserId(database);
|
|
|
|
const authorId = currentUserId.pipe(
|
|
switchMap((userId) => of$(getUserIdFromChannelName(userId, channelName))),
|
|
);
|
|
|
|
const author = authorId.pipe(
|
|
switchMap((id) => {
|
|
return observeUser(database, id);
|
|
}),
|
|
);
|
|
|
|
return {
|
|
author,
|
|
};
|
|
});
|
|
|
|
export default withDatabase(enhance(DmAvatar));
|