tuwunel_api_client/versions.rs
1use std::iter::once;
2
3use axum::extract::State;
4use ruma::api::client::discovery::get_supported_versions::{self, Server};
5use tuwunel_core::{
6 Result,
7 info::rustc::version as rustc_version,
8 version::{name as package_name, version as package_version},
9};
10
11use crate::Ruma;
12
13/// # `GET /_matrix/client/versions`
14///
15/// Get the versions of the specification and unstable features supported by
16/// this server.
17///
18/// - Versions take the form MAJOR.MINOR.PATCH
19/// - Only the latest PATCH release will be reported for each MAJOR.MINOR value
20/// - Unstable features are namespaced and may include version information in
21/// their name
22///
23/// Note: Unstable features are used while developing new features. Clients
24/// should avoid using unstable features in their stable releases
25pub(crate) async fn get_supported_versions_route(
26 State(services): State<crate::State>,
27 _body: Ruma<get_supported_versions::Request>,
28) -> Result<get_supported_versions::Response> {
29 // MSC4383: client-side parity with /_matrix/federation/v1/version.
30 let server = Server {
31 compiler: rustc_version().map(Into::into),
32 ..Server::new(package_name().into(), package_version().into())
33 };
34
35 let unstable_features = UNSTABLE_FEATURES
36 .into_iter()
37 .chain(
38 services
39 .config
40 .rendezvous
41 .enable
42 .then_some("org.matrix.msc4108"),
43 )
44 .chain(
45 services
46 .oauth
47 .server
48 .is_some()
49 .then_some(OIDC_FEATURES)
50 .into_iter()
51 .flatten(),
52 )
53 .chain(
54 services
55 .delayed_events
56 .limits()
57 .is_some()
58 .then_some(DELAYED_EVENTS_FEATURES)
59 .into_iter()
60 .flatten(),
61 )
62 .map(Into::into)
63 .zip(once(true).cycle())
64 .collect();
65
66 Ok(get_supported_versions::Response {
67 versions: VERSIONS.into_iter().map(Into::into).collect(),
68 unstable_features,
69 server: Some(server),
70 })
71}
72
73static VERSIONS: [&str; 27] = [
74 "r0.0.1", /* Historical */
75 "r0.1.0", /* Historical */
76 "r0.2.0", /* Historical */
77 "r0.3.0", /* Historical */
78 "r0.4.0", /* Historical */
79 "r0.5.0", /* Historical */
80 "r0.6.0", /* Historical */
81 "r0.6.1", /* Historical */
82 "v1.1", /* Stable; Tested */
83 "v1.2", /* Stable; Tested */
84 "v1.3", /* Stable; Tested */
85 "v1.4", /* Tested; private read receipts, threads */
86 "v1.5", /* Stable; Tested */
87 "v1.6", /* jump to date (element-web labs gate) */
88 "v1.7", /* intentional mentions */
89 "v1.8", /* no action */
90 "v1.9", /* no action */
91 "v1.10", /* Tested; relations recursion */
92 "v1.11", /* Tested; authenticated media */
93 "v1.12", /* no action */
94 "v1.13", /* no action */
95 "v1.14", /* no action */
96 "v1.15", /* OIDC auth metadata */
97 "v1.16", /* extended profiles (MSC4133) */
98 "v1.17", /* no action */
99 "v1.18", /* policy servers (MSC4284) */
100 "v1.19", /* mutual rooms (MSC2666) */
101];
102
103static UNSTABLE_FEATURES: [&str; 37] = [
104 "org.matrix.e2e_cross_signing",
105 // private read receipts (https://github.com/matrix-org/matrix-spec-proposals/pull/2285)
106 "org.matrix.msc2285.stable",
107 // appservice ping https://github.com/matrix-org/matrix-spec-proposals/pull/2659)
108 "fi.mau.msc2659.stable",
109 // query mutual rooms (https://github.com/matrix-org/matrix-spec-proposals/pull/2666)
110 "uk.half-shot.msc2666.query_mutual_rooms",
111 "uk.half-shot.msc2666.query_mutual_rooms.stable",
112 // threading/threads (https://github.com/matrix-org/matrix-spec-proposals/pull/2836)
113 "org.matrix.msc2836",
114 // jump to date (https://github.com/matrix-org/matrix-spec-proposals/pull/3030)
115 "org.matrix.msc3030",
116 // spaces/hierarchy summaries (https://github.com/matrix-org/matrix-spec-proposals/pull/2946)
117 "org.matrix.msc2946",
118 // busy presence status (https://github.com/matrix-org/matrix-spec-proposals/pull/3026)
119 "org.matrix.msc3026.busy_presence",
120 // sliding sync (https://github.com/matrix-org/matrix-spec-proposals/pull/3575/files#r1588877046)
121 "org.matrix.msc3575",
122 // dehydrated devices
123 "org.matrix.msc3814",
124 // filtering of /publicRooms by room type (https://github.com/matrix-org/matrix-spec-proposals/pull/3827)
125 "org.matrix.msc3827",
126 "org.matrix.msc3827.stable",
127 // authenticated media (https://github.com/matrix-org/matrix-spec-proposals/pull/3916)
128 "org.matrix.msc3916.stable",
129 // intentional mentions (https://github.com/matrix-org/matrix-spec-proposals/pull/3952)
130 "org.matrix.msc3952_intentional_mentions",
131 // MatrixRTC transport discovery (https://github.com/matrix-org/matrix-spec-proposals/pull/4143)
132 "org.matrix.msc4143",
133 // MSC4133 (custom profile fields) and MSC4175 (m.tz) stabilized in
134 // Matrix 1.16; advertise the historical unstable prefixes alongside
135 // the post-merge `.stable` flags for clients that haven't migrated.
136 "uk.tcpip.msc4133",
137 "uk.tcpip.msc4133.stable",
138 "us.cloke.msc4175",
139 "us.cloke.msc4175.stable",
140 // stable flag for 3916 (https://github.com/matrix-org/matrix-spec-proposals/pull/4180)
141 "org.matrix.msc4180",
142 // Simplified Sliding sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4186)
143 "org.matrix.simplified_msc3575",
144 // Sliding sync profiles extension (https://github.com/matrix-org/matrix-spec-proposals/pull/4262)
145 "org.matrix.msc4262",
146 // Sliding sync to-device extension (https://github.com/matrix-org/matrix-spec-proposals/pull/4538)
147 "org.matrix.msc4538",
148 // Profile updates for legacy sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4429)
149 "org.matrix.msc4429",
150 // Allow room moderators to view redacted event content (https://github.com/matrix-org/matrix-spec-proposals/pull/2815)
151 "fi.mau.msc2815",
152 // Backwards-compatible redaction sending via /send (https://github.com/matrix-org/matrix-spec-proposals/pull/4169)
153 "com.beeper.msc4169",
154 // Invite filtering lists in m.invite_permission_config (https://github.com/matrix-org/matrix-spec-proposals/pull/4155)
155 "org.matrix.msc4155",
156 // Invite blocking via m.invite_permission_config (https://github.com/matrix-org/matrix-spec-proposals/pull/4380)
157 "org.matrix.msc4380",
158 "org.matrix.msc4380.stable",
159 // Client-server discovery of server version (https://github.com/matrix-org/matrix-spec-proposals/pull/4383)
160 "net.zemos.msc4383",
161 // Read receipts for threads (https://github.com/matrix-org/matrix-spec-proposals/pull/3771)
162 "org.matrix.msc3771",
163 // Notifications for threads (https://github.com/matrix-org/matrix-spec-proposals/pull/3773)
164 "org.matrix.msc3773",
165 // Threading via m.thread relations, stable since Matrix 1.4 (https://github.com/matrix-org/matrix-spec-proposals/pull/3440)
166 "org.matrix.msc3440.stable",
167 // state_after on /sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4222)
168 "org.matrix.msc4222",
169 // Backward fully-read moves on request (https://github.com/matrix-org/matrix-spec-proposals/pull/4446)
170 "com.beeper.msc4446",
171 // Profile change propagation (https://github.com/matrix-org/matrix-spec-proposals/pull/4466)
172 "computer.gingershaped.msc4466",
173];
174
175static OIDC_FEATURES: [&str; 6] = [
176 // OIDC-native auth umbrella (https://github.com/matrix-org/matrix-spec-proposals/pull/3861)
177 "org.matrix.msc3861",
178 // OIDC-native auth: authorization code grant (https://github.com/matrix-org/matrix-spec-proposals/pull/2964)
179 "org.matrix.msc2964",
180 // OIDC-native auth: auth issuer discovery (https://github.com/matrix-org/matrix-spec-proposals/pull/2965)
181 "org.matrix.msc2965",
182 // OIDC-native auth: dynamic client registration (https://github.com/matrix-org/matrix-spec-proposals/pull/2966)
183 "org.matrix.msc2966",
184 // OIDC-native auth: API scopes (https://github.com/matrix-org/matrix-spec-proposals/pull/2967)
185 "org.matrix.msc2967",
186 // OIDC delegation aware
187 "org.matrix.msc3824",
188];
189
190static DELAYED_EVENTS_FEATURES: [&str; 2] = [
191 // Delayed events (https://github.com/matrix-org/matrix-spec-proposals/pull/4140)
192 "org.matrix.msc4140",
193 // Delayed events on their stable endpoints, ahead of a spec version
194 "org.matrix.msc4140.stable",
195];