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 { export interface IHierarchyRelation extends IStrippedState {
room_id: string;
origin_server_ts: number; origin_server_ts: number;
content: { content: {
order?: string; order?: string;

View File

@@ -50,6 +50,7 @@ import {
PREFIX_IDENTITY_V2, PREFIX_IDENTITY_V2,
PREFIX_MEDIA_R0, PREFIX_MEDIA_R0,
PREFIX_R0, PREFIX_R0,
PREFIX_V1,
PREFIX_UNSTABLE, PREFIX_UNSTABLE,
retryNetworkOperation, retryNetworkOperation,
UploadContentResponseType, UploadContentResponseType,
@@ -722,6 +723,11 @@ interface IRoomKeysResponse {
interface IRoomsKeysResponse { interface IRoomsKeysResponse {
rooms: Record<string, IRoomKeysResponse>; rooms: Record<string, IRoomKeysResponse>;
} }
interface IRoomHierarchy {
rooms: IHierarchyRoom[];
next_batch?: string;
}
/* eslint-enable camelcase */ /* eslint-enable camelcase */
// We're using this constant for methods overloading and inspect whether a variable // We're using this constant for methods overloading and inspect whether a variable
@@ -8372,24 +8378,32 @@ export class MatrixClient extends EventEmitter {
maxDepth?: number, maxDepth?: number,
suggestedOnly = false, suggestedOnly = false,
fromToken?: string, fromToken?: string,
): Promise<{ ): Promise<IRoomHierarchy> {
rooms: IHierarchyRoom[];
next_batch?: string; // eslint-disable-line camelcase
}> {
const path = utils.encodeUri("/rooms/$roomId/hierarchy", { const path = utils.encodeUri("/rooms/$roomId/hierarchy", {
$roomId: roomId, $roomId: roomId,
}); });
return this.http.authedRequest<{ return this.http.authedRequest<IRoomHierarchy>(undefined, Method.Get, path, {
rooms: IHierarchyRoom[];
next_batch?: string; // eslint-disable-line camelcase
}>(undefined, Method.Get, path, {
suggested_only: String(suggestedOnly), suggested_only: String(suggestedOnly),
max_depth: maxDepth?.toString(), max_depth: maxDepth?.toString(),
from: fromToken, from: fromToken,
limit: limit?.toString(), limit: limit?.toString(),
}, undefined, { }, 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<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 => { }).catch(e => {
if (e.errcode === "M_UNRECOGNIZED") { if (e.errcode === "M_UNRECOGNIZED") {
// fall back to the older space summary API as it exposes the same data just in a different shape. // 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"; 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. * 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)) { if (!this.backRefs.has(childRoomId)) {
this.backRefs.set(childRoomId, []); this.backRefs.set(childRoomId, []);
} }
this.backRefs.get(childRoomId).push(ev.room_id); this.backRefs.get(childRoomId).push(room.room_id);
// fill viaMap // fill viaMap
if (Array.isArray(ev.content.via)) { if (Array.isArray(ev.content.via)) {