From 4b0951d3fdbb2e87178f40d95a08ceb671831855 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 5 Oct 2020 09:30:02 +0100 Subject: [PATCH 1/2] Sending events should return eventIDs --- src/components/intent.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/components/intent.ts b/src/components/intent.ts index 512940e3..f0344970 100644 --- a/src/components/intent.ts +++ b/src/components/intent.ts @@ -358,7 +358,9 @@ export class Intent { * @param type The event type * @param content The event content */ - public async sendEvent(roomId: string, type: string, content: Record) { + public async sendEvent(roomId: string, type: string, content: Record) + // eslint-disable-next-line camelcase + : Promise<{event_id: string}> { if (this.encryption) { // We *need* to sync before we can send a message. await this.ensureRegistered(); @@ -366,9 +368,10 @@ export class Intent { } await this._ensureJoined(roomId); await this._ensureHasPowerLevelFor(roomId, type); - return this._joinGuard(roomId, async() => ( - this.client.sendEvent(roomId, type, content) - )); + return this._joinGuard(roomId, async() => + // eslint-disable-next-line camelcase + this.client.sendEvent(roomId, type, content) as Promise<{event_id: string}> + ); } /** @@ -381,12 +384,15 @@ export class Intent { * @param skey The state key * @param content The event content */ - public async sendStateEvent(roomId: string, type: string, skey: string, content: Record) { + public async sendStateEvent(roomId: string, type: string, skey: string, content: Record + // eslint-disable-next-line camelcase + ): Promise<{event_id: string}> { await this._ensureJoined(roomId); await this._ensureHasPowerLevelFor(roomId, type); - return this._joinGuard(roomId, async() => ( - this.client.sendStateEvent(roomId, type, content, skey) - )); + return this._joinGuard(roomId, async() => + // eslint-disable-next-line camelcase + this.client.sendStateEvent(roomId, type, content, skey) as Promise<{event_id: string}> + ); } /** @@ -682,7 +688,7 @@ export class Intent { // Guard a function which returns a promise which may reject if the user is not // in the room. If the promise rejects, join the room and retry the function. - private async _joinGuard(roomId: string, promiseFn: () => Promise) { + private async _joinGuard(roomId: string, promiseFn: () => Promise): Promise { try { // await so we can handle the error return await promiseFn(); From 6e029b988d049484515e81d10fbaf9be856bb15b Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 5 Oct 2020 09:32:49 +0100 Subject: [PATCH 2/2] changelog --- changelog.d/242.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/242.misc diff --git a/changelog.d/242.misc b/changelog.d/242.misc new file mode 100644 index 00000000..a08e1f96 --- /dev/null +++ b/changelog.d/242.misc @@ -0,0 +1 @@ +Return `event_id` when sending a event or state event