Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MSC3030 /timestamp_to_event #2072

Merged
merged 5 commits into from
Dec 15, 2021
Merged
Changes from 4 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
35 changes: 35 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,11 @@ interface IRoomHierarchy {
rooms: IHierarchyRoom[];
next_batch?: string;
}

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 @@ -8937,6 +8942,36 @@ export class MatrixClient extends EventEmitter {
public async whoami(): Promise<{ user_id: string }> { // eslint-disable-line camelcase
return this.http.authedRequest(undefined, Method.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
*/
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
public async timestampToEvent(
roomId: string,
timestamp: number,
dir: Direction,
): Promise<ITimestampToEventResponse> {
const path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", {
$roomId: roomId,
});

return await this.http.authedRequest(
undefined,
Method.Get,
path,
{
ts: timestamp.toString(),
dir: dir,
},
undefined,
{
prefix: "/_matrix/client/unstable/org.matrix.msc3030",
},
);
}
}

/**
Expand Down