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.
 
 
 
 
 
 

176 lines
7.8 KiB

  1. # Copyright 2021 The Matrix.org Foundation C.I.C.
  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 typing import Any, Optional
  15. import attr
  16. from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersions
  17. from synapse.config import ConfigError
  18. from synapse.config._base import Config
  19. from synapse.types import JsonDict
  20. @attr.s(auto_attribs=True, frozen=True, slots=True)
  21. class MSC3866Config:
  22. """Configuration for MSC3866 (mandating approval for new users)"""
  23. # Whether the base support for the approval process is enabled. This includes the
  24. # ability for administrators to check and update the approval of users, even if no
  25. # approval is currently required.
  26. enabled: bool = False
  27. # Whether to require that new users are approved by an admin before their account
  28. # can be used. Note that this setting is ignored if 'enabled' is false.
  29. require_approval_for_new_accounts: bool = False
  30. class ExperimentalConfig(Config):
  31. """Config section for enabling experimental features"""
  32. section = "experimental"
  33. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  34. experimental = config.get("experimental_features") or {}
  35. # MSC3026 (busy presence state)
  36. self.msc3026_enabled: bool = experimental.get("msc3026_enabled", False)
  37. # MSC2716 (importing historical messages)
  38. self.msc2716_enabled: bool = experimental.get("msc2716_enabled", False)
  39. # MSC3244 (room version capabilities)
  40. self.msc3244_enabled: bool = experimental.get("msc3244_enabled", True)
  41. # MSC3266 (room summary api)
  42. self.msc3266_enabled: bool = experimental.get("msc3266_enabled", False)
  43. # MSC2409 (this setting only relates to optionally sending to-device messages).
  44. # Presence, typing and read receipt EDUs are already sent to application services that
  45. # have opted in to receive them. If enabled, this adds to-device messages to that list.
  46. self.msc2409_to_device_messages_enabled: bool = experimental.get(
  47. "msc2409_to_device_messages_enabled", False
  48. )
  49. # The portion of MSC3202 which is related to device masquerading.
  50. self.msc3202_device_masquerading_enabled: bool = experimental.get(
  51. "msc3202_device_masquerading", False
  52. )
  53. # The portion of MSC3202 related to transaction extensions:
  54. # sending device list changes, one-time key counts and fallback key
  55. # usage to application services.
  56. self.msc3202_transaction_extensions: bool = experimental.get(
  57. "msc3202_transaction_extensions", False
  58. )
  59. # MSC3706 (server-side support for partial state in /send_join responses)
  60. # Synapse will always serve partial state responses to requests using the stable
  61. # query parameter `omit_members`. If this flag is set, Synapse will also serve
  62. # partial state responses to requests using the unstable query parameter
  63. # `org.matrix.msc3706.partial_state`.
  64. self.msc3706_enabled: bool = experimental.get("msc3706_enabled", False)
  65. # experimental support for faster joins over federation
  66. # (MSC2775, MSC3706, MSC3895)
  67. # requires a target server that can provide a partial join response (MSC3706)
  68. self.faster_joins_enabled: bool = experimental.get("faster_joins", True)
  69. # MSC3720 (Account status endpoint)
  70. self.msc3720_enabled: bool = experimental.get("msc3720_enabled", False)
  71. # MSC2654: Unread counts
  72. #
  73. # Note that enabling this will result in an incorrect unread count for
  74. # previously calculated push actions.
  75. self.msc2654_enabled: bool = experimental.get("msc2654_enabled", False)
  76. # MSC2815 (allow room moderators to view redacted event content)
  77. self.msc2815_enabled: bool = experimental.get("msc2815_enabled", False)
  78. # MSC3391: Removing account data.
  79. self.msc3391_enabled = experimental.get("msc3391_enabled", False)
  80. # MSC3773: Thread notifications
  81. self.msc3773_enabled: bool = experimental.get("msc3773_enabled", False)
  82. # MSC3664: Pushrules to match on related events
  83. self.msc3664_enabled: bool = experimental.get("msc3664_enabled", False)
  84. # MSC3848: Introduce errcodes for specific event sending failures
  85. self.msc3848_enabled: bool = experimental.get("msc3848_enabled", False)
  86. # MSC3852: Expose last seen user agent field on /_matrix/client/v3/devices.
  87. self.msc3852_enabled: bool = experimental.get("msc3852_enabled", False)
  88. # MSC3866: M_USER_AWAITING_APPROVAL error code
  89. raw_msc3866_config = experimental.get("msc3866", {})
  90. self.msc3866 = MSC3866Config(**raw_msc3866_config)
  91. # MSC3881: Remotely toggle push notifications for another client
  92. self.msc3881_enabled: bool = experimental.get("msc3881_enabled", False)
  93. # MSC3882: Allow an existing session to sign in a new session
  94. self.msc3882_enabled: bool = experimental.get("msc3882_enabled", False)
  95. self.msc3882_ui_auth: bool = experimental.get("msc3882_ui_auth", True)
  96. self.msc3882_token_timeout = self.parse_duration(
  97. experimental.get("msc3882_token_timeout", "5m")
  98. )
  99. # MSC3874: Filtering /messages with rel_types / not_rel_types.
  100. self.msc3874_enabled: bool = experimental.get("msc3874_enabled", False)
  101. # MSC3886: Simple client rendezvous capability
  102. self.msc3886_endpoint: Optional[str] = experimental.get(
  103. "msc3886_endpoint", None
  104. )
  105. # MSC3890: Remotely silence local notifications
  106. # Note: This option requires "experimental_features.msc3391_enabled" to be
  107. # set to "true", in order to communicate account data deletions to clients.
  108. self.msc3890_enabled: bool = experimental.get("msc3890_enabled", False)
  109. if self.msc3890_enabled and not self.msc3391_enabled:
  110. raise ConfigError(
  111. "Option 'experimental_features.msc3391' must be set to 'true' to "
  112. "enable 'experimental_features.msc3890'. MSC3391 functionality is "
  113. "required to communicate account data deletions to clients."
  114. )
  115. # MSC3381: Polls.
  116. # In practice, supporting polls in Synapse only requires an implementation of
  117. # MSC3930: Push rules for MSC3391 polls; which is what this option enables.
  118. self.msc3381_polls_enabled: bool = experimental.get(
  119. "msc3381_polls_enabled", False
  120. )
  121. # MSC3912: Relation-based redactions.
  122. self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False)
  123. # MSC1767 and friends: Extensible Events
  124. self.msc1767_enabled: bool = experimental.get("msc1767_enabled", False)
  125. if self.msc1767_enabled:
  126. # Enable room version (and thus applicable push rules from MSC3931/3932)
  127. version_id = RoomVersions.MSC1767v10.identifier
  128. KNOWN_ROOM_VERSIONS[version_id] = RoomVersions.MSC1767v10
  129. # MSC3391: Removing account data.
  130. self.msc3391_enabled = experimental.get("msc3391_enabled", False)
  131. # MSC3925: do not replace events with their edits
  132. self.msc3925_inhibit_edit = experimental.get("msc3925_inhibit_edit", False)
  133. # MSC3952: Intentional mentions
  134. self.msc3952_intentional_mentions = experimental.get(
  135. "msc3952_intentional_mentions", False
  136. )