Fix review issues, move state-res to spec-comp branch

This commit is contained in:
Devin Ragotzy 2020-08-26 11:15:52 -04:00
parent d9a29e3e5c
commit f46c2d1eec
8 changed files with 106 additions and 138 deletions

View file

@ -63,26 +63,11 @@ pub async fn get_public_rooms_route(
db: State<'_, Database>,
body: Ruma<get_public_rooms::IncomingRequest>,
) -> ConduitResult<get_public_rooms::Response> {
let Ruma {
body:
get_public_rooms::IncomingRequest {
limit,
server,
since,
},
..
} = body;
let get_public_rooms_filtered::Response {
chunk,
prev_batch,
next_batch,
total_room_count_estimate,
} = get_public_rooms_filtered_helper(
let response = get_public_rooms_filtered_helper(
&db,
server.as_deref(),
limit,
since.as_deref(),
body.body.server.as_deref(),
body.body.limit,
body.body.since.as_deref(),
None, // This is not used
None, // This is not used
)
@ -90,10 +75,10 @@ pub async fn get_public_rooms_route(
.0;
Ok(get_public_rooms::Response {
chunk,
prev_batch,
next_batch,
total_room_count_estimate,
chunk: response.chunk,
prev_batch: response.prev_batch,
next_batch: response.next_batch,
total_room_count_estimate: response.total_room_count_estimate,
}
.into())
}

View file

@ -483,12 +483,12 @@ async fn join_room_by_id_helper(
.await?;
dbg!(&send_join_response);
// todo!("Take send_join_response and 'create' the room using that data");
let mut event_map = send_join_response
.room_state
.state
.iter()
.chain(send_join_response.room_state.auth_chain.iter())
.map(|pdu| {
pdu.deserialize()
.map(StateEvent::Full)
@ -497,14 +497,6 @@ async fn join_room_by_id_helper(
.collect::<Result<BTreeMap<EventId, StateEvent>, _>>()
.map_err(|_| Error::bad_database("Invalid PDU found in db."))?;
let auth_chain = send_join_response
.room_state
.auth_chain
.iter()
.flat_map(|pdu| pdu.deserialize().ok())
.map(StateEvent::Full)
.collect::<Vec<_>>();
let power_events = event_map
.values()
.filter(|pdu| pdu.is_power_event())
@ -518,9 +510,11 @@ async fn join_room_by_id_helper(
&power_events,
&mut event_map,
&db.rooms,
&auth_chain // if we only use it here just build this list in the first place
&send_join_response
.room_state
.auth_chain
.iter()
.map(|pdu| pdu.event_id())
.filter_map(|pdu| Some(StateEvent::Full(pdu.deserialize().ok()?).event_id()))
.collect::<Vec<_>>(),
);

View file

@ -195,7 +195,6 @@ pub fn create_room_route(
content: match preset {
create_room::RoomPreset::PublicChat => {
serde_json::to_value(guest_access::GuestAccessEventContent::new(
// In a public room, joining is the only way to access
guest_access::GuestAccess::Forbidden,
))
.expect("event is valid, we just created it")

View file

@ -1,5 +1,5 @@
use super::State;
use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Ruma};
use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma};
use ruma::{
api::client::{
error::ErrorKind,
@ -9,7 +9,7 @@ use ruma::{
},
},
events::{AnyStateEventContent, EventContent},
RoomId, UserId,
EventId, RoomId, UserId,
};
#[cfg(feature = "conduit_bin")]
@ -33,13 +33,16 @@ pub fn send_state_event_for_key_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?;
send_state_event_for_key_helper(
&db,
sender_id,
&body.content,
content,
&body.room_id,
Some(body.state_key.clone()),
Ok(
send_state_event_for_key::Response::new(send_state_event_for_key_helper(
&db,
sender_id,
&body.content,
content,
&body.room_id,
Some(body.state_key.clone()),
)?)
.into(),
)
}
@ -67,8 +70,8 @@ pub fn send_state_event_for_empty_key_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?;
Ok(send_state_event_for_empty_key::Response::new(
send_state_event_for_key_helper(
Ok(
send_state_event_for_empty_key::Response::new(send_state_event_for_key_helper(
&db,
sender_id
.as_ref()
@ -77,11 +80,9 @@ pub fn send_state_event_for_empty_key_route(
json,
&body.room_id,
Some("".into()),
)?
.0
.event_id,
)?)
.into(),
)
.into())
}
#[cfg_attr(
@ -183,7 +184,7 @@ pub fn send_state_event_for_key_helper(
json: serde_json::Value,
room_id: &RoomId,
state_key: Option<String>,
) -> ConduitResult<send_state_event_for_key::Response> {
) -> Result<EventId> {
let sender_id = sender;
if let AnyStateEventContent::RoomCanonicalAlias(canonical_alias) = content {
@ -224,5 +225,5 @@ pub fn send_state_event_for_key_helper(
&db.account_data,
)?;
Ok(send_state_event_for_key::Response::new(event_id).into())
Ok(event_id)
}

View file

@ -475,7 +475,7 @@ pub async fn sync_events_route(
}
for user_id in left_encrypted_users {
let user_target_encrypted = db
let still_share_encrypted_room = db
.rooms
.get_shared_rooms(vec![sender_id.clone(), user_id.clone()])
.filter_map(|r| r.ok())
@ -490,7 +490,7 @@ pub async fn sync_events_route(
.all(|encrypted| !encrypted);
// If the user doesn't share an encrypted room with the target anymore, we need to tell
// them
if user_target_encrypted {
if still_share_encrypted_room {
device_list_left.insert(user_id);
}
}