1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Convert getLocalAliases to a stable API call (#2402)

* Convert getLocalAliases to a stable API call

* Appease the linter
This commit is contained in:
Travis Ralston
2022-05-25 15:56:27 -06:00
committed by GitHub
parent b2120a0a13
commit 12253064d1
4 changed files with 42 additions and 8 deletions

View File

@@ -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

View File

@@ -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);
});
});
});

View File

@@ -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<EmittedEvents, ClientEventHa
}
/**
* @param {string} roomId
* @param {module:client.callback} callback Optional.
* Gets the local aliases for the room. Note: this includes all local aliases, unlike the
* curated list from the m.room.canonical_alias state event.
* @param {string} roomId The room ID to get local aliases for.
* @return {Promise} Resolves: an object with an `aliases` property, containing an array of local aliases
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public unstableGetLocalAliases(roomId: string, callback?: Callback): Promise<{ aliases: string[] }> {
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 });
}
/**

View File

@@ -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.
*/