From 02c0739ba1dcb959c28135414194a79aa3535a3f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 15 Nov 2021 10:52:02 +0000 Subject: [PATCH 1/3] Use v1 prefix for /hierarchy API, falling back to both previous variants --- src/client.ts | 17 ++++++++++++++++- src/http-api.js | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index e9512912375..e9033967fa8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -45,6 +45,7 @@ import { PREFIX_IDENTITY_V2, PREFIX_MEDIA_R0, PREFIX_R0, + PREFIX_V1, PREFIX_UNSTABLE, retryNetworkOperation, } from "./http-api"; @@ -8096,7 +8097,21 @@ export class MatrixClient extends EventEmitter { from: fromToken, limit, }, 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, "GET", path, { + suggested_only: suggestedOnly, + max_depth: maxDepth, + from: fromToken, + 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.js b/src/http-api.js index 92c6e420f72..5c662b8f36f 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -40,6 +40,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. */ From 98a329343b1ed9bcff4a2034644b85f02e2c4d71 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 15 Nov 2021 13:02:20 +0000 Subject: [PATCH 2/3] Remove deprecated field --- src/@types/spaces.ts | 1 - 1 file changed, 1 deletion(-) 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; From bbdd4468b13b34b8d1344afd30fcb183ae5aba50 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 Dec 2021 15:44:28 +0000 Subject: [PATCH 3/3] Post-merge fix --- src/client.ts | 23 +++++++++++------------ src/room-hierarchy.ts | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/client.ts b/src/client.ts index 7ed8eb1a62e..4ac5ecdb2c8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -723,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 @@ -8376,18 +8381,12 @@ 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: String(maxDepth), from: fromToken, @@ -8397,11 +8396,11 @@ export class MatrixClient extends EventEmitter { }).catch(e => { if (e.errcode === "M_UNRECOGNIZED") { // fall back to the development prefix - return this.http.authedRequest(undefined, "GET", path, { - suggested_only: suggestedOnly, - max_depth: maxDepth, + return this.http.authedRequest(undefined, Method.Get, path, { + suggested_only: String(suggestedOnly), + max_depth: String(maxDepth), from: fromToken, - limit, + limit: String(limit), }, undefined, { prefix: "/_matrix/client/unstable/org.matrix.msc2946", }); 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)) {