mattermost-mobile/app/components/post_draft/send_handler/send_handler.tsx
Christopher Speller 6000e69886
Agents "RHS" view (#9318)
* Add agents RHS functionality for mobile

Implements a dedicated agents interface accessible from the home screen, featuring:
- Agent chat screen with bot selector and message input
- Thread list screen showing all agent conversations
- Remote actions for fetching bots and threads from plugin API
- Navigation between chat, threads, and individual conversations
- Integration with plus menu for easy access

Follows similar pattern to playbooks with modal screens and navigation helpers.

* Fix icon name for agents menu item

Change robot-happy-outline to robot-happy to resolve PropType validation error.

* Add agents button to sidebar and fix agent chat issues

- Add AgentsButton component to channel list sidebar below Drafts
- Fix thread navigation to use fetchAndSwitchToThread instead of switchToChannelById
- Replace custom TextInput with PostDraft component in agent_chat
- Fix icon name from message-reply-text-outline to reply-outline
- Add missing i18n translations for agents UI

* Implement automatic navigation to thread after sending agent message

* Implement bot selector bottom sheet with avatars. Replace click-and-cycle behavior with a proper bottom sheet menu showing all available agents with their profile pictures. Add bot avatar display to the dropdown button for better visual identification.

* Top bar design modifications.

* Add intro graphic and text

* Fix autocomplete not working

* Tweak styles and icons.

* Remove unused

* Add version/enabled check

* Remove excessive agent button

* Style fixes

* Use non-blocking then() for onPostCreated callback in send message hook

* Add unit tests for agents product components and actions

* Review feedback, offline support

* I18n

* Tests

* Address PR review feedback: deletion handling, UI fixes, schema docs

* Remove unnecessary deleteNotPresent flag from agents handlers

* Fix agents archived channel, empty data guard, and stale relative time

* Add smoke test for AgentChat and extend ToolCard test coverage

* Fix test quality issues: remove useless tests, strengthen assertions

* Address PR review: remove barrel file, add version comment

* Mock reanimated in CitationsList test to fix CI failure

* Fix CitationsList tests after always-mounted animation change

* Address PR review: typography, Pressable, FormattedText, schema bump, and cleanup

* Apply CLAUDE.md patterns across agents codebase: Pressable, typography, FormattedText, logDebug

* Fix schema test to expect version 19
2026-03-16 09:48:32 -07:00

190 lines
6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback} from 'react';
import {updateDraftBoRConfig, updateDraftPriority} from '@actions/local/draft';
import SendDraft from '@components/draft_scheduled_post/draft_scheduled_post_actions/send_draft';
import DraftInput from '@components/post_draft/draft_input/';
import {PostPriorityType} from '@constants/post';
import {useServerUrl} from '@context/server';
import {useHandleSendMessage} from '@hooks/handle_send_message';
import type {DraftType} from '@constants/draft';
import type CustomEmojiModel from '@typings/database/models/servers/custom_emoji';
import type {AvailableScreens} from '@typings/screens/navigation';
type Props = {
testID?: string;
channelId: string;
channelType?: ChannelType;
channelName?: string;
rootId: string;
canShowPostPriority?: boolean;
setIsFocused: (isFocused: boolean) => void;
// From database
currentUserId: string;
cursorPosition: number;
enableConfirmNotificationsToChannel?: boolean;
maxMessageLength: number;
membersCount?: number;
useChannelMentions: boolean;
userIsOutOfOffice: boolean;
customEmojis: CustomEmojiModel[];
// DRAFT Handler
value: string;
files: FileInfo[];
clearDraft: () => void;
updateValue: React.Dispatch<React.SetStateAction<string>>;
updateCursorPosition: React.Dispatch<React.SetStateAction<number>>;
updatePostInputTop: (top: number) => void;
addFiles: (file: FileInfo[]) => void;
uploadFileError: React.ReactNode;
persistentNotificationInterval: number;
persistentNotificationMaxRecipients: number;
postPriority: PostPriority;
postBoRConfig?: PostBoRConfig;
draftType?: DraftType;
postId?: string;
bottomSheetId?: AvailableScreens;
channelDisplayName?: string;
isFromDraftView?: boolean;
draftReceiverUserName?: string;
onPostCreated?: (postId: string) => void;
location?: AvailableScreens;
}
export const INITIAL_PRIORITY = {
priority: PostPriorityType.STANDARD,
requested_ack: false,
persistent_notifications: false,
};
export default function SendHandler({
testID,
channelId,
channelType,
channelName,
channelDisplayName,
currentUserId,
enableConfirmNotificationsToChannel,
files,
maxMessageLength,
membersCount = 0,
cursorPosition,
rootId,
canShowPostPriority,
useChannelMentions,
userIsOutOfOffice,
customEmojis,
value,
clearDraft,
updateValue,
addFiles,
uploadFileError,
updateCursorPosition,
updatePostInputTop,
setIsFocused,
persistentNotificationInterval,
persistentNotificationMaxRecipients,
postPriority,
bottomSheetId,
draftReceiverUserName,
isFromDraftView,
draftType,
postId,
onPostCreated,
postBoRConfig,
location,
}: Props) {
const serverUrl = useServerUrl();
const handlePostPriority = useCallback((priority: PostPriority) => {
updateDraftPriority(serverUrl, channelId, rootId, priority);
}, [serverUrl, channelId, rootId]);
const handlePostBoRStatus = useCallback((config: PostBoRConfig) => {
updateDraftBoRConfig(serverUrl, channelId, rootId, config);
}, [channelId, rootId, serverUrl]);
const {handleSendMessage, canSend} = useHandleSendMessage({
value,
channelId,
rootId,
files,
maxMessageLength,
customEmojis,
enableConfirmNotificationsToChannel,
useChannelMentions,
membersCount,
userIsOutOfOffice,
currentUserId,
channelType,
postPriority,
clearDraft,
onPostCreated,
postBoRConfig,
});
if (isFromDraftView) {
return (
<SendDraft
channelId={channelId}
rootId={rootId}
channelType={channelType}
currentUserId={currentUserId}
channelName={channelName}
channelDisplayName={channelDisplayName}
enableConfirmNotificationsToChannel={enableConfirmNotificationsToChannel}
maxMessageLength={maxMessageLength}
membersCount={membersCount}
useChannelMentions={useChannelMentions}
userIsOutOfOffice={userIsOutOfOffice}
customEmojis={customEmojis}
bottomSheetId={bottomSheetId}
value={value}
files={files}
postPriority={postPriority}
persistentNotificationInterval={persistentNotificationInterval}
persistentNotificationMaxRecipients={persistentNotificationMaxRecipients}
draftReceiverUserName={draftReceiverUserName}
draftType={draftType}
postId={postId}
/>
);
}
return (
<DraftInput
testID={testID}
channelId={channelId}
channelType={channelType}
channelName={channelName}
currentUserId={currentUserId}
rootId={rootId}
canShowPostPriority={canShowPostPriority}
cursorPosition={cursorPosition}
updateCursorPosition={updateCursorPosition}
value={value}
files={files}
updateValue={updateValue}
addFiles={addFiles}
uploadFileError={uploadFileError}
sendMessage={handleSendMessage}
canSend={canSend}
maxMessageLength={maxMessageLength}
updatePostInputTop={updatePostInputTop}
postPriority={postPriority}
postBoRConfig={postBoRConfig}
updatePostPriority={handlePostPriority}
updatePostBoRStatus={handlePostBoRStatus}
persistentNotificationInterval={persistentNotificationInterval}
persistentNotificationMaxRecipients={persistentNotificationMaxRecipients}
setIsFocused={setIsFocused}
location={location}
/>
);
}