Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
eabc5f82
Commit
eabc5f82
authored
6 years ago
by
Neil Johnson
Browse files
Options
Downloads
Patches
Plain Diff
wip cut at sending resource server notices
parent
c24fc979
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
synapse/server_notices/resource_limits_server_notices.py
+35
-34
35 additions, 34 deletions
synapse/server_notices/resource_limits_server_notices.py
synapse/server_notices/server_notices_manager.py
+20
-10
20 additions, 10 deletions
synapse/server_notices/server_notices_manager.py
with
55 additions
and
44 deletions
synapse/server_notices/resource_limits_server_notices.py
+
35
−
34
View file @
eabc5f82
...
...
@@ -40,6 +40,7 @@ class ResourceLimitsServerNotices(object):
self
.
_notified_of_blocking
=
set
()
self
.
_resouce_limited
=
False
# Config checks?
@defer.inlineCallbacks
...
...
@@ -69,43 +70,43 @@ class ResourceLimitsServerNotices(object):
self
.
_resouce_limited
=
False
# Need to start removing notices
if
user_id
in
self
.
_notified_of_blocking
:
# Send message to remove warning - needs updating
# Send message to remove warning
# send state event here
# How do I do this? if drop the id, how to refer to it?
content
=
{
'
body
'
:
''
,
'
admin_email
'
:
''
,
"
pinned
"
:[]
}
self
.
_send_server_notice
(
user_id
,
content
)
yield
self
.
_server_notices_manager
.
send_notice
(
user_id
,
content
,
EventTypes
.
Pinned
,
''
,
)
self
.
_notified_of_blocking
.
remove
(
user_id
)
except
AuthError
as
e
:
# Need to start notifying of blocking
self
.
_resouce_limited
=
True
if
user_id
not
in
self
.
_notified_of_blocking
:
# TODO use admin email contained in error once PR lands
content
=
{
'
body
'
:
e
.
msg
,
'
admin_email
'
:
'
stunt@adminemail.com
'
,
'
msgtype
'
:
'
m.text
'
}
self
.
_send_server_notice
(
user_id
,
content
)
self
.
_notified_of_blocking
.
add
(
user_id
)
@defer.inlineCallbacks
def
_send_server_notice
(
self
,
user_id
,
content
):
"""
Sends Server notice
Args:
user_id(str): The user to send to
content(str): The content of the message
Returns:
Deferred[]
"""
try
:
yield
self
.
_server_notices_manager
.
send_notice
(
user_id
,
content
)
except
SynapseError
as
e
:
logger
.
error
(
"
Error sending server notice about resource limits: %s
"
,
e
)
try
:
self
.
_resouce_limited
=
True
if
user_id
not
in
self
.
_notified_of_blocking
:
# TODO use admin email contained in error once PR lands
content
=
{
'
body
'
:
e
.
msg
,
'
admin_email
'
:
'
stunt@adminemail.com
'
,
}
event
=
yield
self
.
_server_notices_manager
.
send_notice
(
user_id
,
content
,
EventTypes
.
ServerNoticeLimitReached
)
# send server notices state event here
# TODO Over writing pinned events
content
=
{
"
pinned
"
:[
event
.
event_id
,
]
}
yield
self
.
_server_notices_manager
.
send_notice
(
user_id
,
content
,
EventTypes
.
Pinned
,
''
,
)
self
.
_notified_of_blocking
.
add
(
user_id
)
except
SynapseError
as
e
:
logger
.
error
(
"
Error sending server notice about resource limits: %s
"
,
e
)
This diff is collapsed.
Click to expand it.
synapse/server_notices/server_notices_manager.py
+
20
−
10
View file @
eabc5f82
...
...
@@ -46,7 +46,10 @@ class ServerNoticesManager(object):
return
self
.
_config
.
server_notices_mxid
is
not
None
@defer.inlineCallbacks
def
send_notice
(
self
,
user_id
,
event_content
):
def
send_notice
(
self
,
user_id
,
event_content
,
type
=
EventTypes
.
Message
,
state_key
=
None
):
"""
Send a notice to the given user
Creates the server notices room, if none exists.
...
...
@@ -54,9 +57,11 @@ class ServerNoticesManager(object):
Args:
user_id (str): mxid of user to send event to.
event_content (dict): content of event to send
type(EventTypes): type of event
is_state_event(bool): Is the event a state event
Returns:
Deferred[
None
]
Deferred[
FrozenEvent
]
"""
room_id
=
yield
self
.
get_notice_room_for_user
(
user_id
)
...
...
@@ -65,15 +70,19 @@ class ServerNoticesManager(object):
logger
.
info
(
"
Sending server notice to %s
"
,
user_id
)
yield
self
.
_event_creation_handler
.
create_and_send_nonmember_event
(
requester
,
{
"
type
"
:
EventTypes
.
Message
,
"
room_id
"
:
room_id
,
"
sender
"
:
system_mxid
,
"
content
"
:
event_content
,
},
ratelimit
=
False
,
event_dict
=
{
"
type
"
:
type
,
"
room_id
"
:
room_id
,
"
sender
"
:
system_mxid
,
"
content
"
:
event_content
,
}
if
state_key
:
event_dict
[
'
state_key
'
]
=
state_key
res
=
yield
self
.
_event_creation_handler
.
create_and_send_nonmember_event
(
requester
,
event_dict
,
ratelimit
=
False
,
)
defer
.
returnValue
(
res
)
@cachedInlineCallbacks
()
def
get_notice_room_for_user
(
self
,
user_id
):
...
...
@@ -141,6 +150,7 @@ class ServerNoticesManager(object):
creator_join_profile
=
join_profile
,
)
room_id
=
info
[
'
room_id
'
]
yield
self
.
_store
.
add_tag_to_room
(
user_id
,
room_id
,
'
m.server_notice
'
,
None
)
logger
.
info
(
"
Created server notices room %s for %s
"
,
room_id
,
user_id
)
defer
.
returnValue
(
room_id
)
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