versions.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright 2016 OpenMarket Ltd
  2. # Copyright 2017 Vector Creations Ltd
  3. # Copyright 2018-2019 New Vector Ltd
  4. # Copyright 2019 The Matrix.org Foundation C.I.C.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import logging
  18. import re
  19. from typing import TYPE_CHECKING, Tuple
  20. from twisted.web.server import Request
  21. from synapse.api.constants import RoomCreationPreset
  22. from synapse.http.server import HttpServer
  23. from synapse.http.servlet import RestServlet
  24. from synapse.types import JsonDict
  25. if TYPE_CHECKING:
  26. from synapse.server import HomeServer
  27. logger = logging.getLogger(__name__)
  28. class VersionsRestServlet(RestServlet):
  29. PATTERNS = [re.compile("^/_matrix/client/versions$")]
  30. def __init__(self, hs: "HomeServer"):
  31. super().__init__()
  32. self.config = hs.config
  33. # Calculate these once since they shouldn't change after start-up.
  34. self.e2ee_forced_public = (
  35. RoomCreationPreset.PUBLIC_CHAT
  36. in self.config.room.encryption_enabled_by_default_for_room_presets
  37. )
  38. self.e2ee_forced_private = (
  39. RoomCreationPreset.PRIVATE_CHAT
  40. in self.config.room.encryption_enabled_by_default_for_room_presets
  41. )
  42. self.e2ee_forced_trusted_private = (
  43. RoomCreationPreset.TRUSTED_PRIVATE_CHAT
  44. in self.config.room.encryption_enabled_by_default_for_room_presets
  45. )
  46. def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
  47. return (
  48. 200,
  49. {
  50. "versions": [
  51. # XXX: at some point we need to decide whether we need to include
  52. # the previous version numbers, given we've defined r0.3.0 to be
  53. # backwards compatible with r0.2.0. But need to check how
  54. # conscientious we've been in compatibility, and decide whether the
  55. # middle number is the major revision when at 0.X.Y (as opposed to
  56. # X.Y.Z). And we need to decide whether it's fair to make clients
  57. # parse the version string to figure out what's going on.
  58. "r0.0.1",
  59. "r0.1.0",
  60. "r0.2.0",
  61. "r0.3.0",
  62. "r0.4.0",
  63. "r0.5.0",
  64. "r0.6.0",
  65. "r0.6.1",
  66. "v1.1",
  67. "v1.2",
  68. ],
  69. # as per MSC1497:
  70. "unstable_features": {
  71. # Implements support for label-based filtering as described in
  72. # MSC2326.
  73. "org.matrix.label_based_filtering": True,
  74. # Implements support for cross signing as described in MSC1756
  75. "org.matrix.e2e_cross_signing": True,
  76. # Implements additional endpoints as described in MSC2432
  77. "org.matrix.msc2432": True,
  78. # Implements additional endpoints as described in MSC2666
  79. "uk.half-shot.msc2666.mutual_rooms": True,
  80. # Whether new rooms will be set to encrypted or not (based on presets).
  81. "io.element.e2ee_forced.public": self.e2ee_forced_public,
  82. "io.element.e2ee_forced.private": self.e2ee_forced_private,
  83. "io.element.e2ee_forced.trusted_private": self.e2ee_forced_trusted_private,
  84. # Supports the busy presence state described in MSC3026.
  85. "org.matrix.msc3026.busy_presence": self.config.experimental.msc3026_enabled,
  86. # Supports receiving private read receipts as per MSC2285
  87. "org.matrix.msc2285": self.config.experimental.msc2285_enabled,
  88. # Adds support for importing historical messages as per MSC2716
  89. "org.matrix.msc2716": self.config.experimental.msc2716_enabled,
  90. # Adds support for jump to date endpoints (/timestamp_to_event) as per MSC3030
  91. "org.matrix.msc3030": self.config.experimental.msc3030_enabled,
  92. # Adds support for thread relations, per MSC3440.
  93. "org.matrix.msc3440.stable": True, # TODO: remove when "v1.3" is added above
  94. # Allows moderators to fetch redacted event content as described in MSC2815
  95. "fi.mau.msc2815": self.config.experimental.msc2815_enabled,
  96. },
  97. },
  98. )
  99. def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
  100. VersionsRestServlet(hs).register(http_server)