Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Allow overriding the server_notices user's avatar
Browse files Browse the repository at this point in the history
probably should have done this in the first place, like @turt2live suggested.
  • Loading branch information
richvdh committed May 23, 2018
1 parent 043f05a commit 9bf4b2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
9 changes: 6 additions & 3 deletions docs/server_notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ section, which should look like this:
server_notices:
system_mxid_localpart: server
system_mxid_display_name: "Server Notices"
system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"
room_name: "Server Notices"
```
The only compulsory setting is `system_mxid_localpart`, which defines the user
id of the server notices user, as above. `system_mxid_display_name` and
`room_name` define the displayname of the system notices user, and of
the notices room, respectively.
id of the Server Notices user, as above. `room_name` defines the name of the
room which will be created.

`system_mxid_display_name` and `system_mxid_avatar_url` can be used to set the
displayname and avatar of the Server Notices user.

Sending notices
---------------
Expand Down
15 changes: 12 additions & 3 deletions synapse/config/server_notices_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
# setting, which defines the id of the user which will be used to send the
# notices.
#
# It's also possible to override the room name, or the display name of the
# "notices" user.
# It's also possible to override the room name, the display name of the
# "notices" user, and the avatar for the user.
#
# server_notices:
# system_mxid_localpart: notices
# system_mxid_display_name: "Server Notices"
# system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"

This comment has been minimized.

Copy link
@rubo77

rubo77 Jun 14, 2018

Contributor

please explain, how to get this mcx URL. When I copy the URL of any Avatar, I get an URL like

https://matrix.myserver.de/_matrix/media/v1/download/matrix.myserver.de/greUvyYjEsnkDaenIguVCHVa

How does the mxc have to look like in this case?

# room_name: "Server Notices"
"""

Expand All @@ -48,6 +49,10 @@ class ServerNoticesConfig(Config):
The display name to use for the server notices user.
None if server notices are not enabled.
server_notices_mxid_avatar_url (str|None):
The display name to use for the server notices user.
None if server notices are not enabled.
server_notices_room_name (str|None):
The name to use for the server notices room.
None if server notices are not enabled.
Expand All @@ -56,6 +61,7 @@ def __init__(self):
super(ServerNoticesConfig, self).__init__()
self.server_notices_mxid = None
self.server_notices_mxid_display_name = None
self.server_notices_mxid_avatar_url = None
self.server_notices_room_name = None

def read_config(self, config):
Expand All @@ -68,7 +74,10 @@ def read_config(self, config):
mxid_localpart, self.server_name,
).to_string()
self.server_notices_mxid_display_name = c.get(
'system_mxid_display_name', 'Server Notices',
'system_mxid_display_name', None,
)
self.server_notices_mxid_avatar_url = c.get(
'system_mxid_avatar_url', None,
)
# todo: i18n
self.server_notices_room_name = c.get('room_name', "Server Notices")
Expand Down
17 changes: 14 additions & 3 deletions synapse/server_notices/server_notices_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ def get_notice_room_for_user(self, user_id):
# apparently no existing notice room: create a new one
logger.info("Creating server notices room for %s", user_id)

# see if we want to override the profile info for the server user.
# note that if we want to override either the display name or the
# avatar, we have to use both.
join_profile = None
if (
self._config.server_notices_mxid_display_name is not None or
self._config.server_notices_mxid_avatar_url is not None
):
join_profile = {
"displayname": self._config.server_notices_mxid_display_name,
"avatar_url": self._config.server_notices_mxid_avatar_url,
}

requester = create_requester(system_mxid)
info = yield self._room_creation_handler.create_room(
requester,
Expand All @@ -125,9 +138,7 @@ def get_notice_room_for_user(self, user_id):
"invite": (user_id,)
},
ratelimit=False,
creator_join_profile={
"displayname": self._config.server_notices_mxid_display_name,
},
creator_join_profile=join_profile,
)
room_id = info['room_id']

Expand Down

0 comments on commit 9bf4b2b

Please sign in to comment.