diff --git a/src/matrix/room/sending/PendingEvent.js b/src/matrix/room/sending/PendingEvent.js index 8d8d316e..f95b19e0 100644 --- a/src/matrix/room/sending/PendingEvent.js +++ b/src/matrix/room/sending/PendingEvent.js @@ -13,9 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import {EventEmitter} from "../../../utils/EventEmitter"; import {createEnum} from "../../../utils/enum"; import {AbortError} from "../../../utils/error"; +import {Deferred} from "../../../utils/Deferred"; import {REDACTION_TYPE} from "../common"; import {getRelationFromContent, getRelationTarget, setRelationTarget} from "../timeline/relations.js"; @@ -31,9 +31,8 @@ export const SendStatus = createEnum( const unencryptedContentFields = [ "m.relates_to" ]; -export class PendingEvent extends EventEmitter { +export class PendingEvent { constructor({data, remove, emitUpdate, attachments}) { - super(); this._data = data; this._attachments = attachments; this._emitUpdate = emitUpdate; @@ -42,6 +41,7 @@ export class PendingEvent extends EventEmitter { this._status = SendStatus.Waiting; this._sendRequest = null; this._attachmentsTotalBytes = 0; + this._deferred = new Deferred() if (this._attachments) { this._attachmentsTotalBytes = Object.values(this._attachments).reduce((t, a) => t + a.size, 0); } @@ -230,12 +230,16 @@ export class PendingEvent extends EventEmitter { this._sendRequest = null; // both /send and /redact have the same response format this._data.remoteId = response.event_id; - this.emit("remote-id", this.remoteId); + this._deferred.resolve(response.event_id); log.set("id", this._data.remoteId); this._status = SendStatus.Sent; this._emitUpdate("status"); } + getRemoteId() { + return this._deferred.promise; + } + dispose() { if (this._attachments) { for (const attachment of Object.values(this._attachments)) { diff --git a/src/matrix/verification/SAS/channel/RoomChannel.ts b/src/matrix/verification/SAS/channel/RoomChannel.ts index 801ec7a7..c22a8cb1 100644 --- a/src/matrix/verification/SAS/channel/RoomChannel.ts +++ b/src/matrix/verification/SAS/channel/RoomChannel.ts @@ -126,7 +126,7 @@ export class RoomChannel extends Disposables implements IChannel { to: this.otherUserId, }); const pendingEvent = await this.room.sendEvent("m.room.message", content, undefined, log); - this.track(pendingEvent.disposableOn("remote-id", (id: string) => { this.id = id; })); + this.id = await pendingEvent.getRemoteId(); this.sentMessages.set(eventType, {content}); }); }