1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Use v1 prefix for /hierarchy API, falling back to both previous variants (#2022)

This commit is contained in:
Michael Telatynski
2021-12-15 09:56:07 +00:00
committed by GitHub
parent e4d3124e72
commit 6ac84a2465
4 changed files with 29 additions and 11 deletions

View File

@@ -44,7 +44,6 @@ export interface ISpaceSummaryEvent {
}
export interface IHierarchyRelation extends IStrippedState {
room_id: string;
origin_server_ts: number;
content: {
order?: string;

View File

@@ -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<string, IRoomKeysResponse>;
}
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<IRoomHierarchy> {
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<IRoomHierarchy>(undefined, Method.Get, path, {
suggested_only: String(suggestedOnly),
max_depth: maxDepth?.toString(),
from: fromToken,
limit: limit?.toString(),
}, undefined, {
prefix: PREFIX_V1,
}).catch(e => {
if (e.errcode === "M_UNRECOGNIZED") {
// fall back to the development prefix
return this.http.authedRequest<IRoomHierarchy>(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.

View File

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

View File

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