Skip to content

Commit dd23a1a

Browse files
Add support for MSC3030 /timestamp_to_event (#2072)
- `/jumptodate` slash command is being worked on in matrix-org/matrix-react-sdk#7372 - Jump to date headers are being worked on in matrix-org/matrix-react-sdk#7339 Related to element-hq/element-web#7677 Part of MSC3030: matrix-org/matrix-spec-proposals#3030 Experimental Synapse implementation added in matrix-org/synapse#9445
1 parent 6ac84a2 commit dd23a1a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/client.ts

+35
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ interface IRoomHierarchy {
728728
rooms: IHierarchyRoom[];
729729
next_batch?: string;
730730
}
731+
732+
interface ITimestampToEventResponse {
733+
event_id: string;
734+
origin_server_ts: string;
735+
}
731736
/* eslint-enable camelcase */
732737

733738
// We're using this constant for methods overloading and inspect whether a variable
@@ -8937,6 +8942,36 @@ export class MatrixClient extends EventEmitter {
89378942
public async whoami(): Promise<{ user_id: string }> { // eslint-disable-line camelcase
89388943
return this.http.authedRequest(undefined, Method.Get, "/account/whoami");
89398944
}
8945+
8946+
/**
8947+
* Find the event_id closest to the given timestamp in the given direction.
8948+
* @return {Promise} A promise of an object containing the event_id and
8949+
* origin_server_ts of the closest event to the timestamp in the given
8950+
* direction
8951+
*/
8952+
public async timestampToEvent(
8953+
roomId: string,
8954+
timestamp: number,
8955+
dir: Direction,
8956+
): Promise<ITimestampToEventResponse> {
8957+
const path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", {
8958+
$roomId: roomId,
8959+
});
8960+
8961+
return await this.http.authedRequest(
8962+
undefined,
8963+
Method.Get,
8964+
path,
8965+
{
8966+
ts: timestamp.toString(),
8967+
dir: dir,
8968+
},
8969+
undefined,
8970+
{
8971+
prefix: "/_matrix/client/unstable/org.matrix.msc3030",
8972+
},
8973+
);
8974+
}
89408975
}
89418976

89428977
/**

0 commit comments

Comments
 (0)