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
This commit is contained in:
Bruno Windels 2021-06-16 10:23:22 +02:00
parent e5c1094153
commit 3b629622d9
2 changed files with 12 additions and 11 deletions

View file

@ -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) {

View file

@ -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();
}
}