mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-19 01:48:16 +00:00
This PR adds comprehensive support for advanced interactive dialog features through the DialogRouter component, which routes between legacy InteractiveDialog and modern AppsForm implementations based on the FeatureFlagInteractiveDialogAppsForm feature flag.
68 lines
2.7 KiB
TypeScript
68 lines
2.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
//
|
|
|
|
import DatabaseManager from '@database/manager';
|
|
import IntegrationsMananger from '@managers/integrations_manager';
|
|
import NetworkManager from '@managers/network_manager';
|
|
import {getCurrentChannelId, getCurrentTeamId} from '@queries/servers/system';
|
|
import {getFullErrorMessage} from '@utils/errors';
|
|
import {logDebug} from '@utils/log';
|
|
|
|
import {forceLogoutIfNecessary} from './session';
|
|
|
|
export const submitInteractiveDialog = async (serverUrl: string, submission: DialogSubmission) => {
|
|
try {
|
|
const client = NetworkManager.getClient(serverUrl);
|
|
const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
|
|
|
submission.channel_id = await getCurrentChannelId(database);
|
|
submission.team_id = await getCurrentTeamId(database);
|
|
const data = await client.submitInteractiveDialog(submission);
|
|
|
|
return {data};
|
|
} catch (error) {
|
|
logDebug('error on submitInteractiveDialog', getFullErrorMessage(error));
|
|
forceLogoutIfNecessary(serverUrl, error);
|
|
return {error};
|
|
}
|
|
};
|
|
|
|
export const lookupInteractiveDialog = async (serverUrl: string, submission: DialogSubmission) => {
|
|
try {
|
|
const client = NetworkManager.getClient(serverUrl);
|
|
const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
|
|
|
submission.channel_id = await getCurrentChannelId(database);
|
|
submission.team_id = await getCurrentTeamId(database);
|
|
|
|
const data = await client.lookupInteractiveDialog(submission);
|
|
return {data};
|
|
} catch (error) {
|
|
logDebug('error on lookupInteractiveDialog', getFullErrorMessage(error));
|
|
forceLogoutIfNecessary(serverUrl, error);
|
|
return {error};
|
|
}
|
|
};
|
|
|
|
export const postActionWithCookie = async (serverUrl: string, postId: string, actionId: string, actionCookie: string, selectedOption = '') => {
|
|
try {
|
|
const client = NetworkManager.getClient(serverUrl);
|
|
|
|
const data = await client.doPostActionWithCookie(postId, actionId, actionCookie, selectedOption);
|
|
if (data?.trigger_id) {
|
|
IntegrationsMananger.getManager(serverUrl)?.setTriggerId(data.trigger_id);
|
|
}
|
|
|
|
return {data};
|
|
} catch (error) {
|
|
logDebug('error on postActionWithCookie', getFullErrorMessage(error));
|
|
forceLogoutIfNecessary(serverUrl, error);
|
|
return {error};
|
|
}
|
|
};
|
|
|
|
export const selectAttachmentMenuAction = (serverUrl: string, postId: string, actionId: string, selectedOption: string) => {
|
|
return postActionWithCookie(serverUrl, postId, actionId, '', selectedOption);
|
|
};
|