mattermost-mobile/app/products/calls/client/rest.ts
Christopher Poile 10479d1d35
MM-42821 - Calls mobile: Default calls doesn't work on mobile (#6107)
* use call config when checking for Enable/Disable and StartCall permissions

* store config, refresh after 20 minutes

* load config on startup

* batch load calls and load config on startup/reconnect
2022-04-01 10:17:48 -04:00

56 lines
1.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type {ServerChannelState, ServerConfig} from '@mmproducts/calls/store/types/calls';
export interface ClientCallsMix {
getEnabled: () => Promise<Boolean>;
getCalls: () => Promise<ServerChannelState[]>;
getCallsConfig: () => Promise<ServerConfig>;
enableChannelCalls: (channelId: string) => Promise<ServerChannelState>;
disableChannelCalls: (channelId: string) => Promise<ServerChannelState>;
}
const ClientCalls = (superclass: any) => class extends superclass {
getEnabled = async () => {
try {
await this.doFetch(
`${this.getCallsRoute()}/version`,
{method: 'get'},
);
return true;
} catch (e) {
return false;
}
};
getCalls = async () => {
return this.doFetch(
`${this.getCallsRoute()}/channels`,
{method: 'get'},
);
};
getCallsConfig = async () => {
return this.doFetch(
`${this.getCallsRoute()}/config`,
{method: 'get'},
) as ServerConfig;
};
enableChannelCalls = async (channelId: string) => {
return this.doFetch(
`${this.getCallsRoute()}/${channelId}`,
{method: 'post', body: JSON.stringify({enabled: true})},
);
};
disableChannelCalls = async (channelId: string) => {
return this.doFetch(
`${this.getCallsRoute()}/${channelId}`,
{method: 'post', body: JSON.stringify({enabled: false})},
);
};
};
export default ClientCalls;