mattermost-mobile/app/queries/servers/group.ts
Shaz MJ dcfc6e7927
[Gekidou] Groups + group-memberships deferred fetch (#6370)
* WIP

* Actions updated to fetch remote first, and local on error

* Groups fetch and save

* PR Feedback: prepare vs store and undefined fix

* Forgot to add file

* Groups Mention WIP

* Groups highlight!

* Merge, PR Feedback

* PR Feedback

* PR Feedback: Try/Catch blocks

* PR Feedback

* Rebased with PR feedback

* Exclusion fix, plus id order

* Tidies up iterations

* Loops updated

* Update app/database/operator/server_data_operator/handlers/group.ts

Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>

* PR Feedback: Remove unnecessary prepare/store methods

* Newline ESLint error

* Extracts out id generation for group-associations

* Batches if not fetchOnly

Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>
2022-07-07 12:20:06 +02:00

43 lines
1.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Database, Q} from '@nozbe/watermelondb';
import {MM_TABLES} from '@constants/database';
import type GroupModel from '@typings/database/models/servers/group';
import type GroupMembershipModel from '@typings/database/models/servers/group_membership';
const {SERVER: {GROUP, GROUP_CHANNEL, GROUP_MEMBERSHIP, GROUP_TEAM}} = MM_TABLES;
export const queryGroupsByName = (database: Database, name: string) => {
return database.collections.get<GroupModel>(GROUP).query(
Q.where('name', Q.like(`%${Q.sanitizeLikeString(name)}%`)),
);
};
export const queryGroupsByNames = (database: Database, names: string[]) => {
return database.collections.get<GroupModel>(GROUP).query(
Q.where('name', Q.oneOf(names)),
);
};
export const queryGroupsByNameInTeam = (database: Database, name: string, teamId: string) => {
return database.collections.get<GroupModel>(GROUP).query(
Q.on(GROUP_TEAM, 'team_id', teamId),
Q.where('name', Q.like(`%${Q.sanitizeLikeString(name)}%`)),
);
};
export const queryGroupsByNameInChannel = (database: Database, name: string, channelId: string) => {
return database.collections.get<GroupModel>(GROUP).query(
Q.on(GROUP_CHANNEL, 'channel_id', channelId),
Q.where('name', Q.like(`%${Q.sanitizeLikeString(name)}%`)),
);
};
export const queryGroupMembershipForMember = (database: Database, userId: string) => {
return database.collections.get<GroupMembershipModel>(GROUP_MEMBERSHIP).query(
Q.where('user_id', userId),
);
};