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

provide account local part via Stud.IP config, use MATRIX_SERVER config entry...

provide account local part via Stud.IP config, use MATRIX_SERVER config entry for auto discovery as well as full URL
parent e5387435
No related branches found
No related tags found
No related merge requests found
......@@ -40,40 +40,66 @@ class MatrixChatController extends AuthenticatedController
{
Navigation::activateItem('/course/matrix/matrix_chat');
if (!Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
PageLayout::postInfo(
sprintf(
dgettext('matrix', 'Sollten Sie sich noch nie beim Chat angemeldet haben, ' .
'tun Sie dies bitte jetzt und %sladen danach die Seite neu%s.'),
'<a href="" title="' . dgettext('matrix', 'Seite neu laden') . '">',
'</a>'
)
);
}
$this->noChat = false;
$member = CourseMember::find([$this->course->id, User::findCurrent()->id]);
// Chat can only be used if user is visible (Matrix has no privacy settings in chat)
if ($member->visible == 'yes' || $member->visible == 'unknown' && Config::get()->USER_VISIBILITY_UNKNOWN) {
if (!Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
PageLayout::postInfo(
sprintf(
dgettext('matrix', 'Sollten Sie sich noch nie beim Chat angemeldet haben, ' .
'tun Sie dies bitte jetzt und %sladen danach die Seite neu%s.'),
'<a href="" title="' . dgettext('matrix', 'Seite neu laden') . '">',
'</a>'
)
);
}
// Check if current user has a Matrix account.
$this->account = MatrixAccount::find(User::findCurrent()->id);
// Check if current user has a Matrix account.
$this->account = MatrixAccount::find(User::findCurrent()->id);
$this->no_account_wanted = UserConfig::get(User::findCurrent()->id)->MATRIX_NO_ACCOUNT_WANTED;
if ($this->no_account_wanted = UserConfig::get(User::findCurrent()->id)->MATRIX_NO_ACCOUNT_WANTED) {
$this->noChat = true;
}
if (!$this->account && !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
$this->account = new MatrixAccount();
$this->account->user_id = User::findCurrent()->id;
$this->account->matrix_account_id = '@' . User::findCurrent()->username . ':' . Config::get()->MATRIX_SERVER_HOSTNAME;
$this->account->matrix_password = '';
$this->account->store();
}
if (!$this->account && !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
$this->account = new MatrixAccount();
$this->account->user_id = User::findCurrent()->id;
$this->account->matrix_account_id = '@' . User::findCurrent()->username . ':' .
Config::get()->MATRIX_ACCOUNTS_LOCAL_PART;
$this->account->matrix_password = '';
$this->account->store();
}
$this->hasToCreate = false;
if ($this->account || !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
if (!($room = MatrixRoom::findOneByRange_id(Course::findCurrent()->id))) {
$this->hasToCreate = true;
} else {
$this->hasToCreate = false;
$this->hasToCreate = false;
if ($this->account || !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
if (!($room = MatrixRoom::findOneByRange_id(Course::findCurrent()->id))) {
$this->hasToCreate = true;
} else {
$this->hasToCreate = false;
//$room->requireMembership($this->account->getLinkedAccount());
$room->requireInvitation($this->account->getLinkedAccount());
//$room->requireMembership($this->account->getLinkedAccount());
$room->requireInvitation($this->account->getLinkedAccount());
}
}
} else {
PageLayout::postInfo(sprintf(
dgettext('matrix', 'Sie sind nicht in der Teilnehmendenliste der ' .
'Veranstaltung sichtbar. Da dies im Matrixchat nicht abgebildet werden kann, müssen Sie sich ' .
'erst %ssichtbar schalten%s, bevor Sie am Chat teilnehmen können.'),
'<a href="' . URLHelper::getURL(
'dispatch.php/course/members/change_visibility/make_visible/participant',
['cid' => $this->course->id]) . '">',
'</a>'
)
);
$this->noChat = true;
}
}
......
......@@ -49,12 +49,13 @@ class InitMatrixChat extends Migration
// Create global config entries
$entries = [
'MATRIX_SERVER_HOSTNAME' => [
'MATRIX_SERVER' => [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'matrix',
'description' => 'Unter welchem Hostnamen ist der Matrixserver erreichbar?'
'description' => 'Hostname oder URL des Matrixservers (falls die Konfiguration über einen ' .
'.well-known-Eintrag erfolgt, reicht der Hostname aus)'
],
'MATRIX_SYSTEM_ACCOUNT_USERNAME' => [
'value' => '',
......@@ -84,7 +85,15 @@ class InitMatrixChat extends Migration
'section' => 'matrix',
'description' => 'Soll automatisch versucht werden, Matrixaccounts anzulegen? Andernfalls wird ' .
'ein Link zum Chatserver angezeigt.'
]
],
'MATRIX_ACCOUNTS_LOCAL_PART' => [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'matrix',
'description' => 'Local part der verwendeten Matrixkennungen. Wird nur verwendet, wenn ' .
'MATRIX_AUTO_CREATE_ACCOUNTS auf false steht.'
],
];
foreach ($entries as $name => $data) {
......@@ -102,7 +111,7 @@ class InitMatrixChat extends Migration
DBManager::get()->execute("DROP TABLE IF EXISTS `matrix_accounts`");
DBManager::get()->execute("DROP TABLE IF EXISTS `matrix_rooms`");
// Remove config entries.
Config::get()->delete('MATRIX_SERVER_HOSTNAME');
Config::get()->delete('MATRIX_SERVER');
Config::get()->delete('MATRIX_SYSTEM_ACCOUNT_USERNAME');
Config::get()->delete('MATRIX_SYSTEM_ACCOUNT_PASSWORD');
Config::get()->delete('MATRIX_CHATSERVER_URL');
......
......@@ -29,8 +29,13 @@ class MatrixClient
public static function get()
{
if (is_null(MatrixClient::$client)) {
// Check if the global config entry is just a hostname or a full URL
$parsed = parse_url(Config::get()->MATRIX_SERVER);
MatrixClient::$client = new Patrix\MatrixClient(
Config::get()->MATRIX_SERVER_HOSTNAME
$parsed['scheme'] ? $parsed['host'] : $parsed['path'],
$parsed['scheme'] ? Config::get()->MATRIX_SERVER : ''
);
}
......
pluginname=Matrix-Chat
pluginclassname=MatrixPlugin
origin=data-quest
version=0.95
version=0.96
screenshot=assets/images/matrix_logo.png
description=Matrix chat for Stud.IP courses
studipMinVersion=4.5
......
libpatrix @ 403ac1cf
Subproject commit 19fd4fcb03af057641cd7f7e30264957ce3b2378
Subproject commit 403ac1cf84c817250e8b2757feb07d85dabdad7f
......@@ -20,6 +20,6 @@
<div class="matrix-loading" data-endpoint="<?= htmlReady($controller->link_for('matrix_chat/require_room')) ?>">
<?= Assets::img('ajax-indicator-black.svg') ?>
</div>
<? else : ?>
<? elseif (!$noChat) : ?>
<iframe src="<?php echo htmlReady(Config::get()->MATRIX_CHATSERVER_URL) ?>" width="100%" height="100%"></iframe>
<? endif;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment