forked from mystiq/hydrogen-web
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:
parent
e5c1094153
commit
3b629622d9
2 changed files with 12 additions and 11 deletions
|
@ -34,7 +34,7 @@ export class ReactionsViewModel {
|
||||||
this._map.update(key);
|
this._map.update(key);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
this._map.update(existingKey);
|
||||||
}
|
}
|
||||||
} else if (!hasPending) {
|
} else if (!hasPending) {
|
||||||
if (this._map.get(existingKey)._tryUpdatePending(0)) {
|
if (this._map.get(existingKey)._tryUpdatePending(null)) {
|
||||||
this._map.update(existingKey);
|
this._map.update(existingKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ class ReactionViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
get count() {
|
get count() {
|
||||||
let count = this._pendingCount;
|
let count = this._pendingCount || 0;
|
||||||
if (this._annotation) {
|
if (this._annotation) {
|
||||||
count += this._annotation.count;
|
count += this._annotation.count;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,9 @@ class ReactionViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
get isPending() {
|
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() {
|
get haveReacted() {
|
||||||
|
@ -158,8 +160,8 @@ class ReactionViewModel {
|
||||||
}
|
}
|
||||||
this._isToggling = true;
|
this._isToggling = true;
|
||||||
try {
|
try {
|
||||||
const haveLocalRedaction = this._pendingCount < 0;
|
const haveLocalRedaction = this.isPending && this._pendingCount < 0;
|
||||||
const havePendingReaction = this._pendingCount > 0;
|
const havePendingReaction = this.isPending && this._pendingCount > 0;
|
||||||
const haveRemoteReaction = this._annotation?.me;
|
const haveRemoteReaction = this._annotation?.me;
|
||||||
const haveReaction = havePendingReaction || (haveRemoteReaction && !haveLocalRedaction);
|
const haveReaction = havePendingReaction || (haveRemoteReaction && !haveLocalRedaction);
|
||||||
if (haveReaction) {
|
if (haveReaction) {
|
||||||
|
|
|
@ -47,11 +47,10 @@ export class PendingAnnotations {
|
||||||
if (count !== undefined) {
|
if (count !== undefined) {
|
||||||
const addend = entry.isRedaction ? 1 : -1;
|
const addend = entry.isRedaction ? 1 : -1;
|
||||||
count += addend;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue