mattermost-mobile-upstream/app/actions/remote/integrations.ts
Daniel Espino García 84ea188366
Mattermost Blocks (#9764)
* Mattermost Blocks

* Move block renderer to its own components folder

* Sync translation layer

* UX fixes

* Refactor button to use the button component

* Code review

* Fix CI

* Add animations to collapse blocks

* Add unit tests

* Add e2e tests and related fixes

* Address coderabbit comments

* Address UX comments

* Address feedback

* Address coderabbit comments

* Fix snapshots

* Sync with webapp translation

* Add node limit to button markdown node

* Address feedback

* i18n-extract

* Fix test

* Move image utils to the utils folder

* Remove unneeded style

* Revert build script change

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2026-06-29 18:42:16 +02:00

76 lines
2.8 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 = '',
query?: Record<string, string>,
integrationFormat: PostActionIntegrationFormat = 'attachment',
) => {
try {
const client = NetworkManager.getClient(serverUrl);
const data = await client.doPostActionWithCookie(postId, actionId, actionCookie, selectedOption, query, integrationFormat);
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);
};