From fa95b9ed5eccd87805ab10f08bf1424ddac24bec Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 15 Dec 2021 04:36:47 -0600 Subject: [PATCH 1/4] Add support for MSC3030 /timestamp_to_event --- src/client.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/client.ts b/src/client.ts index ecb684cfce5..c7107184067 100644 --- a/src/client.ts +++ b/src/client.ts @@ -689,6 +689,11 @@ interface IRoomKeysResponse { interface IRoomsKeysResponse { rooms: Record; } + +interface ITimestampToEventResponse { + event_id: string; + origin_server_ts: string; +} /* eslint-enable camelcase */ // We're using this constant for methods overloading and inspect whether a variable @@ -8909,6 +8914,38 @@ export class MatrixClient extends EventEmitter { public async whoami(): Promise<{ user_id: string }> { // eslint-disable-line camelcase return this.http.authedRequest(undefined, "GET", "/account/whoami"); } + + /** + * Find the event_id closest to the given timestamp in the given direction. + * @return {Promise} A promise of an object containing the event_id and + * origin_server_ts of the closest event to the timestamp in the given + * direction + */ + public async timestampToEvent( + roomId: string, + timestamp: number, + dir: Direction, + ): Promise { + const path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", { + $roomId: roomId, + }); + + const params: Record = { + ts: timestamp, + dir: dir, + }; + + return await this.http.authedRequest( + undefined, + "GET", + path, + params, + undefined, + { + prefix: "/_matrix/client/unstable/org.matrix.msc3030", + }, + ); + } } /** From 63e3eda7a45741e4f46520fec585e604b6fce6ac Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 15 Dec 2021 04:40:52 -0600 Subject: [PATCH 2/4] Fix lints --- src/client.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index c7107184067..7e004f9e7b0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8921,11 +8921,11 @@ export class MatrixClient extends EventEmitter { * origin_server_ts of the closest event to the timestamp in the given * direction */ - public async timestampToEvent( + public async timestampToEvent( roomId: string, timestamp: number, dir: Direction, - ): Promise { + ): Promise { const path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", { $roomId: roomId, }); @@ -8934,7 +8934,7 @@ export class MatrixClient extends EventEmitter { ts: timestamp, dir: dir, }; - + return await this.http.authedRequest( undefined, "GET", From e9916095d060636269715a7f67684bbf2e5d46ca Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 15 Dec 2021 04:54:49 -0600 Subject: [PATCH 3/4] Fix lints --- src/client.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/client.ts b/src/client.ts index 5e2f1370054..359a76a7448 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8958,16 +8958,14 @@ export class MatrixClient extends EventEmitter { $roomId: roomId, }); - const params: Record = { - ts: timestamp, - dir: dir, - }; - return await this.http.authedRequest( undefined, - "GET", + Method.Get, path, - params, + { + ts: timestamp.toString(), + dir: dir, + }, undefined, { prefix: "/_matrix/client/unstable/org.matrix.msc3030", From a1418e0ccef33e8088f4e2b28e55f29e6159963c Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 15 Dec 2021 04:58:44 -0600 Subject: [PATCH 4/4] Fix comment indenting Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index 359a76a7448..a54161d6df1 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8946,8 +8946,8 @@ export class MatrixClient extends EventEmitter { /** * Find the event_id closest to the given timestamp in the given direction. * @return {Promise} A promise of an object containing the event_id and - * origin_server_ts of the closest event to the timestamp in the given - * direction + * origin_server_ts of the closest event to the timestamp in the given + * direction */ public async timestampToEvent( roomId: string,