mattermost-mobile-upstream/app/client/rest/properties.ts
Andre Vasconcelos 10207015a5
Classification Markings: Cached request timer and PSv2 Implementation (#9926)
* 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
2026-08-13 15:24:07 +03:00

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;