mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-10 13:10:14 +00:00
* Added mechanism to prevent repeated classification calls via inmemory cache * Adding version-aware forking of requests to new PSv2 API * Addressing PR feedback * Pushing fixes for cache issues with builds * Resolving issues with banner vanishing when opening a channel
41 lines
2.4 KiB
TypeScript
41 lines
2.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {safeArrayCast} from '@utils/helpers';
|
|
|
|
import type ClientBase from './base';
|
|
|
|
export interface ClientPropertiesMix {
|
|
getPropertyValues: <T>(groupName: string, objectType: string, targetId: string, groupLabel?: RequestGroupLabel) => Promise<Array<PropertyValue<T>>>;
|
|
getPropertyFields: (groupName: string, objectType: string, targetType: string, targetId?: string, groupLabel?: RequestGroupLabel) => Promise<PropertyField[]>;
|
|
searchPropertyFields: (groupName: string, options: PropertyFieldSearchOpts, groupLabel?: RequestGroupLabel) => Promise<PropertyField[]>;
|
|
getSystemPropertyValues: <T>(groupName: string, groupLabel?: RequestGroupLabel) => Promise<Array<PropertyValue<T>>>;
|
|
}
|
|
|
|
const ClientProperties = <TBase extends Constructor<ClientBase>>(superclass: TBase) => class extends superclass {
|
|
getPropertyValues = async <T>(groupName: string, objectType: string, targetId: string, groupLabel?: RequestGroupLabel) => {
|
|
const url = `${this.urlVersion}/properties/groups/${groupName}/${objectType}/values/${targetId}`;
|
|
return safeArrayCast<PropertyValue<T>>(await this.doFetch(url, {method: 'get', groupLabel}));
|
|
};
|
|
|
|
getPropertyFields = async (groupName: string, objectType: string, targetType: string, targetId?: string, groupLabel?: RequestGroupLabel) => {
|
|
let url = `${this.urlVersion}/properties/groups/${groupName}/${objectType}/fields?target_type=${targetType}`;
|
|
if (targetId !== undefined) {
|
|
url += `&target_id=${encodeURIComponent(targetId)}`;
|
|
}
|
|
return safeArrayCast<PropertyField>(await this.doFetch(url, {method: 'get', groupLabel}));
|
|
};
|
|
|
|
searchPropertyFields = async (groupName: string, options: PropertyFieldSearchOpts, groupLabel?: RequestGroupLabel) => {
|
|
const url = `${this.urlVersion}/properties/groups/${groupName}/fields/search`;
|
|
return safeArrayCast<PropertyField>(await this.doFetch(url, {method: 'post', body: options, groupLabel}));
|
|
};
|
|
|
|
getSystemPropertyValues = async <T>(groupName: string, groupLabel?: RequestGroupLabel) => {
|
|
const url = `${this.urlVersion}/properties/groups/${groupName}/system/values`;
|
|
return safeArrayCast<PropertyValue<T>>(await this.doFetch(url, {method: 'get', groupLabel}));
|
|
};
|
|
};
|
|
|
|
export default ClientProperties;
|