1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Allow knocking rooms (#3647)

Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>
This commit is contained in:
Charly Nguyen
2023-08-03 10:16:18 +02:00
committed by GitHub
parent 61c0a49971
commit 2ef7ae7661
3 changed files with 120 additions and 1 deletions

View File

@@ -134,6 +134,7 @@ import {
ITagsResponse,
IStatusResponse,
IAddThreePidBody,
KnockRoomOpts,
} from "./@types/requests";
import {
EventType,
@@ -4158,6 +4159,34 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
return syncRoom;
}
/**
* Knock a room. If you have already knocked the room, this will no-op.
* @param roomIdOrAlias - The room ID or room alias to knock.
* @param opts - Options when knocking the room.
* @returns Promise which resolves: `{room_id: {string}}`
* @returns Rejects: with an error response.
*/
public knockRoom(roomIdOrAlias: string, opts: KnockRoomOpts = {}): Promise<{ room_id: string }> {
const room = this.getRoom(roomIdOrAlias);
if (room?.hasMembershipState(this.credentials.userId!, "knock")) {
return Promise.resolve({ room_id: room.roomId });
}
const path = utils.encodeUri("/knock/$roomIdOrAlias", { $roomIdOrAlias: roomIdOrAlias });
const queryParams: Record<string, string | string[]> = {};
if (opts.viaServers) {
queryParams.server_name = opts.viaServers;
}
const body: Record<string, string> = {};
if (opts.reason) {
body.reason = opts.reason;
}
return this.http.authedRequest(Method.Post, path, queryParams, body);
}
/**
* Resend an event. Will also retry any to-device messages waiting to be sent.
* @param event - The event to resend.