experimental.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. # MSC3983: Proxying OTK claim requests to exclusive ASes.
  60. self.msc3983_appservice_otk_claims: bool = experimental.get(
  61. "msc3983_appservice_otk_claims", False
  62. )
  63. # MSC3984: Proxying key queries to exclusive ASes.
  64. self.msc3984_appservice_key_query: bool = experimental.get(
  65. "msc3984_appservice_key_query", False
  66. )
  67. # MSC3706 (server-side support for partial state in /send_join responses)
  68. # Synapse will always serve partial state responses to requests using the stable
  69. # query parameter `omit_members`. If this flag is set, Synapse will also serve
  70. # partial state responses to requests using the unstable query parameter
  71. # `org.matrix.msc3706.partial_state`.
  72. self.msc3706_enabled: bool = experimental.get("msc3706_enabled", False)
  73. # experimental support for faster joins over federation
  74. # (MSC2775, MSC3706, MSC3895)
  75. # requires a target server that can provide a partial join response (MSC3706)
  76. self.faster_joins_enabled: bool = experimental.get("faster_joins", True)
  77. # MSC3720 (Account status endpoint)
  78. self.msc3720_enabled: bool = experimental.get("msc3720_enabled", False)
  79. # MSC2654: Unread counts
  80. #
  81. # Note that enabling this will result in an incorrect unread count for
  82. # previously calculated push actions.
  83. self.msc2654_enabled: bool = experimental.get("msc2654_enabled", False)
  84. # MSC2815 (allow room moderators to view redacted event content)
  85. self.msc2815_enabled: bool = experimental.get("msc2815_enabled", False)
  86. # MSC3391: Removing account data.
  87. self.msc3391_enabled = experimental.get("msc3391_enabled", False)
  88. # MSC3773: Thread notifications
  89. self.msc3773_enabled: bool = experimental.get("msc3773_enabled", False)
  90. # MSC3664: Pushrules to match on related events
  91. self.msc3664_enabled: bool = experimental.get("msc3664_enabled", False)
  92. # MSC3848: Introduce errcodes for specific event sending failures
  93. self.msc3848_enabled: bool = experimental.get("msc3848_enabled", False)
  94. # MSC3852: Expose last seen user agent field on /_matrix/client/v3/devices.
  95. self.msc3852_enabled: bool = experimental.get("msc3852_enabled", False)
  96. # MSC3866: M_USER_AWAITING_APPROVAL error code
  97. raw_msc3866_config = experimental.get("msc3866", {})
  98. self.msc3866 = MSC3866Config(**raw_msc3866_config)
  99. # MSC3881: Remotely toggle push notifications for another client
  100. self.msc3881_enabled: bool = experimental.get("msc3881_enabled", False)
  101. # MSC3882: Allow an existing session to sign in a new session
  102. self.msc3882_enabled: bool = experimental.get("msc3882_enabled", False)
  103. self.msc3882_ui_auth: bool = experimental.get("msc3882_ui_auth", True)
  104. self.msc3882_token_timeout = self.parse_duration(
  105. experimental.get("msc3882_token_timeout", "5m")
  106. )
  107. # MSC3874: Filtering /messages with rel_types / not_rel_types.
  108. self.msc3874_enabled: bool = experimental.get("msc3874_enabled", False)
  109. # MSC3886: Simple client rendezvous capability
  110. self.msc3886_endpoint: Optional[str] = experimental.get(
  111. "msc3886_endpoint", None
  112. )
  113. # MSC3890: Remotely silence local notifications
  114. # Note: This option requires "experimental_features.msc3391_enabled" to be
  115. # set to "true", in order to communicate account data deletions to clients.
  116. self.msc3890_enabled: bool = experimental.get("msc3890_enabled", False)
  117. if self.msc3890_enabled and not self.msc3391_enabled:
  118. raise ConfigError(
  119. "Option 'experimental_features.msc3391' must be set to 'true' to "
  120. "enable 'experimental_features.msc3890'. MSC3391 functionality is "
  121. "required to communicate account data deletions to clients."
  122. )
  123. # MSC3381: Polls.
  124. # In practice, supporting polls in Synapse only requires an implementation of
  125. # MSC3930: Push rules for MSC3391 polls; which is what this option enables.
  126. self.msc3381_polls_enabled: bool = experimental.get(
  127. "msc3381_polls_enabled", False
  128. )
  129. # MSC3912: Relation-based redactions.
  130. self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False)
  131. # MSC1767 and friends: Extensible Events
  132. self.msc1767_enabled: bool = experimental.get("msc1767_enabled", False)
  133. if self.msc1767_enabled:
  134. # Enable room version (and thus applicable push rules from MSC3931/3932)
  135. version_id = RoomVersions.MSC1767v10.identifier
  136. KNOWN_ROOM_VERSIONS[version_id] = RoomVersions.MSC1767v10
  137. # MSC3391: Removing account data.
  138. self.msc3391_enabled = experimental.get("msc3391_enabled", False)
  139. # MSC3952: Intentional mentions, this depends on MSC3966.
  140. self.msc3952_intentional_mentions = experimental.get(
  141. "msc3952_intentional_mentions", False
  142. )
  143. # MSC3959: Do not generate notifications for edits.
  144. self.msc3958_supress_edit_notifs = experimental.get(
  145. "msc3958_supress_edit_notifs", False
  146. )
  147. # MSC3967: Do not require UIA when first uploading cross signing keys
  148. self.msc3967_enabled = experimental.get("msc3967_enabled", False)
  149. # MSC3981: Recurse relations
  150. self.msc3981_recurse_relations = experimental.get(
  151. "msc3981_recurse_relations", False
  152. )
  153. # MSC3970: Scope transaction IDs to devices
  154. self.msc3970_enabled = experimental.get("msc3970_enabled", False)
  155. # MSC4009: E.164 Matrix IDs
  156. self.msc4009_e164_mxids = experimental.get("msc4009_e164_mxids", False)
  157. # MSC4010: Do not allow setting m.push_rules account data.
  158. self.msc4010_push_rules_account_data = experimental.get(
  159. "msc4010_push_rules_account_data", False
  160. )