Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/@types/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export interface ISpaceSummaryEvent {
}

export interface IHierarchyRelation extends IStrippedState {
room_id: string;
origin_server_ts: number;
content: {
order?: string;
Expand Down
32 changes: 23 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
PREFIX_IDENTITY_V2,
PREFIX_MEDIA_R0,
PREFIX_R0,
PREFIX_V1,
PREFIX_UNSTABLE,
retryNetworkOperation,
UploadContentResponseType,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -8375,24 +8381,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: String(maxDepth),
from: fromToken,
limit: String(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<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.
Expand Down
5 changes: 5 additions & 0 deletions src/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/room-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down