Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3a18976
Prefer stable endpoint first
MadLittleMods Nov 29, 2022
d3f08fe
Add tests
MadLittleMods Dec 1, 2022
d1ede03
Add return type
MadLittleMods Dec 1, 2022
9a731cd
Add some comments
MadLittleMods Dec 1, 2022
ad8bb5d
Fix lints
MadLittleMods Dec 1, 2022
9a98e80
Fix relevant strict ts error
MadLittleMods Dec 1, 2022
bf78a64
Remove console coloring in favor of future PR
MadLittleMods Dec 8, 2022
c953fc9
Update casing
MadLittleMods Dec 8, 2022
ed91bd9
Merge branch 'develop' into madlittlemods/stablize-msc3030-timestamp-…
MadLittleMods Dec 9, 2022
9841f92
Fix some eslint
MadLittleMods Dec 9, 2022
fcf12b4
Merge branch 'develop' into madlittlemods/stablize-msc3030-timestamp-…
MadLittleMods Dec 13, 2022
70a033c
Prettier fixes
MadLittleMods Dec 13, 2022
a0aa507
Fix prefix lint
MadLittleMods Dec 13, 2022
4683fbe
Merge branch 'develop' into madlittlemods/stablize-msc3030-timestamp-…
MadLittleMods Dec 16, 2022
ca98d9f
Tests for convertQueryDictToStringRecord
andybalaam Jan 6, 2023
b1566ee
Switch to a Map for convertQueryDictToStringRecord
andybalaam Jan 6, 2023
d744214
Rename convertQueryDictToMap
andybalaam Jan 6, 2023
c4ca0b2
Refactor timestampToEvent tests
andybalaam Jan 6, 2023
628bcbf
Fall back to the unstable endpoint if we receive a 405 status
andybalaam Jan 6, 2023
12cc7be
Test 400, 429 and 502 responses
andybalaam Jan 6, 2023
f00f70b
Merge branch 'develop' into madlittlemods/stablize-msc3030-timestamp-…
andybalaam Jan 6, 2023
981acf0
Rename test to fit renamed function.
andybalaam Jan 6, 2023
c7c1625
Update comment to reflect commonality between 404 and 405 status
andybalaam Jan 9, 2023
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
52 changes: 36 additions & 16 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9297,31 +9297,51 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa

/**
* 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
* @return {Promise} Resolves: A promise of an object containing the event_id and
* origin_server_ts of the closest event to the timestamp in the given direction
* @return {module:http-api.MatrixError} Rejects: when the request fails
*/
public timestampToEvent(
public async timestampToEvent(
roomId: string,
timestamp: number,
dir: Direction,
): Promise<ITimestampToEventResponse> {
const path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", {
$roomId: roomId,
});
const queryParams = {
ts: timestamp.toString(),
dir: dir,
};

return this.http.authedRequest(
Method.Get,
path,
{
ts: timestamp.toString(),
dir: dir,
},
undefined,
{
prefix: "/_matrix/client/unstable/org.matrix.msc3030",
},
);
try {
return await this.http.authedRequest(
Method.Get,
path,
queryParams,
undefined,
{
prefix: ClientPrefix.V1,
},
);
} catch (err) {
// Fallback to the prefixed unstable endpoint. Since the stable endpoint is
// new, we should also try the unstable endpoint before giving up. We can
// remove this fallback request in a year (remove after 2023-11-28).
if ((<MatrixError>err).httpStatus === 400 && (<MatrixError>err).errcode === "M_UNRECOGNIZED") {
return await this.http.authedRequest(
Method.Get,
path,
queryParams,
undefined,
{
prefix: "/_matrix/client/unstable/org.matrix.msc3030",
},
);
}

throw err;
}
}
}

Expand Down