From 3b629622d9a3d76a9eef76eaed41592059d57d58 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 16 Jun 2021 10:23:22 +0200 Subject: [PATCH] need to keep pending count around if 0 or less for redaction local echo also need to be able to tell the difference between no pending reactions and redactions and the sum being 0 (having both a redaction and reaction) so we keep isPending to true --- .../session/room/timeline/ReactionsViewModel.js | 14 ++++++++------ src/matrix/room/timeline/PendingAnnotations.js | 9 ++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/domain/session/room/timeline/ReactionsViewModel.js b/src/domain/session/room/timeline/ReactionsViewModel.js index dea74ccf..5df57089 100644 --- a/src/domain/session/room/timeline/ReactionsViewModel.js +++ b/src/domain/session/room/timeline/ReactionsViewModel.js @@ -34,7 +34,7 @@ export class ReactionsViewModel { this._map.update(key); } } else { - this._map.add(key, new ReactionViewModel(key, annotation, 0, this._parentEntry)); + this._map.add(key, new ReactionViewModel(key, annotation, null, this._parentEntry)); } } } @@ -61,7 +61,7 @@ export class ReactionsViewModel { this._map.update(existingKey); } } else if (!hasPending) { - if (this._map.get(existingKey)._tryUpdatePending(0)) { + if (this._map.get(existingKey)._tryUpdatePending(null)) { this._map.update(existingKey); } } @@ -110,7 +110,7 @@ class ReactionViewModel { } get count() { - let count = this._pendingCount; + let count = this._pendingCount || 0; if (this._annotation) { count += this._annotation.count; } @@ -118,7 +118,9 @@ class ReactionViewModel { } get isPending() { - return this._pendingCount !== 0; + // even if pendingCount is 0, + // it means we have both a pending reaction and redaction + return this._pendingCount !== null; } get haveReacted() { @@ -158,8 +160,8 @@ class ReactionViewModel { } this._isToggling = true; try { - const haveLocalRedaction = this._pendingCount < 0; - const havePendingReaction = this._pendingCount > 0; + const haveLocalRedaction = this.isPending && this._pendingCount < 0; + const havePendingReaction = this.isPending && this._pendingCount > 0; const haveRemoteReaction = this._annotation?.me; const haveReaction = havePendingReaction || (haveRemoteReaction && !haveLocalRedaction); if (haveReaction) { diff --git a/src/matrix/room/timeline/PendingAnnotations.js b/src/matrix/room/timeline/PendingAnnotations.js index 38034a00..05495bc3 100644 --- a/src/matrix/room/timeline/PendingAnnotations.js +++ b/src/matrix/room/timeline/PendingAnnotations.js @@ -47,11 +47,10 @@ export class PendingAnnotations { if (count !== undefined) { const addend = entry.isRedaction ? 1 : -1; count += addend; - if (count <= 0) { - this.aggregatedAnnotations.delete(key); - } else { - this.aggregatedAnnotations.set(key, count); - } + this.aggregatedAnnotations.set(key, count); + } + if (!this._entries.length) { + this.aggregatedAnnotations.clear(); } }