@@ -57,6 +57,9 @@ pub struct Capabilities {
5757 pub update_delayed_event : bool ,
5858 /// This allows the widget to send events with a delay.
5959 pub send_delayed_event : bool ,
60+
61+ /// This allows the widget to download files as per MSC4039.
62+ pub download_file : bool ,
6063}
6164
6265impl Capabilities {
@@ -114,6 +117,8 @@ pub(super) const REQUIRES_CLIENT: &str = "io.element.requires_client";
114117pub ( super ) const SEND_DELAYED_EVENT : & str = "org.matrix.msc4157.send.delayed_event" ;
115118pub ( super ) const UPDATE_DELAYED_EVENT : & str = "org.matrix.msc4157.update_delayed_event" ;
116119
120+ pub ( super ) const DOWNLOAD_FILE : & str = "org.matrix.msc4039.download_file" ;
121+
117122impl Serialize for Capabilities {
118123 fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
119124 where
@@ -174,6 +179,9 @@ impl Serialize for Capabilities {
174179 if self . send_delayed_event {
175180 seq. serialize_element ( SEND_DELAYED_EVENT ) ?;
176181 }
182+ if self . download_file {
183+ seq. serialize_element ( DOWNLOAD_FILE ) ?;
184+ }
177185 for filter in & self . read {
178186 let name = match filter {
179187 Filter :: MessageLike ( _) => READ_EVENT ,
@@ -204,6 +212,7 @@ impl<'de> Deserialize<'de> for Capabilities {
204212 RequiresClient ,
205213 UpdateDelayedEvent ,
206214 SendDelayedEvent ,
215+ DownloadFile ,
207216 Read ( Filter ) ,
208217 Send ( Filter ) ,
209218 Unknown ,
@@ -224,6 +233,9 @@ impl<'de> Deserialize<'de> for Capabilities {
224233 if s == SEND_DELAYED_EVENT {
225234 return Ok ( Self :: SendDelayedEvent ) ;
226235 }
236+ if s == DOWNLOAD_FILE {
237+ return Ok ( Self :: DownloadFile ) ;
238+ }
227239
228240 match s. split_once ( ':' ) {
229241 Some ( ( READ_EVENT , filter_s) ) => Ok ( Permission :: Read ( Filter :: MessageLike (
@@ -284,6 +296,7 @@ impl<'de> Deserialize<'de> for Capabilities {
284296 Permission :: Unknown => { }
285297 Permission :: UpdateDelayedEvent => capabilities. update_delayed_event = true ,
286298 Permission :: SendDelayedEvent => capabilities. send_delayed_event = true ,
299+ Permission :: DownloadFile => capabilities. download_file = true ,
287300 }
288301 }
289302
@@ -321,7 +334,8 @@ mod tests {
321334 "org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#@user:matrix.server",
322335 "org.matrix.msc3819.send.to_device:io.element.call.encryption_keys",
323336 "org.matrix.msc4157.send.delayed_event",
324- "org.matrix.msc4157.update_delayed_event"
337+ "org.matrix.msc4157.update_delayed_event",
338+ "org.matrix.msc4039.download_file"
325339 ]"# ;
326340
327341 let parsed = serde_json:: from_str :: < Capabilities > ( capabilities_str) . unwrap ( ) ;
@@ -351,6 +365,7 @@ mod tests {
351365 requires_client : true ,
352366 update_delayed_event : true ,
353367 send_delayed_event : true ,
368+ download_file : true ,
354369 } ;
355370
356371 assert_eq ! ( parsed, expected) ;
@@ -381,6 +396,7 @@ mod tests {
381396 requires_client : true ,
382397 update_delayed_event : false ,
383398 send_delayed_event : false ,
399+ download_file : false ,
384400 } ;
385401
386402 let capabilities_str = serde_json:: to_string ( & capabilities) . unwrap ( ) ;
0 commit comments