Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,11 @@ interface IRoomKeysResponse {
interface IRoomsKeysResponse {
rooms: Record<string, IRoomKeysResponse>;
}

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
Expand Down Expand Up @@ -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<ITimestampToEventResponse> {
const path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", {
$roomId: roomId,
});

const params: Record<string, string | number> = {
ts: timestamp,
dir: dir,
};

return await this.http.authedRequest(
undefined,
"GET",
path,
params,
undefined,
{
prefix: "/_matrix/client/unstable/org.matrix.msc3030",
},
);
}
}

/**
Expand Down