We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add a capabilties flag for MSC3440
Per https://github.com/matrix-org/matrix-doc/commit/fc81bbd836955876c931c95277249981b3e2778c



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `synapse/rest/client/capabilities.py`
Content:
```
1 # Copyright 2019 New Vector
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 import logging
15 from typing import TYPE_CHECKING, Tuple
16 
17 from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, MSC3244_CAPABILITIES
18 from synapse.http.server import HttpServer
19 from synapse.http.servlet import RestServlet
20 from synapse.http.site import SynapseRequest
21 from synapse.types import JsonDict
22 
23 from ._base import client_patterns
24 
25 if TYPE_CHECKING:
26     from synapse.server import HomeServer
27 
28 logger = logging.getLogger(__name__)
29 
30 
31 class CapabilitiesRestServlet(RestServlet):
32     """End point to expose the capabilities of the server."""
33 
34     PATTERNS = client_patterns("/capabilities$")
35 
36     def __init__(self, hs: "HomeServer"):
37         super().__init__()
38         self.hs = hs
39         self.config = hs.config
40         self.auth = hs.get_auth()
41         self.auth_handler = hs.get_auth_handler()
42 
43     async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
44         await self.auth.get_user_by_req(request, allow_guest=True)
45         change_password = self.auth_handler.can_change_password()
46 
47         response: JsonDict = {
48             "capabilities": {
49                 "m.room_versions": {
50                     "default": self.config.server.default_room_version.identifier,
51                     "available": {
52                         v.identifier: v.disposition
53                         for v in KNOWN_ROOM_VERSIONS.values()
54                     },
55                 },
56                 "m.change_password": {"enabled": change_password},
57             }
58         }
59 
60         if self.config.experimental.msc3244_enabled:
61             response["capabilities"]["m.room_versions"][
62                 "org.matrix.msc3244.room_capabilities"
63             ] = MSC3244_CAPABILITIES
64 
65         if self.config.experimental.msc3283_enabled:
66             response["capabilities"]["org.matrix.msc3283.set_displayname"] = {
67                 "enabled": self.config.registration.enable_set_displayname
68             }
69             response["capabilities"]["org.matrix.msc3283.set_avatar_url"] = {
70                 "enabled": self.config.registration.enable_set_avatar_url
71             }
72             response["capabilities"]["org.matrix.msc3283.3pid_changes"] = {
73                 "enabled": self.config.registration.enable_3pid_changes
74             }
75 
76         return 200, response
77 
78 
79 def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
80     CapabilitiesRestServlet(hs).register(http_server)
81
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/synapse/rest/client/capabilities.py b/synapse/rest/client/capabilities.py
--- a/synapse/rest/client/capabilities.py
+++ b/synapse/rest/client/capabilities.py
@@ -73,6 +73,9 @@
                 "enabled": self.config.registration.enable_3pid_changes
             }
 
+        if self.config.experimental.msc3440_enabled:
+            response["capabilities"]["io.element.thread"] = {"enabled": True}
+
         return 200, response

{"golden_diff": "diff --git a/synapse/rest/client/capabilities.py b/synapse/rest/client/capabilities.py\n--- a/synapse/rest/client/capabilities.py\n+++ b/synapse/rest/client/capabilities.py\n@@ -73,6 +73,9 @@\n                 \"enabled\": self.config.registration.enable_3pid_changes\n             }\n \n+        if self.config.experimental.msc3440_enabled:\n+            response[\"capabilities\"][\"io.element.thread\"] = {\"enabled\": True}\n+\n         return 200, response\n", "issue": "Add a capabilties flag for MSC3440\nPer https://github.com/matrix-org/matrix-doc/commit/fc81bbd836955876c931c95277249981b3e2778c\r\n\r\n\n", "before_files": [{"content": "# Copyright 2019 New Vector\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport logging\nfrom typing import TYPE_CHECKING, Tuple\n\nfrom synapse.api.room_versions import KNOWN_ROOM_VERSIONS, MSC3244_CAPABILITIES\nfrom synapse.http.server import HttpServer\nfrom synapse.http.servlet import RestServlet\nfrom synapse.http.site import SynapseRequest\nfrom synapse.types import JsonDict\n\nfrom ._base import client_patterns\n\nif TYPE_CHECKING:\n    from synapse.server import HomeServer\n\nlogger = logging.getLogger(__name__)\n\n\nclass CapabilitiesRestServlet(RestServlet):\n    \"\"\"End point to expose the capabilities of the server.\"\"\"\n\n    PATTERNS = client_patterns(\"/capabilities$\")\n\n    def __init__(self, hs: \"HomeServer\"):\n        super().__init__()\n        self.hs = hs\n        self.config = hs.config\n        self.auth = hs.get_auth()\n        self.auth_handler = hs.get_auth_handler()\n\n    async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:\n        await self.auth.get_user_by_req(request, allow_guest=True)\n        change_password = self.auth_handler.can_change_password()\n\n        response: JsonDict = {\n            \"capabilities\": {\n                \"m.room_versions\": {\n                    \"default\": self.config.server.default_room_version.identifier,\n                    \"available\": {\n                        v.identifier: v.disposition\n                        for v in KNOWN_ROOM_VERSIONS.values()\n                    },\n                },\n                \"m.change_password\": {\"enabled\": change_password},\n            }\n        }\n\n        if self.config.experimental.msc3244_enabled:\n            response[\"capabilities\"][\"m.room_versions\"][\n                \"org.matrix.msc3244.room_capabilities\"\n            ] = MSC3244_CAPABILITIES\n\n        if self.config.experimental.msc3283_enabled:\n            response[\"capabilities\"][\"org.matrix.msc3283.set_displayname\"] = {\n                \"enabled\": self.config.registration.enable_set_displayname\n            }\n            response[\"capabilities\"][\"org.matrix.msc3283.set_avatar_url\"] = {\n                \"enabled\": self.config.registration.enable_set_avatar_url\n            }\n            response[\"capabilities\"][\"org.matrix.msc3283.3pid_changes\"] = {\n                \"enabled\": self.config.registration.enable_3pid_changes\n            }\n\n        return 200, response\n\n\ndef register_servlets(hs: \"HomeServer\", http_server: HttpServer) -> None:\n    CapabilitiesRestServlet(hs).register(http_server)\n", "path": "synapse/rest/client/capabilities.py"}], "after_files": [{"content": "# Copyright 2019 New Vector\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport logging\nfrom typing import TYPE_CHECKING, Tuple\n\nfrom synapse.api.room_versions import KNOWN_ROOM_VERSIONS, MSC3244_CAPABILITIES\nfrom synapse.http.server import HttpServer\nfrom synapse.http.servlet import RestServlet\nfrom synapse.http.site import SynapseRequest\nfrom synapse.types import JsonDict\n\nfrom ._base import client_patterns\n\nif TYPE_CHECKING:\n    from synapse.server import HomeServer\n\nlogger = logging.getLogger(__name__)\n\n\nclass CapabilitiesRestServlet(RestServlet):\n    \"\"\"End point to expose the capabilities of the server.\"\"\"\n\n    PATTERNS = client_patterns(\"/capabilities$\")\n\n    def __init__(self, hs: \"HomeServer\"):\n        super().__init__()\n        self.hs = hs\n        self.config = hs.config\n        self.auth = hs.get_auth()\n        self.auth_handler = hs.get_auth_handler()\n\n    async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:\n        await self.auth.get_user_by_req(request, allow_guest=True)\n        change_password = self.auth_handler.can_change_password()\n\n        response: JsonDict = {\n            \"capabilities\": {\n                \"m.room_versions\": {\n                    \"default\": self.config.server.default_room_version.identifier,\n                    \"available\": {\n                        v.identifier: v.disposition\n                        for v in KNOWN_ROOM_VERSIONS.values()\n                    },\n                },\n                \"m.change_password\": {\"enabled\": change_password},\n            }\n        }\n\n        if self.config.experimental.msc3244_enabled:\n            response[\"capabilities\"][\"m.room_versions\"][\n                \"org.matrix.msc3244.room_capabilities\"\n            ] = MSC3244_CAPABILITIES\n\n        if self.config.experimental.msc3283_enabled:\n            response[\"capabilities\"][\"org.matrix.msc3283.set_displayname\"] = {\n                \"enabled\": self.config.registration.enable_set_displayname\n            }\n            response[\"capabilities\"][\"org.matrix.msc3283.set_avatar_url\"] = {\n                \"enabled\": self.config.registration.enable_set_avatar_url\n            }\n            response[\"capabilities\"][\"org.matrix.msc3283.3pid_changes\"] = {\n                \"enabled\": self.config.registration.enable_3pid_changes\n            }\n\n        if self.config.experimental.msc3440_enabled:\n            response[\"capabilities\"][\"io.element.thread\"] = {\"enabled\": True}\n\n        return 200, response\n\n\ndef register_servlets(hs: \"HomeServer\", http_server: HttpServer) -> None:\n    CapabilitiesRestServlet(hs).register(http_server)\n", "path": "synapse/rest/client/capabilities.py"}]}