diff --git a/.eslintrc.js b/.eslintrc.js index 6fc5b99a671..1f5ce5cbd1e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -52,6 +52,8 @@ module.exports = { "@typescript-eslint/no-explicit-any": "off", // We'd rather not do this but we do "@typescript-eslint/ban-ts-comment": "off", + // We're okay with assertion errors when we ask for them + "@typescript-eslint/no-non-null-assertion": "off", "quotes": "off", // We use a `logger` intermediary module diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 489aa167950..795d1ae5c43 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -150,6 +150,10 @@ describe("MatrixClient", function() { } return Promise.resolve(next.data); } + // Jest doesn't let us have custom expectation errors, so if you're seeing this then + // you forgot to handle at least 1 pending request. Check your tests to ensure your + // number of expectations lines up with your number of requests made, and that those + // requests match your expectations. expect(true).toBe(false); return new Promise(() => {}); } @@ -1191,4 +1195,26 @@ describe("MatrixClient", function() { passwordTest({ auth, new_password: newPassword, logout_devices: false }, callback); }); }); + + describe("getLocalAliases", () => { + it("should call the right endpoint", async () => { + const response = { + aliases: ["#woop:example.org", "#another:example.org"], + }; + client.http.authedRequest.mockClear().mockResolvedValue(response); + + const roomId = "!whatever:example.org"; + const result = await client.getLocalAliases(roomId); + + // Current version of the endpoint we support is v3 + const [callback, method, path, queryParams, data, opts] = client.http.authedRequest.mock.calls[0]; + expect(callback).toBeFalsy(); + expect(data).toBeFalsy(); + expect(method).toBe('GET'); + expect(path).toEqual(`/rooms/${encodeURIComponent(roomId)}/aliases`); + expect(opts).toMatchObject({ prefix: "/_matrix/client/v3" }); + expect(queryParams).toBeFalsy(); + expect(result!.aliases).toEqual(response.aliases); + }); + }); }); diff --git a/src/client.ts b/src/client.ts index 7d1787a2b08..f678eefdffe 100644 --- a/src/client.ts +++ b/src/client.ts @@ -61,6 +61,7 @@ import { PREFIX_R0, PREFIX_UNSTABLE, PREFIX_V1, + PREFIX_V3, retryNetworkOperation, UploadContentResponseType, } from "./http-api"; @@ -7531,16 +7532,16 @@ export class MatrixClient extends TypedEventEmitter { - const path = utils.encodeUri("/rooms/$roomId/aliases", - { $roomId: roomId }); - const prefix = PREFIX_UNSTABLE + "/org.matrix.msc2432"; - return this.http.authedRequest(callback, Method.Get, path, null, null, { prefix }); + public getLocalAliases(roomId: string): Promise<{ aliases: string[] }> { + const path = utils.encodeUri("/rooms/$roomId/aliases", { $roomId: roomId }); + const prefix = PREFIX_V3; + return this.http.authedRequest(undefined, Method.Get, path, null, null, { prefix }); } /** diff --git a/src/http-api.ts b/src/http-api.ts index b6a5abb544b..23c692b1fb0 100644 --- a/src/http-api.ts +++ b/src/http-api.ts @@ -48,10 +48,15 @@ TODO: export const PREFIX_R0 = "/_matrix/client/r0"; /** - * A constant representing the URI path for release v1 of the Client-Server HTTP API. + * A constant representing the URI path for the legacy release v1 of the Client-Server HTTP API. */ export const PREFIX_V1 = "/_matrix/client/v1"; +/** + * A constant representing the URI path for Client-Server API endpoints versioned at v3. + */ +export const PREFIX_V3 = "/_matrix/client/v3"; + /** * A constant representing the URI path for as-yet unspecified Client-Server HTTP APIs. */