You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
3.0 KiB

  1. # Copyright 2018 New Vector Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from synapse.types import UserID
  15. from ._base import Config
  16. DEFAULT_CONFIG = """\
  17. # Server Notices room configuration
  18. #
  19. # Uncomment this section to enable a room which can be used to send notices
  20. # from the server to users. It is a special room which cannot be left; notices
  21. # come from a special "notices" user id.
  22. #
  23. # If you uncomment this section, you *must* define the system_mxid_localpart
  24. # setting, which defines the id of the user which will be used to send the
  25. # notices.
  26. #
  27. # It's also possible to override the room name, the display name of the
  28. # "notices" user, and the avatar for the user.
  29. #
  30. #server_notices:
  31. # system_mxid_localpart: notices
  32. # system_mxid_display_name: "Server Notices"
  33. # system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"
  34. # room_name: "Server Notices"
  35. """
  36. class ServerNoticesConfig(Config):
  37. """Configuration for the server notices room.
  38. Attributes:
  39. server_notices_mxid (str|None):
  40. The MXID to use for server notices.
  41. None if server notices are not enabled.
  42. server_notices_mxid_display_name (str|None):
  43. The display name to use for the server notices user.
  44. None if server notices are not enabled.
  45. server_notices_mxid_avatar_url (str|None):
  46. The MXC URL for the avatar of the server notices user.
  47. None if server notices are not enabled.
  48. server_notices_room_name (str|None):
  49. The name to use for the server notices room.
  50. None if server notices are not enabled.
  51. """
  52. section = "servernotices"
  53. def __init__(self, *args):
  54. super().__init__(*args)
  55. self.server_notices_mxid = None
  56. self.server_notices_mxid_display_name = None
  57. self.server_notices_mxid_avatar_url = None
  58. self.server_notices_room_name = None
  59. def read_config(self, config, **kwargs):
  60. c = config.get("server_notices")
  61. if c is None:
  62. return
  63. mxid_localpart = c["system_mxid_localpart"]
  64. self.server_notices_mxid = UserID(mxid_localpart, self.server_name).to_string()
  65. self.server_notices_mxid_display_name = c.get("system_mxid_display_name", None)
  66. self.server_notices_mxid_avatar_url = c.get("system_mxid_avatar_url", None)
  67. # todo: i18n
  68. self.server_notices_room_name = c.get("room_name", "Server Notices")
  69. def generate_config_section(self, **kwargs):
  70. return DEFAULT_CONFIG