From dc420a843bd4bb45e8a39be689e849e3742a26c1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 6 Dec 2022 16:27:07 -0600 Subject: [PATCH] Chats: fix submitting an attachment --- app/soapbox/features/chats/components/chat-composer.tsx | 4 +++- app/soapbox/features/chats/components/chat.tsx | 3 ++- app/soapbox/queries/chats.ts | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-composer.tsx b/app/soapbox/features/chats/components/chat-composer.tsx index 60f4cafa0..f54aeab93 100644 --- a/app/soapbox/features/chats/components/chat-composer.tsx +++ b/app/soapbox/features/chats/components/chat-composer.tsx @@ -39,6 +39,7 @@ interface IChatComposer extends Pick void resetFileKey: number | null + hasAttachment?: boolean } /** Textarea input for chats. */ @@ -52,6 +53,7 @@ const ChatComposer = React.forwardRef onSelectFile, resetFileKey, onPaste, + hasAttachment, }, ref) => { const dispatch = useAppDispatch(); const intl = useIntl(); @@ -66,7 +68,7 @@ const ChatComposer = React.forwardRef const isSuggestionsAvailable = suggestions.list.length > 0; const isOverCharacterLimit = maxCharacterCount && value?.length > maxCharacterCount; - const isSubmitDisabled = disabled || isOverCharacterLimit || value.length === 0; + const isSubmitDisabled = disabled || isOverCharacterLimit || (value.length === 0 && !hasAttachment); const overLimitText = maxCharacterCount ? maxCharacterCount - value?.length : ''; diff --git a/app/soapbox/features/chats/components/chat.tsx b/app/soapbox/features/chats/components/chat.tsx index 9eab2b118..576e10789 100644 --- a/app/soapbox/features/chats/components/chat.tsx +++ b/app/soapbox/features/chats/components/chat.tsx @@ -61,7 +61,7 @@ const Chat: React.FC = ({ chat, inputRef, className }) => { const isSubmitDisabled = content.length === 0 && !attachment; const submitMessage = () => { - createChatMessage.mutate({ chatId: chat.id, content }, { + createChatMessage.mutate({ chatId: chat.id, content, mediaId: attachment?.id }, { onSuccess: () => { setErrorMessage(undefined); }, @@ -197,6 +197,7 @@ const Chat: React.FC = ({ chat, inputRef, className }) => { onSelectFile={handleFiles} resetFileKey={resetFileKey} onPaste={handlePaste} + hasAttachment={!!attachment} /> ); diff --git a/app/soapbox/queries/chats.ts b/app/soapbox/queries/chats.ts index 3be57e8df..15de81e9e 100644 --- a/app/soapbox/queries/chats.ts +++ b/app/soapbox/queries/chats.ts @@ -233,8 +233,8 @@ const useChatActions = (chatId: string) => { const createChatMessage = useMutation( ( - { chatId, content }: { chatId: string, content: string }, - ) => api.post(`/api/v1/pleroma/chats/${chatId}/messages`, { content }), + { chatId, content, mediaId }: { chatId: string, content: string, mediaId?: string }, + ) => api.post(`/api/v1/pleroma/chats/${chatId}/messages`, { content, media_id: mediaId }), { retry: false, onMutate: async (variables) => {