From 6ac84a24657639aad2c3fdf984b5a59614729e5f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 15 Dec 2021 09:56:07 +0000 Subject: [PATCH] Use v1 prefix for /hierarchy API, falling back to both previous variants (#2022) --- src/@types/spaces.ts | 1 - src/client.ts | 32 +++++++++++++++++++++++--------- src/http-api.ts | 5 +++++ src/room-hierarchy.ts | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/@types/spaces.ts b/src/@types/spaces.ts index 088864bd46b..7ca55c39e1b 100644 --- a/src/@types/spaces.ts +++ b/src/@types/spaces.ts @@ -44,7 +44,6 @@ export interface ISpaceSummaryEvent { } export interface IHierarchyRelation extends IStrippedState { - room_id: string; origin_server_ts: number; content: { order?: string; diff --git a/src/client.ts b/src/client.ts index dfed9006318..4824b9063b0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -50,6 +50,7 @@ import { PREFIX_IDENTITY_V2, PREFIX_MEDIA_R0, PREFIX_R0, + PREFIX_V1, PREFIX_UNSTABLE, retryNetworkOperation, UploadContentResponseType, @@ -722,6 +723,11 @@ interface IRoomKeysResponse { interface IRoomsKeysResponse { rooms: Record; } + +interface IRoomHierarchy { + rooms: IHierarchyRoom[]; + next_batch?: string; +} /* eslint-enable camelcase */ // We're using this constant for methods overloading and inspect whether a variable @@ -8372,24 +8378,32 @@ export class MatrixClient extends EventEmitter { maxDepth?: number, suggestedOnly = false, fromToken?: string, - ): Promise<{ - rooms: IHierarchyRoom[]; - next_batch?: string; // eslint-disable-line camelcase - }> { + ): Promise { const path = utils.encodeUri("/rooms/$roomId/hierarchy", { $roomId: roomId, }); - return this.http.authedRequest<{ - rooms: IHierarchyRoom[]; - next_batch?: string; // eslint-disable-line camelcase - }>(undefined, Method.Get, path, { + return this.http.authedRequest(undefined, Method.Get, path, { suggested_only: String(suggestedOnly), max_depth: maxDepth?.toString(), from: fromToken, limit: limit?.toString(), }, undefined, { - prefix: "/_matrix/client/unstable/org.matrix.msc2946", + prefix: PREFIX_V1, + }).catch(e => { + if (e.errcode === "M_UNRECOGNIZED") { + // fall back to the development prefix + return this.http.authedRequest(undefined, Method.Get, path, { + suggested_only: String(suggestedOnly), + max_depth: String(maxDepth), + from: fromToken, + limit: String(limit), + }, undefined, { + prefix: "/_matrix/client/unstable/org.matrix.msc2946", + }); + } + + throw e; }).catch(e => { if (e.errcode === "M_UNRECOGNIZED") { // fall back to the older space summary API as it exposes the same data just in a different shape. diff --git a/src/http-api.ts b/src/http-api.ts index 9e32209a10e..ac98c35ae1c 100644 --- a/src/http-api.ts +++ b/src/http-api.ts @@ -47,6 +47,11 @@ TODO: */ export const PREFIX_R0 = "/_matrix/client/r0"; +/** + * A constant representing the URI path for release v1 of the Client-Server HTTP API. + */ +export const PREFIX_V1 = "/_matrix/client/v1"; + /** * A constant representing the URI path for as-yet unspecified Client-Server HTTP APIs. */ diff --git a/src/room-hierarchy.ts b/src/room-hierarchy.ts index 16b6014ea60..1acf10e586d 100644 --- a/src/room-hierarchy.ts +++ b/src/room-hierarchy.ts @@ -112,7 +112,7 @@ export class RoomHierarchy { if (!this.backRefs.has(childRoomId)) { this.backRefs.set(childRoomId, []); } - this.backRefs.get(childRoomId).push(ev.room_id); + this.backRefs.get(childRoomId).push(room.room_id); // fill viaMap if (Array.isArray(ev.content.via)) {