matrix_sdk_crypto/types/requests/
enums.rsuse std::sync::Arc;
use ruma::{
api::client::{
backup::add_backup_keys::v3::Response as KeysBackupResponse,
keys::{
claim_keys::v3::{Request as KeysClaimRequest, Response as KeysClaimResponse},
get_keys::v3::Response as KeysQueryResponse,
upload_keys::v3::{Request as KeysUploadRequest, Response as KeysUploadResponse},
upload_signatures::v3::{
Request as SignatureUploadRequest, Response as SignatureUploadResponse,
},
upload_signing_keys::v3::Response as SigningKeysUploadResponse,
},
message::send_message_event::v3::Response as RoomMessageResponse,
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
TransactionId,
};
use super::{
KeysQueryRequest, OutgoingRequest, OutgoingVerificationRequest, RoomMessageRequest,
ToDeviceRequest,
};
#[derive(Debug)]
pub enum AnyOutgoingRequest {
KeysUpload(KeysUploadRequest),
KeysQuery(KeysQueryRequest),
KeysClaim(KeysClaimRequest),
ToDeviceRequest(ToDeviceRequest),
SignatureUpload(SignatureUploadRequest),
RoomMessage(RoomMessageRequest),
}
#[cfg(test)]
impl AnyOutgoingRequest {
pub fn to_device(&self) -> Option<&ToDeviceRequest> {
as_variant::as_variant!(self, Self::ToDeviceRequest)
}
}
impl From<KeysQueryRequest> for AnyOutgoingRequest {
fn from(request: KeysQueryRequest) -> Self {
Self::KeysQuery(request)
}
}
impl From<KeysClaimRequest> for AnyOutgoingRequest {
fn from(r: KeysClaimRequest) -> Self {
Self::KeysClaim(r)
}
}
impl From<KeysUploadRequest> for AnyOutgoingRequest {
fn from(request: KeysUploadRequest) -> Self {
Self::KeysUpload(request)
}
}
impl From<ToDeviceRequest> for AnyOutgoingRequest {
fn from(request: ToDeviceRequest) -> Self {
Self::ToDeviceRequest(request)
}
}
impl From<RoomMessageRequest> for AnyOutgoingRequest {
fn from(request: RoomMessageRequest) -> Self {
Self::RoomMessage(request)
}
}
impl From<SignatureUploadRequest> for AnyOutgoingRequest {
fn from(request: SignatureUploadRequest) -> Self {
Self::SignatureUpload(request)
}
}
impl From<OutgoingVerificationRequest> for OutgoingRequest {
fn from(r: OutgoingVerificationRequest) -> Self {
Self { request_id: r.request_id().to_owned(), request: Arc::new(r.into()) }
}
}
impl From<SignatureUploadRequest> for OutgoingRequest {
fn from(r: SignatureUploadRequest) -> Self {
Self { request_id: TransactionId::new(), request: Arc::new(r.into()) }
}
}
impl From<KeysUploadRequest> for OutgoingRequest {
fn from(r: KeysUploadRequest) -> Self {
Self { request_id: TransactionId::new(), request: Arc::new(r.into()) }
}
}
impl From<OutgoingVerificationRequest> for AnyOutgoingRequest {
fn from(request: OutgoingVerificationRequest) -> Self {
match request {
OutgoingVerificationRequest::ToDevice(r) => AnyOutgoingRequest::ToDeviceRequest(r),
OutgoingVerificationRequest::InRoom(r) => AnyOutgoingRequest::RoomMessage(r),
}
}
}
#[derive(Debug)]
pub enum AnyIncomingResponse<'a> {
KeysUpload(&'a KeysUploadResponse),
KeysQuery(&'a KeysQueryResponse),
ToDevice(&'a ToDeviceResponse),
KeysClaim(&'a KeysClaimResponse),
SigningKeysUpload(&'a SigningKeysUploadResponse),
SignatureUpload(&'a SignatureUploadResponse),
RoomMessage(&'a RoomMessageResponse),
KeysBackup(&'a KeysBackupResponse),
}
impl<'a> From<&'a KeysUploadResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a KeysUploadResponse) -> Self {
AnyIncomingResponse::KeysUpload(response)
}
}
impl<'a> From<&'a KeysBackupResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a KeysBackupResponse) -> Self {
AnyIncomingResponse::KeysBackup(response)
}
}
impl<'a> From<&'a KeysQueryResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a KeysQueryResponse) -> Self {
AnyIncomingResponse::KeysQuery(response)
}
}
impl<'a> From<&'a ToDeviceResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a ToDeviceResponse) -> Self {
AnyIncomingResponse::ToDevice(response)
}
}
impl<'a> From<&'a RoomMessageResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a RoomMessageResponse) -> Self {
AnyIncomingResponse::RoomMessage(response)
}
}
impl<'a> From<&'a KeysClaimResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a KeysClaimResponse) -> Self {
AnyIncomingResponse::KeysClaim(response)
}
}
impl<'a> From<&'a SignatureUploadResponse> for AnyIncomingResponse<'a> {
fn from(response: &'a SignatureUploadResponse) -> Self {
AnyIncomingResponse::SignatureUpload(response)
}
}