make the react/redactReaction promise only return after update happened

This commit is contained in:
Bruno Windels 2021-06-23 11:44:53 +02:00
parent 18562d30d8
commit 442d4cce03

View file

@ -27,6 +27,7 @@ export class BaseMessageTile extends SimpleTile {
if (this._entry.annotations || this._entry.pendingAnnotations) { if (this._entry.annotations || this._entry.pendingAnnotations) {
this._updateReactions(); this._updateReactions();
} }
this._pendingReactionChangeCallback = null;
} }
get _mediaRepository() { get _mediaRepository() {
@ -125,12 +126,14 @@ export class BaseMessageTile extends SimpleTile {
react(key, log = null) { react(key, log = null) {
return this.logger.wrapOrRun(log, "react", async log => { return this.logger.wrapOrRun(log, "react", async log => {
const redaction = this._entry.getAnnotationPendingRedaction(key); const redaction = this._entry.getAnnotationPendingRedaction(key);
const updatePromise = new Promise(resolve => this._pendingReactionChangeCallback = resolve);
if (redaction && !redaction.pendingEvent.hasStartedSending) { if (redaction && !redaction.pendingEvent.hasStartedSending) {
log.set("abort_redaction", true); log.set("abort_redaction", true);
await redaction.pendingEvent.abort(); await redaction.pendingEvent.abort();
} else { } else {
await this._room.sendEvent("m.reaction", this._entry.annotate(key), null, log); await this._room.sendEvent("m.reaction", this._entry.annotate(key), null, log);
} }
await updatePromise;
}); });
} }
@ -143,7 +146,9 @@ export class BaseMessageTile extends SimpleTile {
} }
const entry = await this._entry.getOwnAnnotationEntry(this._timeline, key); const entry = await this._entry.getOwnAnnotationEntry(this._timeline, key);
if (entry) { if (entry) {
const updatePromise = new Promise(resolve => this._pendingReactionChangeCallback = resolve);
await this._room.sendRedaction(entry.id, null, log); await this._room.sendRedaction(entry.id, null, log);
await updatePromise;
} else { } else {
log.set("no_reaction", true); log.set("no_reaction", true);
} }
@ -155,12 +160,14 @@ export class BaseMessageTile extends SimpleTile {
if (!annotations && !pendingAnnotations) { if (!annotations && !pendingAnnotations) {
if (this._reactions) { if (this._reactions) {
this._reactions = null; this._reactions = null;
this._pendingReactionChangeCallback && this._pendingReactionChangeCallback();
} }
} else { } else {
if (!this._reactions) { if (!this._reactions) {
this._reactions = new ReactionsViewModel(this); this._reactions = new ReactionsViewModel(this);
} }
this._reactions.update(annotations, pendingAnnotations); this._reactions.update(annotations, pendingAnnotations);
this._pendingReactionChangeCallback && this._pendingReactionChangeCallback();
} }
} }
} }