Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
0eb7e697
Unverified
Commit
0eb7e697
authored
2 years ago
by
David Robertson
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Notifier: accept callbacks to fire on room joins (#13254)
parent
cc107159
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/13254.misc
+1
-0
1 addition, 0 deletions
changelog.d/13254.misc
synapse/notifier.py
+18
-0
18 additions, 0 deletions
synapse/notifier.py
with
19 additions
and
0 deletions
changelog.d/13254.misc
0 → 100644
+
1
−
0
View file @
0eb7e697
Preparatory work for a per-room rate limiter on joins.
This diff is collapsed.
Click to expand it.
synapse/notifier.py
+
18
−
0
View file @
0eb7e697
...
@@ -228,6 +228,7 @@ class Notifier:
...
@@ -228,6 +228,7 @@ class Notifier:
# Called when there are new things to stream over replication
# Called when there are new things to stream over replication
self
.
replication_callbacks
:
List
[
Callable
[[],
None
]]
=
[]
self
.
replication_callbacks
:
List
[
Callable
[[],
None
]]
=
[]
self
.
_new_join_in_room_callbacks
:
List
[
Callable
[[
str
,
str
],
None
]]
=
[]
self
.
_federation_client
=
hs
.
get_federation_http_client
()
self
.
_federation_client
=
hs
.
get_federation_http_client
()
...
@@ -280,6 +281,19 @@ class Notifier:
...
@@ -280,6 +281,19 @@ class Notifier:
"""
"""
self
.
replication_callbacks
.
append
(
cb
)
self
.
replication_callbacks
.
append
(
cb
)
def
add_new_join_in_room_callback
(
self
,
cb
:
Callable
[[
str
,
str
],
None
])
->
None
:
"""
Add a callback that will be called when a user joins a room.
This only fires on genuine membership changes, e.g.
"
invite
"
->
"
join
"
.
Membership transitions like
"
join
"
->
"
join
"
(for e.g. displayname changes) do
not trigger the callback.
When called, the callback receives two arguments: the event ID and the room ID.
It should *not* return a Deferred - if it needs to do any asynchronous work, a
background thread should be started and wrapped with run_as_background_process.
"""
self
.
_new_join_in_room_callbacks
.
append
(
cb
)
async
def
on_new_room_event
(
async
def
on_new_room_event
(
self
,
self
,
event
:
EventBase
,
event
:
EventBase
,
...
@@ -723,6 +737,10 @@ class Notifier:
...
@@ -723,6 +737,10 @@ class Notifier:
for
cb
in
self
.
replication_callbacks
:
for
cb
in
self
.
replication_callbacks
:
cb
()
cb
()
def
notify_user_joined_room
(
self
,
event_id
:
str
,
room_id
:
str
)
->
None
:
for
cb
in
self
.
_new_join_in_room_callbacks
:
cb
(
event_id
,
room_id
)
def
notify_remote_server_up
(
self
,
server
:
str
)
->
None
:
def
notify_remote_server_up
(
self
,
server
:
str
)
->
None
:
"""
Notify any replication that a remote server has come back up
"""
"""
Notify any replication that a remote server has come back up
"""
# We call federation_sender directly rather than registering as a
# We call federation_sender directly rather than registering as a
...
...
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