matrix-synapse 1.143.0__cp310-abi3-manylinux_2_28_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of matrix-synapse might be problematic. Click here for more details.

Files changed (1058) hide show
  1. matrix_synapse-1.143.0.dist-info/AUTHORS.rst +51 -0
  2. matrix_synapse-1.143.0.dist-info/LICENSE-AGPL-3.0 +661 -0
  3. matrix_synapse-1.143.0.dist-info/LICENSE-COMMERCIAL +6 -0
  4. matrix_synapse-1.143.0.dist-info/METADATA +385 -0
  5. matrix_synapse-1.143.0.dist-info/RECORD +1058 -0
  6. matrix_synapse-1.143.0.dist-info/WHEEL +4 -0
  7. matrix_synapse-1.143.0.dist-info/entry_points.txt +14 -0
  8. synapse/__init__.py +97 -0
  9. synapse/_scripts/__init__.py +0 -0
  10. synapse/_scripts/export_signing_key.py +109 -0
  11. synapse/_scripts/generate_config.py +83 -0
  12. synapse/_scripts/generate_log_config.py +56 -0
  13. synapse/_scripts/generate_signing_key.py +55 -0
  14. synapse/_scripts/generate_workers_map.py +318 -0
  15. synapse/_scripts/hash_password.py +95 -0
  16. synapse/_scripts/move_remote_media_to_new_store.py +128 -0
  17. synapse/_scripts/register_new_matrix_user.py +402 -0
  18. synapse/_scripts/review_recent_signups.py +212 -0
  19. synapse/_scripts/synapse_port_db.py +1604 -0
  20. synapse/_scripts/synctl.py +365 -0
  21. synapse/_scripts/update_synapse_database.py +130 -0
  22. synapse/api/__init__.py +20 -0
  23. synapse/api/auth/__init__.py +207 -0
  24. synapse/api/auth/base.py +406 -0
  25. synapse/api/auth/internal.py +299 -0
  26. synapse/api/auth/mas.py +436 -0
  27. synapse/api/auth/msc3861_delegated.py +617 -0
  28. synapse/api/auth_blocking.py +144 -0
  29. synapse/api/constants.py +362 -0
  30. synapse/api/errors.py +907 -0
  31. synapse/api/filtering.py +537 -0
  32. synapse/api/presence.py +102 -0
  33. synapse/api/ratelimiting.py +480 -0
  34. synapse/api/room_versions.py +535 -0
  35. synapse/api/urls.py +118 -0
  36. synapse/app/__init__.py +60 -0
  37. synapse/app/_base.py +862 -0
  38. synapse/app/admin_cmd.py +388 -0
  39. synapse/app/appservice.py +30 -0
  40. synapse/app/client_reader.py +30 -0
  41. synapse/app/complement_fork_starter.py +206 -0
  42. synapse/app/event_creator.py +29 -0
  43. synapse/app/federation_reader.py +30 -0
  44. synapse/app/federation_sender.py +30 -0
  45. synapse/app/frontend_proxy.py +30 -0
  46. synapse/app/generic_worker.py +474 -0
  47. synapse/app/homeserver.py +505 -0
  48. synapse/app/media_repository.py +30 -0
  49. synapse/app/phone_stats_home.py +296 -0
  50. synapse/app/pusher.py +30 -0
  51. synapse/app/synchrotron.py +30 -0
  52. synapse/app/user_dir.py +31 -0
  53. synapse/appservice/__init__.py +458 -0
  54. synapse/appservice/api.py +567 -0
  55. synapse/appservice/scheduler.py +564 -0
  56. synapse/config/__init__.py +27 -0
  57. synapse/config/__main__.py +62 -0
  58. synapse/config/_base.py +1106 -0
  59. synapse/config/_base.pyi +215 -0
  60. synapse/config/_util.py +99 -0
  61. synapse/config/account_validity.py +116 -0
  62. synapse/config/api.py +141 -0
  63. synapse/config/appservice.py +210 -0
  64. synapse/config/auth.py +80 -0
  65. synapse/config/auto_accept_invites.py +43 -0
  66. synapse/config/background_updates.py +44 -0
  67. synapse/config/cache.py +231 -0
  68. synapse/config/captcha.py +90 -0
  69. synapse/config/cas.py +116 -0
  70. synapse/config/consent.py +73 -0
  71. synapse/config/database.py +184 -0
  72. synapse/config/emailconfig.py +367 -0
  73. synapse/config/experimental.py +595 -0
  74. synapse/config/federation.py +114 -0
  75. synapse/config/homeserver.py +141 -0
  76. synapse/config/jwt.py +55 -0
  77. synapse/config/key.py +447 -0
  78. synapse/config/logger.py +390 -0
  79. synapse/config/mas.py +192 -0
  80. synapse/config/matrixrtc.py +66 -0
  81. synapse/config/metrics.py +84 -0
  82. synapse/config/modules.py +40 -0
  83. synapse/config/oembed.py +185 -0
  84. synapse/config/oidc.py +509 -0
  85. synapse/config/password_auth_providers.py +82 -0
  86. synapse/config/push.py +64 -0
  87. synapse/config/ratelimiting.py +254 -0
  88. synapse/config/redis.py +74 -0
  89. synapse/config/registration.py +296 -0
  90. synapse/config/repository.py +311 -0
  91. synapse/config/retention.py +162 -0
  92. synapse/config/room.py +88 -0
  93. synapse/config/room_directory.py +165 -0
  94. synapse/config/saml2.py +251 -0
  95. synapse/config/server.py +1170 -0
  96. synapse/config/server_notices.py +84 -0
  97. synapse/config/spam_checker.py +66 -0
  98. synapse/config/sso.py +121 -0
  99. synapse/config/stats.py +54 -0
  100. synapse/config/third_party_event_rules.py +40 -0
  101. synapse/config/tls.py +192 -0
  102. synapse/config/tracer.py +71 -0
  103. synapse/config/user_directory.py +47 -0
  104. synapse/config/user_types.py +42 -0
  105. synapse/config/voip.py +59 -0
  106. synapse/config/workers.py +642 -0
  107. synapse/crypto/__init__.py +20 -0
  108. synapse/crypto/context_factory.py +278 -0
  109. synapse/crypto/event_signing.py +194 -0
  110. synapse/crypto/keyring.py +931 -0
  111. synapse/event_auth.py +1266 -0
  112. synapse/events/__init__.py +667 -0
  113. synapse/events/auto_accept_invites.py +216 -0
  114. synapse/events/builder.py +387 -0
  115. synapse/events/presence_router.py +243 -0
  116. synapse/events/snapshot.py +559 -0
  117. synapse/events/utils.py +924 -0
  118. synapse/events/validator.py +305 -0
  119. synapse/federation/__init__.py +22 -0
  120. synapse/federation/federation_base.py +382 -0
  121. synapse/federation/federation_client.py +2132 -0
  122. synapse/federation/federation_server.py +1540 -0
  123. synapse/federation/persistence.py +70 -0
  124. synapse/federation/send_queue.py +531 -0
  125. synapse/federation/sender/__init__.py +1164 -0
  126. synapse/federation/sender/per_destination_queue.py +886 -0
  127. synapse/federation/sender/transaction_manager.py +210 -0
  128. synapse/federation/transport/__init__.py +28 -0
  129. synapse/federation/transport/client.py +1199 -0
  130. synapse/federation/transport/server/__init__.py +334 -0
  131. synapse/federation/transport/server/_base.py +429 -0
  132. synapse/federation/transport/server/federation.py +910 -0
  133. synapse/federation/units.py +133 -0
  134. synapse/handlers/__init__.py +20 -0
  135. synapse/handlers/account.py +162 -0
  136. synapse/handlers/account_data.py +360 -0
  137. synapse/handlers/account_validity.py +361 -0
  138. synapse/handlers/admin.py +615 -0
  139. synapse/handlers/appservice.py +989 -0
  140. synapse/handlers/auth.py +2481 -0
  141. synapse/handlers/cas.py +413 -0
  142. synapse/handlers/deactivate_account.py +363 -0
  143. synapse/handlers/delayed_events.py +599 -0
  144. synapse/handlers/device.py +1870 -0
  145. synapse/handlers/devicemessage.py +399 -0
  146. synapse/handlers/directory.py +545 -0
  147. synapse/handlers/e2e_keys.py +1834 -0
  148. synapse/handlers/e2e_room_keys.py +455 -0
  149. synapse/handlers/event_auth.py +390 -0
  150. synapse/handlers/events.py +201 -0
  151. synapse/handlers/federation.py +2039 -0
  152. synapse/handlers/federation_event.py +2419 -0
  153. synapse/handlers/identity.py +812 -0
  154. synapse/handlers/initial_sync.py +528 -0
  155. synapse/handlers/jwt.py +120 -0
  156. synapse/handlers/message.py +2347 -0
  157. synapse/handlers/oidc.py +1801 -0
  158. synapse/handlers/pagination.py +768 -0
  159. synapse/handlers/password_policy.py +102 -0
  160. synapse/handlers/presence.py +2633 -0
  161. synapse/handlers/profile.py +655 -0
  162. synapse/handlers/push_rules.py +164 -0
  163. synapse/handlers/read_marker.py +79 -0
  164. synapse/handlers/receipts.py +351 -0
  165. synapse/handlers/register.py +1059 -0
  166. synapse/handlers/relations.py +623 -0
  167. synapse/handlers/reports.py +98 -0
  168. synapse/handlers/room.py +2448 -0
  169. synapse/handlers/room_list.py +632 -0
  170. synapse/handlers/room_member.py +2365 -0
  171. synapse/handlers/room_member_worker.py +146 -0
  172. synapse/handlers/room_policy.py +186 -0
  173. synapse/handlers/room_summary.py +1057 -0
  174. synapse/handlers/saml.py +524 -0
  175. synapse/handlers/search.py +723 -0
  176. synapse/handlers/send_email.py +209 -0
  177. synapse/handlers/set_password.py +71 -0
  178. synapse/handlers/sliding_sync/__init__.py +1701 -0
  179. synapse/handlers/sliding_sync/extensions.py +969 -0
  180. synapse/handlers/sliding_sync/room_lists.py +2262 -0
  181. synapse/handlers/sliding_sync/store.py +128 -0
  182. synapse/handlers/sso.py +1291 -0
  183. synapse/handlers/state_deltas.py +82 -0
  184. synapse/handlers/stats.py +321 -0
  185. synapse/handlers/sync.py +3106 -0
  186. synapse/handlers/thread_subscriptions.py +190 -0
  187. synapse/handlers/typing.py +606 -0
  188. synapse/handlers/ui_auth/__init__.py +48 -0
  189. synapse/handlers/ui_auth/checkers.py +332 -0
  190. synapse/handlers/user_directory.py +783 -0
  191. synapse/handlers/worker_lock.py +371 -0
  192. synapse/http/__init__.py +105 -0
  193. synapse/http/additional_resource.py +62 -0
  194. synapse/http/client.py +1373 -0
  195. synapse/http/connectproxyclient.py +316 -0
  196. synapse/http/federation/__init__.py +19 -0
  197. synapse/http/federation/matrix_federation_agent.py +490 -0
  198. synapse/http/federation/srv_resolver.py +196 -0
  199. synapse/http/federation/well_known_resolver.py +367 -0
  200. synapse/http/matrixfederationclient.py +1873 -0
  201. synapse/http/proxy.py +290 -0
  202. synapse/http/proxyagent.py +497 -0
  203. synapse/http/replicationagent.py +202 -0
  204. synapse/http/request_metrics.py +309 -0
  205. synapse/http/server.py +1110 -0
  206. synapse/http/servlet.py +1018 -0
  207. synapse/http/site.py +825 -0
  208. synapse/http/types.py +27 -0
  209. synapse/logging/__init__.py +31 -0
  210. synapse/logging/_remote.py +261 -0
  211. synapse/logging/_terse_json.py +95 -0
  212. synapse/logging/context.py +1209 -0
  213. synapse/logging/formatter.py +62 -0
  214. synapse/logging/handlers.py +99 -0
  215. synapse/logging/loggers.py +25 -0
  216. synapse/logging/opentracing.py +1132 -0
  217. synapse/logging/scopecontextmanager.py +160 -0
  218. synapse/media/_base.py +830 -0
  219. synapse/media/filepath.py +417 -0
  220. synapse/media/media_repository.py +1580 -0
  221. synapse/media/media_storage.py +702 -0
  222. synapse/media/oembed.py +277 -0
  223. synapse/media/preview_html.py +556 -0
  224. synapse/media/storage_provider.py +195 -0
  225. synapse/media/thumbnailer.py +833 -0
  226. synapse/media/url_previewer.py +875 -0
  227. synapse/metrics/__init__.py +748 -0
  228. synapse/metrics/_gc.py +219 -0
  229. synapse/metrics/_reactor_metrics.py +171 -0
  230. synapse/metrics/_types.py +38 -0
  231. synapse/metrics/background_process_metrics.py +555 -0
  232. synapse/metrics/common_usage_metrics.py +94 -0
  233. synapse/metrics/jemalloc.py +248 -0
  234. synapse/module_api/__init__.py +2131 -0
  235. synapse/module_api/callbacks/__init__.py +50 -0
  236. synapse/module_api/callbacks/account_validity_callbacks.py +106 -0
  237. synapse/module_api/callbacks/media_repository_callbacks.py +157 -0
  238. synapse/module_api/callbacks/ratelimit_callbacks.py +78 -0
  239. synapse/module_api/callbacks/spamchecker_callbacks.py +991 -0
  240. synapse/module_api/callbacks/third_party_event_rules_callbacks.py +592 -0
  241. synapse/module_api/errors.py +42 -0
  242. synapse/notifier.py +970 -0
  243. synapse/push/__init__.py +212 -0
  244. synapse/push/bulk_push_rule_evaluator.py +635 -0
  245. synapse/push/clientformat.py +126 -0
  246. synapse/push/emailpusher.py +333 -0
  247. synapse/push/httppusher.py +564 -0
  248. synapse/push/mailer.py +1010 -0
  249. synapse/push/presentable_names.py +216 -0
  250. synapse/push/push_tools.py +114 -0
  251. synapse/push/push_types.py +141 -0
  252. synapse/push/pusher.py +87 -0
  253. synapse/push/pusherpool.py +501 -0
  254. synapse/push/rulekinds.py +33 -0
  255. synapse/py.typed +0 -0
  256. synapse/replication/__init__.py +20 -0
  257. synapse/replication/http/__init__.py +68 -0
  258. synapse/replication/http/_base.py +468 -0
  259. synapse/replication/http/account_data.py +297 -0
  260. synapse/replication/http/deactivate_account.py +81 -0
  261. synapse/replication/http/delayed_events.py +62 -0
  262. synapse/replication/http/devices.py +254 -0
  263. synapse/replication/http/federation.py +334 -0
  264. synapse/replication/http/login.py +106 -0
  265. synapse/replication/http/membership.py +364 -0
  266. synapse/replication/http/presence.py +133 -0
  267. synapse/replication/http/push.py +156 -0
  268. synapse/replication/http/register.py +172 -0
  269. synapse/replication/http/send_events.py +182 -0
  270. synapse/replication/http/state.py +82 -0
  271. synapse/replication/http/streams.py +101 -0
  272. synapse/replication/tcp/__init__.py +56 -0
  273. synapse/replication/tcp/client.py +552 -0
  274. synapse/replication/tcp/commands.py +569 -0
  275. synapse/replication/tcp/context.py +41 -0
  276. synapse/replication/tcp/external_cache.py +156 -0
  277. synapse/replication/tcp/handler.py +922 -0
  278. synapse/replication/tcp/protocol.py +608 -0
  279. synapse/replication/tcp/redis.py +509 -0
  280. synapse/replication/tcp/resource.py +348 -0
  281. synapse/replication/tcp/streams/__init__.py +96 -0
  282. synapse/replication/tcp/streams/_base.py +765 -0
  283. synapse/replication/tcp/streams/events.py +287 -0
  284. synapse/replication/tcp/streams/federation.py +92 -0
  285. synapse/replication/tcp/streams/partial_state.py +80 -0
  286. synapse/res/providers.json +29 -0
  287. synapse/res/templates/_base.html +29 -0
  288. synapse/res/templates/account_previously_renewed.html +6 -0
  289. synapse/res/templates/account_renewed.html +6 -0
  290. synapse/res/templates/add_threepid.html +8 -0
  291. synapse/res/templates/add_threepid.txt +6 -0
  292. synapse/res/templates/add_threepid_failure.html +7 -0
  293. synapse/res/templates/add_threepid_success.html +6 -0
  294. synapse/res/templates/already_in_use.html +12 -0
  295. synapse/res/templates/already_in_use.txt +10 -0
  296. synapse/res/templates/auth_success.html +21 -0
  297. synapse/res/templates/invalid_token.html +6 -0
  298. synapse/res/templates/mail-Element.css +7 -0
  299. synapse/res/templates/mail-Vector.css +7 -0
  300. synapse/res/templates/mail-expiry.css +4 -0
  301. synapse/res/templates/mail.css +156 -0
  302. synapse/res/templates/notice_expiry.html +46 -0
  303. synapse/res/templates/notice_expiry.txt +7 -0
  304. synapse/res/templates/notif.html +51 -0
  305. synapse/res/templates/notif.txt +22 -0
  306. synapse/res/templates/notif_mail.html +59 -0
  307. synapse/res/templates/notif_mail.txt +10 -0
  308. synapse/res/templates/password_reset.html +10 -0
  309. synapse/res/templates/password_reset.txt +7 -0
  310. synapse/res/templates/password_reset_confirmation.html +15 -0
  311. synapse/res/templates/password_reset_failure.html +7 -0
  312. synapse/res/templates/password_reset_success.html +6 -0
  313. synapse/res/templates/recaptcha.html +42 -0
  314. synapse/res/templates/registration.html +12 -0
  315. synapse/res/templates/registration.txt +10 -0
  316. synapse/res/templates/registration_failure.html +6 -0
  317. synapse/res/templates/registration_success.html +6 -0
  318. synapse/res/templates/registration_token.html +18 -0
  319. synapse/res/templates/room.html +33 -0
  320. synapse/res/templates/room.txt +9 -0
  321. synapse/res/templates/sso.css +129 -0
  322. synapse/res/templates/sso_account_deactivated.html +25 -0
  323. synapse/res/templates/sso_auth_account_details.html +186 -0
  324. synapse/res/templates/sso_auth_account_details.js +116 -0
  325. synapse/res/templates/sso_auth_bad_user.html +26 -0
  326. synapse/res/templates/sso_auth_confirm.html +27 -0
  327. synapse/res/templates/sso_auth_success.html +26 -0
  328. synapse/res/templates/sso_error.html +71 -0
  329. synapse/res/templates/sso_footer.html +19 -0
  330. synapse/res/templates/sso_login_idp_picker.html +60 -0
  331. synapse/res/templates/sso_new_user_consent.html +30 -0
  332. synapse/res/templates/sso_partial_profile.html +19 -0
  333. synapse/res/templates/sso_redirect_confirm.html +39 -0
  334. synapse/res/templates/style.css +33 -0
  335. synapse/res/templates/terms.html +27 -0
  336. synapse/rest/__init__.py +197 -0
  337. synapse/rest/admin/__init__.py +390 -0
  338. synapse/rest/admin/_base.py +72 -0
  339. synapse/rest/admin/background_updates.py +171 -0
  340. synapse/rest/admin/devices.py +221 -0
  341. synapse/rest/admin/event_reports.py +173 -0
  342. synapse/rest/admin/events.py +69 -0
  343. synapse/rest/admin/experimental_features.py +137 -0
  344. synapse/rest/admin/federation.py +243 -0
  345. synapse/rest/admin/media.py +540 -0
  346. synapse/rest/admin/registration_tokens.py +358 -0
  347. synapse/rest/admin/rooms.py +1061 -0
  348. synapse/rest/admin/scheduled_tasks.py +70 -0
  349. synapse/rest/admin/server_notice_servlet.py +132 -0
  350. synapse/rest/admin/statistics.py +132 -0
  351. synapse/rest/admin/username_available.py +58 -0
  352. synapse/rest/admin/users.py +1606 -0
  353. synapse/rest/client/__init__.py +20 -0
  354. synapse/rest/client/_base.py +113 -0
  355. synapse/rest/client/account.py +930 -0
  356. synapse/rest/client/account_data.py +319 -0
  357. synapse/rest/client/account_validity.py +103 -0
  358. synapse/rest/client/appservice_ping.py +125 -0
  359. synapse/rest/client/auth.py +218 -0
  360. synapse/rest/client/auth_metadata.py +122 -0
  361. synapse/rest/client/capabilities.py +121 -0
  362. synapse/rest/client/delayed_events.py +165 -0
  363. synapse/rest/client/devices.py +587 -0
  364. synapse/rest/client/directory.py +211 -0
  365. synapse/rest/client/events.py +116 -0
  366. synapse/rest/client/filter.py +112 -0
  367. synapse/rest/client/initial_sync.py +65 -0
  368. synapse/rest/client/keys.py +678 -0
  369. synapse/rest/client/knock.py +104 -0
  370. synapse/rest/client/login.py +750 -0
  371. synapse/rest/client/login_token_request.py +127 -0
  372. synapse/rest/client/logout.py +93 -0
  373. synapse/rest/client/matrixrtc.py +52 -0
  374. synapse/rest/client/media.py +285 -0
  375. synapse/rest/client/mutual_rooms.py +93 -0
  376. synapse/rest/client/notifications.py +137 -0
  377. synapse/rest/client/openid.py +109 -0
  378. synapse/rest/client/password_policy.py +69 -0
  379. synapse/rest/client/presence.py +131 -0
  380. synapse/rest/client/profile.py +291 -0
  381. synapse/rest/client/push_rule.py +331 -0
  382. synapse/rest/client/pusher.py +181 -0
  383. synapse/rest/client/read_marker.py +104 -0
  384. synapse/rest/client/receipts.py +165 -0
  385. synapse/rest/client/register.py +1067 -0
  386. synapse/rest/client/relations.py +138 -0
  387. synapse/rest/client/rendezvous.py +76 -0
  388. synapse/rest/client/reporting.py +207 -0
  389. synapse/rest/client/room.py +1669 -0
  390. synapse/rest/client/room_keys.py +426 -0
  391. synapse/rest/client/room_upgrade_rest_servlet.py +112 -0
  392. synapse/rest/client/sendtodevice.py +85 -0
  393. synapse/rest/client/sync.py +1131 -0
  394. synapse/rest/client/tags.py +129 -0
  395. synapse/rest/client/thirdparty.py +130 -0
  396. synapse/rest/client/thread_subscriptions.py +247 -0
  397. synapse/rest/client/tokenrefresh.py +52 -0
  398. synapse/rest/client/transactions.py +149 -0
  399. synapse/rest/client/user_directory.py +90 -0
  400. synapse/rest/client/versions.py +191 -0
  401. synapse/rest/client/voip.py +88 -0
  402. synapse/rest/consent/__init__.py +0 -0
  403. synapse/rest/consent/consent_resource.py +210 -0
  404. synapse/rest/health.py +38 -0
  405. synapse/rest/key/__init__.py +20 -0
  406. synapse/rest/key/v2/__init__.py +40 -0
  407. synapse/rest/key/v2/local_key_resource.py +125 -0
  408. synapse/rest/key/v2/remote_key_resource.py +302 -0
  409. synapse/rest/media/__init__.py +0 -0
  410. synapse/rest/media/config_resource.py +53 -0
  411. synapse/rest/media/create_resource.py +90 -0
  412. synapse/rest/media/download_resource.py +110 -0
  413. synapse/rest/media/media_repository_resource.py +113 -0
  414. synapse/rest/media/preview_url_resource.py +77 -0
  415. synapse/rest/media/thumbnail_resource.py +142 -0
  416. synapse/rest/media/upload_resource.py +187 -0
  417. synapse/rest/media/v1/__init__.py +39 -0
  418. synapse/rest/media/v1/_base.py +23 -0
  419. synapse/rest/media/v1/media_storage.py +23 -0
  420. synapse/rest/media/v1/storage_provider.py +23 -0
  421. synapse/rest/synapse/__init__.py +20 -0
  422. synapse/rest/synapse/client/__init__.py +93 -0
  423. synapse/rest/synapse/client/federation_whitelist.py +66 -0
  424. synapse/rest/synapse/client/jwks.py +77 -0
  425. synapse/rest/synapse/client/new_user_consent.py +115 -0
  426. synapse/rest/synapse/client/oidc/__init__.py +45 -0
  427. synapse/rest/synapse/client/oidc/backchannel_logout_resource.py +42 -0
  428. synapse/rest/synapse/client/oidc/callback_resource.py +48 -0
  429. synapse/rest/synapse/client/password_reset.py +129 -0
  430. synapse/rest/synapse/client/pick_idp.py +107 -0
  431. synapse/rest/synapse/client/pick_username.py +153 -0
  432. synapse/rest/synapse/client/rendezvous.py +58 -0
  433. synapse/rest/synapse/client/saml2/__init__.py +42 -0
  434. synapse/rest/synapse/client/saml2/metadata_resource.py +46 -0
  435. synapse/rest/synapse/client/saml2/response_resource.py +52 -0
  436. synapse/rest/synapse/client/sso_register.py +56 -0
  437. synapse/rest/synapse/client/unsubscribe.py +88 -0
  438. synapse/rest/synapse/mas/__init__.py +71 -0
  439. synapse/rest/synapse/mas/_base.py +55 -0
  440. synapse/rest/synapse/mas/devices.py +239 -0
  441. synapse/rest/synapse/mas/users.py +469 -0
  442. synapse/rest/well_known.py +148 -0
  443. synapse/server.py +1257 -0
  444. synapse/server_notices/__init__.py +0 -0
  445. synapse/server_notices/consent_server_notices.py +136 -0
  446. synapse/server_notices/resource_limits_server_notices.py +215 -0
  447. synapse/server_notices/server_notices_manager.py +388 -0
  448. synapse/server_notices/server_notices_sender.py +67 -0
  449. synapse/server_notices/worker_server_notices_sender.py +46 -0
  450. synapse/spam_checker_api/__init__.py +31 -0
  451. synapse/state/__init__.py +1022 -0
  452. synapse/state/v1.py +369 -0
  453. synapse/state/v2.py +984 -0
  454. synapse/static/client/login/index.html +47 -0
  455. synapse/static/client/login/js/jquery-3.4.1.min.js +2 -0
  456. synapse/static/client/login/js/login.js +291 -0
  457. synapse/static/client/login/spinner.gif +0 -0
  458. synapse/static/client/login/style.css +79 -0
  459. synapse/static/index.html +63 -0
  460. synapse/storage/__init__.py +43 -0
  461. synapse/storage/_base.py +245 -0
  462. synapse/storage/admin_client_config.py +25 -0
  463. synapse/storage/background_updates.py +1188 -0
  464. synapse/storage/controllers/__init__.py +57 -0
  465. synapse/storage/controllers/persist_events.py +1237 -0
  466. synapse/storage/controllers/purge_events.py +455 -0
  467. synapse/storage/controllers/state.py +950 -0
  468. synapse/storage/controllers/stats.py +119 -0
  469. synapse/storage/database.py +2719 -0
  470. synapse/storage/databases/__init__.py +175 -0
  471. synapse/storage/databases/main/__init__.py +420 -0
  472. synapse/storage/databases/main/account_data.py +1059 -0
  473. synapse/storage/databases/main/appservice.py +473 -0
  474. synapse/storage/databases/main/cache.py +911 -0
  475. synapse/storage/databases/main/censor_events.py +225 -0
  476. synapse/storage/databases/main/client_ips.py +815 -0
  477. synapse/storage/databases/main/delayed_events.py +562 -0
  478. synapse/storage/databases/main/deviceinbox.py +1271 -0
  479. synapse/storage/databases/main/devices.py +2578 -0
  480. synapse/storage/databases/main/directory.py +212 -0
  481. synapse/storage/databases/main/e2e_room_keys.py +689 -0
  482. synapse/storage/databases/main/end_to_end_keys.py +1894 -0
  483. synapse/storage/databases/main/event_federation.py +2508 -0
  484. synapse/storage/databases/main/event_push_actions.py +1933 -0
  485. synapse/storage/databases/main/events.py +3765 -0
  486. synapse/storage/databases/main/events_bg_updates.py +2910 -0
  487. synapse/storage/databases/main/events_forward_extremities.py +126 -0
  488. synapse/storage/databases/main/events_worker.py +2786 -0
  489. synapse/storage/databases/main/experimental_features.py +130 -0
  490. synapse/storage/databases/main/filtering.py +231 -0
  491. synapse/storage/databases/main/keys.py +291 -0
  492. synapse/storage/databases/main/lock.py +553 -0
  493. synapse/storage/databases/main/media_repository.py +1068 -0
  494. synapse/storage/databases/main/metrics.py +460 -0
  495. synapse/storage/databases/main/monthly_active_users.py +443 -0
  496. synapse/storage/databases/main/openid.py +60 -0
  497. synapse/storage/databases/main/presence.py +509 -0
  498. synapse/storage/databases/main/profile.py +539 -0
  499. synapse/storage/databases/main/purge_events.py +521 -0
  500. synapse/storage/databases/main/push_rule.py +970 -0
  501. synapse/storage/databases/main/pusher.py +793 -0
  502. synapse/storage/databases/main/receipts.py +1341 -0
  503. synapse/storage/databases/main/registration.py +3072 -0
  504. synapse/storage/databases/main/rejections.py +37 -0
  505. synapse/storage/databases/main/relations.py +1116 -0
  506. synapse/storage/databases/main/room.py +2779 -0
  507. synapse/storage/databases/main/roommember.py +2110 -0
  508. synapse/storage/databases/main/search.py +939 -0
  509. synapse/storage/databases/main/session.py +151 -0
  510. synapse/storage/databases/main/signatures.py +94 -0
  511. synapse/storage/databases/main/sliding_sync.py +603 -0
  512. synapse/storage/databases/main/state.py +1002 -0
  513. synapse/storage/databases/main/state_deltas.py +329 -0
  514. synapse/storage/databases/main/stats.py +789 -0
  515. synapse/storage/databases/main/stream.py +2577 -0
  516. synapse/storage/databases/main/tags.py +360 -0
  517. synapse/storage/databases/main/task_scheduler.py +225 -0
  518. synapse/storage/databases/main/thread_subscriptions.py +589 -0
  519. synapse/storage/databases/main/transactions.py +675 -0
  520. synapse/storage/databases/main/ui_auth.py +420 -0
  521. synapse/storage/databases/main/user_directory.py +1330 -0
  522. synapse/storage/databases/main/user_erasure_store.py +117 -0
  523. synapse/storage/databases/state/__init__.py +22 -0
  524. synapse/storage/databases/state/bg_updates.py +497 -0
  525. synapse/storage/databases/state/deletion.py +557 -0
  526. synapse/storage/databases/state/store.py +948 -0
  527. synapse/storage/engines/__init__.py +70 -0
  528. synapse/storage/engines/_base.py +154 -0
  529. synapse/storage/engines/postgres.py +261 -0
  530. synapse/storage/engines/sqlite.py +199 -0
  531. synapse/storage/invite_rule.py +112 -0
  532. synapse/storage/keys.py +40 -0
  533. synapse/storage/prepare_database.py +730 -0
  534. synapse/storage/push_rule.py +28 -0
  535. synapse/storage/roommember.py +88 -0
  536. synapse/storage/schema/README.md +4 -0
  537. synapse/storage/schema/__init__.py +186 -0
  538. synapse/storage/schema/common/delta/25/00background_updates.sql +40 -0
  539. synapse/storage/schema/common/delta/35/00background_updates_add_col.sql +36 -0
  540. synapse/storage/schema/common/delta/58/00background_update_ordering.sql +38 -0
  541. synapse/storage/schema/common/full_schemas/72/full.sql.postgres +8 -0
  542. synapse/storage/schema/common/full_schemas/72/full.sql.sqlite +6 -0
  543. synapse/storage/schema/common/schema_version.sql +60 -0
  544. synapse/storage/schema/main/delta/12/v12.sql +82 -0
  545. synapse/storage/schema/main/delta/13/v13.sql +38 -0
  546. synapse/storage/schema/main/delta/14/v14.sql +42 -0
  547. synapse/storage/schema/main/delta/15/appservice_txns.sql +50 -0
  548. synapse/storage/schema/main/delta/15/presence_indices.sql +2 -0
  549. synapse/storage/schema/main/delta/15/v15.sql +24 -0
  550. synapse/storage/schema/main/delta/16/events_order_index.sql +4 -0
  551. synapse/storage/schema/main/delta/16/remote_media_cache_index.sql +2 -0
  552. synapse/storage/schema/main/delta/16/remove_duplicates.sql +9 -0
  553. synapse/storage/schema/main/delta/16/room_alias_index.sql +3 -0
  554. synapse/storage/schema/main/delta/16/unique_constraints.sql +72 -0
  555. synapse/storage/schema/main/delta/16/users.sql +56 -0
  556. synapse/storage/schema/main/delta/17/drop_indexes.sql +37 -0
  557. synapse/storage/schema/main/delta/17/server_keys.sql +43 -0
  558. synapse/storage/schema/main/delta/17/user_threepids.sql +9 -0
  559. synapse/storage/schema/main/delta/18/server_keys_bigger_ints.sql +51 -0
  560. synapse/storage/schema/main/delta/19/event_index.sql +38 -0
  561. synapse/storage/schema/main/delta/20/dummy.sql +1 -0
  562. synapse/storage/schema/main/delta/20/pushers.py +93 -0
  563. synapse/storage/schema/main/delta/21/end_to_end_keys.sql +53 -0
  564. synapse/storage/schema/main/delta/21/receipts.sql +57 -0
  565. synapse/storage/schema/main/delta/22/receipts_index.sql +41 -0
  566. synapse/storage/schema/main/delta/22/user_threepids_unique.sql +19 -0
  567. synapse/storage/schema/main/delta/24/stats_reporting.sql +37 -0
  568. synapse/storage/schema/main/delta/25/fts.py +81 -0
  569. synapse/storage/schema/main/delta/25/guest_access.sql +44 -0
  570. synapse/storage/schema/main/delta/25/history_visibility.sql +44 -0
  571. synapse/storage/schema/main/delta/25/tags.sql +57 -0
  572. synapse/storage/schema/main/delta/26/account_data.sql +36 -0
  573. synapse/storage/schema/main/delta/27/account_data.sql +55 -0
  574. synapse/storage/schema/main/delta/27/forgotten_memberships.sql +45 -0
  575. synapse/storage/schema/main/delta/27/ts.py +61 -0
  576. synapse/storage/schema/main/delta/28/event_push_actions.sql +46 -0
  577. synapse/storage/schema/main/delta/28/events_room_stream.sql +39 -0
  578. synapse/storage/schema/main/delta/28/public_roms_index.sql +39 -0
  579. synapse/storage/schema/main/delta/28/receipts_user_id_index.sql +41 -0
  580. synapse/storage/schema/main/delta/28/upgrade_times.sql +40 -0
  581. synapse/storage/schema/main/delta/28/users_is_guest.sql +41 -0
  582. synapse/storage/schema/main/delta/29/push_actions.sql +54 -0
  583. synapse/storage/schema/main/delta/30/alias_creator.sql +35 -0
  584. synapse/storage/schema/main/delta/30/as_users.py +82 -0
  585. synapse/storage/schema/main/delta/30/deleted_pushers.sql +44 -0
  586. synapse/storage/schema/main/delta/30/presence_stream.sql +49 -0
  587. synapse/storage/schema/main/delta/30/public_rooms.sql +42 -0
  588. synapse/storage/schema/main/delta/30/push_rule_stream.sql +57 -0
  589. synapse/storage/schema/main/delta/30/threepid_guest_access_tokens.sql +43 -0
  590. synapse/storage/schema/main/delta/31/invites.sql +61 -0
  591. synapse/storage/schema/main/delta/31/local_media_repository_url_cache.sql +46 -0
  592. synapse/storage/schema/main/delta/31/pushers_0.py +92 -0
  593. synapse/storage/schema/main/delta/31/pushers_index.sql +41 -0
  594. synapse/storage/schema/main/delta/31/search_update.py +65 -0
  595. synapse/storage/schema/main/delta/32/events.sql +35 -0
  596. synapse/storage/schema/main/delta/32/openid.sql +9 -0
  597. synapse/storage/schema/main/delta/32/pusher_throttle.sql +42 -0
  598. synapse/storage/schema/main/delta/32/remove_indices.sql +52 -0
  599. synapse/storage/schema/main/delta/32/reports.sql +44 -0
  600. synapse/storage/schema/main/delta/33/access_tokens_device_index.sql +36 -0
  601. synapse/storage/schema/main/delta/33/devices.sql +40 -0
  602. synapse/storage/schema/main/delta/33/devices_for_e2e_keys.sql +38 -0
  603. synapse/storage/schema/main/delta/33/devices_for_e2e_keys_clear_unknown_device.sql +39 -0
  604. synapse/storage/schema/main/delta/33/event_fields.py +61 -0
  605. synapse/storage/schema/main/delta/33/remote_media_ts.py +43 -0
  606. synapse/storage/schema/main/delta/33/user_ips_index.sql +36 -0
  607. synapse/storage/schema/main/delta/34/appservice_stream.sql +42 -0
  608. synapse/storage/schema/main/delta/34/cache_stream.py +50 -0
  609. synapse/storage/schema/main/delta/34/device_inbox.sql +43 -0
  610. synapse/storage/schema/main/delta/34/push_display_name_rename.sql +39 -0
  611. synapse/storage/schema/main/delta/34/received_txn_purge.py +36 -0
  612. synapse/storage/schema/main/delta/35/contains_url.sql +36 -0
  613. synapse/storage/schema/main/delta/35/device_outbox.sql +58 -0
  614. synapse/storage/schema/main/delta/35/device_stream_id.sql +40 -0
  615. synapse/storage/schema/main/delta/35/event_push_actions_index.sql +36 -0
  616. synapse/storage/schema/main/delta/35/public_room_list_change_stream.sql +52 -0
  617. synapse/storage/schema/main/delta/35/stream_order_to_extrem.sql +56 -0
  618. synapse/storage/schema/main/delta/36/readd_public_rooms.sql +45 -0
  619. synapse/storage/schema/main/delta/37/remove_auth_idx.py +89 -0
  620. synapse/storage/schema/main/delta/37/user_threepids.sql +71 -0
  621. synapse/storage/schema/main/delta/38/postgres_fts_gist.sql +38 -0
  622. synapse/storage/schema/main/delta/39/appservice_room_list.sql +48 -0
  623. synapse/storage/schema/main/delta/39/device_federation_stream_idx.sql +35 -0
  624. synapse/storage/schema/main/delta/39/event_push_index.sql +36 -0
  625. synapse/storage/schema/main/delta/39/federation_out_position.sql +41 -0
  626. synapse/storage/schema/main/delta/39/membership_profile.sql +39 -0
  627. synapse/storage/schema/main/delta/40/current_state_idx.sql +36 -0
  628. synapse/storage/schema/main/delta/40/device_inbox.sql +40 -0
  629. synapse/storage/schema/main/delta/40/device_list_streams.sql +79 -0
  630. synapse/storage/schema/main/delta/40/event_push_summary.sql +57 -0
  631. synapse/storage/schema/main/delta/40/pushers.sql +58 -0
  632. synapse/storage/schema/main/delta/41/device_list_stream_idx.sql +36 -0
  633. synapse/storage/schema/main/delta/41/device_outbound_index.sql +35 -0
  634. synapse/storage/schema/main/delta/41/event_search_event_id_idx.sql +36 -0
  635. synapse/storage/schema/main/delta/41/ratelimit.sql +41 -0
  636. synapse/storage/schema/main/delta/42/current_state_delta.sql +48 -0
  637. synapse/storage/schema/main/delta/42/device_list_last_id.sql +52 -0
  638. synapse/storage/schema/main/delta/42/event_auth_state_only.sql +36 -0
  639. synapse/storage/schema/main/delta/42/user_dir.py +88 -0
  640. synapse/storage/schema/main/delta/43/blocked_rooms.sql +40 -0
  641. synapse/storage/schema/main/delta/43/quarantine_media.sql +36 -0
  642. synapse/storage/schema/main/delta/43/url_cache.sql +35 -0
  643. synapse/storage/schema/main/delta/43/user_share.sql +52 -0
  644. synapse/storage/schema/main/delta/44/expire_url_cache.sql +60 -0
  645. synapse/storage/schema/main/delta/45/group_server.sql +186 -0
  646. synapse/storage/schema/main/delta/45/profile_cache.sql +47 -0
  647. synapse/storage/schema/main/delta/46/drop_refresh_tokens.sql +36 -0
  648. synapse/storage/schema/main/delta/46/drop_unique_deleted_pushers.sql +54 -0
  649. synapse/storage/schema/main/delta/46/group_server.sql +51 -0
  650. synapse/storage/schema/main/delta/46/local_media_repository_url_idx.sql +43 -0
  651. synapse/storage/schema/main/delta/46/user_dir_null_room_ids.sql +54 -0
  652. synapse/storage/schema/main/delta/46/user_dir_typos.sql +43 -0
  653. synapse/storage/schema/main/delta/47/last_access_media.sql +35 -0
  654. synapse/storage/schema/main/delta/47/postgres_fts_gin.sql +36 -0
  655. synapse/storage/schema/main/delta/47/push_actions_staging.sql +47 -0
  656. synapse/storage/schema/main/delta/48/add_user_consent.sql +37 -0
  657. synapse/storage/schema/main/delta/48/add_user_ips_last_seen_index.sql +36 -0
  658. synapse/storage/schema/main/delta/48/deactivated_users.sql +44 -0
  659. synapse/storage/schema/main/delta/48/group_unique_indexes.py +67 -0
  660. synapse/storage/schema/main/delta/48/groups_joinable.sql +41 -0
  661. synapse/storage/schema/main/delta/49/add_user_consent_server_notice_sent.sql +39 -0
  662. synapse/storage/schema/main/delta/49/add_user_daily_visits.sql +40 -0
  663. synapse/storage/schema/main/delta/49/add_user_ips_last_seen_only_index.sql +36 -0
  664. synapse/storage/schema/main/delta/50/add_creation_ts_users_index.sql +38 -0
  665. synapse/storage/schema/main/delta/50/erasure_store.sql +40 -0
  666. synapse/storage/schema/main/delta/50/make_event_content_nullable.py +102 -0
  667. synapse/storage/schema/main/delta/51/e2e_room_keys.sql +58 -0
  668. synapse/storage/schema/main/delta/51/monthly_active_users.sql +46 -0
  669. synapse/storage/schema/main/delta/52/add_event_to_state_group_index.sql +38 -0
  670. synapse/storage/schema/main/delta/52/device_list_streams_unique_idx.sql +55 -0
  671. synapse/storage/schema/main/delta/52/e2e_room_keys.sql +72 -0
  672. synapse/storage/schema/main/delta/53/add_user_type_to_users.sql +38 -0
  673. synapse/storage/schema/main/delta/53/drop_sent_transactions.sql +35 -0
  674. synapse/storage/schema/main/delta/53/event_format_version.sql +35 -0
  675. synapse/storage/schema/main/delta/53/user_dir_populate.sql +49 -0
  676. synapse/storage/schema/main/delta/53/user_ips_index.sql +49 -0
  677. synapse/storage/schema/main/delta/53/user_share.sql +63 -0
  678. synapse/storage/schema/main/delta/53/user_threepid_id.sql +48 -0
  679. synapse/storage/schema/main/delta/53/users_in_public_rooms.sql +47 -0
  680. synapse/storage/schema/main/delta/54/account_validity_with_renewal.sql +49 -0
  681. synapse/storage/schema/main/delta/54/add_validity_to_server_keys.sql +42 -0
  682. synapse/storage/schema/main/delta/54/delete_forward_extremities.sql +42 -0
  683. synapse/storage/schema/main/delta/54/drop_legacy_tables.sql +49 -0
  684. synapse/storage/schema/main/delta/54/drop_presence_list.sql +35 -0
  685. synapse/storage/schema/main/delta/54/relations.sql +46 -0
  686. synapse/storage/schema/main/delta/54/stats.sql +99 -0
  687. synapse/storage/schema/main/delta/54/stats2.sql +47 -0
  688. synapse/storage/schema/main/delta/55/access_token_expiry.sql +37 -0
  689. synapse/storage/schema/main/delta/55/track_threepid_validations.sql +50 -0
  690. synapse/storage/schema/main/delta/55/users_alter_deactivated.sql +38 -0
  691. synapse/storage/schema/main/delta/56/add_spans_to_device_lists.sql +39 -0
  692. synapse/storage/schema/main/delta/56/current_state_events_membership.sql +41 -0
  693. synapse/storage/schema/main/delta/56/current_state_events_membership_mk2.sql +43 -0
  694. synapse/storage/schema/main/delta/56/delete_keys_from_deleted_backups.sql +44 -0
  695. synapse/storage/schema/main/delta/56/destinations_failure_ts.sql +44 -0
  696. synapse/storage/schema/main/delta/56/destinations_retry_interval_type.sql.postgres +18 -0
  697. synapse/storage/schema/main/delta/56/device_stream_id_insert.sql +39 -0
  698. synapse/storage/schema/main/delta/56/devices_last_seen.sql +43 -0
  699. synapse/storage/schema/main/delta/56/drop_unused_event_tables.sql +39 -0
  700. synapse/storage/schema/main/delta/56/event_expiry.sql +40 -0
  701. synapse/storage/schema/main/delta/56/event_labels.sql +49 -0
  702. synapse/storage/schema/main/delta/56/event_labels_background_update.sql +36 -0
  703. synapse/storage/schema/main/delta/56/fix_room_keys_index.sql +37 -0
  704. synapse/storage/schema/main/delta/56/hidden_devices.sql +37 -0
  705. synapse/storage/schema/main/delta/56/hidden_devices_fix.sql.sqlite +42 -0
  706. synapse/storage/schema/main/delta/56/nuke_empty_communities_from_db.sql +48 -0
  707. synapse/storage/schema/main/delta/56/public_room_list_idx.sql +35 -0
  708. synapse/storage/schema/main/delta/56/redaction_censor.sql +35 -0
  709. synapse/storage/schema/main/delta/56/redaction_censor2.sql +41 -0
  710. synapse/storage/schema/main/delta/56/redaction_censor3_fix_update.sql.postgres +25 -0
  711. synapse/storage/schema/main/delta/56/redaction_censor4.sql +35 -0
  712. synapse/storage/schema/main/delta/56/remove_tombstoned_rooms_from_directory.sql +38 -0
  713. synapse/storage/schema/main/delta/56/room_key_etag.sql +36 -0
  714. synapse/storage/schema/main/delta/56/room_membership_idx.sql +37 -0
  715. synapse/storage/schema/main/delta/56/room_retention.sql +52 -0
  716. synapse/storage/schema/main/delta/56/signing_keys.sql +75 -0
  717. synapse/storage/schema/main/delta/56/signing_keys_nonunique_signatures.sql +41 -0
  718. synapse/storage/schema/main/delta/56/stats_separated.sql +175 -0
  719. synapse/storage/schema/main/delta/56/unique_user_filter_index.py +46 -0
  720. synapse/storage/schema/main/delta/56/user_external_ids.sql +43 -0
  721. synapse/storage/schema/main/delta/56/users_in_public_rooms_idx.sql +36 -0
  722. synapse/storage/schema/main/delta/57/delete_old_current_state_events.sql +41 -0
  723. synapse/storage/schema/main/delta/57/device_list_remote_cache_stale.sql +44 -0
  724. synapse/storage/schema/main/delta/57/local_current_membership.py +111 -0
  725. synapse/storage/schema/main/delta/57/remove_sent_outbound_pokes.sql +40 -0
  726. synapse/storage/schema/main/delta/57/rooms_version_column.sql +43 -0
  727. synapse/storage/schema/main/delta/57/rooms_version_column_2.sql.postgres +35 -0
  728. synapse/storage/schema/main/delta/57/rooms_version_column_2.sql.sqlite +22 -0
  729. synapse/storage/schema/main/delta/57/rooms_version_column_3.sql.postgres +39 -0
  730. synapse/storage/schema/main/delta/57/rooms_version_column_3.sql.sqlite +23 -0
  731. synapse/storage/schema/main/delta/58/02remove_dup_outbound_pokes.sql +41 -0
  732. synapse/storage/schema/main/delta/58/03persist_ui_auth.sql +55 -0
  733. synapse/storage/schema/main/delta/58/05cache_instance.sql.postgres +30 -0
  734. synapse/storage/schema/main/delta/58/06dlols_unique_idx.py +83 -0
  735. synapse/storage/schema/main/delta/58/07add_method_to_thumbnail_constraint.sql.postgres +33 -0
  736. synapse/storage/schema/main/delta/58/07add_method_to_thumbnail_constraint.sql.sqlite +44 -0
  737. synapse/storage/schema/main/delta/58/07persist_ui_auth_ips.sql +44 -0
  738. synapse/storage/schema/main/delta/58/08_media_safe_from_quarantine.sql.postgres +18 -0
  739. synapse/storage/schema/main/delta/58/08_media_safe_from_quarantine.sql.sqlite +18 -0
  740. synapse/storage/schema/main/delta/58/09shadow_ban.sql +37 -0
  741. synapse/storage/schema/main/delta/58/10_pushrules_enabled_delete_obsolete.sql +47 -0
  742. synapse/storage/schema/main/delta/58/10drop_local_rejections_stream.sql +41 -0
  743. synapse/storage/schema/main/delta/58/10federation_pos_instance_name.sql +41 -0
  744. synapse/storage/schema/main/delta/58/11dehydration.sql +39 -0
  745. synapse/storage/schema/main/delta/58/11fallback.sql +43 -0
  746. synapse/storage/schema/main/delta/58/11user_id_seq.py +38 -0
  747. synapse/storage/schema/main/delta/58/12room_stats.sql +51 -0
  748. synapse/storage/schema/main/delta/58/13remove_presence_allow_inbound.sql +36 -0
  749. synapse/storage/schema/main/delta/58/14events_instance_name.sql +35 -0
  750. synapse/storage/schema/main/delta/58/14events_instance_name.sql.postgres +28 -0
  751. synapse/storage/schema/main/delta/58/15_catchup_destination_rooms.sql +61 -0
  752. synapse/storage/schema/main/delta/58/15unread_count.sql +45 -0
  753. synapse/storage/schema/main/delta/58/16populate_stats_process_rooms_fix.sql +41 -0
  754. synapse/storage/schema/main/delta/58/17_catchup_last_successful.sql +40 -0
  755. synapse/storage/schema/main/delta/58/18stream_positions.sql +41 -0
  756. synapse/storage/schema/main/delta/58/19instance_map.sql.postgres +25 -0
  757. synapse/storage/schema/main/delta/58/19txn_id.sql +59 -0
  758. synapse/storage/schema/main/delta/58/20instance_name_event_tables.sql +36 -0
  759. synapse/storage/schema/main/delta/58/20user_daily_visits.sql +37 -0
  760. synapse/storage/schema/main/delta/58/21as_device_stream.sql +36 -0
  761. synapse/storage/schema/main/delta/58/21drop_device_max_stream_id.sql +1 -0
  762. synapse/storage/schema/main/delta/58/22puppet_token.sql +36 -0
  763. synapse/storage/schema/main/delta/58/22users_have_local_media.sql +2 -0
  764. synapse/storage/schema/main/delta/58/23e2e_cross_signing_keys_idx.sql +36 -0
  765. synapse/storage/schema/main/delta/58/24drop_event_json_index.sql +38 -0
  766. synapse/storage/schema/main/delta/58/25user_external_ids_user_id_idx.sql +36 -0
  767. synapse/storage/schema/main/delta/58/26access_token_last_validated.sql +37 -0
  768. synapse/storage/schema/main/delta/58/27local_invites.sql +37 -0
  769. synapse/storage/schema/main/delta/58/28drop_last_used_column.sql.postgres +16 -0
  770. synapse/storage/schema/main/delta/58/28drop_last_used_column.sql.sqlite +62 -0
  771. synapse/storage/schema/main/delta/59/01ignored_user.py +85 -0
  772. synapse/storage/schema/main/delta/59/02shard_send_to_device.sql +37 -0
  773. synapse/storage/schema/main/delta/59/03shard_send_to_device_sequence.sql.postgres +25 -0
  774. synapse/storage/schema/main/delta/59/04_event_auth_chains.sql +71 -0
  775. synapse/storage/schema/main/delta/59/04_event_auth_chains.sql.postgres +16 -0
  776. synapse/storage/schema/main/delta/59/04drop_account_data.sql +36 -0
  777. synapse/storage/schema/main/delta/59/05cache_invalidation.sql +36 -0
  778. synapse/storage/schema/main/delta/59/06chain_cover_index.sql +36 -0
  779. synapse/storage/schema/main/delta/59/06shard_account_data.sql +39 -0
  780. synapse/storage/schema/main/delta/59/06shard_account_data.sql.postgres +32 -0
  781. synapse/storage/schema/main/delta/59/07shard_account_data_fix.sql +37 -0
  782. synapse/storage/schema/main/delta/59/08delete_pushers_for_deactivated_accounts.sql +39 -0
  783. synapse/storage/schema/main/delta/59/08delete_stale_pushers.sql +39 -0
  784. synapse/storage/schema/main/delta/59/09rejected_events_metadata.sql +45 -0
  785. synapse/storage/schema/main/delta/59/10delete_purged_chain_cover.sql +36 -0
  786. synapse/storage/schema/main/delta/59/11add_knock_members_to_stats.sql +39 -0
  787. synapse/storage/schema/main/delta/59/11drop_thumbnail_constraint.sql.postgres +22 -0
  788. synapse/storage/schema/main/delta/59/12account_validity_token_used_ts_ms.sql +37 -0
  789. synapse/storage/schema/main/delta/59/12presence_stream_instance.sql +37 -0
  790. synapse/storage/schema/main/delta/59/12presence_stream_instance_seq.sql.postgres +20 -0
  791. synapse/storage/schema/main/delta/59/13users_to_send_full_presence_to.sql +53 -0
  792. synapse/storage/schema/main/delta/59/14refresh_tokens.sql +53 -0
  793. synapse/storage/schema/main/delta/59/15locks.sql +56 -0
  794. synapse/storage/schema/main/delta/59/16federation_inbound_staging.sql +51 -0
  795. synapse/storage/schema/main/delta/60/01recreate_stream_ordering.sql.postgres +45 -0
  796. synapse/storage/schema/main/delta/60/02change_stream_ordering_columns.sql.postgres +30 -0
  797. synapse/storage/schema/main/delta/61/01change_appservices_txns.sql.postgres +23 -0
  798. synapse/storage/schema/main/delta/61/01insertion_event_lookups.sql +68 -0
  799. synapse/storage/schema/main/delta/61/02drop_redundant_room_depth_index.sql +37 -0
  800. synapse/storage/schema/main/delta/61/03recreate_min_depth.py +74 -0
  801. synapse/storage/schema/main/delta/62/01insertion_event_extremities.sql +43 -0
  802. synapse/storage/schema/main/delta/63/01create_registration_tokens.sql +42 -0
  803. synapse/storage/schema/main/delta/63/02delete_unlinked_email_pushers.sql +39 -0
  804. synapse/storage/schema/main/delta/63/02populate-rooms-creator.sql +36 -0
  805. synapse/storage/schema/main/delta/63/03session_store.sql +42 -0
  806. synapse/storage/schema/main/delta/63/04add_presence_stream_not_offline_index.sql +37 -0
  807. synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.postgres +23 -0
  808. synapse/storage/schema/main/delta/64/01msc2716_chunk_to_batch_rename.sql.sqlite +37 -0
  809. synapse/storage/schema/main/delta/65/01msc2716_insertion_event_edges.sql +38 -0
  810. synapse/storage/schema/main/delta/65/03remove_hidden_devices_from_device_inbox.sql +41 -0
  811. synapse/storage/schema/main/delta/65/04_local_group_updates.sql +37 -0
  812. synapse/storage/schema/main/delta/65/05_remove_room_stats_historical_and_user_stats_historical.sql +38 -0
  813. synapse/storage/schema/main/delta/65/06remove_deleted_devices_from_device_inbox.sql +53 -0
  814. synapse/storage/schema/main/delta/65/07_arbitrary_relations.sql +37 -0
  815. synapse/storage/schema/main/delta/65/08_device_inbox_background_updates.sql +37 -0
  816. synapse/storage/schema/main/delta/65/10_expirable_refresh_tokens.sql +47 -0
  817. synapse/storage/schema/main/delta/65/11_devices_auth_provider_session.sql +46 -0
  818. synapse/storage/schema/main/delta/67/01drop_public_room_list_stream.sql +37 -0
  819. synapse/storage/schema/main/delta/68/01event_columns.sql +45 -0
  820. synapse/storage/schema/main/delta/68/02_msc2409_add_device_id_appservice_stream_type.sql +40 -0
  821. synapse/storage/schema/main/delta/68/03_delete_account_data_for_deactivated_accounts.sql +39 -0
  822. synapse/storage/schema/main/delta/68/04_refresh_tokens_index_next_token_id.sql +47 -0
  823. synapse/storage/schema/main/delta/68/04partial_state_rooms.sql +60 -0
  824. synapse/storage/schema/main/delta/68/05_delete_non_strings_from_event_search.sql.sqlite +22 -0
  825. synapse/storage/schema/main/delta/68/05partial_state_rooms_triggers.py +80 -0
  826. synapse/storage/schema/main/delta/68/06_msc3202_add_device_list_appservice_stream_type.sql +42 -0
  827. synapse/storage/schema/main/delta/69/01as_txn_seq.py +54 -0
  828. synapse/storage/schema/main/delta/69/01device_list_oubound_by_room.sql +57 -0
  829. synapse/storage/schema/main/delta/69/02cache_invalidation_index.sql +37 -0
  830. synapse/storage/schema/main/delta/70/01clean_table_purged_rooms.sql +39 -0
  831. synapse/storage/schema/main/delta/71/01rebuild_event_edges.sql.postgres +43 -0
  832. synapse/storage/schema/main/delta/71/01rebuild_event_edges.sql.sqlite +47 -0
  833. synapse/storage/schema/main/delta/71/01remove_noop_background_updates.sql +80 -0
  834. synapse/storage/schema/main/delta/71/02event_push_summary_unique.sql +37 -0
  835. synapse/storage/schema/main/delta/72/01add_room_type_to_state_stats.sql +38 -0
  836. synapse/storage/schema/main/delta/72/01event_push_summary_receipt.sql +54 -0
  837. synapse/storage/schema/main/delta/72/02event_push_actions_index.sql +38 -0
  838. synapse/storage/schema/main/delta/72/03bg_populate_events_columns.py +57 -0
  839. synapse/storage/schema/main/delta/72/03drop_event_reference_hashes.sql +36 -0
  840. synapse/storage/schema/main/delta/72/03remove_groups.sql +50 -0
  841. synapse/storage/schema/main/delta/72/04drop_column_application_services_state_last_txn.sql.postgres +17 -0
  842. synapse/storage/schema/main/delta/72/04drop_column_application_services_state_last_txn.sql.sqlite +40 -0
  843. synapse/storage/schema/main/delta/72/05receipts_event_stream_ordering.sql +38 -0
  844. synapse/storage/schema/main/delta/72/05remove_unstable_private_read_receipts.sql +38 -0
  845. synapse/storage/schema/main/delta/72/06add_consent_ts_to_users.sql +35 -0
  846. synapse/storage/schema/main/delta/72/06thread_notifications.sql +49 -0
  847. synapse/storage/schema/main/delta/72/07force_update_current_state_events_membership.py +67 -0
  848. synapse/storage/schema/main/delta/72/07thread_receipts.sql.postgres +30 -0
  849. synapse/storage/schema/main/delta/72/07thread_receipts.sql.sqlite +70 -0
  850. synapse/storage/schema/main/delta/72/08begin_cache_invalidation_seq_at_2.sql.postgres +23 -0
  851. synapse/storage/schema/main/delta/72/08thread_receipts.sql +39 -0
  852. synapse/storage/schema/main/delta/72/09partial_indices.sql.sqlite +56 -0
  853. synapse/storage/schema/main/delta/73/01event_failed_pull_attempts.sql +48 -0
  854. synapse/storage/schema/main/delta/73/02add_pusher_enabled.sql +35 -0
  855. synapse/storage/schema/main/delta/73/02room_id_indexes_for_purging.sql +41 -0
  856. synapse/storage/schema/main/delta/73/03pusher_device_id.sql +39 -0
  857. synapse/storage/schema/main/delta/73/03users_approved_column.sql +39 -0
  858. synapse/storage/schema/main/delta/73/04partial_join_details.sql +42 -0
  859. synapse/storage/schema/main/delta/73/04pending_device_list_updates.sql +47 -0
  860. synapse/storage/schema/main/delta/73/05old_push_actions.sql.postgres +22 -0
  861. synapse/storage/schema/main/delta/73/05old_push_actions.sql.sqlite +24 -0
  862. synapse/storage/schema/main/delta/73/06thread_notifications_thread_id_idx.sql +42 -0
  863. synapse/storage/schema/main/delta/73/08thread_receipts_non_null.sql.postgres +23 -0
  864. synapse/storage/schema/main/delta/73/08thread_receipts_non_null.sql.sqlite +76 -0
  865. synapse/storage/schema/main/delta/73/09partial_joined_via_destination.sql +37 -0
  866. synapse/storage/schema/main/delta/73/09threads_table.sql +49 -0
  867. synapse/storage/schema/main/delta/73/10_update_sqlite_fts4_tokenizer.py +71 -0
  868. synapse/storage/schema/main/delta/73/10login_tokens.sql +54 -0
  869. synapse/storage/schema/main/delta/73/11event_search_room_id_n_distinct.sql.postgres +33 -0
  870. synapse/storage/schema/main/delta/73/12refactor_device_list_outbound_pokes.sql +72 -0
  871. synapse/storage/schema/main/delta/73/13add_device_lists_index.sql +39 -0
  872. synapse/storage/schema/main/delta/73/20_un_partial_stated_room_stream.sql +51 -0
  873. synapse/storage/schema/main/delta/73/21_un_partial_stated_room_stream_seq.sql.postgres +20 -0
  874. synapse/storage/schema/main/delta/73/22_rebuild_user_dir_stats.sql +48 -0
  875. synapse/storage/schema/main/delta/73/22_un_partial_stated_event_stream.sql +53 -0
  876. synapse/storage/schema/main/delta/73/23_fix_thread_index.sql +52 -0
  877. synapse/storage/schema/main/delta/73/23_un_partial_stated_room_stream_seq.sql.postgres +20 -0
  878. synapse/storage/schema/main/delta/73/24_events_jump_to_date_index.sql +36 -0
  879. synapse/storage/schema/main/delta/73/25drop_presence.sql +36 -0
  880. synapse/storage/schema/main/delta/74/01_user_directory_stale_remote_users.sql +58 -0
  881. synapse/storage/schema/main/delta/74/02_set_device_id_for_pushers_bg_update.sql +38 -0
  882. synapse/storage/schema/main/delta/74/03_membership_tables_event_stream_ordering.sql.postgres +29 -0
  883. synapse/storage/schema/main/delta/74/03_membership_tables_event_stream_ordering.sql.sqlite +23 -0
  884. synapse/storage/schema/main/delta/74/03_room_membership_index.sql +38 -0
  885. synapse/storage/schema/main/delta/74/04_delete_e2e_backup_keys_for_deactivated_users.sql +36 -0
  886. synapse/storage/schema/main/delta/74/04_membership_tables_event_stream_ordering_triggers.py +87 -0
  887. synapse/storage/schema/main/delta/74/05_events_txn_id_device_id.sql +72 -0
  888. synapse/storage/schema/main/delta/74/90COMMENTS_destinations.sql.postgres +52 -0
  889. synapse/storage/schema/main/delta/76/01_add_profiles_full_user_id_column.sql +39 -0
  890. synapse/storage/schema/main/delta/76/02_add_user_filters_full_user_id_column.sql +39 -0
  891. synapse/storage/schema/main/delta/76/03_per_user_experimental_features.sql +46 -0
  892. synapse/storage/schema/main/delta/76/04_add_room_forgetter.sql +43 -0
  893. synapse/storage/schema/main/delta/77/01_add_profiles_not_valid_check.sql.postgres +16 -0
  894. synapse/storage/schema/main/delta/77/02_add_user_filters_not_valid_check.sql.postgres +16 -0
  895. synapse/storage/schema/main/delta/77/03bg_populate_full_user_id_profiles.sql +35 -0
  896. synapse/storage/schema/main/delta/77/04bg_populate_full_user_id_user_filters.sql +35 -0
  897. synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql +67 -0
  898. synapse/storage/schema/main/delta/77/06thread_notifications_not_null.sql.sqlite +102 -0
  899. synapse/storage/schema/main/delta/77/06thread_notifications_not_null_event_push_actions.sql.postgres +27 -0
  900. synapse/storage/schema/main/delta/77/06thread_notifications_not_null_event_push_actions_staging.sql.postgres +27 -0
  901. synapse/storage/schema/main/delta/77/06thread_notifications_not_null_event_push_summary.sql.postgres +29 -0
  902. synapse/storage/schema/main/delta/77/14bg_indices_event_stream_ordering.sql +39 -0
  903. synapse/storage/schema/main/delta/78/01_validate_and_update_profiles.py +99 -0
  904. synapse/storage/schema/main/delta/78/02_validate_and_update_user_filters.py +100 -0
  905. synapse/storage/schema/main/delta/78/03_remove_unused_indexes_user_filters.py +72 -0
  906. synapse/storage/schema/main/delta/78/03event_extremities_constraints.py +65 -0
  907. synapse/storage/schema/main/delta/78/04_add_full_user_id_index_user_filters.py +32 -0
  908. synapse/storage/schema/main/delta/79/03_read_write_locks_triggers.sql.postgres +102 -0
  909. synapse/storage/schema/main/delta/79/03_read_write_locks_triggers.sql.sqlite +72 -0
  910. synapse/storage/schema/main/delta/79/04_mitigate_stream_ordering_update_race.py +70 -0
  911. synapse/storage/schema/main/delta/79/05_read_write_locks_triggers.sql.postgres +69 -0
  912. synapse/storage/schema/main/delta/79/05_read_write_locks_triggers.sql.sqlite +65 -0
  913. synapse/storage/schema/main/delta/80/01_users_alter_locked.sql +35 -0
  914. synapse/storage/schema/main/delta/80/02_read_write_locks_unlogged.sql.postgres +30 -0
  915. synapse/storage/schema/main/delta/80/02_scheduled_tasks.sql +47 -0
  916. synapse/storage/schema/main/delta/80/03_read_write_locks_triggers.sql.postgres +37 -0
  917. synapse/storage/schema/main/delta/80/04_read_write_locks_deadlock.sql.postgres +71 -0
  918. synapse/storage/schema/main/delta/82/02_scheduled_tasks_index.sql +35 -0
  919. synapse/storage/schema/main/delta/82/04_add_indices_for_purging_rooms.sql +39 -0
  920. synapse/storage/schema/main/delta/82/05gaps.sql +44 -0
  921. synapse/storage/schema/main/delta/83/01_drop_old_tables.sql +43 -0
  922. synapse/storage/schema/main/delta/83/03_instance_name_receipts.sql.sqlite +17 -0
  923. synapse/storage/schema/main/delta/83/05_cross_signing_key_update_grant.sql +34 -0
  924. synapse/storage/schema/main/delta/83/06_event_push_summary_room.sql +36 -0
  925. synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres +20 -0
  926. synapse/storage/schema/main/delta/84/02_auth_links_index.sql +16 -0
  927. synapse/storage/schema/main/delta/84/03_auth_links_analyze.sql.postgres +16 -0
  928. synapse/storage/schema/main/delta/84/04_access_token_index.sql +15 -0
  929. synapse/storage/schema/main/delta/85/01_add_suspended.sql +14 -0
  930. synapse/storage/schema/main/delta/85/02_add_instance_names.sql +27 -0
  931. synapse/storage/schema/main/delta/85/03_new_sequences.sql.postgres +54 -0
  932. synapse/storage/schema/main/delta/85/04_cleanup_device_federation_outbox.sql +15 -0
  933. synapse/storage/schema/main/delta/85/05_add_instance_names_converted_pos.sql +16 -0
  934. synapse/storage/schema/main/delta/85/06_add_room_reports.sql +20 -0
  935. synapse/storage/schema/main/delta/86/01_authenticate_media.sql +15 -0
  936. synapse/storage/schema/main/delta/86/02_receipts_event_id_index.sql +15 -0
  937. synapse/storage/schema/main/delta/87/01_sliding_sync_memberships.sql +169 -0
  938. synapse/storage/schema/main/delta/87/02_per_connection_state.sql +81 -0
  939. synapse/storage/schema/main/delta/87/03_current_state_index.sql +19 -0
  940. synapse/storage/schema/main/delta/88/01_add_delayed_events.sql +43 -0
  941. synapse/storage/schema/main/delta/88/01_custom_profile_fields.sql +15 -0
  942. synapse/storage/schema/main/delta/88/02_fix_sliding_sync_membership_snapshots_forgotten_column.sql +21 -0
  943. synapse/storage/schema/main/delta/88/03_add_otk_ts_added_index.sql +18 -0
  944. synapse/storage/schema/main/delta/88/04_current_state_delta_index.sql +18 -0
  945. synapse/storage/schema/main/delta/88/05_drop_old_otks.sql.postgres +19 -0
  946. synapse/storage/schema/main/delta/88/05_drop_old_otks.sql.sqlite +19 -0
  947. synapse/storage/schema/main/delta/88/05_sliding_sync_room_config_index.sql +20 -0
  948. synapse/storage/schema/main/delta/88/06_events_received_ts_index.sql +17 -0
  949. synapse/storage/schema/main/delta/89/01_sliding_sync_membership_snapshot_index.sql +15 -0
  950. synapse/storage/schema/main/delta/90/01_add_column_participant_room_memberships_table.sql +16 -0
  951. synapse/storage/schema/main/delta/91/01_media_hash.sql +28 -0
  952. synapse/storage/schema/main/delta/92/01_remove_trigger.sql.postgres +16 -0
  953. synapse/storage/schema/main/delta/92/01_remove_trigger.sql.sqlite +16 -0
  954. synapse/storage/schema/main/delta/92/02_remove_populate_participant_bg_update.sql +17 -0
  955. synapse/storage/schema/main/delta/92/04_ss_membership_snapshot_idx.sql +16 -0
  956. synapse/storage/schema/main/delta/92/04_thread_subscriptions.sql +59 -0
  957. synapse/storage/schema/main/delta/92/04_thread_subscriptions_seq.sql.postgres +19 -0
  958. synapse/storage/schema/main/delta/92/05_fixup_max_depth_cap.sql +17 -0
  959. synapse/storage/schema/main/delta/92/05_thread_subscriptions_comments.sql.postgres +18 -0
  960. synapse/storage/schema/main/delta/92/06_device_federation_inbox_index.sql +16 -0
  961. synapse/storage/schema/main/delta/92/06_threads_last_sent_stream_ordering_comments.sql.postgres +24 -0
  962. synapse/storage/schema/main/delta/92/07_add_user_reports.sql +22 -0
  963. synapse/storage/schema/main/delta/92/07_event_txn_id_device_id_txn_id2.sql +15 -0
  964. synapse/storage/schema/main/delta/92/08_room_ban_redactions.sql +21 -0
  965. synapse/storage/schema/main/delta/92/08_thread_subscriptions_seq_fixup.sql.postgres +19 -0
  966. synapse/storage/schema/main/delta/92/09_thread_subscriptions_update.sql +20 -0
  967. synapse/storage/schema/main/delta/92/09_thread_subscriptions_update.sql.postgres +18 -0
  968. synapse/storage/schema/main/delta/93/01_add_delayed_events.sql +15 -0
  969. synapse/storage/schema/main/full_schemas/72/full.sql.postgres +1344 -0
  970. synapse/storage/schema/main/full_schemas/72/full.sql.sqlite +646 -0
  971. synapse/storage/schema/state/delta/23/drop_state_index.sql +35 -0
  972. synapse/storage/schema/state/delta/32/remove_state_indices.sql +38 -0
  973. synapse/storage/schema/state/delta/35/add_state_index.sql +36 -0
  974. synapse/storage/schema/state/delta/35/state.sql +41 -0
  975. synapse/storage/schema/state/delta/35/state_dedupe.sql +36 -0
  976. synapse/storage/schema/state/delta/47/state_group_seq.py +38 -0
  977. synapse/storage/schema/state/delta/56/state_group_room_idx.sql +36 -0
  978. synapse/storage/schema/state/delta/61/02state_groups_state_n_distinct.sql.postgres +34 -0
  979. synapse/storage/schema/state/delta/70/08_state_group_edges_unique.sql +36 -0
  980. synapse/storage/schema/state/delta/89/01_state_groups_deletion.sql +39 -0
  981. synapse/storage/schema/state/delta/90/02_delete_unreferenced_state_groups.sql +16 -0
  982. synapse/storage/schema/state/delta/90/03_remove_old_deletion_bg_update.sql +15 -0
  983. synapse/storage/schema/state/full_schemas/72/full.sql.postgres +30 -0
  984. synapse/storage/schema/state/full_schemas/72/full.sql.sqlite +20 -0
  985. synapse/storage/types.py +183 -0
  986. synapse/storage/util/__init__.py +20 -0
  987. synapse/storage/util/id_generators.py +928 -0
  988. synapse/storage/util/partial_state_events_tracker.py +194 -0
  989. synapse/storage/util/sequence.py +315 -0
  990. synapse/streams/__init__.py +43 -0
  991. synapse/streams/config.py +91 -0
  992. synapse/streams/events.py +203 -0
  993. synapse/synapse_rust/__init__.pyi +3 -0
  994. synapse/synapse_rust/acl.pyi +20 -0
  995. synapse/synapse_rust/events.pyi +136 -0
  996. synapse/synapse_rust/http_client.pyi +32 -0
  997. synapse/synapse_rust/push.pyi +86 -0
  998. synapse/synapse_rust/rendezvous.pyi +30 -0
  999. synapse/synapse_rust/segmenter.pyi +1 -0
  1000. synapse/synapse_rust.abi3.so +0 -0
  1001. synapse/types/__init__.py +1600 -0
  1002. synapse/types/handlers/__init__.py +93 -0
  1003. synapse/types/handlers/policy_server.py +16 -0
  1004. synapse/types/handlers/sliding_sync.py +908 -0
  1005. synapse/types/rest/__init__.py +25 -0
  1006. synapse/types/rest/client/__init__.py +413 -0
  1007. synapse/types/state.py +634 -0
  1008. synapse/types/storage/__init__.py +66 -0
  1009. synapse/util/__init__.py +169 -0
  1010. synapse/util/async_helpers.py +1045 -0
  1011. synapse/util/background_queue.py +142 -0
  1012. synapse/util/batching_queue.py +202 -0
  1013. synapse/util/caches/__init__.py +300 -0
  1014. synapse/util/caches/cached_call.py +143 -0
  1015. synapse/util/caches/deferred_cache.py +530 -0
  1016. synapse/util/caches/descriptors.py +692 -0
  1017. synapse/util/caches/dictionary_cache.py +346 -0
  1018. synapse/util/caches/expiringcache.py +249 -0
  1019. synapse/util/caches/lrucache.py +975 -0
  1020. synapse/util/caches/response_cache.py +322 -0
  1021. synapse/util/caches/stream_change_cache.py +370 -0
  1022. synapse/util/caches/treecache.py +189 -0
  1023. synapse/util/caches/ttlcache.py +197 -0
  1024. synapse/util/cancellation.py +63 -0
  1025. synapse/util/check_dependencies.py +335 -0
  1026. synapse/util/clock.py +567 -0
  1027. synapse/util/constants.py +22 -0
  1028. synapse/util/daemonize.py +165 -0
  1029. synapse/util/distributor.py +157 -0
  1030. synapse/util/events.py +134 -0
  1031. synapse/util/file_consumer.py +164 -0
  1032. synapse/util/frozenutils.py +57 -0
  1033. synapse/util/gai_resolver.py +178 -0
  1034. synapse/util/hash.py +38 -0
  1035. synapse/util/httpresourcetree.py +108 -0
  1036. synapse/util/iterutils.py +189 -0
  1037. synapse/util/json.py +56 -0
  1038. synapse/util/linked_list.py +156 -0
  1039. synapse/util/logcontext.py +46 -0
  1040. synapse/util/logformatter.py +28 -0
  1041. synapse/util/macaroons.py +325 -0
  1042. synapse/util/manhole.py +191 -0
  1043. synapse/util/metrics.py +339 -0
  1044. synapse/util/module_loader.py +116 -0
  1045. synapse/util/msisdn.py +51 -0
  1046. synapse/util/patch_inline_callbacks.py +250 -0
  1047. synapse/util/pydantic_models.py +63 -0
  1048. synapse/util/ratelimitutils.py +419 -0
  1049. synapse/util/retryutils.py +339 -0
  1050. synapse/util/rlimit.py +42 -0
  1051. synapse/util/rust.py +133 -0
  1052. synapse/util/sentinel.py +21 -0
  1053. synapse/util/stringutils.py +293 -0
  1054. synapse/util/task_scheduler.py +493 -0
  1055. synapse/util/templates.py +126 -0
  1056. synapse/util/threepids.py +123 -0
  1057. synapse/util/wheel_timer.py +112 -0
  1058. synapse/visibility.py +835 -0
