Update state-res crate
parent
f46c2d1eec
commit
3b40f3d60e
|
@ -2070,7 +2070,7 @@ checksum = "7345c971d1ef21ffdbd103a75990a15eb03604fc8b8852ca8cb418ee1a099028"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "state-res"
|
name = "state-res"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/ruma/state-res?branch=spec-comp#17958665f6592af3ef478024fd1d75c384a30e7f"
|
source = "git+https://github.com/ruma/state-res?branch=spec-comp#394d26744a6586ccdc01838964bb27dab289eee5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools",
|
"itertools",
|
||||||
"js_int",
|
"js_int",
|
||||||
|
|
|
@ -19,13 +19,12 @@ use ruma::{
|
||||||
EventId, Raw, RoomAliasId, RoomId, UserId,
|
EventId, Raw, RoomAliasId, RoomId, UserId,
|
||||||
};
|
};
|
||||||
use sled::IVec;
|
use sled::IVec;
|
||||||
use state_res::{event_auth, Requester, StateEvent, StateMap, StateStore};
|
use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
mem,
|
mem,
|
||||||
result::Result as StdResult,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The unique identifier of each state group.
|
/// The unique identifier of each state group.
|
||||||
|
@ -67,28 +66,32 @@ pub struct Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StateStore for Rooms {
|
impl StateStore for Rooms {
|
||||||
fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> StdResult<StateEvent, String> {
|
fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> state_res::Result<StateEvent> {
|
||||||
let pid = self
|
let pid = self
|
||||||
.eventid_pduid
|
.eventid_pduid
|
||||||
.get(event_id.as_bytes())
|
.get(event_id.as_bytes())
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(StateError::custom)?
|
||||||
.ok_or_else(|| "PDU via room_id and event_id not found in the db.".to_owned())?;
|
.ok_or_else(|| {
|
||||||
|
StateError::NotFound("PDU via room_id and event_id not found in the db.".into())
|
||||||
|
})?;
|
||||||
|
|
||||||
serde_json::from_slice(
|
serde_json::from_slice(
|
||||||
&self
|
&self
|
||||||
.pduid_pdu
|
.pduid_pdu
|
||||||
.get(pid)
|
.get(pid)
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(StateError::custom)?
|
||||||
.ok_or_else(|| "PDU via pduid not found in db.".to_owned())?,
|
.ok_or_else(|| StateError::NotFound("PDU via pduid not found in db.".into()))?,
|
||||||
)
|
)
|
||||||
.map_err(|e| e.to_string())
|
.map_err(Into::into)
|
||||||
.and_then(|pdu: StateEvent| {
|
.and_then(|pdu: StateEvent| {
|
||||||
// conduit's PDU's always contain a room_id but some
|
// conduit's PDU's always contain a room_id but some
|
||||||
// of ruma's do not so this must be an Option
|
// of ruma's do not so this must be an Option
|
||||||
if pdu.room_id() == Some(room_id) {
|
if pdu.room_id() == Some(room_id) {
|
||||||
Ok(pdu)
|
Ok(pdu)
|
||||||
} else {
|
} else {
|
||||||
Err("Found PDU for incorrect room in db.".into())
|
Err(StateError::NotFound(
|
||||||
|
"Found PDU for incorrect room in db.".into(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -732,27 +735,37 @@ impl Rooms {
|
||||||
// Don't allow encryption events when it's disabled
|
// Don't allow encryption events when it's disabled
|
||||||
!globals.encryption_disabled()
|
!globals.encryption_disabled()
|
||||||
}
|
}
|
||||||
EventType::RoomMember => event_auth::is_membership_change_allowed(
|
EventType::RoomMember => {
|
||||||
// TODO this is a bit of a hack but not sure how to have a type
|
let prev_event = self
|
||||||
// declared in `state_res` crate easily convert to/from conduit::PduEvent
|
.get_pdu(prev_events.iter().next().ok_or(Error::BadRequest(
|
||||||
Requester {
|
ErrorKind::Unknown,
|
||||||
prev_event_ids: prev_events.to_owned(),
|
"Membership can't be the first event",
|
||||||
room_id: &room_id,
|
))?)?
|
||||||
content: &content,
|
.map(|pdu| pdu.convert_for_state_res())
|
||||||
state_key: Some(state_key.to_owned()),
|
.transpose()?;
|
||||||
sender: &sender,
|
event_auth::valid_membership_change(
|
||||||
},
|
// TODO this is a bit of a hack but not sure how to have a type
|
||||||
&auth_events
|
// declared in `state_res` crate easily convert to/from conduit::PduEvent
|
||||||
.iter()
|
Requester {
|
||||||
.map(|((ty, key), pdu)| {
|
prev_event_ids: prev_events.to_owned(),
|
||||||
Ok(((ty.clone(), key.clone()), pdu.convert_for_state_res()?))
|
room_id: &room_id,
|
||||||
})
|
content: &content,
|
||||||
.collect::<Result<StateMap<_>>>()?,
|
state_key: Some(state_key.to_owned()),
|
||||||
)
|
sender: &sender,
|
||||||
.map_err(|e| {
|
},
|
||||||
log::error!("{}", e);
|
prev_event.as_ref(),
|
||||||
Error::Conflict("Found incoming PDU with invalid data.")
|
&auth_events
|
||||||
})?,
|
.iter()
|
||||||
|
.map(|((ty, key), pdu)| {
|
||||||
|
Ok(((ty.clone(), key.clone()), pdu.convert_for_state_res()?))
|
||||||
|
})
|
||||||
|
.collect::<Result<StateMap<_>>>()?,
|
||||||
|
)
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!("{}", e);
|
||||||
|
Error::Conflict("Found incoming PDU with invalid data.")
|
||||||
|
})?
|
||||||
|
}
|
||||||
EventType::RoomCreate => prev_events.is_empty(),
|
EventType::RoomCreate => prev_events.is_empty(),
|
||||||
// Not allow any of the following events if the sender is not joined.
|
// Not allow any of the following events if the sender is not joined.
|
||||||
_ if sender_membership != member::MembershipState::Join => false,
|
_ if sender_membership != member::MembershipState::Join => false,
|
||||||
|
|
Loading…
Reference in New Issue