use std::{collections::BTreeMap, time::Duration};
use ruma_common::{
api::{request, response, Metadata},
encryption::OneTimeKey,
metadata,
serde::Raw,
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedOneTimeKeyId, OwnedUserId,
};
use serde_json::Value as JsonValue;
const METADATA: Metadata = metadata! {
method: POST,
rate_limited: false,
authentication: AccessToken,
history: {
unstable => "/_matrix/client/unstable/org.matrix.msc3983/keys/claim",
}
};
#[request(error = crate::Error)]
pub struct Request {
#[serde(
with = "ruma_common::serde::duration::opt_ms",
default,
skip_serializing_if = "Option::is_none"
)]
pub timeout: Option<Duration>,
pub one_time_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Vec<OneTimeKeyAlgorithm>>>,
}
#[response(error = crate::Error)]
pub struct Response {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub failures: BTreeMap<String, JsonValue>,
pub one_time_keys: BTreeMap<OwnedUserId, OneTimeKeys>,
}
impl Request {
pub fn new(
one_time_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Vec<OneTimeKeyAlgorithm>>>,
) -> Self {
Self { timeout: Some(Duration::from_secs(10)), one_time_keys }
}
}
impl Response {
pub fn new(one_time_keys: BTreeMap<OwnedUserId, OneTimeKeys>) -> Self {
Self { failures: BTreeMap::new(), one_time_keys }
}
}
pub type OneTimeKeys = BTreeMap<OwnedDeviceId, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>>;