Implement invite from command

This commit is contained in:
RMidhunSuresh 2023-08-18 23:13:26 +05:30
parent 2f05cd5028
commit 4f058e3b2c
No known key found for this signature in database
3 changed files with 24 additions and 0 deletions

View File

@ -273,6 +273,14 @@ export class RoomViewModel extends ErrorReportViewModel {
this.reportError(new Error("join syntax: /join <room-id>")); this.reportError(new Error("join syntax: /join <room-id>"));
} }
break; break;
case "invite":
if (args.length === 1) {
const userId = args[0];
await this._room.inviteUser(userId);
} else {
this.reportError(new Error("invite syntax: /invite <user-id>"));
}
break;
case "shrug": case "shrug":
message = "¯\\_(ツ)_/¯ " + args.join(" "); message = "¯\\_(ツ)_/¯ " + args.join(" ");
msgtype = "m.text"; msgtype = "m.text";

View File

@ -267,6 +267,15 @@ export class HomeServerApi {
return this._get("/pushers", undefined, undefined, options); return this._get("/pushers", undefined, undefined, options);
} }
invite(roomId: string, userId: string, reason?: string, options?: BaseRequestOptions): IHomeServerRequest {
return this._post(
`/rooms/${encodeURIComponent(roomId)}/invite`,
{},
{ user_id: userId, reason },
options
);
}
join(roomId: string, options?: BaseRequestOptions): IHomeServerRequest { join(roomId: string, options?: BaseRequestOptions): IHomeServerRequest {
return this._post(`/rooms/${encodeURIComponent(roomId)}/join`, {}, {}, options); return this._post(`/rooms/${encodeURIComponent(roomId)}/join`, {}, {}, options);
} }

View File

@ -470,6 +470,13 @@ export class Room extends BaseRoom {
}); });
} }
async inviteUser(userId, reason) {
if (!userId) {
throw new Error("userId is null/undefined");
}
await this._hsApi.invite(this.id, userId, reason).response();
}
/* called by BaseRoom to pass pendingEvents when opening the timeline */ /* called by BaseRoom to pass pendingEvents when opening the timeline */
_getPendingEvents() { _getPendingEvents() {
return this._sendQueue.pendingEvents; return this._sendQueue.pendingEvents;