ruma_client_api/backup/add_backup_keys_for_session.rs
1//! `PUT /_matrix/client/*/room_keys/keys/{roomId}/{sessionId}`
2//!
3//! Store keys in the backup for a session.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3room_keyskeysroomidsessionid
9
10 use js_int::UInt;
11 use ruma_common::{
12 api::{request, response, Metadata},
13 metadata,
14 serde::Raw,
15 OwnedRoomId,
16 };
17
18 use crate::backup::KeyBackupData;
19
20 const METADATA: Metadata = metadata! {
21 method: PUT,
22 rate_limited: true,
23 authentication: AccessToken,
24 history: {
25 unstable => "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id",
26 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id/:session_id",
27 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id/:session_id",
28 }
29 };
30
31 /// Request type for the `add_backup_keys_for_session` 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 /// The ID of the room to add keys to.
41 #[ruma_api(path)]
42 pub room_id: OwnedRoomId,
43
44 /// The ID of the megolm session to add keys to.
45 #[ruma_api(path)]
46 pub session_id: String,
47
48 /// The key information to store.
49 #[ruma_api(body)]
50 pub session_data: Raw<KeyBackupData>,
51 }
52
53 /// Response type for the `add_backup_keys_for_session` endpoint.
54 #[response(error = crate::Error)]
55 pub struct Response {
56 /// An opaque string representing stored keys in the backup.
57 ///
58 /// Clients can compare it with the etag value they received in the request of their last
59 /// key storage request.
60 pub etag: String,
61
62 /// The number of keys stored in the backup.
63 pub count: UInt,
64 }
65
66 impl Request {
67 /// Creates a new `Request` with the given version, room_id, session_id and session_data.
68 pub fn new(
69 version: String,
70 room_id: OwnedRoomId,
71 session_id: String,
72 session_data: Raw<KeyBackupData>,
73 ) -> Self {
74 Self { version, room_id, session_id, session_data }
75 }
76 }
77
78 impl Response {
79 /// Creates an new `Response` with the given etag and count.
80 pub fn new(etag: String, count: UInt) -> Self {
81 Self { etag, count }
82 }
83 }
84}