diff options
author | Maksim Sukharev <antreesy.web@gmail.com> | 2023-06-07 16:31:28 +0200 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2023-06-08 16:20:40 +0000 |
commit | 56942ca52f8505b167cf44ba967e7c70d9800a51 (patch) | |
tree | 0e8b0dc7b2115f0da584cd572fbe4d9de49d1aba /src | |
parent | 514d430068001d9c72df6ed25a2f607ebf61b55b (diff) |
send typing signal on first keystroke, and repeat every 10s if still typing
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/NewMessage/NewMessage.vue | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/components/NewMessage/NewMessage.vue b/src/components/NewMessage/NewMessage.vue index 037dc617e..f0be88acb 100644 --- a/src/components/NewMessage/NewMessage.vue +++ b/src/components/NewMessage/NewMessage.vue @@ -279,7 +279,8 @@ export default { // Check empty template by default userData: {}, clipboardTimeStamp: null, - typingTimeout: null, + typingInterval: null, + wasTypingWithinInterval: false, } }, @@ -389,18 +390,22 @@ export default { // Enable signal sending, only if indicator for this input is on if (this.showTypingStatus) { - if (!newValue) { - this.resetTypingIndicator() - return - } - - if (!this.typingTimeout) { - this.typingTimeout = setTimeout(() => { - this.resetTypingIndicator() - }, 5000) + if (!this.typingInterval) { + // Send first signal after first keystroke this.$store.dispatch('sendTypingSignal', { typing: true }) - } + // Continuously send signals with 10s interval if still typing + this.typingInterval = setInterval(() => { + if (this.wasTypingWithinInterval) { + this.$store.dispatch('sendTypingSignal', { typing: true }) + this.wasTypingWithinInterval = false + } else { + this.clearTypingInterval() + } + }, 10000) + } else { + this.wasTypingWithinInterval = true + } } }, @@ -410,7 +415,7 @@ export default { } else { this.text = '' } - this.resetTypingIndicator() + this.clearTypingInterval() }, }, @@ -432,11 +437,17 @@ export default { }, methods: { + clearTypingInterval() { + clearInterval(this.typingInterval) + this.typingInterval = null + this.wasTypingWithinInterval = false + }, + resetTypingIndicator() { - if (this.typingTimeout) { - clearTimeout(this.typingTimeout) - } this.$store.dispatch('sendTypingSignal', { typing: false }) + if (this.typingInterval) { + this.clearTypingInterval() + } }, handleUploadStart() { @@ -475,6 +486,7 @@ export default { await this.$store.dispatch('addTemporaryMessage', temporaryMessage) } this.text = '' + this.resetTypingIndicator() this.userData = {} // Scrolls the message list to the last added message EventBus.$emit('smooth-scroll-chat-to-bottom') |