From 442d4cce03d8cf160eee406a7362ad4defcc1135 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 23 Jun 2021 11:44:53 +0200 Subject: [PATCH] make the react/redactReaction promise only return after update happened --- src/domain/session/room/timeline/tiles/BaseMessageTile.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/domain/session/room/timeline/tiles/BaseMessageTile.js b/src/domain/session/room/timeline/tiles/BaseMessageTile.js index b73e1c26..5dad667c 100644 --- a/src/domain/session/room/timeline/tiles/BaseMessageTile.js +++ b/src/domain/session/room/timeline/tiles/BaseMessageTile.js @@ -27,6 +27,7 @@ export class BaseMessageTile extends SimpleTile { if (this._entry.annotations || this._entry.pendingAnnotations) { this._updateReactions(); } + this._pendingReactionChangeCallback = null; } get _mediaRepository() { @@ -125,12 +126,14 @@ export class BaseMessageTile extends SimpleTile { react(key, log = null) { return this.logger.wrapOrRun(log, "react", async log => { const redaction = this._entry.getAnnotationPendingRedaction(key); + const updatePromise = new Promise(resolve => this._pendingReactionChangeCallback = resolve); if (redaction && !redaction.pendingEvent.hasStartedSending) { log.set("abort_redaction", true); await redaction.pendingEvent.abort(); } else { 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); if (entry) { + const updatePromise = new Promise(resolve => this._pendingReactionChangeCallback = resolve); await this._room.sendRedaction(entry.id, null, log); + await updatePromise; } else { log.set("no_reaction", true); } @@ -155,12 +160,14 @@ export class BaseMessageTile extends SimpleTile { if (!annotations && !pendingAnnotations) { if (this._reactions) { this._reactions = null; + this._pendingReactionChangeCallback && this._pendingReactionChangeCallback(); } } else { if (!this._reactions) { this._reactions = new ReactionsViewModel(this); } this._reactions.update(annotations, pendingAnnotations); + this._pendingReactionChangeCallback && this._pendingReactionChangeCallback(); } } }