@@ -0,0 +1,2131 @@
1
+ #
2
+ # This file is licensed under the Affero General Public License (AGPL) version 3.
3
+ #
4
+ # Copyright 2020 The Matrix.org Foundation C.I.C.
5
+ # Copyright (C) 2023 New Vector, Ltd
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as
9
+ # published by the Free Software Foundation, either version 3 of the
10
+ # License, or (at your option) any later version.
11
+ #
12
+ # See the GNU Affero General Public License for more details:
13
+ # <https://www.gnu.org/licenses/agpl-3.0.html>.
14
+ #
15
+ # Originally licensed under the Apache License, Version 2.0:
16
+ # <http://www.apache.org/licenses/LICENSE-2.0>.
17
+ #
18
+ # [This file includes modifications made by New Vector Limited]
19
+ #
20
+ #
21
+ import email.utils
22
+ import logging
23
+ from typing import (
24
+ TYPE_CHECKING,
25
+ Any,
26
+ Awaitable,
27
+ Callable,
28
+ Collection,
29
+ Generator,
30
+ Iterable,
31
+ Mapping,
32
+ TypeVar,
33
+ )
34
+
35
+ import attr
36
+ import jinja2
37
+ from typing_extensions import Concatenate, ParamSpec
38
+
39
+ from twisted.internet import defer
40
+ from twisted.internet.interfaces import IDelayedCall
41
+ from twisted.python.threadpool import ThreadPool
42
+ from twisted.web.resource import Resource
43
+
44
+ from synapse.api import errors
45
+ from synapse.api.constants import ProfileFields
46
+ from synapse.api.errors import SynapseError
47
+ from synapse.api.presence import UserPresenceState
48
+ from synapse.config import ConfigError
49
+ from synapse.config.repository import MediaUploadLimit
50
+ from synapse.events import EventBase
51
+ from synapse.events.presence_router import (
52
+ GET_INTERESTED_USERS_CALLBACK,
53
+ GET_USERS_FOR_STATES_CALLBACK,
54
+ PresenceRouter,
55
+ )
56
+ from synapse.events.utils import ADD_EXTRA_FIELDS_TO_UNSIGNED_CLIENT_EVENT_CALLBACK
57
+ from synapse.handlers.account_data import ON_ACCOUNT_DATA_UPDATED_CALLBACK
58
+ from synapse.handlers.auth import (
59
+ CHECK_3PID_AUTH_CALLBACK,
60
+ CHECK_AUTH_CALLBACK,
61
+ GET_DISPLAYNAME_FOR_REGISTRATION_CALLBACK,
62
+ GET_USERNAME_FOR_REGISTRATION_CALLBACK,
63
+ IS_3PID_ALLOWED_CALLBACK,
64
+ ON_LOGGED_OUT_CALLBACK,
65
+ AuthHandler,
66
+ )
67
+ from synapse.handlers.push_rules import RuleSpec, check_actions
68
+ from synapse.http.client import SimpleHttpClient
69
+ from synapse.http.server import (
70
+ DirectServeHtmlResource,
71
+ DirectServeJsonResource,
72
+ respond_with_html,
73
+ )
74
+ from synapse.http.servlet import parse_json_object_from_request
75
+ from synapse.http.site import SynapseRequest
76
+ from synapse.logging.context import (
77
+ defer_to_thread,
78
+ defer_to_threadpool,
79
+ make_deferred_yieldable,
80
+ run_in_background,
81
+ )
82
+ from synapse.metrics.background_process_metrics import (
83
+ run_as_background_process as _run_as_background_process,
84
+ )
85
+ from synapse.module_api.callbacks.account_validity_callbacks import (
86
+ IS_USER_EXPIRED_CALLBACK,
87
+ ON_LEGACY_ADMIN_REQUEST,
88
+ ON_LEGACY_RENEW_CALLBACK,
89
+ ON_LEGACY_SEND_MAIL_CALLBACK,
90
+ ON_USER_LOGIN_CALLBACK,
91
+ ON_USER_REGISTRATION_CALLBACK,
92
+ )
93
+ from synapse.module_api.callbacks.media_repository_callbacks import (
94
+ GET_MEDIA_CONFIG_FOR_USER_CALLBACK,
95
+ GET_MEDIA_UPLOAD_LIMITS_FOR_USER_CALLBACK,
96
+ IS_USER_ALLOWED_TO_UPLOAD_MEDIA_OF_SIZE_CALLBACK,
97
+ ON_MEDIA_UPLOAD_LIMIT_EXCEEDED_CALLBACK,
98
+ )
99
+ from synapse.module_api.callbacks.ratelimit_callbacks import (
100
+ GET_RATELIMIT_OVERRIDE_FOR_USER_CALLBACK,
101
+ RatelimitOverride,
102
+ )
103
+ from synapse.module_api.callbacks.spamchecker_callbacks import (
104
+ CHECK_EVENT_FOR_SPAM_CALLBACK,
105
+ CHECK_LOGIN_FOR_SPAM_CALLBACK,
106
+ CHECK_MEDIA_FILE_FOR_SPAM_CALLBACK,
107
+ CHECK_REGISTRATION_FOR_SPAM_CALLBACK,
108
+ CHECK_USERNAME_FOR_SPAM_CALLBACK,
109
+ FEDERATED_USER_MAY_INVITE_CALLBACK,
110
+ SHOULD_DROP_FEDERATED_EVENT_CALLBACK,
111
+ USER_MAY_CREATE_ROOM_ALIAS_CALLBACK,
112
+ USER_MAY_CREATE_ROOM_CALLBACK,
113
+ USER_MAY_INVITE_CALLBACK,
114
+ USER_MAY_JOIN_ROOM_CALLBACK,
115
+ USER_MAY_PUBLISH_ROOM_CALLBACK,
116
+ USER_MAY_SEND_3PID_INVITE_CALLBACK,
117
+ USER_MAY_SEND_STATE_EVENT_CALLBACK,
118
+ SpamCheckerModuleApiCallbacks,
119
+ )
120
+ from synapse.module_api.callbacks.third_party_event_rules_callbacks import (
121
+ CHECK_CAN_DEACTIVATE_USER_CALLBACK,
122
+ CHECK_CAN_SHUTDOWN_ROOM_CALLBACK,
123
+ CHECK_EVENT_ALLOWED_CALLBACK,
124
+ CHECK_THREEPID_CAN_BE_INVITED_CALLBACK,
125
+ CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK,
126
+ ON_ADD_USER_THIRD_PARTY_IDENTIFIER_CALLBACK,
127
+ ON_CREATE_ROOM_CALLBACK,
128
+ ON_NEW_EVENT_CALLBACK,
129
+ ON_PROFILE_UPDATE_CALLBACK,
130
+ ON_REMOVE_USER_THIRD_PARTY_IDENTIFIER_CALLBACK,
131
+ ON_THREEPID_BIND_CALLBACK,
132
+ ON_USER_DEACTIVATION_STATUS_CHANGED_CALLBACK,
133
+ )
134
+ from synapse.push.httppusher import HttpPusher
135
+ from synapse.rest.client.login import LoginResponse
136
+ from synapse.storage import DataStore
137
+ from synapse.storage.background_updates import (
138
+ DEFAULT_BATCH_SIZE_CALLBACK,
139
+ MIN_BATCH_SIZE_CALLBACK,
140
+ ON_UPDATE_CALLBACK,
141
+ )
142
+ from synapse.storage.database import DatabasePool, LoggingTransaction
143
+ from synapse.storage.databases.main.roommember import ProfileInfo
144
+ from synapse.types import (
145
+ DomainSpecificString,
146
+ JsonDict,
147
+ JsonMapping,
148
+ Requester,
149
+ RoomAlias,
150
+ RoomID,
151
+ StateMap,
152
+ UserID,
153
+ UserInfo,
154
+ UserProfile,
155
+ create_requester,
156
+ )
157
+ from synapse.types.state import StateFilter
158
+ from synapse.util.async_helpers import maybe_awaitable
159
+ from synapse.util.caches.descriptors import CachedFunction, cached as _cached
160
+ from synapse.util.clock import Clock
161
+ from synapse.util.frozenutils import freeze
162
+
163
+ if TYPE_CHECKING:
164
+ # Old versions don't have `LiteralString`
165
+ from typing_extensions import LiteralString
166
+
167
+ from synapse.app.generic_worker import GenericWorkerStore
168
+ from synapse.server import HomeServer
169
+
170
+
171
+ T = TypeVar("T")
172
+ P = ParamSpec("P")
173
+ F = TypeVar("F", bound=Callable[..., Any])
174
+
175
+ """
176
+ This package defines the 'stable' API which can be used by extension modules which
177
+ are loaded into Synapse.
178
+ """
179
+
180
+ PRESENCE_ALL_USERS = PresenceRouter.ALL_USERS
181
+ NOT_SPAM = SpamCheckerModuleApiCallbacks.NOT_SPAM
182
+
183
+ __all__ = [
184
+ "errors",
185
+ "make_deferred_yieldable",
186
+ "parse_json_object_from_request",
187
+ "respond_with_html",
188
+ "run_in_background",
189
+ "run_as_background_process",
190
+ "cached",
191
+ "NOT_SPAM",
192
+ "UserID",
193
+ "DatabasePool",
194
+ "LoggingTransaction",
195
+ "DirectServeHtmlResource",
196
+ "DirectServeJsonResource",
197
+ "ModuleApi",
198
+ "PRESENCE_ALL_USERS",
199
+ "LoginResponse",
200
+ "JsonDict",
201
+ "JsonMapping",
202
+ "EventBase",
203
+ "StateMap",
204
+ "ProfileInfo",
205
+ "RoomAlias",
206
+ "UserProfile",
207
+ "RatelimitOverride",
208
+ "MediaUploadLimit",
209
+ ]
210
+
211
+ logger = logging.getLogger(__name__)
212
+
213
+
214
+ @attr.s(auto_attribs=True)
215
+ class UserIpAndAgent:
216
+ """
217
+ An IP address and user agent used by a user to connect to this homeserver.
218
+ """
219
+
220
+ ip: str
221
+ user_agent: str
222
+ # The time at which this user agent/ip was last seen.
223
+ last_seen: int
224
+
225
+
226
+ def run_as_background_process(
227
+ desc: "LiteralString",
228
+ func: Callable[..., Awaitable[T | None]],
229
+ *args: Any,
230
+ bg_start_span: bool = True,
231
+ **kwargs: Any,
232
+ ) -> "defer.Deferred[T | None]":
233
+ """
234
+ XXX: Deprecated: use `ModuleApi.run_as_background_process` instead.
235
+
236
+ Run the given function in its own logcontext, with resource metrics
237
+
238
+ This should be used to wrap processes which are fired off to run in the
239
+ background, instead of being associated with a particular request.
240
+
241
+ It returns a Deferred which completes when the function completes, but it doesn't
242
+ follow the synapse logcontext rules, which makes it appropriate for passing to
243
+ clock.looping_call and friends (or for firing-and-forgetting in the middle of a
244
+ normal synapse async function).
245
+
246
+ Args:
247
+ desc: a description for this background process type
248
+ server_name: The homeserver name that this background process is being run for
249
+ (this should be `hs.hostname`).
250
+ func: a function, which may return a Deferred or a coroutine
251
+ bg_start_span: Whether to start an opentracing span. Defaults to True.
252
+ Should only be disabled for processes that will not log to or tag
253
+ a span.
254
+ args: positional args for func
255
+ kwargs: keyword args for func
256
+
257
+ Returns:
258
+ Deferred which returns the result of func, or `None` if func raises.
259
+ Note that the returned Deferred does not follow the synapse logcontext
260
+ rules.
261
+ """
262
+
263
+ logger.warning(
264
+ "Using deprecated `run_as_background_process` that's exported from the Module API. "
265
+ "Prefer `ModuleApi.run_as_background_process` instead.",
266
+ )
267
+
268
+ # Historically, since this function is exported from the module API, we can't just
269
+ # change the signature to require a `server_name` argument. Since
270
+ # `run_as_background_process` internally in Synapse requires `server_name` now, we
271
+ # just have to stub this out with a placeholder value and tell people to use the new
272
+ # function instead.
273
+ stub_server_name = "synapse_module_running_from_unknown_server"
274
+
275
+ # Ignore the linter error here. Since this is leveraging the
276
+ # `run_as_background_process` function directly and we don't want to break the
277
+ # module api, we need to keep the function signature the same. This means we don't
278
+ # have access to the running `HomeServer` and cannot track this background process
279
+ # for cleanup during shutdown.
280
+ # This is not an issue during runtime and is only potentially problematic if the
281
+ # application cares about being able to garbage collect `HomeServer` instances
282
+ # during runtime.
283
+ return _run_as_background_process( # type: ignore[untracked-background-process]
284
+ desc,
285
+ stub_server_name,
286
+ func,
287
+ *args,
288
+ bg_start_span=bg_start_span,
289
+ **kwargs,
290
+ )
291
+
292
+
293
+ def cached(
294
+ *,
295
+ max_entries: int = 1000,
296
+ num_args: int | None = None,
297
+ uncached_args: Collection[str] | None = None,
298
+ ) -> Callable[[F], CachedFunction[F]]:
299
+ """Returns a decorator that applies a memoizing cache around the function. This
300
+ decorator behaves similarly to functools.lru_cache.
301
+
302
+ Example:
303
+
304
+ @cached()
305
+ def foo('a', 'b'):
306
+ ...
307
+
308
+ Added in Synapse v1.74.0.
309
+
310
+ Args:
311
+ max_entries: The maximum number of entries in the cache. If the cache is full
312
+ and a new entry is added, the least recently accessed entry will be evicted
313
+ from the cache.
314
+ num_args: The number of positional arguments (excluding `self`) to use as cache
315
+ keys. Defaults to all named args of the function.
316
+ uncached_args: A list of argument names to not use as the cache key. (`self` is
317
+ always ignored.) Cannot be used with num_args.
318
+
319
+ Returns:
320
+ A decorator that applies a memoizing cache around the function.
321
+ """
322
+ return _cached(
323
+ max_entries=max_entries,
324
+ num_args=num_args,
325
+ uncached_args=uncached_args,
326
+ )
327
+
328
+
329
+ class ModuleApi:
330
+ """A proxy object that gets passed to various plugin modules so they
331
+ can register new users etc if necessary.
332
+ """
333
+
334
+ def __init__(self, hs: "HomeServer", auth_handler: AuthHandler) -> None:
335
+ self._hs = hs
336
+
337
+ # TODO: Fix this type hint once the types for the data stores have been ironed
338
+ # out.
339
+ self._store: DataStore | "GenericWorkerStore" = hs.get_datastores().main
340
+ self._storage_controllers = hs.get_storage_controllers()
341
+ self._auth = hs.get_auth()
342
+ self._auth_handler = auth_handler
343
+ self._server_name = hs.hostname
344
+ self._presence_stream = hs.get_event_sources().sources.presence
345
+ self._state = hs.get_state_handler()
346
+ self._clock: Clock = hs.get_clock()
347
+ self._registration_handler = hs.get_registration_handler()
348
+ self._send_email_handler = hs.get_send_email_handler()
349
+ self._push_rules_handler = hs.get_push_rules_handler()
350
+ self._pusherpool = hs.get_pusherpool()
351
+ self._device_handler = hs.get_device_handler()
352
+ self.custom_template_dir = hs.config.server.custom_template_directory
353
+ self._callbacks = hs.get_module_api_callbacks()
354
+ self._auth_delegation_enabled = (
355
+ hs.config.mas.enabled or hs.config.experimental.msc3861.enabled
356
+ )
357
+ self._event_serializer = hs.get_event_client_serializer()
358
+
359
+ try:
360
+ app_name = self._hs.config.email.email_app_name
361
+
362
+ self._from_string = self._hs.config.email.email_notif_from % { # type: ignore[operator]
363
+ "app": app_name
364
+ }
365
+ except (KeyError, TypeError):
366
+ # If substitution failed (which can happen if the string contains
367
+ # placeholders other than just "app", or if the type of the placeholder is
368
+ # not a string), fall back to the bare strings.
369
+ self._from_string = self._hs.config.email.email_notif_from
370
+
371
+ self._raw_from = email.utils.parseaddr(self._from_string)[1]
372
+
373
+ # We expose these as properties below in order to attach a helpful docstring.
374
+ self._http_client: SimpleHttpClient = hs.get_simple_http_client()
375
+ self._public_room_list_manager = PublicRoomListManager(hs)
376
+ self._account_data_manager = AccountDataManager(hs)
377
+
378
+ self._password_auth_provider = hs.get_password_auth_provider()
379
+ self._presence_router = hs.get_presence_router()
380
+ self._account_data_handler = hs.get_account_data_handler()
381
+
382
+ #################################################################################
383
+ # The following methods should only be called during the module's initialisation.
384
+
385
+ def register_spam_checker_callbacks(
386
+ self,
387
+ *,
388
+ check_event_for_spam: CHECK_EVENT_FOR_SPAM_CALLBACK | None = None,
389
+ should_drop_federated_event: SHOULD_DROP_FEDERATED_EVENT_CALLBACK | None = None,
390
+ user_may_join_room: USER_MAY_JOIN_ROOM_CALLBACK | None = None,
391
+ user_may_invite: USER_MAY_INVITE_CALLBACK | None = None,
392
+ federated_user_may_invite: FEDERATED_USER_MAY_INVITE_CALLBACK | None = None,
393
+ user_may_send_3pid_invite: USER_MAY_SEND_3PID_INVITE_CALLBACK | None = None,
394
+ user_may_create_room: USER_MAY_CREATE_ROOM_CALLBACK | None = None,
395
+ user_may_create_room_alias: USER_MAY_CREATE_ROOM_ALIAS_CALLBACK | None = None,
396
+ user_may_publish_room: USER_MAY_PUBLISH_ROOM_CALLBACK | None = None,
397
+ user_may_send_state_event: USER_MAY_SEND_STATE_EVENT_CALLBACK | None = None,
398
+ check_username_for_spam: CHECK_USERNAME_FOR_SPAM_CALLBACK | None = None,
399
+ check_registration_for_spam: CHECK_REGISTRATION_FOR_SPAM_CALLBACK | None = None,
400
+ check_media_file_for_spam: CHECK_MEDIA_FILE_FOR_SPAM_CALLBACK | None = None,
401
+ check_login_for_spam: CHECK_LOGIN_FOR_SPAM_CALLBACK | None = None,
402
+ ) -> None:
403
+ """Registers callbacks for spam checking capabilities.
404
+
405
+ Added in Synapse v1.37.0.
406
+ """
407
+ return self._callbacks.spam_checker.register_callbacks(
408
+ check_event_for_spam=check_event_for_spam,
409
+ should_drop_federated_event=should_drop_federated_event,
410
+ user_may_join_room=user_may_join_room,
411
+ user_may_invite=user_may_invite,
412
+ federated_user_may_invite=federated_user_may_invite,
413
+ user_may_send_3pid_invite=user_may_send_3pid_invite,
414
+ user_may_create_room=user_may_create_room,
415
+ user_may_create_room_alias=user_may_create_room_alias,
416
+ user_may_publish_room=user_may_publish_room,
417
+ check_username_for_spam=check_username_for_spam,
418
+ check_registration_for_spam=check_registration_for_spam,
419
+ check_media_file_for_spam=check_media_file_for_spam,
420
+ check_login_for_spam=check_login_for_spam,
421
+ user_may_send_state_event=user_may_send_state_event,
422
+ )
423
+
424
+ def register_account_validity_callbacks(
425
+ self,
426
+ *,
427
+ is_user_expired: IS_USER_EXPIRED_CALLBACK | None = None,
428
+ on_user_registration: ON_USER_REGISTRATION_CALLBACK | None = None,
429
+ on_user_login: ON_USER_LOGIN_CALLBACK | None = None,
430
+ on_legacy_send_mail: ON_LEGACY_SEND_MAIL_CALLBACK | None = None,
431
+ on_legacy_renew: ON_LEGACY_RENEW_CALLBACK | None = None,
432
+ on_legacy_admin_request: ON_LEGACY_ADMIN_REQUEST | None = None,
433
+ ) -> None:
434
+ """Registers callbacks for account validity capabilities.
435
+
436
+ Added in Synapse v1.39.0.
437
+ """
438
+ return self._callbacks.account_validity.register_callbacks(
439
+ is_user_expired=is_user_expired,
440
+ on_user_registration=on_user_registration,
441
+ on_user_login=on_user_login,
442
+ on_legacy_send_mail=on_legacy_send_mail,
443
+ on_legacy_renew=on_legacy_renew,
444
+ on_legacy_admin_request=on_legacy_admin_request,
445
+ )
446
+
447
+ def register_ratelimit_callbacks(
448
+ self,
449
+ *,
450
+ get_ratelimit_override_for_user: GET_RATELIMIT_OVERRIDE_FOR_USER_CALLBACK
451
+ | None = None,
452
+ ) -> None:
453
+ """Registers callbacks for ratelimit capabilities.
454
+ Added in Synapse v1.132.0.
455
+ """
456
+ return self._callbacks.ratelimit.register_callbacks(
457
+ get_ratelimit_override_for_user=get_ratelimit_override_for_user,
458
+ )
459
+
460
+ def register_media_repository_callbacks(
461
+ self,
462
+ *,
463
+ get_media_config_for_user: GET_MEDIA_CONFIG_FOR_USER_CALLBACK | None = None,
464
+ is_user_allowed_to_upload_media_of_size: IS_USER_ALLOWED_TO_UPLOAD_MEDIA_OF_SIZE_CALLBACK
465
+ | None = None,
466
+ get_media_upload_limits_for_user: GET_MEDIA_UPLOAD_LIMITS_FOR_USER_CALLBACK
467
+ | None = None,
468
+ on_media_upload_limit_exceeded: ON_MEDIA_UPLOAD_LIMIT_EXCEEDED_CALLBACK
469
+ | None = None,
470
+ ) -> None:
471
+ """Registers callbacks for media repository capabilities.
472
+ Added in Synapse v1.132.0.
473
+ """
474
+ return self._callbacks.media_repository.register_callbacks(
475
+ get_media_config_for_user=get_media_config_for_user,
476
+ is_user_allowed_to_upload_media_of_size=is_user_allowed_to_upload_media_of_size,
477
+ get_media_upload_limits_for_user=get_media_upload_limits_for_user,
478
+ on_media_upload_limit_exceeded=on_media_upload_limit_exceeded,
479
+ )
480
+
481
+ def register_third_party_rules_callbacks(
482
+ self,
483
+ *,
484
+ check_event_allowed: CHECK_EVENT_ALLOWED_CALLBACK | None = None,
485
+ on_create_room: ON_CREATE_ROOM_CALLBACK | None = None,
486
+ check_threepid_can_be_invited: CHECK_THREEPID_CAN_BE_INVITED_CALLBACK
487
+ | None = None,
488
+ check_visibility_can_be_modified: CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK
489
+ | None = None,
490
+ on_new_event: ON_NEW_EVENT_CALLBACK | None = None,
491
+ check_can_shutdown_room: CHECK_CAN_SHUTDOWN_ROOM_CALLBACK | None = None,
492
+ check_can_deactivate_user: CHECK_CAN_DEACTIVATE_USER_CALLBACK | None = None,
493
+ on_profile_update: ON_PROFILE_UPDATE_CALLBACK | None = None,
494
+ on_user_deactivation_status_changed: ON_USER_DEACTIVATION_STATUS_CHANGED_CALLBACK
495
+ | None = None,
496
+ on_threepid_bind: ON_THREEPID_BIND_CALLBACK | None = None,
497
+ on_add_user_third_party_identifier: ON_ADD_USER_THIRD_PARTY_IDENTIFIER_CALLBACK
498
+ | None = None,
499
+ on_remove_user_third_party_identifier: ON_REMOVE_USER_THIRD_PARTY_IDENTIFIER_CALLBACK
500
+ | None = None,
501
+ ) -> None:
502
+ """Registers callbacks for third party event rules capabilities.
503
+
504
+ Added in Synapse v1.39.0.
505
+ """
506
+ return self._callbacks.third_party_event_rules.register_third_party_rules_callbacks(
507
+ check_event_allowed=check_event_allowed,
508
+ on_create_room=on_create_room,
509
+ check_threepid_can_be_invited=check_threepid_can_be_invited,
510
+ check_visibility_can_be_modified=check_visibility_can_be_modified,
511
+ on_new_event=on_new_event,
512
+ check_can_shutdown_room=check_can_shutdown_room,
513
+ check_can_deactivate_user=check_can_deactivate_user,
514
+ on_profile_update=on_profile_update,
515
+ on_user_deactivation_status_changed=on_user_deactivation_status_changed,
516
+ on_threepid_bind=on_threepid_bind,
517
+ on_add_user_third_party_identifier=on_add_user_third_party_identifier,
518
+ on_remove_user_third_party_identifier=on_remove_user_third_party_identifier,
519
+ )
520
+
521
+ def register_presence_router_callbacks(
522
+ self,
523
+ *,
524
+ get_users_for_states: GET_USERS_FOR_STATES_CALLBACK | None = None,
525
+ get_interested_users: GET_INTERESTED_USERS_CALLBACK | None = None,
526
+ ) -> None:
527
+ """Registers callbacks for presence router capabilities.
528
+
529
+ Added in Synapse v1.42.0.
530
+ """
531
+ return self._presence_router.register_presence_router_callbacks(
532
+ get_users_for_states=get_users_for_states,
533
+ get_interested_users=get_interested_users,
534
+ )
535
+
536
+ def register_password_auth_provider_callbacks(
537
+ self,
538
+ *,
539
+ check_3pid_auth: CHECK_3PID_AUTH_CALLBACK | None = None,
540
+ on_logged_out: ON_LOGGED_OUT_CALLBACK | None = None,
541
+ auth_checkers: dict[tuple[str, tuple[str, ...]], CHECK_AUTH_CALLBACK]
542
+ | None = None,
543
+ is_3pid_allowed: IS_3PID_ALLOWED_CALLBACK | None = None,
544
+ get_username_for_registration: GET_USERNAME_FOR_REGISTRATION_CALLBACK
545
+ | None = None,
546
+ get_displayname_for_registration: GET_DISPLAYNAME_FOR_REGISTRATION_CALLBACK
547
+ | None = None,
548
+ ) -> None:
549
+ """Registers callbacks for password auth provider capabilities.
550
+
551
+ Added in Synapse v1.46.0.
552
+ """
553
+ if self._auth_delegation_enabled:
554
+ raise ConfigError(
555
+ "Cannot use password auth provider callbacks when OAuth delegation is enabled"
556
+ )
557
+
558
+ return self._password_auth_provider.register_password_auth_provider_callbacks(
559
+ check_3pid_auth=check_3pid_auth,
560
+ on_logged_out=on_logged_out,
561
+ is_3pid_allowed=is_3pid_allowed,
562
+ auth_checkers=auth_checkers,
563
+ get_username_for_registration=get_username_for_registration,
564
+ get_displayname_for_registration=get_displayname_for_registration,
565
+ )
566
+
567
+ def register_background_update_controller_callbacks(
568
+ self,
569
+ *,
570
+ on_update: ON_UPDATE_CALLBACK,
571
+ default_batch_size: DEFAULT_BATCH_SIZE_CALLBACK | None = None,
572
+ min_batch_size: MIN_BATCH_SIZE_CALLBACK | None = None,
573
+ ) -> None:
574
+ """Registers background update controller callbacks.
575
+
576
+ Added in Synapse v1.49.0.
577
+ """
578
+
579
+ for db in self._hs.get_datastores().databases:
580
+ db.updates.register_update_controller_callbacks(
581
+ on_update=on_update,
582
+ default_batch_size=default_batch_size,
583
+ min_batch_size=min_batch_size,
584
+ )
585
+
586
+ def register_account_data_callbacks(
587
+ self,
588
+ *,
589
+ on_account_data_updated: ON_ACCOUNT_DATA_UPDATED_CALLBACK | None = None,
590
+ ) -> None:
591
+ """Registers account data callbacks.
592
+
593
+ Added in Synapse 1.57.0.
594
+ """
595
+ return self._account_data_handler.register_module_callbacks(
596
+ on_account_data_updated=on_account_data_updated,
597
+ )
598
+
599
+ def register_web_resource(self, path: str, resource: Resource) -> None:
600
+ """Registers a web resource to be served at the given path.
601
+
602
+ This function should be called during initialisation of the module.
603
+
604
+ If multiple modules register a resource for the same path, the module that
605
+ appears the highest in the configuration file takes priority.
606
+
607
+ Added in Synapse v1.37.0.
608
+
609
+ Args:
610
+ path: The path to register the resource for.
611
+ resource: The resource to attach to this path.
612
+ """
613
+ self._hs.register_module_web_resource(path, resource)
614
+
615
+ def register_add_extra_fields_to_unsigned_client_event_callbacks(
616
+ self,
617
+ *,
618
+ add_field_to_unsigned_callback: ADD_EXTRA_FIELDS_TO_UNSIGNED_CLIENT_EVENT_CALLBACK
619
+ | None = None,
620
+ ) -> None:
621
+ """Registers a callback that can be used to add fields to the unsigned
622
+ section of events.
623
+
624
+ The callback is called every time an event is sent down to a client.
625
+
626
+ Added in Synapse 1.96.0
627
+ """
628
+ if add_field_to_unsigned_callback is not None:
629
+ self._event_serializer.register_add_extra_fields_to_unsigned_client_event_callback(
630
+ add_field_to_unsigned_callback
631
+ )
632
+
633
+ #########################################################################
634
+ # The following methods can be called by the module at any point in time.
635
+
636
+ @property
637
+ def http_client(self) -> SimpleHttpClient:
638
+ """Allows making outbound HTTP requests to remote resources.
639
+
640
+ An instance of synapse.http.client.SimpleHttpClient
641
+
642
+ Added in Synapse v1.22.0.
643
+ """
644
+ return self._http_client
645
+
646
+ @property
647
+ def public_room_list_manager(self) -> "PublicRoomListManager":
648
+ """Allows adding to, removing from and checking the status of rooms in the
649
+ public room list.
650
+
651
+ An instance of synapse.module_api.PublicRoomListManager
652
+
653
+ Added in Synapse v1.22.0.
654
+ """
655
+ return self._public_room_list_manager
656
+
657
+ @property
658
+ def account_data_manager(self) -> "AccountDataManager":
659
+ """Allows reading and modifying users' account data.
660
+
661
+ Added in Synapse v1.57.0.
662
+ """
663
+ return self._account_data_manager
664
+
665
+ @property
666
+ def public_baseurl(self) -> str:
667
+ """The configured public base URL for this homeserver.
668
+
669
+ Added in Synapse v1.39.0.
670
+ """
671
+ return self._hs.config.server.public_baseurl
672
+
673
+ @property
674
+ def email_app_name(self) -> str:
675
+ """The application name configured in the homeserver's configuration.
676
+
677
+ Added in Synapse v1.39.0.
678
+ """
679
+ return self._hs.config.email.email_app_name
680
+
681
+ @property
682
+ def server_name(self) -> str:
683
+ """The server name for the local homeserver.
684
+
685
+ Added in Synapse v1.53.0.
686
+ """
687
+ return self._server_name
688
+
689
+ @property
690
+ def worker_name(self) -> str | None:
691
+ """The name of the worker this specific instance is running as per the
692
+ "worker_name" configuration setting, or None if it's the main process.
693
+
694
+ Added in Synapse v1.53.0.
695
+ """
696
+ return self._hs.config.worker.worker_name
697
+
698
+ @property
699
+ def worker_app(self) -> str | None:
700
+ """The name of the worker app this specific instance is running as per the
701
+ "worker_app" configuration setting, or None if it's the main process.
702
+
703
+ Added in Synapse v1.53.0.
704
+ """
705
+ return self._hs.config.worker.worker_app
706
+
707
+ async def get_userinfo_by_id(self, user_id: str) -> UserInfo | None:
708
+ """Get user info by user_id
709
+
710
+ Added in Synapse v1.41.0.
711
+
712
+ Args:
713
+ user_id: Fully qualified user id.
714
+ Returns:
715
+ UserInfo object if a user was found, otherwise None
716
+ """
717
+ return await self._store.get_user_by_id(user_id)
718
+
719
+ async def get_user_by_req(
720
+ self,
721
+ req: SynapseRequest,
722
+ allow_guest: bool = False,
723
+ allow_expired: bool = False,
724
+ ) -> Requester:
725
+ """Check the access_token provided for a request
726
+
727
+ Added in Synapse v1.39.0.
728
+
729
+ Args:
730
+ req: Incoming HTTP request
731
+ allow_guest: True if guest users should be allowed. If this
732
+ is False, and the access token is for a guest user, an
733
+ AuthError will be thrown
734
+ allow_expired: True if expired users should be allowed. If this
735
+ is False, and the access token is for an expired user, an
736
+ AuthError will be thrown
737
+
738
+ Returns:
739
+ The requester for this request
740
+
741
+ Raises:
742
+ InvalidClientCredentialsError: if no user by that token exists,
743
+ or the token is invalid.
744
+ """
745
+ return await self._auth.get_user_by_req(
746
+ req,
747
+ allow_guest,
748
+ allow_expired=allow_expired,
749
+ )
750
+
751
+ async def is_user_admin(self, user_id: str) -> bool:
752
+ """Checks if a user is a server admin.
753
+
754
+ Added in Synapse v1.39.0.
755
+
756
+ Args:
757
+ user_id: The Matrix ID of the user to check.
758
+
759
+ Returns:
760
+ True if the user is a server admin, False otherwise.
761
+ """
762
+ return await self._store.is_server_admin(user_id)
763
+
764
+ async def set_user_admin(self, user_id: str, admin: bool) -> None:
765
+ """Sets if a user is a server admin.
766
+
767
+ Added in Synapse v1.56.0.
768
+
769
+ Args:
770
+ user_id: The Matrix ID of the user to set admin status for.
771
+ admin: True iff the user is to be a server admin, false otherwise.
772
+ """
773
+ await self._store.set_server_admin(UserID.from_string(user_id), admin)
774
+
775
+ def get_qualified_user_id(self, username: str) -> str:
776
+ """Qualify a user id, if necessary
777
+
778
+ Takes a user id provided by the user and adds the @ and :domain to
779
+ qualify it, if necessary
780
+
781
+ Added in Synapse v0.25.0.
782
+
783
+ Args:
784
+ username: provided user id
785
+
786
+ Returns:
787
+ qualified @user:id
788
+ """
789
+ if username.startswith("@"):
790
+ return username
791
+ return UserID(username, self._hs.hostname).to_string()
792
+
793
+ async def get_profile_for_user(self, localpart: str) -> ProfileInfo:
794
+ """Look up the profile info for the user with the given localpart.
795
+
796
+ Added in Synapse v1.39.0.
797
+
798
+ Args:
799
+ localpart: The localpart to look up profile information for.
800
+
801
+ Returns:
802
+ The profile information (i.e. display name and avatar URL).
803
+ """
804
+ server_name = self._hs.hostname
805
+ user_id = UserID.from_string(f"@{localpart}:{server_name}")
806
+ return await self._store.get_profileinfo(user_id)
807
+
808
+ async def get_threepids_for_user(self, user_id: str) -> list[dict[str, str]]:
809
+ """Look up the threepids (email addresses and phone numbers) associated with the
810
+ given Matrix user ID.
811
+
812
+ Added in Synapse v1.39.0.
813
+
814
+ Args:
815
+ user_id: The Matrix user ID to look up threepids for.
816
+
817
+ Returns:
818
+ A list of threepids, each threepid being represented by a dictionary
819
+ containing a "medium" key which value is "email" for email addresses and
820
+ "msisdn" for phone numbers, and an "address" key which value is the
821
+ threepid's address.
822
+ """
823
+ return [attr.asdict(t) for t in await self._store.user_get_threepids(user_id)]
824
+
825
+ def check_user_exists(self, user_id: str) -> "defer.Deferred[str | None]":
826
+ """Check if user exists.
827
+
828
+ Added in Synapse v0.25.0.
829
+
830
+ Args:
831
+ user_id: Complete @user:id
832
+
833
+ Returns:
834
+ Canonical (case-corrected) user_id, or None
835
+ if the user is not registered.
836
+ """
837
+ return defer.ensureDeferred(self._auth_handler.check_user_exists(user_id))
838
+
839
+ @defer.inlineCallbacks
840
+ def register(
841
+ self,
842
+ localpart: str,
843
+ displayname: str | None = None,
844
+ emails: list[str] | None = None,
845
+ ) -> Generator["defer.Deferred[Any]", Any, tuple[str, str]]:
846
+ """Registers a new user with given localpart and optional displayname, emails.
847
+
848
+ Also returns an access token for the new user.
849
+
850
+ Deprecated: avoid this, as it generates a new device with no way to
851
+ return that device to the user. Prefer separate calls to register_user and
852
+ register_device.
853
+
854
+ Added in Synapse v0.25.0.
855
+
856
+ Args:
857
+ localpart: The localpart of the new user.
858
+ displayname: The displayname of the new user.
859
+ emails: Emails to bind to the new user.
860
+
861
+ Returns:
862
+ a 2-tuple of (user_id, access_token)
863
+ """
864
+ logger.warning(
865
+ "Using deprecated ModuleApi.register which creates a dummy user device."
866
+ )
867
+ user_id = yield self.register_user(localpart, displayname, emails or [])
868
+ _, access_token, _, _ = yield self.register_device(user_id)
869
+ return user_id, access_token
870
+
871
+ def register_user(
872
+ self,
873
+ localpart: str,
874
+ displayname: str | None = None,
875
+ emails: list[str] | None = None,
876
+ admin: bool = False,
877
+ ) -> "defer.Deferred[str]":
878
+ """Registers a new user with given localpart and optional displayname, emails.
879
+
880
+ Added in Synapse v1.2.0.
881
+ Changed in Synapse v1.56.0: add 'admin' argument to register the user as admin.
882
+
883
+ Args:
884
+ localpart: The localpart of the new user.
885
+ displayname: The displayname of the new user.
886
+ emails: Emails to bind to the new user.
887
+ admin: True if the user should be registered as a server admin.
888
+
889
+ Raises:
890
+ SynapseError if there is an error performing the registration. Check the
891
+ 'errcode' property for more information on the reason for failure
892
+
893
+ Returns:
894
+ user_id
895
+ """
896
+ return defer.ensureDeferred(
897
+ self._hs.get_registration_handler().register_user(
898
+ localpart=localpart,
899
+ default_display_name=displayname,
900
+ bind_emails=emails or [],
901
+ admin=admin,
902
+ )
903
+ )
904
+
905
+ def register_device(
906
+ self,
907
+ user_id: str,
908
+ device_id: str | None = None,
909
+ initial_display_name: str | None = None,
910
+ ) -> "defer.Deferred[tuple[str, str, int | None, str | None]]":
911
+ """Register a device for a user and generate an access token.
912
+
913
+ Added in Synapse v1.2.0.
914
+
915
+ Args:
916
+ user_id: full canonical @user:id
917
+ device_id: The device ID to check, or None to generate
918
+ a new one.
919
+ initial_display_name: An optional display name for the
920
+ device.
921
+
922
+ Returns:
923
+ Tuple of device ID, access token, access token expiration time and refresh token
924
+ """
925
+ return defer.ensureDeferred(
926
+ self._hs.get_registration_handler().register_device(
927
+ user_id=user_id,
928
+ device_id=device_id,
929
+ initial_display_name=initial_display_name,
930
+ )
931
+ )
932
+
933
+ def record_user_external_id(
934
+ self, auth_provider_id: str, remote_user_id: str, registered_user_id: str
935
+ ) -> defer.Deferred:
936
+ """Record a mapping between an external user id from a single sign-on provider
937
+ and a mxid.
938
+
939
+ Added in Synapse v1.9.0.
940
+
941
+ Args:
942
+ auth_provider: identifier for the remote auth provider, see `sso` and
943
+ `oidc_providers` in the homeserver configuration.
944
+
945
+ Note that no error is raised if the provided value is not in the
946
+ homeserver configuration.
947
+ external_id: id on that system
948
+ user_id: complete mxid that it is mapped to
949
+ """
950
+ return defer.ensureDeferred(
951
+ self._store.record_user_external_id(
952
+ auth_provider_id, remote_user_id, registered_user_id
953
+ )
954
+ )
955
+
956
+ async def create_login_token(
957
+ self,
958
+ user_id: str,
959
+ duration_in_ms: int = (2 * 60 * 1000),
960
+ auth_provider_id: str | None = None,
961
+ auth_provider_session_id: str | None = None,
962
+ ) -> str:
963
+ """Create a login token suitable for m.login.token authentication
964
+
965
+ Added in Synapse v1.69.0.
966
+
967
+ Args:
968
+ user_id: gives the ID of the user that the token is for
969
+
970
+ duration_in_ms: the time that the token will be valid for
971
+
972
+ auth_provider_id: the ID of the SSO IdP that the user used to authenticate
973
+ to get this token, if any. This is encoded in the token so that
974
+ /login can report stats on number of successful logins by IdP.
975
+
976
+ auth_provider_session_id: The session ID got during login from the SSO IdP,
977
+ if any.
978
+ """
979
+ return await self._hs.get_auth_handler().create_login_token_for_user_id(
980
+ user_id,
981
+ duration_in_ms,
982
+ auth_provider_id,
983
+ auth_provider_session_id,
984
+ )
985
+
986
+ @defer.inlineCallbacks
987
+ def invalidate_access_token(
988
+ self, access_token: str
989
+ ) -> Generator["defer.Deferred[Any]", Any, None]:
990
+ """Invalidate an access token for a user
991
+
992
+ Added in Synapse v0.25.0.
993
+
994
+ Args:
995
+ access_token: access token
996
+
997
+ Returns:
998
+ twisted.internet.defer.Deferred - resolves once the access token
999
+ has been removed.
1000
+
1001
+ Raises:
1002
+ synapse.api.errors.AuthError: the access token is invalid
1003
+ """
1004
+ # see if the access token corresponds to a device
1005
+ user_info = yield defer.ensureDeferred(
1006
+ self._auth.get_user_by_access_token(access_token)
1007
+ )
1008
+ device_id = user_info.get("device_id")
1009
+ user_id = user_info["user"].to_string()
1010
+ if device_id:
1011
+ # delete the device, which will also delete its access tokens
1012
+ yield defer.ensureDeferred(
1013
+ self._device_handler.delete_devices(user_id, [device_id])
1014
+ )
1015
+ else:
1016
+ # no associated device. Just delete the access token.
1017
+ yield defer.ensureDeferred(
1018
+ self._auth_handler.delete_access_token(access_token)
1019
+ )
1020
+
1021
+ def run_db_interaction(
1022
+ self,
1023
+ desc: str,
1024
+ func: Callable[Concatenate[LoggingTransaction, P], T],
1025
+ *args: P.args,
1026
+ **kwargs: P.kwargs,
1027
+ ) -> "defer.Deferred[T]":
1028
+ """Run a function with a database connection
1029
+
1030
+ Added in Synapse v0.25.0.
1031
+
1032
+ Args:
1033
+ desc: description for the transaction, for metrics etc
1034
+ func: function to be run. Passed a database cursor object
1035
+ as well as *args and **kwargs
1036
+ *args: positional args to be passed to func
1037
+ **kwargs: named args to be passed to func
1038
+
1039
+ Returns:
1040
+ Result of func
1041
+ """
1042
+ # type-ignore: See https://github.com/python/mypy/issues/8862
1043
+ return defer.ensureDeferred(
1044
+ self._store.db_pool.runInteraction(desc, func, *args, **kwargs) # type: ignore[arg-type]
1045
+ )
1046
+
1047
+ def register_cached_function(self, cached_func: CachedFunction) -> None:
1048
+ """Register a cached function that should be invalidated across workers.
1049
+ Invalidation local to a worker can be done directly using `cached_func.invalidate`,
1050
+ however invalidation that needs to go to other workers needs to call `invalidate_cache`
1051
+ on the module API instead.
1052
+
1053
+ Added in Synapse v1.69.0.
1054
+
1055
+ Args:
1056
+ cached_function: The cached function that will be registered to receive invalidation
1057
+ locally and from other workers.
1058
+ """
1059
+ self._store.register_external_cached_function(
1060
+ f"{cached_func.__module__}.{cached_func.__name__}", cached_func
1061
+ )
1062
+
1063
+ async def invalidate_cache(
1064
+ self, cached_func: CachedFunction, keys: tuple[Any, ...]
1065
+ ) -> None:
1066
+ """Invalidate a cache entry of a cached function across workers. The cached function
1067
+ needs to be registered on all workers first with `register_cached_function`.
1068
+
1069
+ Added in Synapse v1.69.0.
1070
+
1071
+ Args:
1072
+ cached_function: The cached function that needs an invalidation
1073
+ keys: keys of the entry to invalidate, usually matching the arguments of the
1074
+ cached function.
1075
+ """
1076
+ cached_func.invalidate(keys)
1077
+ await self._store.send_invalidation_to_replication(
1078
+ f"{cached_func.__module__}.{cached_func.__name__}",
1079
+ keys,
1080
+ )
1081
+
1082
+ async def complete_sso_login_async(
1083
+ self,
1084
+ registered_user_id: str,
1085
+ request: SynapseRequest,
1086
+ client_redirect_url: str,
1087
+ new_user: bool = False,
1088
+ auth_provider_id: str = "<unknown>",
1089
+ ) -> None:
1090
+ """Complete a SSO login by redirecting the user to a page to confirm whether they
1091
+ want their access token sent to `client_redirect_url`, or redirect them to that
1092
+ URL with a token directly if the URL matches with one of the whitelisted clients.
1093
+
1094
+ Added in Synapse v1.13.0.
1095
+
1096
+ Args:
1097
+ registered_user_id: The MXID that has been registered as a previous step of
1098
+ of this SSO login.
1099
+ request: The request to respond to.
1100
+ client_redirect_url: The URL to which to offer to redirect the user (or to
1101
+ redirect them directly if whitelisted).
1102
+ new_user: set to true to use wording for the consent appropriate to a user
1103
+ who has just registered.
1104
+ auth_provider_id: the ID of the SSO IdP which was used to log in. This
1105
+ is used to track counts of sucessful logins by IdP.
1106
+ """
1107
+ await self._auth_handler.complete_sso_login(
1108
+ registered_user_id,
1109
+ auth_provider_id,
1110
+ request,
1111
+ client_redirect_url,
1112
+ new_user=new_user,
1113
+ )
1114
+
1115
+ @defer.inlineCallbacks
1116
+ def get_state_events_in_room(
1117
+ self, room_id: str, types: Iterable[tuple[str, str | None]]
1118
+ ) -> Generator[defer.Deferred, Any, Iterable[EventBase]]:
1119
+ """Gets current state events for the given room.
1120
+
1121
+ (This is exposed for compatibility with the old SpamCheckerApi. We should
1122
+ probably deprecate it and replace it with an async method in a subclass.)
1123
+
1124
+ Added in Synapse v1.22.0.
1125
+
1126
+ Args:
1127
+ room_id: The room ID to get state events in.
1128
+ types: The event type and state key (using None
1129
+ to represent 'any') of the room state to acquire.
1130
+
1131
+ Returns:
1132
+ The filtered state events in the room.
1133
+ """
1134
+ state_ids = yield defer.ensureDeferred(
1135
+ self._storage_controllers.state.get_current_state_ids(
1136
+ room_id=room_id, state_filter=StateFilter.from_types(types)
1137
+ )
1138
+ )
1139
+ state = yield defer.ensureDeferred(self._store.get_events(state_ids.values()))
1140
+ return state.values()
1141
+
1142
+ async def update_room_membership(
1143
+ self,
1144
+ sender: str,
1145
+ target: str,
1146
+ room_id: str,
1147
+ new_membership: str,
1148
+ content: JsonDict | None = None,
1149
+ remote_room_hosts: list[str] | None = None,
1150
+ ) -> EventBase:
1151
+ """Updates the membership of a user to the given value.
1152
+
1153
+ Added in Synapse v1.46.0.
1154
+ Changed in Synapse v1.65.0: Added the 'remote_room_hosts' parameter.
1155
+
1156
+ Args:
1157
+ sender: The user performing the membership change. Must be a user local to
1158
+ this homeserver.
1159
+ target: The user whose membership is changing. This is often the same value
1160
+ as `sender`, but it might differ in some cases (e.g. when kicking a user,
1161
+ the `sender` is the user performing the kick and the `target` is the user
1162
+ being kicked).
1163
+ room_id: The room in which to change the membership.
1164
+ new_membership: The new membership state of `target` after this operation. See
1165
+ https://spec.matrix.org/unstable/client-server-api/#mroommember for the
1166
+ list of allowed values.
1167
+ content: Additional values to include in the resulting event's content.
1168
+ remote_room_hosts: Remote servers to use for remote joins/knocks/etc.
1169
+
1170
+ Returns:
1171
+ The newly created membership event.
1172
+
1173
+ Raises:
1174
+ RuntimeError if the `sender` isn't a local user.
1175
+ ShadowBanError if a shadow-banned requester attempts to send an invite.
1176
+ SynapseError if the module attempts to send a membership event that isn't
1177
+ allowed, either by the server's configuration (e.g. trying to set a
1178
+ per-room display name that's too long) or by the validation rules around
1179
+ membership updates (e.g. the `membership` value is invalid).
1180
+ """
1181
+ if not self.is_mine(sender):
1182
+ raise RuntimeError(
1183
+ "Tried to send an event as a user that isn't local to this homeserver",
1184
+ )
1185
+
1186
+ requester = create_requester(sender)
1187
+ target_user_id = UserID.from_string(target)
1188
+
1189
+ if content is None:
1190
+ content = {}
1191
+
1192
+ # Set the profile if not already done by the module.
1193
+ if (
1194
+ ProfileFields.AVATAR_URL not in content
1195
+ or ProfileFields.DISPLAYNAME not in content
1196
+ ):
1197
+ try:
1198
+ # Try to fetch the user's profile.
1199
+ profile = await self._hs.get_profile_handler().get_profile(
1200
+ target_user_id.to_string(),
1201
+ )
1202
+ except SynapseError as e:
1203
+ # If the profile couldn't be found, use default values.
1204
+ profile = {
1205
+ ProfileFields.DISPLAYNAME: target_user_id.localpart,
1206
+ ProfileFields.AVATAR_URL: None,
1207
+ }
1208
+
1209
+ if e.code != 404:
1210
+ # If the error isn't 404, it means we tried to fetch the profile over
1211
+ # federation but the remote server responded with a non-standard
1212
+ # status code.
1213
+ logger.error(
1214
+ "Got non-404 error status when fetching profile for %s",
1215
+ target_user_id.to_string(),
1216
+ )
1217
+
1218
+ # Set the profile where it needs to be set.
1219
+ for field_name in [ProfileFields.AVATAR_URL, ProfileFields.DISPLAYNAME]:
1220
+ if field_name not in content and field_name in profile:
1221
+ content[field_name] = profile[field_name]
1222
+
1223
+ event_id, _ = await self._hs.get_room_member_handler().update_membership(
1224
+ requester=requester,
1225
+ target=target_user_id,
1226
+ room_id=room_id,
1227
+ action=new_membership,
1228
+ content=content,
1229
+ remote_room_hosts=remote_room_hosts,
1230
+ )
1231
+
1232
+ # Try to retrieve the resulting event.
1233
+ event = await self._hs.get_datastores().main.get_event(event_id)
1234
+
1235
+ return event
1236
+
1237
+ async def create_and_send_event_into_room(self, event_dict: JsonDict) -> EventBase:
1238
+ """Create and send an event into a room.
1239
+
1240
+ Membership events are not supported by this method. To update a user's membership
1241
+ in a room, please use the `update_room_membership` method instead.
1242
+
1243
+ Added in Synapse v1.22.0.
1244
+
1245
+ Args:
1246
+ event_dict: A dictionary representing the event to send.
1247
+ Required keys are `type`, `room_id`, `sender` and `content`.
1248
+
1249
+ Returns:
1250
+ The event that was sent. If state event deduplication happened, then
1251
+ the previous, duplicate event instead.
1252
+
1253
+ Raises:
1254
+ SynapseError if the event was not allowed.
1255
+ """
1256
+ # Create a requester object
1257
+ requester = create_requester(
1258
+ event_dict["sender"], authenticated_entity=self._server_name
1259
+ )
1260
+
1261
+ # Create and send the event
1262
+ (
1263
+ event,
1264
+ _,
1265
+ ) = await self._hs.get_event_creation_handler().create_and_send_nonmember_event(
1266
+ requester,
1267
+ event_dict,
1268
+ ratelimit=False,
1269
+ ignore_shadow_ban=True,
1270
+ )
1271
+
1272
+ return event
1273
+
1274
+ async def send_local_online_presence_to(self, users: Iterable[str]) -> None:
1275
+ """
1276
+ Forces the equivalent of a presence initial_sync for a set of local or remote
1277
+ users. The users will receive presence for all currently online users that they
1278
+ are considered interested in.
1279
+
1280
+ Updates to remote users will be sent immediately, whereas local users will receive
1281
+ them on their next sync attempt.
1282
+
1283
+ Note that this method can only be run on the process that is configured to write to the
1284
+ presence stream. By default this is the main process.
1285
+
1286
+ Added in Synapse v1.32.0.
1287
+ """
1288
+ if self._hs._instance_name not in self._hs.config.worker.writers.presence:
1289
+ raise Exception(
1290
+ "send_local_online_presence_to can only be run "
1291
+ "on the process that is configured to write to the "
1292
+ "presence stream (by default this is the main process)",
1293
+ )
1294
+
1295
+ local_users = set()
1296
+ remote_users = set()
1297
+ for user in users:
1298
+ if self._hs.is_mine_id(user):
1299
+ local_users.add(user)
1300
+ else:
1301
+ remote_users.add(user)
1302
+
1303
+ # We pull out the presence handler here to break a cyclic
1304
+ # dependency between the presence router and module API.
1305
+ presence_handler = self._hs.get_presence_handler()
1306
+
1307
+ if local_users:
1308
+ # Force a presence initial_sync for these users next time they sync.
1309
+ await presence_handler.send_full_presence_to_users(local_users)
1310
+
1311
+ for user in remote_users:
1312
+ # Retrieve presence state for currently online users that this user
1313
+ # is considered interested in.
1314
+ presence_events, _ = await self._presence_stream.get_new_events(
1315
+ UserID.from_string(user), from_key=None, include_offline=False
1316
+ )
1317
+
1318
+ # Send to remote destinations.
1319
+ destination = UserID.from_string(user).domain
1320
+ await presence_handler.get_federation_queue().send_presence_to_destinations(
1321
+ presence_events, [destination]
1322
+ )
1323
+
1324
+ async def set_presence_for_users(
1325
+ self, users: Mapping[str, tuple[str, str | None]]
1326
+ ) -> None:
1327
+ """
1328
+ Update the internal presence state of users.
1329
+
1330
+ This can be used for either local or remote users.
1331
+
1332
+ Note that this method can only be run on the process that is configured to write to the
1333
+ presence stream. By default, this is the main process.
1334
+
1335
+ Added in Synapse v1.96.0.
1336
+ """
1337
+
1338
+ # We pull out the presence handler here to break a cyclic
1339
+ # dependency between the presence router and module API.
1340
+ presence_handler = self._hs.get_presence_handler()
1341
+
1342
+ from synapse.handlers.presence import PresenceHandler
1343
+
1344
+ assert isinstance(presence_handler, PresenceHandler)
1345
+
1346
+ states = await presence_handler.current_state_for_users(users.keys())
1347
+ for user_id, (state, status_msg) in users.items():
1348
+ prev_state = states.setdefault(user_id, UserPresenceState.default(user_id))
1349
+ states[user_id] = prev_state.copy_and_replace(
1350
+ state=state, status_msg=status_msg
1351
+ )
1352
+
1353
+ await presence_handler._update_states(states.values(), force_notify=True)
1354
+
1355
+ def looping_background_call(
1356
+ self,
1357
+ f: Callable,
1358
+ msec: float,
1359
+ *args: object,
1360
+ desc: str | None = None,
1361
+ run_on_all_instances: bool = False,
1362
+ **kwargs: object,
1363
+ ) -> None:
1364
+ """Wraps a function as a background process and calls it repeatedly.
1365
+
1366
+ NOTE: Will only run on the instance that is configured to run
1367
+ background processes (which is the main process by default), unless
1368
+ `run_on_all_workers` is set.
1369
+
1370
+ Waits `msec` initially before calling `f` for the first time.
1371
+
1372
+ Added in Synapse v1.39.0.
1373
+
1374
+ Args:
1375
+ f: The function to call repeatedly. f can be either synchronous or
1376
+ asynchronous, and must follow Synapse's logcontext rules.
1377
+ More info about logcontexts is available at
1378
+ https://element-hq.github.io/synapse/latest/log_contexts.html
1379
+ msec: How long to wait between calls in milliseconds.
1380
+ *args: Positional arguments to pass to function.
1381
+ desc: The background task's description. Default to the function's name.
1382
+ run_on_all_instances: Whether to run this on all instances, rather
1383
+ than just the instance configured to run background tasks.
1384
+ **kwargs: Key arguments to pass to function.
1385
+ """
1386
+ if desc is None:
1387
+ desc = f.__name__
1388
+
1389
+ if self._hs.config.worker.run_background_tasks or run_on_all_instances:
1390
+ self._clock.looping_call(
1391
+ self._hs.run_as_background_process,
1392
+ msec,
1393
+ desc,
1394
+ lambda: maybe_awaitable(f(*args, **kwargs)),
1395
+ )
1396
+ else:
1397
+ logger.warning(
1398
+ "Not running looping call %s as the configuration forbids it",
1399
+ f,
1400
+ )
1401
+
1402
+ def should_run_background_tasks(self) -> bool:
1403
+ """
1404
+ Return true if and only if the current worker is configured to run
1405
+ background tasks.
1406
+ There should only be one worker configured to run background tasks, so
1407
+ this is helpful when you need to only run a task on one worker but don't
1408
+ have any other good way to choose which one.
1409
+
1410
+ Added in Synapse v1.89.0.
1411
+ """
1412
+ return self._hs.config.worker.run_background_tasks
1413
+
1414
+ def delayed_background_call(
1415
+ self,
1416
+ msec: float,
1417
+ f: Callable,
1418
+ *args: object,
1419
+ desc: str | None = None,
1420
+ **kwargs: object,
1421
+ ) -> IDelayedCall:
1422
+ """Wraps a function as a background process and calls it in a given number of milliseconds.
1423
+
1424
+ The scheduled call is not persistent: if the current Synapse instance is
1425
+ restarted before the call is made, the call will not be made.
1426
+
1427
+ Added in Synapse v1.90.0.
1428
+
1429
+ Args:
1430
+ msec: How long to wait before calling, in milliseconds.
1431
+ f: The function to call once. f can be either synchronous or
1432
+ asynchronous, and must follow Synapse's logcontext rules.
1433
+ More info about logcontexts is available at
1434
+ https://element-hq.github.io/synapse/latest/log_contexts.html
1435
+ *args: Positional arguments to pass to function.
1436
+ desc: The background task's description. Default to the function's name.
1437
+ **kwargs: Keyword arguments to pass to function.
1438
+
1439
+ Returns:
1440
+ IDelayedCall handle from twisted, which allows to cancel the delayed call if desired.
1441
+ """
1442
+
1443
+ if desc is None:
1444
+ desc = f.__name__
1445
+
1446
+ return self._clock.call_later(
1447
+ # convert ms to seconds as needed by call_later.
1448
+ msec * 0.001,
1449
+ self._hs.run_as_background_process,
1450
+ desc,
1451
+ lambda: maybe_awaitable(f(*args, **kwargs)),
1452
+ )
1453
+
1454
+ async def sleep(self, seconds: float) -> None:
1455
+ """Sleeps for the given number of seconds.
1456
+
1457
+ Added in Synapse v1.49.0.
1458
+ """
1459
+
1460
+ await self._clock.sleep(seconds)
1461
+
1462
+ async def send_http_push_notification(
1463
+ self,
1464
+ user_id: str,
1465
+ device_id: str | None,
1466
+ content: JsonDict,
1467
+ tweaks: JsonMapping | None = None,
1468
+ default_payload: JsonMapping | None = None,
1469
+ ) -> dict[str, bool]:
1470
+ """Send an HTTP push notification that is forwarded to the registered push gateway
1471
+ for the specified user/device.
1472
+
1473
+ Added in Synapse v1.82.0.
1474
+
1475
+ Args:
1476
+ user_id: The user ID to send the push notification to.
1477
+ device_id: The device ID of the device where to send the push notification. If `None`,
1478
+ the notification will be sent to all registered HTTP pushers of the user.
1479
+ content: A dict of values that will be put in the `notification` field of the push
1480
+ (cf Push Gateway spec). `devices` field will be overrided if included.
1481
+ tweaks: A dict of `tweaks` that will be inserted in the `devices` section, cf spec.
1482
+ default_payload: default payload to add in `devices[0].data.default_payload`.
1483
+ This will be merged (and override if some matching values already exist there)
1484
+ with existing `default_payload`.
1485
+
1486
+ Returns:
1487
+ a dict reprensenting the status of the push per device ID
1488
+ """
1489
+ status = {}
1490
+ if user_id in self._pusherpool.pushers:
1491
+ for p in self._pusherpool.pushers[user_id].values():
1492
+ if isinstance(p, HttpPusher) and (
1493
+ not device_id or p.device_id == device_id
1494
+ ):
1495
+ res = await p.dispatch_push(content, tweaks, default_payload)
1496
+ # Check if the push was successful and no pushers were rejected.
1497
+ sent = res is not False and not res
1498
+
1499
+ # This is mainly to accomodate mypy
1500
+ # device_id should never be empty after the `set_device_id_for_pushers`
1501
+ # background job has been properly run.
1502
+ if p.device_id:
1503
+ status[p.device_id] = sent
1504
+ return status
1505
+
1506
+ async def send_mail(
1507
+ self,
1508
+ recipient: str,
1509
+ subject: str,
1510
+ html: str,
1511
+ text: str,
1512
+ ) -> None:
1513
+ """Send an email on behalf of the homeserver.
1514
+
1515
+ Added in Synapse v1.39.0.
1516
+
1517
+ Args:
1518
+ recipient: The email address for the recipient.
1519
+ subject: The email's subject.
1520
+ html: The email's HTML content.
1521
+ text: The email's text content.
1522
+ """
1523
+ await self._send_email_handler.send_email(
1524
+ email_address=recipient,
1525
+ subject=subject,
1526
+ app_name=self.email_app_name,
1527
+ html=html,
1528
+ text=text,
1529
+ )
1530
+
1531
+ def read_templates(
1532
+ self,
1533
+ filenames: list[str],
1534
+ custom_template_directory: str | None = None,
1535
+ ) -> list[jinja2.Template]:
1536
+ """Read and load the content of the template files at the given location.
1537
+ By default, Synapse will look for these templates in its configured template
1538
+ directory, but another directory to search in can be provided.
1539
+
1540
+ Added in Synapse v1.39.0.
1541
+
1542
+ Args:
1543
+ filenames: The name of the template files to look for.
1544
+ custom_template_directory: An additional directory to look for the files in.
1545
+
1546
+ Returns:
1547
+ A list containing the loaded templates, with the orders matching the one of
1548
+ the filenames parameter.
1549
+ """
1550
+ return self._hs.config.server.read_templates(
1551
+ filenames,
1552
+ (td for td in (self.custom_template_dir, custom_template_directory) if td),
1553
+ )
1554
+
1555
+ def is_mine(self, id: str | DomainSpecificString) -> bool:
1556
+ """
1557
+ Checks whether an ID (user id, room, ...) comes from this homeserver.
1558
+
1559
+ Added in Synapse v1.44.0.
1560
+
1561
+ Args:
1562
+ id: any Matrix id (e.g. user id, room id, ...), either as a raw id,
1563
+ e.g. string "@user:example.com" or as a parsed UserID, RoomID, ...
1564
+ Returns:
1565
+ True if id comes from this homeserver, False otherwise.
1566
+ """
1567
+ if isinstance(id, DomainSpecificString):
1568
+ return self._hs.is_mine(id)
1569
+ else:
1570
+ return self._hs.is_mine_id(id)
1571
+
1572
+ async def get_user_ip_and_agents(
1573
+ self, user_id: str, since_ts: int = 0
1574
+ ) -> list[UserIpAndAgent]:
1575
+ """
1576
+ Return the list of user IPs and agents for a user.
1577
+
1578
+ Added in Synapse v1.44.0.
1579
+
1580
+ Args:
1581
+ user_id: the id of a user, local or remote
1582
+ since_ts: a timestamp in seconds since the epoch,
1583
+ or the epoch itself if not specified.
1584
+ Returns:
1585
+ The list of all UserIpAndAgent that the user has
1586
+ used to connect to this homeserver since `since_ts`.
1587
+ If the user is remote, this list is empty.
1588
+ """
1589
+ # Don't hit the db if this is not a local user.
1590
+ is_mine = False
1591
+ try:
1592
+ # Let's be defensive against ill-formed strings.
1593
+ if self.is_mine(user_id):
1594
+ is_mine = True
1595
+ except Exception:
1596
+ pass
1597
+
1598
+ if is_mine:
1599
+ raw_data = await self._store.get_user_ip_and_agents(
1600
+ UserID.from_string(user_id), since_ts
1601
+ )
1602
+ # Sanitize some of the data. We don't want to return tokens.
1603
+ return [
1604
+ UserIpAndAgent(
1605
+ ip=data["ip"],
1606
+ user_agent=data["user_agent"],
1607
+ last_seen=data["last_seen"],
1608
+ )
1609
+ for data in raw_data
1610
+ ]
1611
+ else:
1612
+ return []
1613
+
1614
+ async def get_room_state(
1615
+ self,
1616
+ room_id: str,
1617
+ event_filter: Iterable[tuple[str, str | None]] | None = None,
1618
+ ) -> StateMap[EventBase]:
1619
+ """Returns the current state of the given room.
1620
+
1621
+ The events are returned as a mapping, in which the key for each event is a tuple
1622
+ which first element is the event's type and the second one is its state key.
1623
+
1624
+ Added in Synapse v1.47.0
1625
+
1626
+ Args:
1627
+ room_id: The ID of the room to get state from.
1628
+ event_filter: A filter to apply when retrieving events. None if no filter
1629
+ should be applied. If provided, must be an iterable of tuples. A tuple's
1630
+ first element is the event type and the second is the state key, or is
1631
+ None if the state key should not be filtered on.
1632
+ An example of a filter is:
1633
+ [
1634
+ ("m.room.member", "@alice:example.com"), # Member event for @alice:example.com
1635
+ ("org.matrix.some_event", ""), # State event of type "org.matrix.some_event"
1636
+ # with an empty string as its state key
1637
+ ("org.matrix.some_other_event", None), # State events of type "org.matrix.some_other_event"
1638
+ # regardless of their state key
1639
+ ]
1640
+ """
1641
+ state_filter = None
1642
+ if event_filter:
1643
+ # If a filter was provided, turn it into a StateFilter and retrieve a filtered
1644
+ # view of the state.
1645
+ state_filter = StateFilter.from_types(event_filter)
1646
+
1647
+ state_ids = await self._storage_controllers.state.get_current_state_ids(
1648
+ room_id,
1649
+ state_filter,
1650
+ )
1651
+
1652
+ state_events = await self._store.get_events(state_ids.values())
1653
+
1654
+ return {key: state_events[event_id] for key, event_id in state_ids.items()}
1655
+
1656
+ def run_as_background_process(
1657
+ self,
1658
+ desc: "LiteralString",
1659
+ func: Callable[..., Awaitable[T | None]],
1660
+ *args: Any,
1661
+ bg_start_span: bool = True,
1662
+ **kwargs: Any,
1663
+ ) -> "defer.Deferred[T | None]":
1664
+ """Run the given function in its own logcontext, with resource metrics
1665
+
1666
+ This should be used to wrap processes which are fired off to run in the
1667
+ background, instead of being associated with a particular request.
1668
+
1669
+ It returns a Deferred which completes when the function completes, but it doesn't
1670
+ follow the synapse logcontext rules, which makes it appropriate for passing to
1671
+ clock.looping_call and friends (or for firing-and-forgetting in the middle of a
1672
+ normal synapse async function).
1673
+
1674
+ Args:
1675
+ desc: a description for this background process type
1676
+ server_name: The homeserver name that this background process is being run for
1677
+ (this should be `hs.hostname`).
1678
+ func: a function, which may return a Deferred or a coroutine
1679
+ bg_start_span: Whether to start an opentracing span. Defaults to True.
1680
+ Should only be disabled for processes that will not log to or tag
1681
+ a span.
1682
+ args: positional args for func
1683
+ kwargs: keyword args for func
1684
+
1685
+ Returns:
1686
+ Deferred which returns the result of func, or `None` if func raises.
1687
+ Note that the returned Deferred does not follow the synapse logcontext
1688
+ rules.
1689
+ """
1690
+ return self._hs.run_as_background_process(
1691
+ desc, func, *args, bg_start_span=bg_start_span, **kwargs
1692
+ )
1693
+
1694
+ async def defer_to_thread(
1695
+ self,
1696
+ f: Callable[P, T],
1697
+ *args: P.args,
1698
+ **kwargs: P.kwargs,
1699
+ ) -> T:
1700
+ """Runs the given function in a separate thread from Synapse's thread pool.
1701
+
1702
+ Added in Synapse v1.49.0.
1703
+
1704
+ Args:
1705
+ f: The function to run.
1706
+ args: The function's arguments.
1707
+ kwargs: The function's keyword arguments.
1708
+
1709
+ Returns:
1710
+ The return value of the function once ran in a thread.
1711
+ """
1712
+ return await defer_to_thread(self._hs.get_reactor(), f, *args, **kwargs)
1713
+
1714
+ async def defer_to_threadpool(
1715
+ self,
1716
+ threadpool: ThreadPool,
1717
+ f: Callable[P, T],
1718
+ *args: P.args,
1719
+ **kwargs: P.kwargs,
1720
+ ) -> T:
1721
+ """Runs the given function in a separate thread from the given thread pool.
1722
+
1723
+ Allows specifying a custom thread pool instead of using the default Synapse
1724
+ one. To use the default Synapse threadpool, use `defer_to_thread` instead.
1725
+
1726
+ Added in Synapse v1.140.0.
1727
+
1728
+ Args:
1729
+ threadpool: The thread pool to use.
1730
+ f: The function to run.
1731
+ args: The function's arguments.
1732
+ kwargs: The function's keyword arguments.
1733
+
1734
+ Returns:
1735
+ The return value of the function once ran in a thread.
1736
+ """
1737
+ return await defer_to_threadpool(
1738
+ self._hs.get_reactor(), threadpool, f, *args, **kwargs
1739
+ )
1740
+
1741
+ async def check_username(self, username: str) -> None:
1742
+ """Checks if the provided username uses the grammar defined in the Matrix
1743
+ specification, and is already being used by an existing user.
1744
+
1745
+ Added in Synapse v1.52.0.
1746
+
1747
+ Args:
1748
+ username: The username to check. This is the local part of the user's full
1749
+ Matrix user ID, i.e. it's "alice" if the full user ID is "@alice:foo.com".
1750
+
1751
+ Raises:
1752
+ SynapseError with the errcode "M_USER_IN_USE" if the username is already in
1753
+ use.
1754
+ """
1755
+ await self._registration_handler.check_username(username)
1756
+
1757
+ async def store_remote_3pid_association(
1758
+ self, user_id: str, medium: str, address: str, id_server: str
1759
+ ) -> None:
1760
+ """Stores an existing association between a user ID and a third-party identifier.
1761
+
1762
+ The association must already exist on the remote identity server.
1763
+
1764
+ Added in Synapse v1.56.0.
1765
+
1766
+ Args:
1767
+ user_id: The user ID that's been associated with the 3PID.
1768
+ medium: The medium of the 3PID (current supported values are "msisdn" and
1769
+ "email").
1770
+ address: The address of the 3PID.
1771
+ id_server: The identity server the 3PID association has been registered on.
1772
+ This should only be the domain (or IP address, optionally with the port
1773
+ number) for the identity server. This will be used to reach out to the
1774
+ identity server using HTTPS (unless specified otherwise by Synapse's
1775
+ configuration) when attempting to unbind the third-party identifier.
1776
+
1777
+
1778
+ """
1779
+ await self._store.add_user_bound_threepid(user_id, medium, address, id_server)
1780
+
1781
+ def check_push_rule_actions(self, actions: list[str | dict[str, str]]) -> None:
1782
+ """Checks if the given push rule actions are valid according to the Matrix
1783
+ specification.
1784
+
1785
+ See https://spec.matrix.org/v1.2/client-server-api/#actions for the list of valid
1786
+ actions.
1787
+
1788
+ Added in Synapse v1.58.0.
1789
+
1790
+ Args:
1791
+ actions: the actions to check.
1792
+
1793
+ Raises:
1794
+ synapse.module_api.errors.InvalidRuleException if the actions are invalid.
1795
+ """
1796
+ check_actions(actions)
1797
+
1798
+ async def set_push_rule_action(
1799
+ self,
1800
+ user_id: str,
1801
+ scope: str,
1802
+ kind: str,
1803
+ rule_id: str,
1804
+ actions: list[str | dict[str, str]],
1805
+ ) -> None:
1806
+ """Changes the actions of an existing push rule for the given user.
1807
+
1808
+ See https://spec.matrix.org/v1.2/client-server-api/#push-rules for more
1809
+ information about push rules and their syntax.
1810
+
1811
+ Can only be called on the main process.
1812
+
1813
+ Added in Synapse v1.58.0.
1814
+
1815
+ Args:
1816
+ user_id: the user for which to change the push rule's actions.
1817
+ scope: the push rule's scope, currently only "global" is allowed.
1818
+ kind: the push rule's kind.
1819
+ rule_id: the push rule's identifier.
1820
+ actions: the actions to run when the rule's conditions match.
1821
+
1822
+ Raises:
1823
+ RuntimeError if this method is called on a worker or `scope` is invalid.
1824
+ synapse.module_api.errors.RuleNotFoundException if the rule being modified
1825
+ can't be found.
1826
+ synapse.module_api.errors.InvalidRuleException if the actions are invalid.
1827
+ """
1828
+ if self.worker_app is not None:
1829
+ raise RuntimeError("module tried to change push rule actions on a worker")
1830
+
1831
+ if scope != "global":
1832
+ raise RuntimeError(
1833
+ "invalid scope %s, only 'global' is currently allowed" % scope
1834
+ )
1835
+
1836
+ spec = RuleSpec(scope, kind, rule_id, "actions")
1837
+ await self._push_rules_handler.set_rule_attr(
1838
+ user_id, spec, {"actions": actions}
1839
+ )
1840
+
1841
+ async def get_monthly_active_users_by_service(
1842
+ self, start_timestamp: int | None = None, end_timestamp: int | None = None
1843
+ ) -> list[tuple[str, str]]:
1844
+ """Generates list of monthly active users and their services.
1845
+ Please see corresponding storage docstring for more details.
1846
+
1847
+ Added in Synapse v1.61.0.
1848
+
1849
+ Arguments:
1850
+ start_timestamp: If specified, only include users that were first active
1851
+ at or after this point
1852
+ end_timestamp: If specified, only include users that were first active
1853
+ at or before this point
1854
+
1855
+ Returns:
1856
+ A list of tuples (appservice_id, user_id)
1857
+
1858
+ """
1859
+ return await self._store.get_monthly_active_users_by_service(
1860
+ start_timestamp, end_timestamp
1861
+ )
1862
+
1863
+ async def get_canonical_room_alias(self, room_id: RoomID) -> RoomAlias | None:
1864
+ """
1865
+ Retrieve the given room's current canonical alias.
1866
+
1867
+ A room may declare an alias as "canonical", meaning that it is the
1868
+ preferred alias to use when referring to the room. This function
1869
+ retrieves that alias from the room's state.
1870
+
1871
+ Added in Synapse v1.86.0.
1872
+
1873
+ Args:
1874
+ room_id: The Room ID to find the alias of.
1875
+
1876
+ Returns:
1877
+ None if the room ID does not exist, or if the room exists but has no canonical alias.
1878
+ Otherwise, the parsed room alias.
1879
+ """
1880
+ room_alias_str = (
1881
+ await self._storage_controllers.state.get_canonical_alias_for_room(
1882
+ room_id.to_string()
1883
+ )
1884
+ )
1885
+ if room_alias_str:
1886
+ return RoomAlias.from_string(room_alias_str)
1887
+ return None
1888
+
1889
+ async def lookup_room_alias(self, room_alias: str) -> tuple[str, list[str]]:
1890
+ """
1891
+ Get the room ID associated with a room alias.
1892
+
1893
+ Added in Synapse v1.65.0.
1894
+
1895
+ Args:
1896
+ room_alias: The alias to look up.
1897
+
1898
+ Returns:
1899
+ A tuple of:
1900
+ The room ID (str).
1901
+ Hosts likely to be participating in the room ([str]).
1902
+
1903
+ Raises:
1904
+ SynapseError if room alias is invalid or could not be found.
1905
+ """
1906
+ alias = RoomAlias.from_string(room_alias)
1907
+ (room_id, hosts) = await self._hs.get_room_member_handler().lookup_room_alias(
1908
+ alias
1909
+ )
1910
+
1911
+ return room_id.to_string(), hosts
1912
+
1913
+ async def create_room(
1914
+ self,
1915
+ user_id: str,
1916
+ config: JsonDict,
1917
+ ratelimit: bool = True,
1918
+ creator_join_profile: JsonDict | None = None,
1919
+ ) -> tuple[str, str | None]:
1920
+ """Creates a new room.
1921
+
1922
+ Added in Synapse v1.65.0.
1923
+
1924
+ Args:
1925
+ user_id:
1926
+ The user who requested the room creation.
1927
+ config : A dict of configuration options. See "Request body" of:
1928
+ https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3createroom
1929
+ ratelimit: set to False to disable the rate limiter for this specific operation.
1930
+
1931
+ creator_join_profile:
1932
+ Set to override the displayname and avatar for the creating
1933
+ user in this room. If unset, displayname and avatar will be
1934
+ derived from the user's profile. If set, should contain the
1935
+ values to go in the body of the 'join' event (typically
1936
+ `avatar_url` and/or `displayname`.
1937
+
1938
+ Returns:
1939
+ A tuple containing: 1) the room ID (str), 2) if an alias was requested,
1940
+ the room alias (str), otherwise None if no alias was requested.
1941
+
1942
+ Raises:
1943
+ ResourceLimitError if server is blocked to some resource being
1944
+ exceeded.
1945
+ RuntimeError if the user_id does not refer to a local user.
1946
+ SynapseError if the user_id is invalid, room ID couldn't be stored, or
1947
+ something went horribly wrong.
1948
+ """
1949
+ if not self.is_mine(user_id):
1950
+ raise RuntimeError(
1951
+ "Tried to create a room as a user that isn't local to this homeserver",
1952
+ )
1953
+
1954
+ requester = create_requester(user_id)
1955
+ room_id, room_alias, _ = await self._hs.get_room_creation_handler().create_room(
1956
+ requester=requester,
1957
+ config=config,
1958
+ ratelimit=ratelimit,
1959
+ creator_join_profile=creator_join_profile,
1960
+ )
1961
+ room_alias_str = room_alias.to_string() if room_alias else None
1962
+ return room_id, room_alias_str
1963
+
1964
+ async def delete_room(self, room_id: str) -> None:
1965
+ """
1966
+ Schedules the deletion of a room from Synapse's database.
1967
+
1968
+ If the room is already being deleted, this method does nothing.
1969
+ This method does not wait for the room to be deleted.
1970
+
1971
+ Added in Synapse v1.89.0.
1972
+ """
1973
+ # Future extensions to this method might want to e.g. allow use of `force_purge`.
1974
+ # TODO In the future we should make sure this is persistent.
1975
+ await self._hs.get_pagination_handler().start_shutdown_and_purge_room(
1976
+ room_id,
1977
+ {
1978
+ "new_room_user_id": None,
1979
+ "new_room_name": None,
1980
+ "message": None,
1981
+ "requester_user_id": None,
1982
+ "block": False,
1983
+ "purge": True,
1984
+ "force_purge": False,
1985
+ },
1986
+ )
1987
+
1988
+ async def set_displayname(
1989
+ self,
1990
+ user_id: UserID,
1991
+ new_displayname: str,
1992
+ deactivation: bool = False,
1993
+ ) -> None:
1994
+ """Sets a user's display name.
1995
+
1996
+ Added in Synapse v1.76.0.
1997
+
1998
+ Args:
1999
+ user_id:
2000
+ The user whose display name is to be changed.
2001
+ new_displayname:
2002
+ The new display name to give the user.
2003
+ deactivation:
2004
+ Whether this change was made while deactivating the user.
2005
+ """
2006
+ requester = create_requester(user_id)
2007
+ await self._hs.get_profile_handler().set_displayname(
2008
+ target_user=user_id,
2009
+ requester=requester,
2010
+ new_displayname=new_displayname,
2011
+ by_admin=True,
2012
+ deactivation=deactivation,
2013
+ )
2014
+
2015
+ def get_current_time_msec(self) -> int:
2016
+ """Returns the current server time in milliseconds."""
2017
+ return self._clock.time_msec()
2018
+
2019
+
2020
+ class PublicRoomListManager:
2021
+ """Contains methods for adding to, removing from and querying whether a room
2022
+ is in the public room list.
2023
+ """
2024
+
2025
+ def __init__(self, hs: "HomeServer"):
2026
+ self._store = hs.get_datastores().main
2027
+
2028
+ async def room_is_in_public_room_list(self, room_id: str) -> bool:
2029
+ """Checks whether a room is in the public room list.
2030
+
2031
+ Added in Synapse v1.22.0.
2032
+
2033
+ Args:
2034
+ room_id: The ID of the room.
2035
+
2036
+ Returns:
2037
+ Whether the room is in the public room list. Returns False if the room does
2038
+ not exist.
2039
+ """
2040
+ room = await self._store.get_room(room_id)
2041
+ if not room:
2042
+ return False
2043
+
2044
+ # The first item is whether the room is public.
2045
+ return room[0]
2046
+
2047
+ async def add_room_to_public_room_list(self, room_id: str) -> None:
2048
+ """Publishes a room to the public room list.
2049
+
2050
+ Added in Synapse v1.22.0.
2051
+
2052
+ Args:
2053
+ room_id: The ID of the room.
2054
+ """
2055
+ await self._store.set_room_is_public(room_id, True)
2056
+
2057
+ async def remove_room_from_public_room_list(self, room_id: str) -> None:
2058
+ """Removes a room from the public room list.
2059
+
2060
+ Added in Synapse v1.22.0.
2061
+
2062
+ Args:
2063
+ room_id: The ID of the room.
2064
+ """
2065
+ await self._store.set_room_is_public(room_id, False)
2066
+
2067
+
2068
+ class AccountDataManager:
2069
+ """
2070
+ Allows modules to manage account data.
2071
+ """
2072
+
2073
+ def __init__(self, hs: "HomeServer") -> None:
2074
+ self._hs = hs
2075
+ self._store = hs.get_datastores().main
2076
+ self._handler = hs.get_account_data_handler()
2077
+
2078
+ def _validate_user_id(self, user_id: str) -> None:
2079
+ """
2080
+ Validates a user ID is valid and local.
2081
+ Private method to be used in other account data methods.
2082
+ """
2083
+ user = UserID.from_string(user_id)
2084
+ if not self._hs.is_mine(user):
2085
+ raise ValueError(
2086
+ f"{user_id} is not local to this homeserver; can't access account data for remote users."
2087
+ )
2088
+
2089
+ async def get_global(self, user_id: str, data_type: str) -> JsonMapping | None:
2090
+ """
2091
+ Gets some global account data, of a specified type, for the specified user.
2092
+
2093
+ The provided user ID must be a valid user ID of a local user.
2094
+
2095
+ Added in Synapse v1.57.0.
2096
+ """
2097
+ self._validate_user_id(user_id)
2098
+
2099
+ data = await self._store.get_global_account_data_by_type_for_user(
2100
+ user_id, data_type
2101
+ )
2102
+ # We clone and freeze to prevent the module accidentally mutating the
2103
+ # dict that lives in the cache, as that could introduce nasty bugs.
2104
+ return freeze(data)
2105
+
2106
+ async def put_global(
2107
+ self, user_id: str, data_type: str, new_data: JsonDict
2108
+ ) -> None:
2109
+ """
2110
+ Puts some global account data, of a specified type, for the specified user.
2111
+
2112
+ The provided user ID must be a valid user ID of a local user.
2113
+
2114
+ Please note that this will overwrite existing the account data of that type
2115
+ for that user!
2116
+
2117
+ Added in Synapse v1.57.0.
2118
+ """
2119
+ self._validate_user_id(user_id)
2120
+
2121
+ if not isinstance(data_type, str):
2122
+ raise TypeError(f"data_type must be a str; got {type(data_type).__name__}")
2123
+
2124
+ if not isinstance(new_data, dict):
2125
+ raise TypeError(f"new_data must be a dict; got {type(new_data).__name__}")
2126
+
2127
+ # Ensure the user exists, so we don't just write to users that aren't there.
2128
+ if await self._store.get_user_by_id(user_id) is None:
2129
+ raise ValueError(f"User {user_id} does not exist on this server.")
2130
+
2131
+ await self._handler.add_account_data_for_user(user_id, data_type, new_data)