ruma_client_api/keys/claim_keys/
v3.rs1use std::{collections::BTreeMap, time::Duration};
6
7use ruma_common::{
8 api::{request, response, Metadata},
9 encryption::OneTimeKey,
10 metadata,
11 serde::Raw,
12 OneTimeKeyAlgorithm, OwnedDeviceId, OwnedOneTimeKeyId, OwnedUserId,
13};
14use serde_json::Value as JsonValue;
15
16const METADATA: Metadata = metadata! {
17 method: POST,
18 rate_limited: false,
19 authentication: AccessToken,
20 history: {
21 1.0 => "/_matrix/client/r0/keys/claim",
22 1.1 => "/_matrix/client/v3/keys/claim",
23 }
24};
25
26#[request(error = crate::Error)]
28pub struct Request {
29 #[serde(
32 with = "ruma_common::serde::duration::opt_ms",
33 default,
34 skip_serializing_if = "Option::is_none"
35 )]
36 pub timeout: Option<Duration>,
37
38 pub one_time_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, OneTimeKeyAlgorithm>>,
40}
41
42#[response(error = crate::Error)]
44pub struct Response {
45 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
49 pub failures: BTreeMap<String, JsonValue>,
50
51 pub one_time_keys: BTreeMap<OwnedUserId, OneTimeKeys>,
53}
54
55impl Request {
56 pub fn new(
58 one_time_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, OneTimeKeyAlgorithm>>,
59 ) -> Self {
60 Self { timeout: Some(Duration::from_secs(10)), one_time_keys }
61 }
62}
63
64impl Response {
65 pub fn new(one_time_keys: BTreeMap<OwnedUserId, OneTimeKeys>) -> Self {
67 Self { failures: BTreeMap::new(), one_time_keys }
68 }
69}
70
71pub type OneTimeKeys = BTreeMap<OwnedDeviceId, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>>;