Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MatrixPlugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stud.IP
Plugins
MatrixPlugin
Commits
92e79931
Commit
92e79931
authored
Sep 20, 2021
by
Thomas Hackl
Browse files
Options
Downloads
Patches
Plain Diff
post room message on news creation or update
parent
e0cf040a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
MatrixPlugin.php
+25
-4
25 additions, 4 deletions
MatrixPlugin.php
controllers/matrix_chat.php
+0
-5
0 additions, 5 deletions
controllers/matrix_chat.php
models/MatrixRoom.php
+0
-23
0 additions, 23 deletions
models/MatrixRoom.php
with
25 additions
and
32 deletions
MatrixPlugin.php
+
25
−
4
View file @
92e79931
...
...
@@ -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
*/
p
rivate
function
invite
(
$event
,
$membership
)
p
ublic
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
*/
p
rivate
function
uninvite
(
$event
,
$membership
)
p
ublic
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
*/
p
rivate
function
unregister
(
$event
,
$user
)
p
ublic
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
*/
p
rivate
function
deleteRoom
(
$event
,
$course
)
p
ublic
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
This diff is collapsed.
Click to expand it.
controllers/matrix_chat.php
+
0
−
5
View file @
92e79931
...
...
@@ -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>!'
);
}
}
...
...
This diff is collapsed.
Click to expand it.
models/MatrixRoom.php
+
0
−
23
View file @
92e79931
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment