ruma_client_api/backup/
add_backup_keys.rs

1//! `PUT /_matrix/client/*/room_keys/keys`
2//!
3//! Store keys in the backup.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3room_keyskeys
9
10    use std::collections::BTreeMap;
11
12    use js_int::UInt;
13    use ruma_common::{
14        OwnedRoomId,
15        api::{auth_scheme::AccessToken, request, response},
16        metadata,
17    };
18
19    use crate::backup::RoomKeyBackup;
20
21    metadata! {
22        method: PUT,
23        rate_limited: true,
24        authentication: AccessToken,
25        history: {
26            unstable => "/_matrix/client/unstable/room_keys/keys",
27            1.1 => "/_matrix/client/v3/room_keys/keys",
28        }
29    }
30
31    /// Request type for the `add_backup_keys` endpoint.
32    #[request(error = crate::Error)]
33    pub struct Request {
34        /// The backup version to add keys to.
35        ///
36        /// Must be the current backup.
37        #[ruma_api(query)]
38        pub version: String,
39
40        /// A map of room IDs to session IDs to key data to store.
41        pub rooms: BTreeMap<OwnedRoomId, RoomKeyBackup>,
42    }
43
44    /// Response type for the `add_backup_keys` endpoint.
45    #[response(error = crate::Error)]
46    pub struct Response {
47        /// An opaque string representing stored keys in the backup.
48        ///
49        /// Clients can compare it with  the etag value they received in the request of their last
50        /// key storage request.
51        pub etag: String,
52
53        /// The number of keys stored in the backup.
54        pub count: UInt,
55    }
56
57    impl Request {
58        /// Creates a new `Request` with the given version and room key backups.
59        pub fn new(version: String, rooms: BTreeMap<OwnedRoomId, RoomKeyBackup>) -> Self {
60            Self { version, rooms }
61        }
62    }
63
64    impl Response {
65        /// Creates a new `Response` with the given  etag and key count.
66        pub fn new(etag: String, count: UInt) -> Self {
67            Self { etag, count }
68        }
69    }
70}