diff --git a/app/client/rest/apps.ts b/app/client/rest/apps.ts index f8372ff3f..ab11a2774 100644 --- a/app/client/rest/apps.ts +++ b/app/client/rest/apps.ts @@ -2,10 +2,11 @@ // See LICENSE.txt for license information. import type {AppBinding, AppCallRequest, AppCallResponse, AppCallType} from '@mm-redux/types/apps'; +import {buildQueryString} from '@mm-redux/utils/helpers'; export interface ClientAppsMix { executeAppCall: (call: AppCallRequest, type: AppCallType) => Promise; - getAppsBindings: (userID: string, channelID: string) => Promise; + getAppsBindings: (userID: string, channelID: string, teamID: string) => Promise; } const ClientApps = (superclass: any) => class extends superclass { @@ -25,9 +26,16 @@ const ClientApps = (superclass: any) => class extends superclass { ); } - getAppsBindings = async (userID: string, channelID: string) => { + getAppsBindings = async (userID: string, channelID: string, teamID: string) => { + const params = { + user_id: userID, + channel_id: channelID, + team_id: teamID, + user_agent: 'mobile', + }; + return this.doFetch( - this.getAppsProxyRoute() + `/api/v1/bindings?user_id=${userID}&channel_id=${channelID}&user_agent_type=mobile`, + `${this.getAppsProxyRoute()}/api/v1/bindings${buildQueryString(params)}`, {method: 'get'}, ); } diff --git a/app/mm-redux/actions/apps.ts b/app/mm-redux/actions/apps.ts index 9503bd1eb..6bda27950 100644 --- a/app/mm-redux/actions/apps.ts +++ b/app/mm-redux/actions/apps.ts @@ -1,15 +1,22 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. + import {AppsTypes} from '@mm-redux/action_types'; import {Client4} from '@client/rest'; -import {ActionFunc} from '@mm-redux/types/actions'; +import {ActionFunc, DispatchFunc, GetStateFunc} from '@mm-redux/types/actions'; +import {getChannel} from '@mm-redux/selectors/entities/channels'; import {bindClientFunc} from './helpers'; export function fetchAppBindings(userID: string, channelID: string): ActionFunc { - return bindClientFunc({ - clientFunc: () => Client4.getAppsBindings(userID, channelID), - onSuccess: AppsTypes.RECEIVED_APP_BINDINGS, - }); + return async (dispatch: DispatchFunc, getState: GetStateFunc) => { + const channel = getChannel(getState(), channelID); + const teamID = channel?.team_id || ''; + + return dispatch(bindClientFunc({ + clientFunc: () => Client4.getAppsBindings(userID, channelID, teamID), + onSuccess: AppsTypes.RECEIVED_APP_BINDINGS, + })); + }; }