forked from Ivasoft/mattermost-mobile
[Gekidou] Groups API Calls (#6277)
* Adds missing group API calls * Rename methods to fetch and move to remote actions
This commit is contained in:
@@ -17,6 +17,17 @@ export const fetchGroupsForChannel = async (serverUrl: string, channelId: string
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchGroupsForMembership = async (serverUrl: string, userId: string) => {
|
||||||
|
let client: Client;
|
||||||
|
try {
|
||||||
|
client = NetworkManager.getClient(serverUrl);
|
||||||
|
return client.getAllGroupsAssociatedToMembership(userId);
|
||||||
|
} catch (error) {
|
||||||
|
forceLogoutIfNecessary(serverUrl, error as ClientErrorProps);
|
||||||
|
return {error};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const fetchGroupsForTeam = async (serverUrl: string, teamId: string) => {
|
export const fetchGroupsForTeam = async (serverUrl: string, teamId: string) => {
|
||||||
let client: Client;
|
let client: Client;
|
||||||
try {
|
try {
|
||||||
@@ -38,3 +49,56 @@ export const fetchGroupsForAutocomplete = async (serverUrl: string, query: strin
|
|||||||
return {error};
|
return {error};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchMembershipsForGroup = async (serverUrl: string, groupId: string) => {
|
||||||
|
let client: Client;
|
||||||
|
try {
|
||||||
|
client = NetworkManager.getClient(serverUrl);
|
||||||
|
return client.getAllMembershipsAssociatedToGroup(groupId);
|
||||||
|
} catch (error) {
|
||||||
|
forceLogoutIfNecessary(serverUrl, error as ClientErrorProps);
|
||||||
|
return {error};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchTeamsForGroup = async (serverUrl: string, groupId: string) => {
|
||||||
|
let client: Client;
|
||||||
|
try {
|
||||||
|
client = NetworkManager.getClient(serverUrl);
|
||||||
|
return client.getAllTeamsAssociatedToGroup(groupId);
|
||||||
|
} catch (error) {
|
||||||
|
forceLogoutIfNecessary(serverUrl, error as ClientErrorProps);
|
||||||
|
return {error};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchChannelsForGroup = async (serverUrl: string, groupId: string) => {
|
||||||
|
let client: Client;
|
||||||
|
try {
|
||||||
|
client = NetworkManager.getClient(serverUrl);
|
||||||
|
return client.getAllChannelsAssociatedToGroup(groupId);
|
||||||
|
} catch (error) {
|
||||||
|
forceLogoutIfNecessary(serverUrl, error as ClientErrorProps);
|
||||||
|
return {error};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchFilteredTeamGroups = async (serverUrl: string, teamId: string, searchTerm: string) => {
|
||||||
|
const response = await fetchGroupsForTeam(serverUrl, teamId);
|
||||||
|
|
||||||
|
if (response && 'groups' in response) {
|
||||||
|
return response.groups.filter((g) => g.name.toLowerCase().includes(searchTerm.toLowerCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchFilteredChannelGroups = async (serverUrl: string, channelId: string, searchTerm: string) => {
|
||||||
|
const response = await fetchGroupsForChannel(serverUrl, channelId);
|
||||||
|
|
||||||
|
if (response && 'groups' in response) {
|
||||||
|
return response.groups.filter((g) => g.name.toLowerCase().includes(searchTerm.toLowerCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ import {PER_PAGE_DEFAULT} from './constants';
|
|||||||
|
|
||||||
export interface ClientGroupsMix {
|
export interface ClientGroupsMix {
|
||||||
getGroups: (query?: string, filterAllowReference?: boolean, page?: number, perPage?: number, since?: number) => Promise<Group[]>;
|
getGroups: (query?: string, filterAllowReference?: boolean, page?: number, perPage?: number, since?: number) => Promise<Group[]>;
|
||||||
getAllGroupsAssociatedToTeam: (teamID: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
getAllGroupsAssociatedToChannel: (channelId: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
||||||
getAllGroupsAssociatedToChannel: (channelID: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
getAllGroupsAssociatedToMembership: (userId: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
||||||
|
getAllGroupsAssociatedToTeam: (teamId: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
||||||
|
getAllChannelsAssociatedToGroup: (groupId: string, filterAllowReference?: boolean) => Promise<{groupChannels: GroupChannel[]}>;
|
||||||
|
getAllMembershipsAssociatedToGroup: (groupId: string, filterAllowReference?: boolean) => Promise<{groupMemberships: GroupMembership; total_member_count: number}>;
|
||||||
|
getAllTeamsAssociatedToGroup: (groupId: string, filterAllowReference?: boolean) => Promise<{groupTeams: GroupTeam[]}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClientGroups = (superclass: any) => class extends superclass {
|
const ClientGroups = (superclass: any) => class extends superclass {
|
||||||
@@ -19,16 +23,44 @@ const ClientGroups = (superclass: any) => class extends superclass {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
getAllGroupsAssociatedToTeam = async (teamID: string, filterAllowReference = false) => {
|
getAllGroupsAssociatedToChannel = async (channelId: string, filterAllowReference = false) => {
|
||||||
return this.doFetch(
|
return this.doFetch(
|
||||||
`${this.urlVersion}/teams/${teamID}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
`${this.urlVersion}/channels/${channelId}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
||||||
{method: 'get'},
|
{method: 'get'},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
getAllGroupsAssociatedToChannel = async (channelID: string, filterAllowReference = false) => {
|
getAllGroupsAssociatedToTeam = async (teamId: string, filterAllowReference = false) => {
|
||||||
return this.doFetch(
|
return this.doFetch(
|
||||||
`${this.urlVersion}/channels/${channelID}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
`${this.urlVersion}/teams/${teamId}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
||||||
|
{method: 'get'},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAllGroupsAssociatedToMembership = async (userId: string, filterAllowReference = false) => {
|
||||||
|
return this.doFetch(
|
||||||
|
`${this.urlVersion}/users/${userId}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
||||||
|
{method: 'get'},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAllTeamsAssociatedToGroup = async (groupId: string, filterAllowReference = false) => {
|
||||||
|
return this.doFetch(
|
||||||
|
`${this.urlVersion}/groups/${groupId}/teams${buildQueryString({filter_allow_reference: filterAllowReference})}`,
|
||||||
|
{method: 'get'},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAllChannelsAssociatedToGroup = async (groupId: string, filterAllowReference = false) => {
|
||||||
|
return this.doFetch(
|
||||||
|
`${this.urlVersion}/groups/${groupId}/channels${buildQueryString({filter_allow_reference: filterAllowReference})}`,
|
||||||
|
{method: 'get'},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAllMembershipsAssociatedToGroup = async (groupId: string, filterAllowReference = false) => {
|
||||||
|
return this.doFetch(
|
||||||
|
`${this.urlVersion}/groups/${groupId}/members${buildQueryString({filter_allow_reference: filterAllowReference})}`,
|
||||||
{method: 'get'},
|
{method: 'get'},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {debounce} from 'lodash';
|
|||||||
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
||||||
import {Platform, SectionList, SectionListData, SectionListRenderItemInfo} from 'react-native';
|
import {Platform, SectionList, SectionListData, SectionListRenderItemInfo} from 'react-native';
|
||||||
|
|
||||||
import {fetchGroupsForAutocomplete, fetchGroupsForChannel, fetchGroupsForTeam} from '@actions/remote/groups';
|
import {fetchFilteredChannelGroups, fetchFilteredTeamGroups, fetchGroupsForAutocomplete} from '@actions/remote/groups';
|
||||||
import {searchUsers} from '@actions/remote/user';
|
import {searchUsers} from '@actions/remote/user';
|
||||||
import GroupMentionItem from '@components/autocomplete/at_mention_group/at_mention_group';
|
import GroupMentionItem from '@components/autocomplete/at_mention_group/at_mention_group';
|
||||||
import AtMentionItem from '@components/autocomplete/at_mention_item';
|
import AtMentionItem from '@components/autocomplete/at_mention_item';
|
||||||
@@ -172,26 +172,6 @@ const makeSections = (teamMembers: Array<UserProfile | UserModel>, usersInChanne
|
|||||||
return newSections;
|
return newSections;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFilteredTeamGroups = async (serverUrl: string, teamId: string, searchTerm: string) => {
|
|
||||||
const response = await fetchGroupsForTeam(serverUrl, teamId);
|
|
||||||
|
|
||||||
if (response && 'groups' in response) {
|
|
||||||
return response.groups.filter((g) => g.name.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
const getFilteredChannelGroups = async (serverUrl: string, channelId: string, searchTerm: string) => {
|
|
||||||
const response = await fetchGroupsForChannel(serverUrl, channelId);
|
|
||||||
|
|
||||||
if (response && 'groups' in response) {
|
|
||||||
return response.groups.filter((g) => g.name.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
channelId?: string;
|
channelId?: string;
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
@@ -383,7 +363,7 @@ const AtMention = ({
|
|||||||
if (useGroupMentions && matchTerm && matchTerm !== '') {
|
if (useGroupMentions && matchTerm && matchTerm !== '') {
|
||||||
// If the channel is constrained, we only show groups for that channel
|
// If the channel is constrained, we only show groups for that channel
|
||||||
if (isChannelConstrained && channelId) {
|
if (isChannelConstrained && channelId) {
|
||||||
getFilteredChannelGroups(serverUrl, channelId, matchTerm).then((g) => {
|
fetchFilteredChannelGroups(serverUrl, channelId, matchTerm).then((g) => {
|
||||||
setGroups(g.length ? g : emptyGroupList);
|
setGroups(g.length ? g : emptyGroupList);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
setGroups(emptyGroupList);
|
setGroups(emptyGroupList);
|
||||||
@@ -392,7 +372,7 @@ const AtMention = ({
|
|||||||
|
|
||||||
// If there is no channel constraint, but a team constraint - only show groups for team
|
// If there is no channel constraint, but a team constraint - only show groups for team
|
||||||
if (isTeamConstrained && !isChannelConstrained) {
|
if (isTeamConstrained && !isChannelConstrained) {
|
||||||
getFilteredTeamGroups(serverUrl, teamId!, matchTerm).then((g) => {
|
fetchFilteredTeamGroups(serverUrl, teamId!, matchTerm).then((g) => {
|
||||||
setGroups(g.length ? g : emptyGroupList);
|
setGroups(g.length ? g : emptyGroupList);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
setGroups(emptyGroupList);
|
setGroups(emptyGroupList);
|
||||||
|
|||||||
Reference in New Issue
Block a user