Skip to content

Commit 6ac84a2

Browse files
authored
Use v1 prefix for /hierarchy API, falling back to both previous variants (#2022)
1 parent e4d3124 commit 6ac84a2

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/@types/spaces.ts

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export interface ISpaceSummaryEvent {
4444
}
4545

4646
export interface IHierarchyRelation extends IStrippedState {
47-
room_id: string;
4847
origin_server_ts: number;
4948
content: {
5049
order?: string;

src/client.ts

+23-9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
PREFIX_IDENTITY_V2,
5151
PREFIX_MEDIA_R0,
5252
PREFIX_R0,
53+
PREFIX_V1,
5354
PREFIX_UNSTABLE,
5455
retryNetworkOperation,
5556
UploadContentResponseType,
@@ -722,6 +723,11 @@ interface IRoomKeysResponse {
722723
interface IRoomsKeysResponse {
723724
rooms: Record<string, IRoomKeysResponse>;
724725
}
726+
727+
interface IRoomHierarchy {
728+
rooms: IHierarchyRoom[];
729+
next_batch?: string;
730+
}
725731
/* eslint-enable camelcase */
726732

727733
// We're using this constant for methods overloading and inspect whether a variable
@@ -8372,24 +8378,32 @@ export class MatrixClient extends EventEmitter {
83728378
maxDepth?: number,
83738379
suggestedOnly = false,
83748380
fromToken?: string,
8375-
): Promise<{
8376-
rooms: IHierarchyRoom[];
8377-
next_batch?: string; // eslint-disable-line camelcase
8378-
}> {
8381+
): Promise<IRoomHierarchy> {
83798382
const path = utils.encodeUri("/rooms/$roomId/hierarchy", {
83808383
$roomId: roomId,
83818384
});
83828385

8383-
return this.http.authedRequest<{
8384-
rooms: IHierarchyRoom[];
8385-
next_batch?: string; // eslint-disable-line camelcase
8386-
}>(undefined, Method.Get, path, {
8386+
return this.http.authedRequest<IRoomHierarchy>(undefined, Method.Get, path, {
83878387
suggested_only: String(suggestedOnly),
83888388
max_depth: maxDepth?.toString(),
83898389
from: fromToken,
83908390
limit: limit?.toString(),
83918391
}, undefined, {
8392-
prefix: "/_matrix/client/unstable/org.matrix.msc2946",
8392+
prefix: PREFIX_V1,
8393+
}).catch(e => {
8394+
if (e.errcode === "M_UNRECOGNIZED") {
8395+
// fall back to the development prefix
8396+
return this.http.authedRequest<IRoomHierarchy>(undefined, Method.Get, path, {
8397+
suggested_only: String(suggestedOnly),
8398+
max_depth: String(maxDepth),
8399+
from: fromToken,
8400+
limit: String(limit),
8401+
}, undefined, {
8402+
prefix: "/_matrix/client/unstable/org.matrix.msc2946",
8403+
});
8404+
}
8405+
8406+
throw e;
83938407
}).catch(e => {
83948408
if (e.errcode === "M_UNRECOGNIZED") {
83958409
// fall back to the older space summary API as it exposes the same data just in a different shape.

src/http-api.ts

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ TODO:
4747
*/
4848
export const PREFIX_R0 = "/_matrix/client/r0";
4949

50+
/**
51+
* A constant representing the URI path for release v1 of the Client-Server HTTP API.
52+
*/
53+
export const PREFIX_V1 = "/_matrix/client/v1";
54+
5055
/**
5156
* A constant representing the URI path for as-yet unspecified Client-Server HTTP APIs.
5257
*/

src/room-hierarchy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class RoomHierarchy {
112112
if (!this.backRefs.has(childRoomId)) {
113113
this.backRefs.set(childRoomId, []);
114114
}
115-
this.backRefs.get(childRoomId).push(ev.room_id);
115+
this.backRefs.get(childRoomId).push(room.room_id);
116116

117117
// fill viaMap
118118
if (Array.isArray(ev.content.via)) {

0 commit comments

Comments
 (0)