diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4906e54e..34d93f5c1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
## Fixed
- handle double escape on Dialog #4365
- fix random crashes on quote reply #4337
+- avoid drafts in readonly chats #4349
diff --git a/packages/frontend/src/components/composer/Composer.tsx b/packages/frontend/src/components/composer/Composer.tsx
index 4597b78b4..459b359a8 100644
--- a/packages/frontend/src/components/composer/Composer.tsx
+++ b/packages/frontend/src/components/composer/Composer.tsx
@@ -424,6 +424,7 @@ export function useDraft(
chatId: number | null,
isContactRequest: boolean,
isProtectionBroken: boolean,
+ canSend: boolean, // no draft needed in chats we can't send messages
inputRef: React.MutableRefObject
): {
draftState: DraftObject
@@ -443,6 +444,10 @@ export function useDraft(
const loadDraft = useCallback(
(chatId: number) => {
+ if (chatId === null || !canSend) {
+ clearDraft()
+ return
+ }
BackendRemote.rpc.getDraft(selectedAccountId(), chatId).then(newDraft => {
if (!newDraft) {
log.debug('no draft')
@@ -468,7 +473,7 @@ export function useDraft(
})
})
},
- [clearDraft, inputRef]
+ [clearDraft, inputRef, canSend]
)
useEffect(() => {
@@ -482,7 +487,7 @@ export function useDraft(
}, [chatId, loadDraft, isContactRequest, isProtectionBroken])
const saveDraft = useCallback(async () => {
- if (chatId === null) {
+ if (chatId === null || !canSend) {
return
}
if (inputRef.current?.textareaRef.current?.disabled) {
@@ -533,7 +538,7 @@ export function useDraft(
} else {
clearDraft()
}
- }, [chatId, clearDraft, inputRef])
+ }, [chatId, clearDraft, canSend, inputRef])
const updateDraftText = (text: string, InputChatId: number) => {
if (chatId !== InputChatId) {
@@ -586,7 +591,7 @@ export function useDraft(
| KeybindAction.Composer_SelectReplyToUp
| KeybindAction.Composer_SelectReplyToDown
) => {
- if (chatId == undefined) {
+ if (chatId == undefined || !canSend) {
return
}
const quoteMessage = (messageId: number) => {
diff --git a/packages/frontend/src/components/message/MessageListAndComposer.tsx b/packages/frontend/src/components/message/MessageListAndComposer.tsx
index 8314dc67c..d4652c98f 100644
--- a/packages/frontend/src/components/message/MessageListAndComposer.tsx
+++ b/packages/frontend/src/components/message/MessageListAndComposer.tsx
@@ -91,6 +91,7 @@ export default function MessageListAndComposer({ accountId, chat }: Props) {
chat.id,
chat.isContactRequest,
chat.isProtectionBroken,
+ chat.canSend,
messageInputRef
)