state-res: Depend on ruma-* subcrates instead of ruma

This commit is contained in:
Jonas Platte 2021-05-08 00:52:50 +02:00
parent ee39f7c28c
commit f58462a002
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
11 changed files with 80 additions and 79 deletions

View File

@ -12,11 +12,15 @@ version = "0.1.0"
edition = "2018"
[features]
unstable-pre-spec = ["ruma/unstable-pre-spec"]
unstable-pre-spec = ["ruma-events/unstable-pre-spec"]
[dependencies]
itertools = "0.10.0"
ruma = { version = "0.0.3", path = "../ruma", features = ["events", "signatures"] }
js_int = "0.2.0"
ruma-identifiers = { version = "0.19.0", path = "../ruma-identifiers" }
ruma-events = { version = "=0.22.0-alpha.3", path = "../ruma-events" }
ruma-serde = { version = "0.3.1", path = "../ruma-serde" }
ruma-signatures = { version = "0.7.0", path = "../ruma-signatures" }
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.60"
maplit = "1.0.2"

View File

@ -13,18 +13,17 @@ use std::{
use criterion::{criterion_group, criterion_main, Criterion};
use event::StateEvent;
use js_int::uint;
use maplit::btreemap;
use ruma::{
events::{
use ruma_events::{
pdu::{EventHash, Pdu, RoomV3Pdu},
room::{
join_rules::JoinRule,
member::{MemberEventContent, MembershipState},
},
EventType,
},
EventId, RoomId, RoomVersionId, UserId,
};
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
use ruma_state_res::{Error, Event, EventMap, Result, StateMap, StateResolution};
use serde_json::{json, Value as JsonValue};
@ -387,7 +386,7 @@ where
origin: "foo".into(),
auth_events,
prev_events,
depth: ruma::uint!(0),
depth: uint!(0),
hashes: EventHash { sha256: "".into() },
signatures: btreemap! {},
}),
@ -525,14 +524,16 @@ fn BAN_STATE_SET() -> BTreeMap<EventId, Arc<StateEvent>> {
pub mod event {
use std::{collections::BTreeMap, time::SystemTime};
use ruma::{
events::{
use js_int::UInt;
use ruma_events::{
pdu::{EventHash, Pdu},
room::member::MembershipState,
EventType,
},
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
};
use ruma_identifiers::{
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
};
use ruma_serde::CanonicalJsonObject;
use ruma_state_res::Event;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
@ -612,7 +613,7 @@ pub mod event {
pub fn from_id_canon_obj(
id: EventId,
json: ruma::serde::CanonicalJsonObject,
json: CanonicalJsonObject,
) -> Result<Self, serde_json::Error> {
Ok(Self {
event_id: id,

View File

@ -1,19 +1,19 @@
use std::{convert::TryFrom, sync::Arc};
use js_int::int;
use log::warn;
use maplit::btreeset;
use ruma::{
events::{
use ruma_events::{
room::{
create::CreateEventContent,
join_rules::{JoinRule, JoinRulesEventContent},
member::{MembershipState, ThirdPartyInvite},
power_levels::PowerLevelsEventContent,
third_party_invite::ThirdPartyInviteEventContent,
},
EventType,
},
RoomVersionId, UserId,
};
use ruma_identifiers::{RoomVersionId, UserId};
use crate::{room_version::RoomVersion, Error, Event, Result, StateMap};
@ -799,7 +799,7 @@ pub fn can_send_invite<E: Event>(event: &Arc<E>, auth_events: &StateMap<Arc<E>>)
let invite_level = auth_events
.get(&key)
.map_or_else(
|| Ok::<_, Error>(ruma::int!(50)),
|| Ok::<_, Error>(int!(50)),
|power_levels| {
serde_json::from_value::<PowerLevelsEventContent>(power_levels.content())
.map(|pl| pl.invite)
@ -837,9 +837,8 @@ pub fn verify_third_party_invite<E: Event>(
// If any signature in signed matches any public key in the m.room.third_party_invite event,
// allow
if let Ok(tpid_ev) = serde_json::from_value::<
ruma::events::room::third_party_invite::ThirdPartyInviteEventContent,
>(current_tpid.content())
if let Ok(tpid_ev) =
serde_json::from_value::<ThirdPartyInviteEventContent>(current_tpid.content())
{
// A list of public keys in the public_keys field
for key in tpid_ev.public_keys.unwrap_or_default() {

View File

@ -7,16 +7,14 @@ use std::{
use maplit::btreeset;
use room_version::RoomVersion;
use ruma::{
events::{
use ruma_events::{
room::{
member::{MemberEventContent, MembershipState},
power_levels::PowerLevelsEventContent,
},
EventType,
},
EventId, RoomId, RoomVersionId,
};
use ruma_identifiers::{EventId, RoomId, RoomVersionId};
mod error;
pub mod event_auth;

View File

@ -1,4 +1,4 @@
use ruma::RoomVersionId;
use ruma_identifiers::RoomVersionId;
use crate::{Error, Result};

View File

@ -1,9 +1,8 @@
use std::{collections::BTreeMap, time::SystemTime};
use ruma::{
events::{pdu::EventHash, EventType},
EventId, RoomId, ServerName, UInt, UserId,
};
use js_int::UInt;
use ruma_events::{pdu::EventHash, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId};
use serde_json::value::Value as JsonValue;
/// Abstraction of a PDU so users can have their own PDU types.
@ -48,5 +47,5 @@ pub trait Event {
fn hashes(&self) -> &EventHash;
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>>;
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>;
}

View File

@ -1,5 +1,6 @@
use std::sync::Arc;
use ruma_events::EventType;
use ruma_state_res::{event_auth::valid_membership_change, StateMap};
// use ruma_state_res::event_auth:::{
// auth_check, auth_types_for_event, can_federate, check_power_levels, check_redaction,
@ -22,7 +23,7 @@ fn test_ban_pass() {
let requester = to_pdu_event(
"HELLO",
alice(),
ruma::events::EventType::RoomMember,
EventType::RoomMember,
Some(charlie().as_str()),
member_content_ban(),
&[],
@ -54,7 +55,7 @@ fn test_ban_fail() {
let requester = to_pdu_event(
"HELLO",
charlie(),
ruma::events::EventType::RoomMember,
EventType::RoomMember,
Some(alice().as_str()),
member_content_ban(),
&[],

View File

@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use ruma::{events::EventType, EventId};
use ruma_events::EventType;
use ruma_identifiers::EventId;
use ruma_state_res::{is_power_event, room_version::RoomVersion, StateMap, StateResolution};
mod utils;

View File

@ -2,7 +2,8 @@
use std::{collections::BTreeMap, sync::Arc};
use ruma::{events::EventType, EventId, RoomVersionId};
use ruma_events::EventType;
use ruma_identifiers::{EventId, RoomVersionId};
use ruma_state_res::{EventMap, StateMap, StateResolution};
use serde_json::json;

View File

@ -1,10 +1,8 @@
use std::{sync::Arc, time::UNIX_EPOCH};
use maplit::btreemap;
use ruma::{
events::{room::join_rules::JoinRule, EventType},
EventId, RoomVersionId,
};
use ruma_events::{room::join_rules::JoinRule, EventType};
use ruma_identifiers::{EventId, RoomVersionId};
use ruma_state_res::{EventMap, StateMap, StateResolution};
use serde_json::json;
use tracing_subscriber as tracer;

View File

@ -7,18 +7,17 @@ use std::{
time::{Duration, UNIX_EPOCH},
};
use js_int::uint;
use maplit::btreemap;
use ruma::{
events::{
use ruma_events::{
pdu::{EventHash, Pdu, RoomV3Pdu},
room::{
join_rules::JoinRule,
member::{MemberEventContent, MembershipState},
},
EventType,
},
EventId, RoomId, RoomVersionId, UserId,
};
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
use ruma_state_res::{auth_types_for_event, Error, Event, Result, StateMap, StateResolution};
use serde_json::{json, Value as JsonValue};
use tracing_subscriber as tracer;
@ -350,7 +349,7 @@ pub fn to_init_pdu_event(
origin: "foo".into(),
auth_events: vec![],
prev_events: vec![],
depth: ruma::uint!(0),
depth: uint!(0),
hashes: EventHash { sha256: "".into() },
signatures: btreemap! {},
}),
@ -395,7 +394,7 @@ where
origin: "foo".into(),
auth_events,
prev_events,
depth: ruma::uint!(0),
depth: uint!(0),
hashes: EventHash { sha256: "".into() },
signatures: btreemap! {},
}),
@ -499,14 +498,16 @@ pub fn INITIAL_EDGES() -> Vec<EventId> {
pub mod event {
use std::{collections::BTreeMap, time::SystemTime};
use ruma::{
events::{
use js_int::UInt;
use ruma_events::{
pdu::{EventHash, Pdu},
room::member::{MemberEventContent, MembershipState},
EventType,
},
EventId, RoomId, RoomVersionId, ServerName, UInt, UserId,
};
use ruma_identifiers::{
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
};
use ruma_serde::CanonicalJsonObject;
use ruma_state_res::Event;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
@ -552,9 +553,7 @@ pub mod event {
fn hashes(&self) -> &EventHash {
self.hashes()
}
fn signatures(
&self,
) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> {
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>> {
self.signatures()
}
fn unsigned(&self) -> &BTreeMap<String, JsonValue> {
@ -579,7 +578,7 @@ pub mod event {
pub fn from_id_canon_obj(
id: EventId,
json: ruma::serde::CanonicalJsonObject,
json: CanonicalJsonObject,
) -> Result<Self, serde_json::Error> {
Ok(Self {
event_id: id,
@ -704,7 +703,7 @@ pub mod event {
pub fn signatures(
&self,
) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> {
) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>> {
match &self.rest {
Pdu::RoomV1Pdu(_) => maplit::btreemap! {},
Pdu::RoomV3Pdu(ev) => ev.signatures.clone(),