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

post room message on news creation or update

parent e0cf040a
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,8 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
NotificationCenter::addObserver($this, 'uninvite', 'CourseMemberDidDelete');
NotificationCenter::addObserver($this, 'unregister', 'UserDidDelete');
NotificationCenter::addObserver($this, 'deleteRoom', 'CourseDidDelete');
NotificationCenter::addObserver($this, 'postNews', 'StudipNewsDidCreate');
NotificationCenter::addObserver($this, 'postNews', 'StudipNewsDidUpdate');
$this->addScript('assets/javascripts/matrixchat.js');
$this->addStylesheet('assets/stylesheets/matrixchat.scss');
......@@ -130,7 +132,7 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
* @param string $event
* @param CourseMember $membership
*/
private function invite($event, $membership)
public function invite($event, $membership)
{
if ($matrix = MatrixAccount::findByUser_id($membership->user_id) &&
$room = MatrixRoom::findByRange_id($membership->seminar_id)) {
......@@ -148,7 +150,7 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
* @param string $event
* @param CourseMember $membership
*/
private function uninvite($event, $membership)
public function uninvite($event, $membership)
{
if ($matrix = MatrixAccount::findByUser_id($membership->user_id) &&
$room = MatrixRoom::findByRange_id($membership->seminar_id)) {
......@@ -166,7 +168,7 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
* @param string $event
* @param User $user
*/
private function unregister($event, $user)
public function unregister($event, $user)
{
if ($account = MatrixAccount::findByUser_id($user->id)) {
if (MatrixClient::get()->deactivateAccount($account->getLinkedAccount())) {
......@@ -181,7 +183,7 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
* @param string $event
* @param Course $course
*/
private function deleteRoom($event, $course)
public function deleteRoom($event, $course)
{
if ($room = MatrixRoom::findByRange_id($course->id)) {
MatrixClient::get()->deleteRoom(
......@@ -191,4 +193,23 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
}
}
/**
* Auto-post course news to associated Matrix room if configured.
*
* @param string $event
* @param StudipNews $news
*/
public function postNews($event, $news)
{
foreach ($news->news_ranges as $range) {
if ($range->course && MatrixRoom::hasRoom($range->course->id)) {
MatrixClient::get()->postMessage(
MatrixAccount::requireSystemAccount(),
MatrixRoom::find($range->course->id)->getLinkedRoom(),
$news->topic
);
}
}
}
}
\ No newline at end of file
......@@ -51,11 +51,6 @@ class MatrixChatController extends AuthenticatedController
$this->hasToCreate = false;
$room->requireMembership($this->account->getLinkedAccount());
$room->sendMessage(
'Avengers... assemble.',
'<!-- HTML -->Hulk <strong>SMASH</strong>!'
);
}
}
......
......@@ -158,27 +158,4 @@ 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment