Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid drafts in chats where canSend is false #4394

Merged
merged 5 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading