diff --git a/MatrixPlugin.php b/MatrixPlugin.php index 2d2511206d0a5479073b4527abe5fa3b6c5d1249..0e4b205121501c8e8fe6e89c09b6054fe5f50e53 100644 --- a/MatrixPlugin.php +++ b/MatrixPlugin.php @@ -59,6 +59,11 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin $navigation = new Navigation('matrix', PluginEngine::getURL($this, [], 'matrix_chat')); $navigation->setBadgeNumber($num_entries); + $account = MatrixAccount::find(User::findCurrent()->id); + if ($account) { + //$news = MatrixClient::get()->getNews($account->getLinkedAccount()); + } + if ($num_entries > 0) { $navigation->setImage(Icon::create('consultation+new', Icon::ROLE_ATTENTION, ["title" => $text])); } else { diff --git a/migrations/20210519_init.php b/migrations/20210519_init_matrix_chat.php similarity index 77% rename from migrations/20210519_init.php rename to migrations/20210519_init_matrix_chat.php index 0eff528151f277bfc55b7626642121c5dacda86b..4ad10fdfc1829f70b89fed463a252f20c5681541 100644 --- a/migrations/20210519_init.php +++ b/migrations/20210519_init_matrix_chat.php @@ -1,7 +1,8 @@ <?php /** - * Creates necessary database tables and other entries for Matrix matrix_chat integration. + * Class InitMatrixChat + * Creates necessary database tables and other entries for Matrix integration. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -13,12 +14,12 @@ * @category Matrix */ -class Init extends Migration +class InitMatrixChat extends Migration { public function description() { - return 'Creates necessary database tables and other entries for Matrix matrix_chat integration.'; + return 'Creates necessary database tables and other entries for Matrix integration.'; } public function up() @@ -47,29 +48,44 @@ class Init extends Migration ) ENGINE InnoDB ROW_FORMAT=DYNAMIC"); // Create global config entries - try { - Config::get()->create('MATRIX_SERVER_HOSTNAME', [ + $entries = [ + 'MATRIX_SERVER_HOSTNAME' => [ 'value' => '', 'type' => 'string', 'range' => 'global', 'section' => 'matrix', 'description' => 'Unter welchem Hostnamen ist der Matrixserver erreichbar?' - ]); - Config::get()->create('MATRIX_SYSTEM_ACCOUNT_USERNAME', [ + ], + 'MATRIX_SYSTEM_ACCOUNT_USERNAME' => [ 'value' => '', 'type' => 'string', 'range' => 'global', 'section' => 'matrix', 'description' => 'Benutzername der Stud.IP-Matrixkennung, mit der z.B. Räume angelegt werden.' - ]); - Config::get()->create('MATRIX_SYSTEM_ACCOUNT_PASSWORD', [ + ], + 'MATRIX_SYSTEM_ACCOUNT_PASSWORD' => [ 'value' => '', 'type' => 'string', 'range' => 'global', 'section' => 'matrix', 'description' => 'Passwort der Stud.IP-Matrixkennung, mit der z.B. Räume angelegt werden.' - ]); - } catch (Exception $e) {} + ], + 'MATRIX_CHATSERVER_URL' => [ + 'value' => '', + 'type' => 'string', + 'range' => 'global', + 'section' => 'matrix', + 'description' => 'URL des Chatservers (z.B. Element)' + ] + ]; + + foreach ($entries as $name => $data) { + try { + Config::get()->create($name, $data); + } catch (Exception $e) { + } + } + } public function down() @@ -81,6 +97,7 @@ class Init extends Migration Config::get()->delete('MATRIX_SERVER_HOSTNAME'); Config::get()->delete('MATRIX_SYSTEM_ACCOUNT_USERNAME'); Config::get()->delete('MATRIX_SYSTEM_ACCOUNT_PASSWORD'); + Config::get()->delete('MATRIX_CHATSERVER_URL'); } } \ No newline at end of file diff --git a/models/MatrixAccount.php b/models/MatrixAccount.php index 1849973fe3f6b4655eb9c8fbde04d3332de00e4b..091e4b0bee828b4c23831e421e5c38a5df0c974a 100644 --- a/models/MatrixAccount.php +++ b/models/MatrixAccount.php @@ -35,7 +35,9 @@ class MatrixAccount extends SimpleORMap public function getLinkedAccount() { - return new \Patrix\Account($this->matrix_account_id, $this->matrix_password); + $account = new \Patrix\Account($this->matrix_account_id, $this->matrix_password); + MatrixClient::get()->login($account); + return $account; } public static function randomPassword( $length = 14 ) { diff --git a/vendor/libpatrix b/vendor/libpatrix index c05790e055ca90fe7d5867ee6dbd26fd695814ad..56893e89418f3cc7bb78a73a421055ad56fc619c 160000 --- a/vendor/libpatrix +++ b/vendor/libpatrix @@ -1 +1 @@ -Subproject commit c05790e055ca90fe7d5867ee6dbd26fd695814ad +Subproject commit 56893e89418f3cc7bb78a73a421055ad56fc619c diff --git a/views/matrix_chat/index.php b/views/matrix_chat/index.php index 2e87762ccf117b774e911a343a46f6e384539f15..c633d59e23dc42a14a878cee44651c16769de2c3 100644 --- a/views/matrix_chat/index.php +++ b/views/matrix_chat/index.php @@ -21,5 +21,5 @@ <?= Assets::img('ajax-indicator-black.svg') ?> </div> <? else : ?> - <iframe src="http://localhost/element" width="100%" height="100%"></iframe> + <iframe src="<?php echo htmlReady(Config::get()->MATRIX_CHATSERVER_URL) ?>" width="100%" height="100%"></iframe> <? endif;