forked from Ivasoft/mattermost-mobile
* First approach * Lint * Fixes and adding monitoring console statements (to be removed later) * Add pagination and apply graphQL also to login * Get all entry points to use the same GQL call * Unify gql handling * Use graphQL on websocket reconnect * Handle latest changes regarding categories * Use graphQL to properly fetch channel members on other servers * Remove logs and fetch unreads from other teams * Minor fixes * Final fixes * Address feedback, minor refactoring, and fixes around the refactor * Fix custom status duration types * Add missing fields and some reordering * Add timeout to fetch posts for unread channels
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {fetchFilteredChannelGroups, fetchFilteredTeamGroups, fetchGroupsForAutocomplete} from '@actions/remote/groups';
|
|
import DatabaseManager from '@database/manager';
|
|
import {queryGroupsByName, queryGroupsByNameInChannel, queryGroupsByNameInTeam} from '@queries/servers/group';
|
|
import {logError} from '@utils/log';
|
|
|
|
import type GroupModel from '@typings/database/models/servers/group';
|
|
|
|
export const searchGroupsByName = async (serverUrl: string, name: string): Promise<GroupModel[]> => {
|
|
let database;
|
|
|
|
try {
|
|
database = DatabaseManager.getServerDatabaseAndOperator(serverUrl).database;
|
|
} catch (e) {
|
|
logError('searchGroupsByName - DB Error', e);
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const groups = await fetchGroupsForAutocomplete(serverUrl, name);
|
|
|
|
if (groups && Array.isArray(groups)) {
|
|
return groups;
|
|
}
|
|
throw groups.error;
|
|
} catch (e) {
|
|
logError('searchGroupsByName - ERROR', e);
|
|
return queryGroupsByName(database, name).fetch();
|
|
}
|
|
};
|
|
|
|
export const searchGroupsByNameInTeam = async (serverUrl: string, name: string, teamId: string): Promise<GroupModel[]> => {
|
|
let database;
|
|
|
|
try {
|
|
database = DatabaseManager.getServerDatabaseAndOperator(serverUrl).database;
|
|
} catch (e) {
|
|
logError('searchGroupsByNameInTeam - DB Error', e);
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const groups = await fetchFilteredTeamGroups(serverUrl, name, teamId);
|
|
|
|
if (groups && Array.isArray(groups)) {
|
|
return groups;
|
|
}
|
|
throw groups.error;
|
|
} catch (e) {
|
|
logError('searchGroupsByNameInTeam - ERROR', e);
|
|
return queryGroupsByNameInTeam(database, name, teamId).fetch();
|
|
}
|
|
};
|
|
|
|
export const searchGroupsByNameInChannel = async (serverUrl: string, name: string, channelId: string): Promise<GroupModel[]> => {
|
|
let database;
|
|
|
|
try {
|
|
database = DatabaseManager.getServerDatabaseAndOperator(serverUrl).database;
|
|
} catch (e) {
|
|
logError('searchGroupsByNameInChannel - DB Error', e);
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const groups = await fetchFilteredChannelGroups(serverUrl, name, channelId);
|
|
|
|
if (groups && Array.isArray(groups)) {
|
|
return groups;
|
|
}
|
|
throw groups.error;
|
|
} catch (e) {
|
|
logError('searchGroupsByNameInChannel - ERROR', e);
|
|
return queryGroupsByNameInChannel(database, name, channelId).fetch();
|
|
}
|
|
};
|
|
|