diff --git a/controllers/matrix_chat.php b/controllers/matrix_chat.php index 62538a352434c8efe9fae5d6894638ff16c4ce4b..ffc66df015fb8782eea25cdebdce7f2f7409e35b 100644 --- a/controllers/matrix_chat.php +++ b/controllers/matrix_chat.php @@ -51,8 +51,14 @@ class MatrixChatController extends AuthenticatedController $this->hasToCreate = false; $room->requireMembership($this->account->getLinkedAccount()); + + $room->sendMessage( + 'Avengers... assemble.', + '<!-- HTML -->Hulk <strong>SMASH</strong>!' + ); } } + } public function require_room_action() diff --git a/models/MatrixRoom.php b/models/MatrixRoom.php index ac8db994d4d8878da2fb9f233bad350cd45251e2..7caf4fe44be62c5e4a7f64330aab849c3e0cfa26 100644 --- a/models/MatrixRoom.php +++ b/models/MatrixRoom.php @@ -104,7 +104,7 @@ class MatrixRoom extends SimpleORMap ); $newRoom = MatrixClient::get()->createRoom($sysaccount, Context::getHeaderLine(), false, '', - [],$permission_set); + [], $permission_set); $mapping = new self(); $mapping->range_id = $context->getId(); @@ -158,4 +158,27 @@ class MatrixRoom extends SimpleORMap } } + /** + * Sends a message into the current room, sender is the Stud.IP system account. + * + * @param string $title + * @param string $body + */ + public function sendMessage($title, $body) + { + $content = [ + 'msgtype' => 'm.text', + 'format' => 'm.format.custom_html', + 'body' => strip_tags($title . ":\n" . $body), + 'formatted_body' => htmlReady('<strong>' . $title . '</strong><br>' . $body), + ]; + MatrixClient::get()->sendRoomEvent( + MatrixAccount::requireSystemAccount(), + $this->getLinkedRoom(), + 'm.room.message', + '', + $content + ); + } + } \ No newline at end of file