2022-01-20 11:51:31 +01:00
|
|
|
use crate::Error;
|
2020-08-06 08:29:59 -04:00
|
|
|
use ruma::{
|
2022-04-06 21:31:29 +02:00
|
|
|
api::client::uiaa::UiaaResponse, signatures::CanonicalJsonValue, DeviceId, ServerName, UserId,
|
2020-08-06 08:29:59 -04:00
|
|
|
};
|
2021-06-12 15:04:28 +02:00
|
|
|
use std::ops::Deref;
|
2020-07-25 23:08:00 -04:00
|
|
|
|
|
|
|
#[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
|
2022-04-06 21:31:29 +02:00
|
|
|
pub struct Ruma<T> {
|
|
|
|
pub body: T,
|
2021-11-26 20:36:40 +01:00
|
|
|
pub sender_user: Option<Box<UserId>>,
|
2020-10-18 20:33:12 +02:00
|
|
|
pub sender_device: Option<Box<DeviceId>>,
|
2021-05-20 23:46:52 +02:00
|
|
|
pub sender_servername: Option<Box<ServerName>>,
|
2021-04-23 19:04:59 +02:00
|
|
|
// This is None when body is not a valid string
|
2021-05-04 19:03:18 +02:00
|
|
|
pub json_body: Option<CanonicalJsonValue>,
|
2020-12-08 10:33:44 +01:00
|
|
|
pub from_appservice: bool,
|
2020-03-28 18:50:02 +01:00
|
|
|
}
|
2020-03-28 23:08:59 +01:00
|
|
|
|
2022-04-06 21:31:29 +02:00
|
|
|
impl<T> Deref for Ruma<T> {
|
|
|
|
type Target = T;
|
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()
|
|
|
|
}
|
|
|
|
}
|