ruma_client_api/keys/claim_keys/
v4.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 unstable => "/_matrix/client/unstable/org.matrix.msc3983/keys/claim",
22 }
23};
24
25#[request(error = crate::Error)]
27pub struct Request {
28 #[serde(
31 with = "ruma_common::serde::duration::opt_ms",
32 default,
33 skip_serializing_if = "Option::is_none"
34 )]
35 pub timeout: Option<Duration>,
36
37 pub one_time_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Vec<OneTimeKeyAlgorithm>>>,
39}
40
41#[response(error = crate::Error)]
43pub struct Response {
44 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
48 pub failures: BTreeMap<String, JsonValue>,
49
50 pub one_time_keys: BTreeMap<OwnedUserId, OneTimeKeys>,
52}
53
54impl Request {
55 pub fn new(
57 one_time_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Vec<OneTimeKeyAlgorithm>>>,
58 ) -> Self {
59 Self { timeout: Some(Duration::from_secs(10)), one_time_keys }
60 }
61}
62
63impl Response {
64 pub fn new(one_time_keys: BTreeMap<OwnedUserId, OneTimeKeys>) -> Self {
66 Self { failures: BTreeMap::new(), one_time_keys }
67 }
68}
69
70pub type OneTimeKeys = BTreeMap<OwnedDeviceId, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>>;