Upgrade ruma

This commit is contained in:
Jonas Platte 2020-07-26 15:41:28 +02:00
parent f8544bf6e3
commit 09561ccea3
No known key found for this signature in database
GPG key ID: 7D261D771D915378
14 changed files with 154 additions and 180 deletions

50
Cargo.lock generated
View file

@ -1545,14 +1545,14 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-client-api", "ruma-client-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-federation-api", "ruma-federation-api",
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-identifiers",
"ruma-identifiers-macros", "ruma-identifiers-macros",
"ruma-signatures", "ruma-signatures",
] ]
@ -1560,12 +1560,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.16.1" version = "0.16.1"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding", "percent-encoding",
"ruma-api-macros", "ruma-api-macros",
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
@ -1575,7 +1575,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.16.1" version = "0.16.1"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1585,14 +1585,14 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"http", "http",
"js_int", "js_int",
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
@ -1602,7 +1602,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-serde", "ruma-serde",
@ -1614,12 +1614,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.21.3" version = "0.21.3"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
"ruma-events-macros", "ruma-events-macros",
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
@ -1629,7 +1629,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.21.3" version = "0.21.3"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1639,13 +1639,13 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.0.2" version = "0.0.2"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
@ -1653,39 +1653,29 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.17.0" version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"rand", "rand",
"serde", "serde",
"strum", "strum",
] ]
[[package]]
name = "ruma-identifiers"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7046d6ff26cf4f5b8bc77af68527544c61e32cab5810c40035c6491c08da0d3"
dependencies = [
"serde",
"strum",
]
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.17.0" version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"ruma-identifiers 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "ruma-identifiers",
"syn", "syn",
] ]
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.2.2" version = "0.2.2"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
@ -1697,7 +1687,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.6.0-dev.1" version = "0.6.0-dev.1"
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
dependencies = [ dependencies = [
"base64 0.12.3", "base64 0.12.3",
"ring", "ring",

View file

@ -27,4 +27,4 @@ reqwest = "0.10.6"
base64 = "0.12.1" base64 = "0.12.1"
thiserror = "1.0.19" thiserror = "1.0.19"
image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] } image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] }
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "08fbace" } ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "e047c647ddcb368e7eb1e05ae8823a9494273457" }

View file

