Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Allow integration managers to remove users #9211

Merged
merged 19 commits into from
Sep 13, 2022
Merged
Changes from 1 commit
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
56 changes: 56 additions & 0 deletions src/ScalarMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ Example:
}
}

kick
------
Kicks a user from a room. The request will no-op if the user is not in the room.

Request:
- room_id is the room to invite the user into.
- user_id is the user ID to invite.
justinbot marked this conversation as resolved.
Show resolved Hide resolved
- reason is an optional string for the kick reason
Response:
{
success: true
}
Example:
{
action: "kick",
room_id: "!foo:bar",
user_id: "@invitee:bar",
justinbot marked this conversation as resolved.
Show resolved Hide resolved
reason: "Removed from room",
response: {
success: true
}
}

set_bot_options
---------------
Set the m.room.bot.options state event for a bot user.
Expand Down Expand Up @@ -266,6 +289,7 @@ enum Action {
CanSendEvent = "can_send_event",
MembershipState = "membership_state",
invite = "invite",
Kick = "kick",
BotOptions = "bot_options",
SetBotOptions = "set_bot_options",
SetBotPower = "set_bot_power",
Expand Down Expand Up @@ -322,6 +346,35 @@ function inviteUser(event: MessageEvent<any>, roomId: string, userId: string): v
});
}

function kickUser(event: MessageEvent<any>, roomId: string, userId: string): void {
logger.log(`Received request to kick ${userId} from room ${roomId}`);
const client = MatrixClientPeg.get();
if (!client) {
sendError(event, _t('You need to be logged in.'));
return;
}
const room = client.getRoom(roomId);
if (room) {
// if they are already not in the room we can resolve immediately.
const member = room.getMember(userId);
if (!member || (member && member.membership === "leave")) {
justinbot marked this conversation as resolved.
Show resolved Hide resolved
sendResponse(event, {
success: true,
});
return;
}
}

const reason = event.data.reason;
client.kick(roomId, userId, reason).then(function() {
sendResponse(event, {
success: true,
});
}, function(err) {
sendError(event, _t('You need to be able to kick users to do that.'), err);
});
justinbot marked this conversation as resolved.
Show resolved Hide resolved
}

function setWidget(event: MessageEvent<any>, roomId: string): void {
const widgetId = event.data.widget_id;
let widgetType = event.data.type;
Expand Down Expand Up @@ -710,6 +763,9 @@ const onMessage = function(event: MessageEvent<any>): void {
case Action.invite:
inviteUser(event, roomId, userId);
break;
case Action.Kick:
kickUser(event, roomId, userId);
break;
case Action.BotOptions:
botOptions(event, roomId, userId);
break;
Expand Down