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

Add "reason" to leaveRoom. #301

Merged
merged 1 commit into from
Mar 19, 2023
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
5 changes: 3 additions & 2 deletions src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,12 @@ export class MatrixClient extends EventEmitter {
/**
* Leaves the given room
* @param {string} roomId the room ID to leave
* @param {string=} reason Optional reason to be included as the reason for leaving the room.
* @returns {Promise<any>} resolves when left
*/
@timedMatrixClientFunctionCall()
public leaveRoom(roomId: string): Promise<any> {
return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, {});
public leaveRoom(roomId: string, reason?: string): Promise<any> {
return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, { reason });
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/appservice/Intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ export class Intent {
/**
* Leaves the given room.
* @param {string} roomId The room ID to leave
* @param {string=} reason Optional reason to be included as the reason for leaving the room.
* @returns {Promise<any>} Resolves when the room has been left.
*/
@timedIntentFunctionCall()
public async leaveRoom(roomId: string): Promise<any> {
public async leaveRoom(roomId: string, reason?: string): Promise<any> {
await this.ensureRegistered();
return this.client.leaveRoom(roomId).then(async () => {
return this.client.leaveRoom(roomId, reason).then(async () => {
// Recalculate joined rooms now that we've left a room
await this.refreshJoinedRooms();
});
Expand Down
15 changes: 15 additions & 0 deletions test/MatrixClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,21 @@ describe('MatrixClient', () => {

await Promise.all([client.leaveRoom(roomId), http.flushAllExpected()]);
});
it('should include a reason if provided', async () => {
const { client, http, hsUrl } = createTestClient();

const roomId = "!testing:example.org";
const reason = "I am done testing here";

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => {
expect(content).toEqual({ reason });
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/leave`);
return {};
});

await Promise.all([client.leaveRoom(roomId, reason), http.flushAllExpected()]);
});
});

describe('forgetRoom', () => {
Expand Down