Skip to content
Snippets Groups Projects
Commit 48bed5ce authored by Thomas Hackl's avatar Thomas Hackl
Browse files

catch exception if user has already left the matrix room so that they can't be removed anymore

parent 80a5fa93
No related branches found
No related tags found
No related merge requests found
...@@ -157,30 +157,33 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin ...@@ -157,30 +157,33 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
$matrix = MatrixAccount::findOneByUser_id($membership->user_id); $matrix = MatrixAccount::findOneByUser_id($membership->user_id);
$room = MatrixRoom::findOneByRange_id($membership->seminar_id); $room = MatrixRoom::findOneByRange_id($membership->seminar_id);
if (is_a($matrix, MatrixAccount::class) && is_a($room, MatrixRoom::class)) { if (is_a($matrix, MatrixAccount::class) && is_a($room, MatrixRoom::class)) {
/*
* leaveRoom can only be used if we don't authorize our Matrix users with SSO and login token stuff. try {
* Otherwise we use the Stud.IP system account to kick the user from the room. /*
*/ * leaveRoom can only be used if we don't authorize our Matrix users with SSO and login token stuff.
if (Config::get()->MATRIX_SYSTEM_ACCOUNT_ACCESS_TOKEN) { * Otherwise we use the Stud.IP system account to kick the user from the room.
// POST body. */
$data = [ if (Config::get()->MATRIX_SYSTEM_ACCOUNT_ACCESS_TOKEN) {
'user_id' => $matrix->matrix_account_id, // POST body.
'reason' => sprintf('Not a member of course "%s" anymore.', $membership->course->getFullname()) $data = [
]; 'user_id' => $matrix->matrix_account_id,
'reason' => sprintf('Not a member of course "%s" anymore.', $membership->course->getFullname())
MatrixClient::get()->requestServer( ];
sprintf('/_matrix/client/r0/rooms/%s/kick', $room->matrix_room_id),
'POST', MatrixClient::get()->requestServer(
$data, sprintf('/_matrix/client/r0/rooms/%s/kick', $room->matrix_room_id),
[], 'POST',
MatrixAccount::requireSystemAccount() $data,
); [],
} else { MatrixAccount::requireSystemAccount()
MatrixClient::get()->leaveRoom( );
$matrix->getLinkedAccount(), } else {
$room->getLinkedRoom() MatrixClient::get()->leaveRoom(
); $matrix->getLinkedAccount(),
} $room->getLinkedRoom()
);
}
} catch (Exception $e) {}
} }
} }
......
pluginname=Matrix-Chat pluginname=Matrix-Chat
pluginclassname=MatrixPlugin pluginclassname=MatrixPlugin
origin=data-quest origin=data-quest
version=1.4.6 version=1.4.7
screenshot=assets/images/matrix_logo.png screenshot=assets/images/matrix_logo.png
description=Matrix chat for Stud.IP courses description=Matrix chat for Stud.IP courses
studipMinVersion=4.5 studipMinVersion=4.5
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment