server_notices_config.py 3.0 KB

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