Skip to content

Commit e62aabc

Browse files
authored
Add reportRoom API (#4753)
* Add reportRoom * add test * fixdoc * fix doc again * Add docs for matrix version. * lint
1 parent 0f3bcf3 commit e62aabc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

spec/unit/matrix-client.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,26 @@ describe("MatrixClient", function () {
607607
});
608608
});
609609

610+
describe("reportRoom", function () {
611+
const roomId = "!foo:bar";
612+
const reason = "rubbish room";
613+
614+
it("should send an invite HTTP POST", async function () {
615+
httpLookups = [
616+
{
617+
method: "POST",
618+
path: "/rooms/!foo%3Abar/report",
619+
data: {},
620+
expectBody: {
621+
reason,
622+
},
623+
},
624+
];
625+
await client.reportRoom(roomId, reason);
626+
expect(httpLookups.length).toEqual(0);
627+
});
628+
});
629+
610630
describe("sendEvent", () => {
611631
const roomId = "!room:example.org";
612632
const body = "This is the body";

src/client.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8041,7 +8041,24 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
80418041
}
80428042

80438043
/**
8044-
* Fetches or paginates a room hierarchy as defined by MSC2946.
8044+
* Reports a room as inappropriate to the server, which may then notify the appropriate people.
8045+
*
8046+
* This API was introduced in Matrix v1.13.
8047+
*
8048+
* @param roomId - The room being reported.
8049+
* @param reason - The reason the room is being reported. May be blank.
8050+
* @returns Promise which resolves to an empty object if successful
8051+
*/
8052+
public reportRoom(roomId: string, reason: string): Promise<EmptyObject> {
8053+
const path = utils.encodeUri("/rooms/$roomId/report", {
8054+
$roomId: roomId,
8055+
});
8056+
8057+
return this.http.authedRequest(Method.Post, path, undefined, { reason });
8058+
}
8059+
8060+
/**
8061+
* Fetches or paginates a room hierarchy asmatrix-js-sdk/spec/unit/matrix-client.spec.ts defined by MSC2946.
80458062
* Falls back gracefully to sourcing its data from `getSpaceSummary` if this API is not yet supported by the server.
80468063
* @param roomId - The ID of the space-room to use as the root of the summary.
80478064
* @param limit - The maximum number of rooms to return per page.

0 commit comments

Comments
 (0)