Skip to content

Commit

Permalink
Avoid drafts in chats where canSend is false (#4394)
Browse files Browse the repository at this point in the history
* Avoid drafts in chats where canSend is false

resolves #4389

* Disable Ctrl+Up shortcut in readonly chats

* Clear draft if canSend == false
  • Loading branch information
nicodh authored Dec 8, 2024
1 parent d0b1ddd commit 2b3cc19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## Fixed
- handle double escape on Dialog #4365
- fix random crashes on quote reply #4337
- avoid drafts in readonly chats #4349

<a id="1_49_0"></a>

Expand Down
13 changes: 9 additions & 4 deletions packages/frontend/src/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComposerMessageInput | null>
): {
draftState: DraftObject
Expand All @@ -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')
Expand All @@ -468,7 +473,7 @@ export function useDraft(
})
})
},
[clearDraft, inputRef]
[clearDraft, inputRef, canSend]
)

useEffect(() => {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default function MessageListAndComposer({ accountId, chat }: Props) {
chat.id,
chat.isContactRequest,
chat.isProtectionBroken,
chat.canSend,
messageInputRef
)

Expand Down

0 comments on commit 2b3cc19

Please sign in to comment.