@ -64,10 +64,9 @@ use ruma::{
canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction, canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction,
topic, topic,
}, },
AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventJson, AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventType,
EventType,
}, },
identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId}, Raw, RoomAliasId, RoomId, RoomVersionId, UserId,
}; };
use serde_json::json; use serde_json::json;
@ -624,7 +623,7 @@ pub fn set_displayname_route(
EventType::RoomMember, EventType::RoomMember,
serde_json::to_value(ruma::events::room::member::MemberEventContent { serde_json::to_value(ruma::events::room::member::MemberEventContent {
displayname: body.displayname.clone(), displayname: body.displayname.clone(),
..serde_json::from_value::<EventJson<_>>( ..serde_json::from_value::<Raw<_>>(
db.rooms db.rooms
.room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())? .room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())?
.ok_or_else(|| { .ok_or_else(|| {
@ -659,7 +658,7 @@ pub fn set_displayname_route(
.try_into() .try_into()
.expect("time is valid"), .expect("time is valid"),
), ),
presence: ruma::events::presence::PresenceState::Online, presence: ruma::presence::PresenceState::Online,
status_msg: None, status_msg: None,
}, },
sender: user_id.clone(), sender: user_id.clone(),
@ -714,7 +713,7 @@ pub fn set_avatar_url_route(
EventType::RoomMember, EventType::RoomMember,
serde_json::to_value(ruma::events::room::member::MemberEventContent { serde_json::to_value(ruma::events::room::member::MemberEventContent {
avatar_url: body.avatar_url.clone(), avatar_url: body.avatar_url.clone(),
..serde_json::from_value::<EventJson<_>>( ..serde_json::from_value::<Raw<_>>(
db.rooms db.rooms
.room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())? .room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())?
.ok_or_else(|| { .ok_or_else(|| {
@ -749,7 +748,7 @@ pub fn set_avatar_url_route(
.try_into() .try_into()
.expect("time is valid"), .expect("time is valid"),
), ),
presence: ruma::events::presence::PresenceState::Online, presence: ruma::presence::PresenceState::Online,
status_msg: None, status_msg: None,
}, },
sender: user_id.clone(), sender: user_id.clone(),
@ -1605,7 +1604,7 @@ pub fn leave_room_route(
) -> ConduitResult<leave_room::Response> { ) -> ConduitResult<leave_room::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
let mut event = serde_json::from_value::<EventJson<member::MemberEventContent>>( let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
db.rooms db.rooms
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())? .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
.ok_or(Error::BadRequest( .ok_or(Error::BadRequest(
@ -1643,20 +1642,19 @@ pub fn kick_user_route(
) -> ConduitResult<kick_user::Response> { ) -> ConduitResult<kick_user::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
let mut event = let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>( db.rooms
db.rooms .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())? .ok_or(Error::BadRequest(
.ok_or(Error::BadRequest( ErrorKind::BadState,
ErrorKind::BadState, "Cannot kick member that's not in the room.",
"Cannot kick member that's not in the room.", ))?
))? .content
.content .clone(),
.clone(), )
) .map_err(|_| Error::bad_database("Invalid member event in database."))?
.map_err(|_| Error::bad_database("Invalid member event in database."))? .deserialize()
.deserialize() .map_err(|_| Error::bad_database("Invalid member event in database."))?;
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
event.membership = ruma::events::room::member::MembershipState::Leave; event.membership = ruma::events::room::member::MembershipState::Leave;
// TODO: reason // TODO: reason
@ -1697,7 +1695,7 @@ pub fn ban_user_route(
third_party_invite: None, third_party_invite: None,
}), }),
|event| { |event| {
let mut event = serde_json::from_value::<EventJson<member::MemberEventContent>>( let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
event.content.clone(), event.content.clone(),
) )
.map_err(|_| Error::bad_database("Invalid member event in database."))? .map_err(|_| Error::bad_database("Invalid member event in database."))?
@ -1730,20 +1728,19 @@ pub fn unban_user_route(
) -> ConduitResult<unban_user::Response> { ) -> ConduitResult<unban_user::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
let mut event = let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>( db.rooms
db.rooms .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())? .ok_or(Error::BadRequest(
.ok_or(Error::BadRequest( ErrorKind::BadState,
ErrorKind::BadState, "Cannot unban a user who is not banned.",
"Cannot unban a user who is not banned.", ))?
))? .content
.content .clone(),
.clone(), )
) .map_err(|_| Error::bad_database("Invalid member event in database."))?
.map_err(|_| Error::bad_database("Invalid member event in database."))? .deserialize()
.deserialize() .map_err(|_| Error::bad_database("Invalid member event in database."))?;
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
event.membership = ruma::events::room::member::MembershipState::Leave; event.membership = ruma::events::room::member::MembershipState::Leave;
@ -1902,7 +1899,7 @@ pub async fn get_public_rooms_filtered_route(
aliases: Vec::new(), aliases: Vec::new(),
canonical_alias: state.get(&(EventType::RoomCanonicalAlias, "".to_owned())).map_or(Ok::<_, Error>(None), |s| { canonical_alias: state.get(&(EventType::RoomCanonicalAlias, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
Ok(serde_json::from_value::< Ok(serde_json::from_value::<
EventJson<ruma::events::room::canonical_alias::CanonicalAliasEventContent>, Raw<ruma::events::room::canonical_alias::CanonicalAliasEventContent>,
>(s.content.clone()) >(s.content.clone())
.map_err(|_| Error::bad_database("Invalid canonical alias event in database."))? .map_err(|_| Error::bad_database("Invalid canonical alias event in database."))?
.deserialize() .deserialize()
@ -1910,7 +1907,7 @@ pub async fn get_public_rooms_filtered_route(
.alias) .alias)
})?, })?,
name: state.get(&(EventType::RoomName, "".to_owned())).map_or(Ok::<_, Error>(None), |s| { name: state.get(&(EventType::RoomName, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
Ok(serde_json::from_value::<EventJson<ruma::events::room::name::NameEventContent>>( Ok(serde_json::from_value::<Raw<ruma::events::room::name::NameEventContent>>(
s.content.clone(), s.content.clone(),
) )
.map_err(|_| Error::bad_database("Invalid room name event in database."))? .map_err(|_| Error::bad_database("Invalid room name event in database."))?
@ -1923,7 +1920,7 @@ pub async fn get_public_rooms_filtered_route(
room_id, room_id,
topic: state.get(&(EventType::RoomTopic, "".to_owned())).map_or(Ok::<_, Error>(None), |s| { topic: state.get(&(EventType::RoomTopic, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
Ok(Some(serde_json::from_value::< Ok(Some(serde_json::from_value::<
EventJson<ruma::events::room::topic::TopicEventContent>, Raw<ruma::events::room::topic::TopicEventContent>,
>(s.content.clone()) >(s.content.clone())
.map_err(|_| Error::bad_database("Invalid room topic event in database."))? .map_err(|_| Error::bad_database("Invalid room topic event in database."))?
.deserialize() .deserialize()
@ -1932,7 +1929,7 @@ pub async fn get_public_rooms_filtered_route(
})?, })?,
world_readable: state.get(&(EventType::RoomHistoryVisibility, "".to_owned())).map_or(Ok::<_, Error>(false), |s| { world_readable: state.get(&(EventType::RoomHistoryVisibility, "".to_owned())).map_or(Ok::<_, Error>(false), |s| {
Ok(serde_json::from_value::< Ok(serde_json::from_value::<
EventJson<ruma::events::room::history_visibility::HistoryVisibilityEventContent>, Raw<ruma::events::room::history_visibility::HistoryVisibilityEventContent>,
>(s.content.clone()) >(s.content.clone())
.map_err(|_| Error::bad_database("Invalid room history visibility event in database."))? .map_err(|_| Error::bad_database("Invalid room history visibility event in database."))?
.deserialize() .deserialize()
@ -1941,7 +1938,7 @@ pub async fn get_public_rooms_filtered_route(
})?, })?,
guest_can_join: state.get(&(EventType::RoomGuestAccess, "".to_owned())).map_or(Ok::<_, Error>(false), |s| { guest_can_join: state.get(&(EventType::RoomGuestAccess, "".to_owned())).map_or(Ok::<_, Error>(false), |s| {
Ok(serde_json::from_value::< Ok(serde_json::from_value::<
EventJson<ruma::events::room::guest_access::GuestAccessEventContent>, Raw<ruma::events::room::guest_access::GuestAccessEventContent>,
>(s.content.clone()) >(s.content.clone())
.map_err(|_| Error::bad_database("Invalid room guest access event in database."))? .map_err(|_| Error::bad_database("Invalid room guest access event in database."))?
.deserialize() .deserialize()
@ -1950,7 +1947,7 @@ pub async fn get_public_rooms_filtered_route(
})?, })?,
avatar_url: state.get(&(EventType::RoomAvatar, "".to_owned())).map_or( Ok::<_, Error>(None),|s| { avatar_url: state.get(&(EventType::RoomAvatar, "".to_owned())).map_or( Ok::<_, Error>(None),|s| {
Ok(Some(serde_json::from_value::< Ok(Some(serde_json::from_value::<
EventJson<ruma::events::room::avatar::AvatarEventContent>, Raw<ruma::events::room::avatar::AvatarEventContent>,
>(s.content.clone()) >(s.content.clone())
.map_err(|_| Error::bad_database("Invalid room avatar event in database."))? .map_err(|_| Error::bad_database("Invalid room avatar event in database."))?
.deserialize() .deserialize()
@ -2158,7 +2155,7 @@ pub fn create_state_event_for_key_route(
if body.event_type == EventType::RoomCanonicalAlias { if body.event_type == EventType::RoomCanonicalAlias {
let canonical_alias = serde_json::from_value::< let canonical_alias = serde_json::from_value::<
EventJson<canonical_alias::CanonicalAliasEventContent>, Raw<canonical_alias::CanonicalAliasEventContent>,
>(content.clone()) >(content.clone())
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid canonical alias."))? .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid canonical alias."))?
.deserialize() .deserialize()
@ -2375,9 +2372,9 @@ pub fn sync_route(
send_member_count = true; send_member_count = true;
if !joined_since_last_sync && pdu.state_key == Some(user_id.to_string()) { if !joined_since_last_sync && pdu.state_key == Some(user_id.to_string()) {
let content = serde_json::from_value::< let content = serde_json::from_value::<
EventJson<ruma::events::room::member::MemberEventContent>, Raw<ruma::events::room::member::MemberEventContent>,
>(pdu.content.clone()) >(pdu.content.clone())
.expect("EventJson::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
.map_err(|_| Error::bad_database("Invalid PDU in database."))?; .map_err(|_| Error::bad_database("Invalid PDU in database."))?;
if content.membership == ruma::events::room::member::MembershipState::Join { if content.membership == ruma::events::room::member::MembershipState::Join {
@ -2410,7 +2407,7 @@ pub fn sync_route(
.filter(|pdu| pdu.kind == EventType::RoomMember) .filter(|pdu| pdu.kind == EventType::RoomMember)
.map(|pdu| { .map(|pdu| {
let content = serde_json::from_value::< let content = serde_json::from_value::<
EventJson<ruma::events::room::member::MemberEventContent>, Raw<ruma::events::room::member::MemberEventContent>,
>(pdu.content.clone()) >(pdu.content.clone())
.map_err(|_| Error::bad_database("Invalid member event in database."))? .map_err(|_| Error::bad_database("Invalid member event in database."))?
.deserialize() .deserialize()
@ -2418,7 +2415,7 @@ pub fn sync_route(
if let Some(state_key) = &pdu.state_key { if let Some(state_key) = &pdu.state_key {
let current_content = serde_json::from_value::< let current_content = serde_json::from_value::<
EventJson<ruma::events::room::member::MemberEventContent>, Raw<ruma::events::room::member::MemberEventContent>,
>( >(
members members
.get(state_key) .get(state_key)
@ -2660,7 +2657,8 @@ pub fn sync_route(
} }
// Remove all to-device events the device received *last time* // Remove all to-device events the device received *last time*
db.users.remove_to_device_events(user_id, device_id, since)?; db.users
.remove_to_device_events(user_id, device_id, since)?;
Ok(sync_events::Response { Ok(sync_events::Response {
next_batch, next_batch,

View file

@ -1,8 +1,8 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use ruma::{ use ruma::{
api::client::error::ErrorKind, api::client::error::ErrorKind,
events::{AnyEvent as EduEvent, EventJson, EventType}, events::{AnyEvent as EduEvent, EventType},
identifiers::{RoomId, UserId}, Raw, RoomId, UserId,
}; };
use std::{collections::HashMap, convert::TryFrom}; use std::{collections::HashMap, convert::TryFrom};
@ -81,7 +81,7 @@ impl AccountData {
room_id: Option<&RoomId>, room_id: Option<&RoomId>,
user_id: &UserId, user_id: &UserId,
kind: &EventType, kind: &EventType,
) -> Result<Option<EventJson<EduEvent>>> { ) -> Result<Option<Raw<EduEvent>>> {
Ok(self.all(room_id, user_id)?.remove(kind)) Ok(self.all(room_id, user_id)?.remove(kind))
} }
@ -91,7 +91,7 @@ impl AccountData {
room_id: Option<&RoomId>, room_id: Option<&RoomId>,
user_id: &UserId, user_id: &UserId,
since: u64, since: u64,
) -> Result<HashMap<EventType, EventJson<EduEvent>>> { ) -> Result<HashMap<EventType, Raw<EduEvent>>> {
let mut userdata = HashMap::new(); let mut userdata = HashMap::new();
let mut prefix = room_id let mut prefix = room_id
@ -121,7 +121,7 @@ impl AccountData {
.map_err(|_| Error::bad_database("RoomUserData ID in db is invalid."))?, .map_err(|_| Error::bad_database("RoomUserData ID in db is invalid."))?,
) )
.map_err(|_| Error::bad_database("RoomUserData ID in db is invalid."))?, .map_err(|_| Error::bad_database("RoomUserData ID in db is invalid."))?,
serde_json::from_slice::<EventJson<EduEvent>>(&v).map_err(|_| { serde_json::from_slice::<Raw<EduEvent>>(&v).map_err(|_| {
Error::bad_database("Database contains invalid account data.") Error::bad_database("Database contains invalid account data.")
})?, })?,
)) ))
@ -139,7 +139,7 @@ impl AccountData {
&self, &self,
room_id: Option<&RoomId>, room_id: Option<&RoomId>,
user_id: &UserId, user_id: &UserId,
) -> Result<HashMap<EventType, EventJson<EduEvent>>> { ) -> Result<HashMap<EventType, Raw<EduEvent>>> {
self.changes_since(room_id, user_id, 0) self.changes_since(room_id, user_id, 0)
} }
} }

View file

@ -1,5 +1,5 @@
use crate::{Error, Result}; use crate::{Error, Result};
use ruma::events::EventJson; use ruma::Raw;
pub struct GlobalEdus { pub struct GlobalEdus {
//pub globalallid_globalall: sled::Tree, // ToDevice, GlobalAllId = UserId + Count //pub globalallid_globalall: sled::Tree, // ToDevice, GlobalAllId = UserId + Count
@ -47,8 +47,7 @@ impl GlobalEdus {
pub fn presence_since( pub fn presence_since(
&self, &self,
since: u64, since: u64,
) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::presence::PresenceEvent>>>> ) -> Result<impl Iterator<Item = Result<Raw<ruma::events::presence::PresenceEvent>>>> {
{
let first_possible_edu = (since + 1).to_be_bytes().to_vec(); // +1 so we don't send the event at since let first_possible_edu = (since + 1).to_be_bytes().to_vec(); // +1 so we don't send the event at since
Ok(self Ok(self

View file

@ -1,7 +1,7 @@
use std::convert::TryInto; use std::convert::TryInto;
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use ruma::identifiers::ServerName; use ruma::ServerName;
pub const COUNTER: &str = "c"; pub const COUNTER: &str = "c";
pub struct Globals { pub struct Globals {

View file

@ -4,7 +4,7 @@ use ruma::{
error::ErrorKind, error::ErrorKind,
r0::backup::{BackupAlgorithm, KeyData, Sessions}, r0::backup::{BackupAlgorithm, KeyData, Sessions},
}, },
identifiers::{RoomId, UserId}, {RoomId, UserId},
}; };
use std::{collections::BTreeMap, convert::TryFrom}; use std::{collections::BTreeMap, convert::TryFrom};

View file

@ -12,9 +12,9 @@ use ruma::{
power_levels::{self, PowerLevelsEventContent}, power_levels::{self, PowerLevelsEventContent},
redaction, redaction,
}, },
EventJson, EventType, EventType,
}, },
identifiers::{EventId, RoomAliasId, RoomId, UserId}, EventId, Raw, RoomAliasId, RoomId, UserId,
}; };
use sled::IVec; use sled::IVec;
use std::{ use std::{
@ -287,28 +287,24 @@ impl Rooms {
}) })
}, },
|power_levels| { |power_levels| {
Ok( Ok(serde_json::from_value::<Raw<PowerLevelsEventContent>>(
serde_json::from_value::<EventJson<PowerLevelsEventContent>>( power_levels.content.clone(),
power_levels.content.clone(),
)
.expect("EventJson::from_value always works.")
.deserialize()
.map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?,
) )
.expect("Raw::from_value always works.")
.deserialize()
.map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?)
}, },
)?; )?;
let sender_membership = self let sender_membership = self
.room_state_get(&room_id, &EventType::RoomMember, &sender.to_string())? .room_state_get(&room_id, &EventType::RoomMember, &sender.to_string())?
.map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| { .map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
Ok( Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
serde_json::from_value::<EventJson<member::MemberEventContent>>( pdu.content.clone(),
pdu.content.clone(),
)
.expect("EventJson::from_value always works.")
.deserialize()
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
.membership,
) )
.expect("Raw::from_value always works.")
.deserialize()
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
.membership)
})?; })?;
let sender_power = power_levels.users.get(&sender).map_or_else( let sender_power = power_levels.users.get(&sender).map_or_else(
@ -339,24 +335,21 @@ impl Rooms {
&target_user_id.to_string(), &target_user_id.to_string(),
)? )?
.map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| { .map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
Ok( Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
serde_json::from_value::<EventJson<member::MemberEventContent>>( pdu.content.clone(),
pdu.content.clone(),
)
.expect("EventJson::from_value always works.")
.deserialize()
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
.membership,
) )
.expect("Raw::from_value always works.")
.deserialize()
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
.membership)
})?; })?;
let target_membership = serde_json::from_value::< let target_membership =
EventJson<member::MemberEventContent>, serde_json::from_value::<Raw<member::MemberEventContent>>(content.clone())
>(content.clone()) .expect("Raw::from_value always works.")
.expect("EventJson::from_value always works.") .deserialize()
.deserialize() .map_err(|_| Error::bad_database("Invalid Member event in db."))?
.map_err(|_| Error::bad_database("Invalid Member event in db."))? .membership;
.membership;
let target_power = power_levels.users.get(&target_user_id).map_or_else( let target_power = power_levels.users.get(&target_user_id).map_or_else(
|| { || {
@ -374,9 +367,9 @@ impl Rooms {
self.room_state_get(&room_id, &EventType::RoomJoinRules, "")? self.room_state_get(&room_id, &EventType::RoomJoinRules, "")?
.map_or(Ok::<_, Error>(join_rules::JoinRule::Public), |pdu| { .map_or(Ok::<_, Error>(join_rules::JoinRule::Public), |pdu| {
Ok(serde_json::from_value::< Ok(serde_json::from_value::<
EventJson<join_rules::JoinRulesEventContent>, Raw<join_rules::JoinRulesEventContent>,
>(pdu.content.clone()) >(pdu.content.clone())
.expect("EventJson::from_value always works.") .expect("Raw::from_value always works.")
.deserialize() .deserialize()
.map_err(|_| { .map_err(|_| {
Error::bad_database("Database contains invalid JoinRules event") Error::bad_database("Database contains invalid JoinRules event")
@ -581,18 +574,17 @@ impl Rooms {
EventType::RoomRedaction => { EventType::RoomRedaction => {
if let Some(redact_id) = &redacts { if let Some(redact_id) = &redacts {
// TODO: Reason // TODO: Reason
let _reason = serde_json::from_value::< let _reason =
EventJson<redaction::RedactionEventContent>, serde_json::from_value::<Raw<redaction::RedactionEventContent>>(content)
>(content) .expect("Raw::from_value always works.")
.expect("EventJson::from_value always works.") .deserialize()
.deserialize() .map_err(|_| {
.map_err(|_| { Error::BadRequest(
Error::BadRequest( ErrorKind::InvalidParam,
ErrorKind::InvalidParam, "Invalid redaction event content.",
"Invalid redaction event content.", )
) })?
})? .reason;
.reason;
self.redact_pdu(&redact_id)?; self.redact_pdu(&redact_id)?;
} }

View file

@ -1,7 +1,7 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use ruma::{ use ruma::{
events::{AnyEvent as EduEvent, EventJson, SyncEphemeralRoomEvent}, events::{AnyEvent as EduEvent, SyncEphemeralRoomEvent},
identifiers::{RoomId, UserId}, Raw, RoomId, UserId,
}; };
use std::convert::TryFrom; use std::convert::TryFrom;
@ -61,8 +61,7 @@ impl RoomEdus {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::AnySyncEphemeralRoomEvent>>>> ) -> Result<impl Iterator<Item = Result<Raw<ruma::events::AnySyncEphemeralRoomEvent>>>> {
{
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);

View file

@ -4,7 +4,7 @@ use ruma::{
error::ErrorKind, error::ErrorKind,
r0::uiaa::{AuthData, UiaaInfo}, r0::uiaa::{AuthData, UiaaInfo},
}, },
identifiers::{DeviceId, UserId}, DeviceId, UserId,
}; };
pub struct Uiaa { pub struct Uiaa {
@ -149,7 +149,7 @@ impl Uiaa {
) -> Result<()> { ) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
if let Some(uiaainfo) = uiaainfo { if let Some(uiaainfo) = uiaainfo {
self.userdeviceid_uiaainfo.insert( self.userdeviceid_uiaainfo.insert(
@ -171,7 +171,7 @@ impl Uiaa {
) -> Result<UiaaInfo> { ) -> Result<UiaaInfo> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
let uiaainfo = serde_json::from_slice::<UiaaInfo>( let uiaainfo = serde_json::from_slice::<UiaaInfo>(
&self &self

View file

@ -8,8 +8,8 @@ use ruma::{
keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey}, keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
}, },
}, },
events::{AnyToDeviceEvent, EventJson, EventType}, events::{AnyToDeviceEvent, EventType},
identifiers::{DeviceId, UserId}, DeviceId, Raw, UserId,
}; };
use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime}; use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime};
@ -177,7 +177,7 @@ impl Users {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
self.userdeviceid_metadata.insert( self.userdeviceid_metadata.insert(
userdeviceid, userdeviceid,
@ -200,7 +200,7 @@ impl Users {
pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
// Remove tokens // Remove tokens
if let Some(old_token) = self.userdeviceid_token.remove(&userdeviceid)? { if let Some(old_token) = self.userdeviceid_token.remove(&userdeviceid)? {
@ -246,7 +246,7 @@ impl Users {
fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
// All devices have metadata // All devices have metadata
assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some()); assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
@ -273,7 +273,7 @@ impl Users {
) -> Result<()> { ) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.to_string().as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(device_id.as_str().as_bytes()); key.extend_from_slice(device_id.as_bytes());
// All devices have metadata // All devices have metadata
// Only existing devices should be able to call this. // Only existing devices should be able to call this.
@ -305,7 +305,7 @@ impl Users {
) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> { ) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.to_string().as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_str().as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
prefix.push(b'"'); // Annoying quotation mark prefix.push(b'"'); // Annoying quotation mark
prefix.extend_from_slice(key_algorithm.to_string().as_bytes()); prefix.extend_from_slice(key_algorithm.to_string().as_bytes());
@ -340,7 +340,7 @@ impl Users {
) -> Result<BTreeMap<KeyAlgorithm, UInt>> { ) -> Result<BTreeMap<KeyAlgorithm, UInt>> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
let mut counts = BTreeMap::new(); let mut counts = BTreeMap::new();
@ -375,7 +375,7 @@ impl Users {
) -> Result<()> { ) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
self.keyid_key.insert( self.keyid_key.insert(
&userdeviceid, &userdeviceid,
@ -556,7 +556,7 @@ impl Users {
) -> Result<Option<DeviceKeys>> { ) -> Result<Option<DeviceKeys>> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.to_string().as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(device_id.as_str().as_bytes()); key.extend_from_slice(device_id.as_bytes());
self.keyid_key.get(key)?.map_or(Ok(None), |bytes| { self.keyid_key.get(key)?.map_or(Ok(None), |bytes| {
Ok(Some(serde_json::from_slice(&bytes).map_err(|_| { Ok(Some(serde_json::from_slice(&bytes).map_err(|_| {
@ -643,7 +643,7 @@ impl Users {
) -> Result<()> { ) -> Result<()> {
let mut key = target_user_id.to_string().as_bytes().to_vec(); let mut key = target_user_id.to_string().as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(target_device_id.as_str().as_bytes()); key.extend_from_slice(target_device_id.as_bytes());
key.push(0xff); key.push(0xff);
key.extend_from_slice(&globals.next_count()?.to_be_bytes()); key.extend_from_slice(&globals.next_count()?.to_be_bytes());
@ -664,12 +664,12 @@ impl Users {
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
) -> Result<Vec<EventJson<AnyToDeviceEvent>>> { ) -> Result<Vec<Raw<AnyToDeviceEvent>>> {
let mut events = Vec::new(); let mut events = Vec::new();
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.to_string().as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_str().as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
for value in self.todeviceid_events.scan_prefix(&prefix).values() { for value in self.todeviceid_events.scan_prefix(&prefix).values() {
@ -690,7 +690,7 @@ impl Users {
) -> Result<()> { ) -> Result<()> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.to_string().as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_ref().as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
let mut last = prefix.clone(); let mut last = prefix.clone();
@ -725,7 +725,7 @@ impl Users {
) -> Result<()> { ) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
// Only existing devices should be able to call this. // Only existing devices should be able to call this.
assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some()); assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
@ -748,7 +748,7 @@ impl Users {
) -> Result<Option<Device>> { ) -> Result<Option<Device>> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
self.userdeviceid_metadata self.userdeviceid_metadata
.get(&userdeviceid)? .get(&userdeviceid)?

View file

@ -3,10 +3,9 @@ use js_int::UInt;
use ruma::{ use ruma::{
events::{ events::{
pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent, pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent,
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
StateEvent,
}, },
identifiers::{EventId, RoomId, ServerName, UserId}, EventId, Raw, RoomId, ServerName, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
@ -79,40 +78,40 @@ impl PduEvent {
Ok(()) Ok(())
} }
pub fn to_sync_room_event(&self) -> EventJson<AnySyncRoomEvent> { pub fn to_sync_room_event(&self) -> Raw<AnySyncRoomEvent> {
let json = serde_json::to_string(&self).expect("PDUs are always valid"); let json = serde_json::to_string(&self).expect("PDUs are always valid");
serde_json::from_str::<AnySyncRoomEvent>(&json) serde_json::from_str::<AnySyncRoomEvent>(&json)
.map(EventJson::from) .map(Raw::from)
.expect("AnySyncRoomEvent can always be built from a full PDU event") .expect("AnySyncRoomEvent can always be built from a full PDU event")
} }
pub fn to_room_event(&self) -> EventJson<AnyRoomEvent> { pub fn to_room_event(&self) -> Raw<AnyRoomEvent> {
let json = serde_json::to_string(&self).expect("PDUs are always valid"); let json = serde_json::to_string(&self).expect("PDUs are always valid");
serde_json::from_str::<AnyRoomEvent>(&json) serde_json::from_str::<AnyRoomEvent>(&json)
.map(EventJson::from) .map(Raw::from)
.expect("AnyRoomEvent can always be built from a full PDU event") .expect("AnyRoomEvent can always be built from a full PDU event")
} }
pub fn to_state_event(&self) -> EventJson<AnyStateEvent> { pub fn to_state_event(&self) -> Raw<AnyStateEvent> {
let json = serde_json::to_string(&self).expect("PDUs are always valid"); let json = serde_json::to_string(&self).expect("PDUs are always valid");
serde_json::from_str::<AnyStateEvent>(&json) serde_json::from_str::<AnyStateEvent>(&json)
.map(EventJson::from) .map(Raw::from)
.expect("AnyStateEvent can always be built from a full PDU event") .expect("AnyStateEvent can always be built from a full PDU event")
} }
pub fn to_sync_state_event(&self) -> EventJson<AnySyncStateEvent> { pub fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> {
let json = serde_json::to_string(&self).expect("PDUs are always valid"); let json = serde_json::to_string(&self).expect("PDUs are always valid");
serde_json::from_str::<AnySyncStateEvent>(&json) serde_json::from_str::<AnySyncStateEvent>(&json)
.map(EventJson::from) .map(Raw::from)
.expect("AnySyncStateEvent can always be built from a full PDU event") .expect("AnySyncStateEvent can always be built from a full PDU event")
} }
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEvent> { pub fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> {
let json = serde_json::to_string(&self).expect("PDUs are always valid"); let json = serde_json::to_string(&self).expect("PDUs are always valid");
serde_json::from_str::<AnyStrippedStateEvent>(&json) serde_json::from_str::<AnyStrippedStateEvent>(&json)
.map(EventJson::from) .map(Raw::from)
.expect("AnyStrippedStateEvent can always be built from a full PDU event") .expect("AnyStrippedStateEvent can always be built from a full PDU event")
} }
pub fn to_member_event(&self) -> EventJson<StateEvent<MemberEventContent>> { pub fn to_member_event(&self) -> Raw<StateEvent<MemberEventContent>> {
let json = serde_json::to_string(&self).expect("PDUs are always valid"); let json = serde_json::to_string(&self).expect("PDUs are always valid");
serde_json::from_str::<StateEvent<MemberEventContent>>(&json) serde_json::from_str::<StateEvent<MemberEventContent>>(&json)
.map(EventJson::from) .map(Raw::from)
.expect("StateEvent<MemberEventContent> can always be built from a full PDU event") .expect("StateEvent<MemberEventContent> can always be built from a full PDU event")
} }
} }

View file

@ -1,6 +1,6 @@
use js_int::uint; use js_int::uint;
use ruma::{ use ruma::{
identifiers::UserId, UserId,
push::{ push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak, PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak,

View file

@ -7,10 +7,7 @@ use rocket::{
Outcome::*, Outcome::*,
Request, State, Request, State,
}; };
use ruma::{ use ruma::{api::Endpoint, DeviceId, UserId};
api::Endpoint,
identifiers::{DeviceId, UserId},
};
use std::{convert::TryInto, io::Cursor, ops::Deref}; use std::{convert::TryInto, io::Cursor, ops::Deref};
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;