Allow get_power_level_for_sender to soft fail when eventId not found

Hardcode RoomVersion6 into the eventId hashing
This commit is contained in:
Devin Ragotzy 2020-10-27 20:22:13 -04:00
parent c3ba1e33eb
commit ac9282add6
2 changed files with 11 additions and 5 deletions

View File

@ -429,7 +429,11 @@ impl StateResolution {
// TODO store.auth_event_ids returns "self" with the event ids is this ok
// event.auth_event_ids does not include its own event id ?
for aid in event.as_ref().unwrap().auth_events() {
for aid in event
.as_ref()
.map(|pdu| pdu.auth_events())
.unwrap_or_default()
{
if let Some(aev) = StateResolution::get_or_load_event(room_id, &aid, event_map, store) {
if aev.is_type_and_key(EventType::RoomPowerLevels, "") {
pl = Some(aev);
@ -685,7 +689,7 @@ impl StateResolution {
for aid in auth_events {
// dbg!(&aid);
let aev = StateResolution::get_or_load_event(room_id, &aid, event_map, store)
.ok_or(Error::NotFound("Auth event not found".to_owned()))?;
.ok_or_else(|| Error::NotFound("Auth event not found".to_owned()))?;
if aev.is_type_and_key(EventType::RoomPowerLevels, "") {
event = Some(aev);
break;

View File

@ -129,11 +129,12 @@ impl StateEvent {
&serde_json::to_vec(ev).expect("all ruma pdus are json values"),
)
.unwrap();
value.remove("event_id");
EventId::try_from(&*format!(
"${}",
ruma::signatures::reference_hash(&value, &self.room_version())
ruma::signatures::reference_hash(&value, &RoomVersionId::Version6)
.expect("ruma can calculate reference hashes")
))
.expect("ruma's reference hashes are valid event ids")
@ -341,14 +342,15 @@ impl StateEvent {
/// Currently either version 1 or 3 is returned, 3 represents
/// version 3 and above.
pub fn room_version(&self) -> RoomVersionId {
// TODO: We have to know the actual room version this is not sufficient
match self {
Self::Full(ev) => match ev {
Pdu::RoomV1Pdu(_) => RoomVersionId::Version1,
Pdu::RoomV3Pdu(_) => RoomVersionId::Version3,
Pdu::RoomV3Pdu(_) => RoomVersionId::Version6,
},
Self::Sync(ev) => match ev {
PduStub::RoomV1PduStub(_) => RoomVersionId::Version1,
PduStub::RoomV3PduStub(_) => RoomVersionId::Version3,
PduStub::RoomV3PduStub(_) => RoomVersionId::Version6,
},
}
}