You've already forked matrix-js-sdk
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user