Fix slow mode:

focus was lost when textarea got disabled, so it could trigger some Peertube events if the user type some text.
This commit is contained in:
John Livingston 2024-04-03 16:53:01 +02:00
parent 543f18c727
commit 1ceb37da2c
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
3 changed files with 10 additions and 5 deletions

View File

@ -19,6 +19,7 @@ TODO: https://github.com/JohnXLivingston/peertube-plugin-livechat/issues/48
* Some code refactoring.
* New translations: Galician.
* Fix slow mode: focus was lost when textarea got disabled, so it could trigger some Peertube events if the user type some text.
## 8.4.0

View File

@ -123,3 +123,10 @@ body.converse-embedded {
margin-bottom: 6px;
}
}
.conversejs {
// Fix: for the slow mode, we use readonly instead of disabled, we must apply same CSS as ConverseJS.
textarea:read-only {
background-color: var(--chat-textarea-disabled-bg-color) !important;
}
}

View File

@ -31,15 +31,12 @@ export const slowModePlugin = {
// FIXME: field could be enabled by something else (another event in ConverseJS).
// This is not very important: the server will reject messages anyway.
textarea.classList.add('disabled')
textarea.setAttribute('disabled', 'disabled')
textarea.setAttribute('readonly', 'readonly')
// Note: we are adding a 100ms delay.
// To minimize the risk that user can send a message before the server will accept it
// (if the first message lagged for example)
setTimeout(() => {
textarea.classList.remove('disabled')
textarea.removeAttribute('disabled');
(textarea as HTMLTextAreaElement).focus()
textarea.removeAttribute('readonly')
}, slowModeDuration * 1000 + 100)
})
}, 100)