fix(ReactionToaster): discard outdated reactions

- timeout for 30 seconds is set for now (allows 60 immediately fired recations to be shown during that interval)
- should discard suspended reaction without showing them

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
This commit is contained in:
Maksim Sukharev 2025-12-15 12:15:07 +01:00
parent 69719c8d31
commit 0ae7d0e0f4

View file

@ -177,26 +177,39 @@ export default {
? this.actorStore.displayName || t('spreed', 'Guest')
: this.getParticipantName(model),
seed: Math.random(),
timestamp: Date.now(),
})
},
processReactionsQueue() {
if (this.reactionsQueue.length === 0) {
return
}
// Prevent spamming with reactions, if tab was suspended
const now = Date.now()
if (now < nextProcessedTimestamp) {
return
}
// Discard reactions, that should have been fired long ago
if (this.reactionsQueue.at(0).timestamp < now - 30_000) {
this.reactionsQueue = this.reactionsQueue.filter((reaction) => reaction.timestamp >= now - 30_000)
if (this.reactionsQueue.length === 0) {
return
}
}
nextProcessedTimestamp = now + TOAST_INTERVAL
if (this.reactionsQueue.length > 0) {
// Move reactions from queue to visible array
this.toasts.push(this.reactionsQueue.shift())
// Move reactions from queue to visible array
this.toasts.push(this.reactionsQueue.shift())
// Delete reactions from array after animation ends
setTimeout(() => {
this.toasts.shift()
}, ANIMATION_LENGTH)
}
// Delete reactions from array after animation ends
setTimeout(() => {
this.toasts.shift()
}, ANIMATION_LENGTH)
},
getParticipantName(model) {