Skip to content

Commit 316475d

Browse files
committed
Give MatrixClient.invite an options param
1 parent 53f2ad4 commit 316475d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/@types/requests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ export interface IJoinRoomOpts {
4343
viaServers?: string[];
4444
}
4545

46+
/** Options object for {@link MatrixClient.invite}. */
47+
export interface InviteOpts {
48+
/**
49+
* The reason for the invite.
50+
*/
51+
reason?: string;
52+
}
53+
4654
export interface KnockRoomOpts {
4755
/**
4856
* The reason for the knock.

src/client.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import {
115115
type IGuestAccessOpts,
116116
type IJoinRoomOpts,
117117
type INotificationsResponse,
118+
type InviteOpts,
118119
type IPaginateOpts,
119120
type IPresenceOpts,
120121
type IRedactOpts,
@@ -3755,12 +3756,19 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
37553756
}
37563757

37573758
/**
3758-
* @param reason - Optional.
3759-
* @returns Promise which resolves: `{}` an empty object.
3760-
* @returns Rejects: with an error response.
3759+
* Send an invite to the given user to join the given room.
3760+
*
3761+
* @param roomId - The ID of the room to which the user should be invited.
3762+
* @param userId - The ID of the user that should be invited.
3763+
* @param opts - Optional reason object. For backwards compatibility, a string is also accepted, and will be interpreted as a reason.
3764+
*
3765+
* @returns An empty object.
37613766
*/
3762-
public invite(roomId: string, userId: string, reason?: string): Promise<EmptyObject> {
3763-
return this.membershipChange(roomId, userId, KnownMembership.Invite, reason);
3767+
public invite(roomId: string, userId: string, opts: InviteOpts | string = {}): Promise<EmptyObject> {
3768+
if (typeof opts != "object") {
3769+
opts = { reason: opts };
3770+
}
3771+
return this.membershipChange(roomId, userId, KnownMembership.Invite, opts.reason);
37643772
}
37653773

37663774
/**

0 commit comments

Comments
 (0)