mattermost-mobile/app/screens/find_channels/utils.ts
Elias Nahum f973ac8016
[Gekidou] Find channels (remote) (#6203)
* Display local results

* Fix queryPreferencesByCategoryAndName to observeWithColumns value

* Find channels (remote)

* ux feedback review

* dev review

* dev review 2

* Fetch deleted channels from other teams
2022-05-03 14:29:37 -04:00

27 lines
1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Database, Q} from '@nozbe/watermelondb';
import {of as of$} from 'rxjs';
import {MM_TABLES} from '@constants/database';
import type ChannelModel from '@typings/database/models/servers/channel';
import type MyChannelModel from '@typings/database/models/servers/my_channel';
const {SERVER: {CHANNEL, MY_CHANNEL}} = MM_TABLES;
export const retrieveChannels = (database: Database, myChannels: MyChannelModel[], orderedByLastViewedAt = false) => {
const ids = myChannels.map((m) => m.id);
if (ids.length) {
const idsStr = `'${ids.join("','")}'`;
const order = orderedByLastViewedAt ? 'order by my.last_viewed_at desc' : '';
return database.get<ChannelModel>(CHANNEL).query(
Q.unsafeSqlQuery(`select distinct c.* from ${MY_CHANNEL} my
inner join ${CHANNEL} c on c.id=my.id and c.id in (${idsStr})
${order}`),
).observe();
}
return of$([]);
};