1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-28 02:38:30 +00:00
continuwuity/src/ruma_wrapper.rs

46 lines
999 B
Rust
Raw Normal View History

2022-01-20 11:51:31 +01:00
use crate::Error;
use ruma::{
2022-02-18 15:33:14 +01:00
api::client::uiaa::UiaaResponse,
identifiers::{DeviceId, UserId},
signatures::CanonicalJsonValue,
Outgoing, ServerName,
};
use std::ops::Deref;
#[cfg(feature = "conduit_bin")]
2022-01-20 11:51:31 +01:00
mod axum;
2020-02-15 22:42:21 +01:00
2022-01-20 11:51:31 +01:00
/// Extractor for Ruma request structs
pub struct Ruma<T: Outgoing> {
2020-09-08 17:32:03 +02:00
pub body: T::Incoming,
2021-11-26 20:36:40 +01:00
pub sender_user: Option<Box<UserId>>,
pub sender_device: Option<Box<DeviceId>>,
pub sender_servername: Option<Box<ServerName>>,
2021-04-23 19:04:59 +02:00
// This is None when body is not a valid string
pub json_body: Option<CanonicalJsonValue>,
pub from_appservice: bool,
2020-03-28 18:50:02 +01:00
}
2020-03-28 23:08:59 +01:00
impl<T: Outgoing> Deref for Ruma<T> {
2020-09-08 17:32:03 +02:00
type Target = T::Incoming;
2020-02-15 22:42:21 +01:00
fn deref(&self) -> &Self::Target {
2020-03-28 18:50:02 +01:00
&self.body
}
}
2021-06-30 09:52:01 +02:00
#[derive(Clone)]
pub struct RumaResponse<T>(pub T);
impl<T> From<T> for RumaResponse<T> {
2020-06-09 15:13:17 +02:00
fn from(t: T) -> Self {
Self(t)
2020-02-18 22:07:57 +01:00
}
}
2021-06-30 09:52:01 +02:00
impl From<Error> for RumaResponse<UiaaResponse> {
fn from(t: Error) -> Self {
t.to_response()
}
}