Bump dependencies and fixes
This commit is contained in:
parent
873d191569
commit
120b6f4b95
7 changed files with 67 additions and 90 deletions
|
@ -549,7 +549,7 @@ pub fn create_room_route(
|
|||
body: Ruma<create_room::Request>,
|
||||
) -> MatrixResult<create_room::Response> {
|
||||
// TODO: check if room is unique
|
||||
let room_id = RoomId::try_from(data.hostname()).expect("host is valid");
|
||||
let room_id = RoomId::new(data.hostname()).expect("host is valid");
|
||||
let user_id = body.user_id.clone().expect("user is authenticated");
|
||||
|
||||
data.pdu_append(
|
||||
|
@ -756,7 +756,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
chunk.extend_from_slice(
|
||||
&server_server::send_request(
|
||||
&data,
|
||||
"matrix.koesters.xyz".to_owned(),
|
||||
"koesters.xyz".to_owned(),
|
||||
ruma_federation_api::v1::get_public_rooms::Request {
|
||||
limit: None,
|
||||
since: None,
|
||||
|
@ -913,7 +913,6 @@ pub fn sync_route(
|
|||
let room_events = pdus
|
||||
.into_iter()
|
||||
.map(|pdu| pdu.to_room_event())
|
||||
.filter_map(|e| e)
|
||||
.collect();
|
||||
let mut edus = data.roomlatests_since(&room_id, since);
|
||||
edus.extend_from_slice(&data.roomactives_in(&room_id));
|
||||
|
@ -949,7 +948,6 @@ pub fn sync_route(
|
|||
let room_events = pdus
|
||||
.into_iter()
|
||||
.map(|pdu| pdu.to_room_event())
|
||||
.filter_map(|e| e)
|
||||
.collect();
|
||||
let mut edus = data.roomlatests_since(&room_id, since);
|
||||
edus.extend_from_slice(&data.roomactives_in(&room_id));
|
||||
|
@ -973,7 +971,7 @@ pub fn sync_route(
|
|||
let events = data
|
||||
.pdus_since(&room_id, since)
|
||||
.into_iter()
|
||||
.filter_map(|pdu| pdu.to_stripped_state_event())
|
||||
.map(|pdu| pdu.to_stripped_state_event())
|
||||
.collect();
|
||||
|
||||
invited_rooms.insert(
|
||||
|
|
23
src/data.rs
23
src/data.rs
|
@ -1,5 +1,5 @@
|
|||
use crate::{utils, Database, PduEvent};
|
||||
use ruma_events::{collections::only::Event as EduEvent, EventResult, EventType};
|
||||
use ruma_events::{collections::only::Event as EduEvent, EventJson, EventType};
|
||||
use ruma_federation_api::RoomV3Pdu;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::json;
|
||||
|
@ -604,7 +604,7 @@ impl Data {
|
|||
}
|
||||
|
||||
/// Returns a vector of the most recent read_receipts in a room that happened after the event with id `since`.
|
||||
pub fn roomlatests_since(&self, room_id: &RoomId, since: u64) -> Vec<EduEvent> {
|
||||
pub fn roomlatests_since(&self, room_id: &RoomId, since: u64) -> Vec<EventJson<EduEvent>> {
|
||||
let mut room_latests = Vec::new();
|
||||
|
||||
let mut prefix = room_id.to_string().as_bytes().to_vec();
|
||||
|
@ -617,10 +617,11 @@ impl Data {
|
|||
if key.starts_with(&prefix) {
|
||||
current = key.to_vec();
|
||||
room_latests.push(
|
||||
serde_json::from_slice::<EventResult<_>>(&value)
|
||||
serde_json::from_slice::<EventJson<EduEvent>>(&value)
|
||||
.expect("room_latest in db is valid")
|
||||
.into_result()
|
||||
.expect("room_latest in db is valid"),
|
||||
.deserialize()
|
||||
.expect("room_latest in db is valid")
|
||||
.into(),
|
||||
);
|
||||
} else {
|
||||
break;
|
||||
|
@ -691,7 +692,7 @@ impl Data {
|
|||
}
|
||||
|
||||
/// Returns a vector of the most recent read_receipts in a room that happened after the event with id `since`.
|
||||
pub fn roomactives_in(&self, room_id: &RoomId) -> Vec<EduEvent> {
|
||||
pub fn roomactives_in(&self, room_id: &RoomId) -> Vec<EventJson<EduEvent>> {
|
||||
let mut room_actives = Vec::new();
|
||||
|
||||
let mut prefix = room_id.to_string().as_bytes().to_vec();
|
||||
|
@ -704,10 +705,11 @@ impl Data {
|
|||
if key.starts_with(&prefix) {
|
||||
current = key.to_vec();
|
||||
room_actives.push(
|
||||
serde_json::from_slice::<EventResult<_>>(&value)
|
||||
serde_json::from_slice::<EventJson<EduEvent>>(&value)
|
||||
.expect("room_active in db is valid")
|
||||
.into_result()
|
||||
.expect("room_active in db is valid"),
|
||||
.deserialize()
|
||||
.expect("room_active in db is valid")
|
||||
.into(),
|
||||
);
|
||||
} else {
|
||||
break;
|
||||
|
@ -720,7 +722,8 @@ impl Data {
|
|||
user_ids: Vec::new(),
|
||||
},
|
||||
room_id: None, // None because it can be inferred
|
||||
})];
|
||||
})
|
||||
.into()];
|
||||
} else {
|
||||
room_actives
|
||||
}
|
||||
|
|
23
src/pdu.rs
23
src/pdu.rs
|
@ -1,6 +1,6 @@
|
|||
use js_int::UInt;
|
||||
use ruma_events::{
|
||||
collections::all::RoomEvent, stripped::AnyStrippedStateEvent, EventResult, EventType,
|
||||
collections::all::RoomEvent, stripped::AnyStrippedStateEvent, EventJson, EventType,
|
||||
};
|
||||
use ruma_federation_api::EventHash;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
|
@ -31,29 +31,20 @@ pub struct PduEvent {
|
|||
}
|
||||
|
||||
impl PduEvent {
|
||||
// TODO: This shouldn't be an option
|
||||
pub fn to_room_event(&self) -> Option<RoomEvent> {
|
||||
pub fn to_room_event(&self) -> EventJson<RoomEvent> {
|
||||
// Can only fail in rare circumstances that won't ever happen here, see
|
||||
// https://docs.rs/serde_json/1.0.50/serde_json/fn.to_string.html
|
||||
let json = serde_json::to_string(&self).unwrap();
|
||||
// EventResult's deserialize implementation always returns `Ok(...)`
|
||||
Some(
|
||||
serde_json::from_str::<EventResult<RoomEvent>>(&json)
|
||||
.unwrap()
|
||||
.into_result()
|
||||
.ok()?,
|
||||
)
|
||||
// EventJson's deserialize implementation always returns `Ok(...)`
|
||||
serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap()
|
||||
}
|
||||
|
||||
pub fn to_stripped_state_event(&self) -> Option<AnyStrippedStateEvent> {
|
||||
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEvent> {
|
||||
// Can only fail in rare circumstances that won't ever happen here, see
|
||||
// https://docs.rs/serde_json/1.0.50/serde_json/fn.to_string.html
|
||||
let json = serde_json::to_string(&self).unwrap();
|
||||
|
||||
// EventResult's deserialize implementation always returns `Ok(...)`
|
||||
serde_json::from_str::<EventResult<AnyStrippedStateEvent>>(&json)
|
||||
.unwrap()
|
||||
.into_result()
|
||||
.ok()
|
||||
// EventJson's deserialize implementation always returns `Ok(...)`
|
||||
serde_json::from_str::<EventJson<AnyStrippedStateEvent>>(&json).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,11 @@ use rocket::{
|
|||
Request, State,
|
||||
};
|
||||
use ruma_api::{
|
||||
error::{FromHttpRequestError, FromHttpResponseError},
|
||||
Endpoint, Outgoing,
|
||||
Endpoint
|
||||
};
|
||||
use ruma_identifiers::UserId;
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
convert::{TryInto},
|
||||
io::Cursor,
|
||||
ops::Deref,
|
||||
};
|
||||
|
@ -22,21 +21,13 @@ const MESSAGE_LIMIT: u64 = 65535;
|
|||
|
||||
/// This struct converts rocket requests into ruma structs by converting them into http requests
|
||||
/// first.
|
||||
pub struct Ruma<T: Outgoing> {
|
||||
body: T::Incoming,
|
||||
pub struct Ruma<T> {
|
||||
body: T,
|
||||
pub user_id: Option<UserId>,
|
||||
pub json_body: serde_json::Value,
|
||||
}
|
||||
|
||||
impl<'a, T: Endpoint> FromData<'a> for Ruma<T>
|
||||
where
|
||||
// We need to duplicate Endpoint's where clauses because the compiler is not smart enough yet.
|
||||
// See https://github.com/rust-lang/rust/issues/54149
|
||||
<T as Outgoing>::Incoming: TryFrom<http::Request<Vec<u8>>, Error = FromHttpRequestError>,
|
||||
<T::Response as Outgoing>::Incoming: TryFrom<
|
||||
http::Response<Vec<u8>>,
|
||||
Error = FromHttpResponseError<<T as Endpoint>::ResponseError>,
|
||||
>,
|
||||
{
|
||||
type Error = (); // TODO: Better error handling
|
||||
type Owned = Data;
|
||||
|
@ -95,7 +86,7 @@ where
|
|||
let http_request = http_request.body(body.clone()).unwrap();
|
||||
log::info!("{:?}", http_request);
|
||||
|
||||
match T::Incoming::try_from(http_request) {
|
||||
match T::try_from(http_request) {
|
||||
Ok(t) => Success(Ruma {
|
||||
body: t,
|
||||
user_id,
|
||||
|
@ -115,8 +106,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Outgoing> Deref for Ruma<T> {
|
||||
type Target = T::Incoming;
|
||||
impl<T> Deref for Ruma<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.body
|
||||
|
|
|
@ -4,7 +4,7 @@ use log::error;
|
|||
use rocket::{get, options, post, put, response::content::Json, State};
|
||||
use ruma_api::{
|
||||
error::{FromHttpRequestError, FromHttpResponseError},
|
||||
Endpoint, Outgoing,
|
||||
Endpoint,
|
||||
};
|
||||
use ruma_client_api::error::{Error, ErrorKind};
|
||||
use ruma_federation_api::{v1::get_server_version, v2::get_server_keys};
|
||||
|
@ -20,20 +20,11 @@ pub async fn send_request<T: Endpoint>(
|
|||
data: &crate::Data,
|
||||
destination: String,
|
||||
request: T,
|
||||
) -> Option<<T::Response as Outgoing>::Incoming>
|
||||
where
|
||||
// We need to duplicate Endpoint's where clauses because the compiler is not smart enough yet.
|
||||
// See https://github.com/rust-lang/rust/issues/54149
|
||||
<T as Outgoing>::Incoming: TryFrom<http::Request<Vec<u8>>, Error = FromHttpRequestError>,
|
||||
<T::Response as Outgoing>::Incoming: TryFrom<
|
||||
http::Response<Vec<u8>>,
|
||||
Error = FromHttpResponseError<<T as Endpoint>::ResponseError>,
|
||||
>,
|
||||
T::Error: std::fmt::Debug,
|
||||
) -> Option<T::Response>
|
||||
{
|
||||
let mut http_request: http::Request<_> = request.try_into().unwrap();
|
||||
|
||||
*http_request.uri_mut() = ("https://".to_owned() + &destination.clone() + T::METADATA.path).parse().unwrap();
|
||||
*http_request.uri_mut() = format!("https://{}:8448{}", &destination.clone(), T::METADATA.path).parse().unwrap();
|
||||
|
||||
let mut request_map = serde_json::Map::new();
|
||||
|
||||
|
@ -50,7 +41,7 @@ where
|
|||
|
||||
let mut request_json = request_map.into();
|
||||
ruma_signatures::sign_json(data.hostname(), data.keypair(), dbg!(&mut request_json)).unwrap();
|
||||
dbg!(&request_json);
|
||||
println!("{}", &request_json);
|
||||
|
||||
let signatures = request_json["signatures"]
|
||||
.as_object()
|
||||
|
@ -101,7 +92,7 @@ where
|
|||
.into_iter()
|
||||
.collect();
|
||||
Some(
|
||||
<T::Response as Outgoing>::Incoming::try_from(
|
||||
<T::Response>::try_from(
|
||||
dbg!(http_response.body(body)).unwrap(),
|
||||
)
|
||||
.ok()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue