mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-27 04:53:50 +03:00
Upgrade ruma
This commit is contained in:
parent
f8544bf6e3
commit
09561ccea3
14 changed files with 154 additions and 180 deletions
50
Cargo.lock
generated
50
Cargo.lock
generated
|
@ -1545,14 +1545,14 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma"
|
||||
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 = [
|
||||
"ruma-api",
|
||||
"ruma-client-api",
|
||||
"ruma-common",
|
||||
"ruma-events",
|
||||
"ruma-federation-api",
|
||||
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
|
||||
"ruma-identifiers",
|
||||
"ruma-identifiers-macros",
|
||||
"ruma-signatures",
|
||||
]
|
||||
|
@ -1560,12 +1560,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-api"
|
||||
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 = [
|
||||
"http",
|
||||
"percent-encoding",
|
||||
"ruma-api-macros",
|
||||
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
|
||||
"ruma-identifiers",
|
||||
"ruma-serde",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -1575,7 +1575,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-api-macros"
|
||||
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 = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1585,14 +1585,14 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
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 = [
|
||||
"http",
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
"ruma-common",
|
||||
"ruma-events",
|
||||
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
|
||||
"ruma-identifiers",
|
||||
"ruma-serde",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -1602,7 +1602,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-common"
|
||||
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 = [
|
||||
"js_int",
|
||||
"ruma-serde",
|
||||
|
@ -1614,12 +1614,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events"
|
||||
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 = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
"ruma-events-macros",
|
||||
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
|
||||
"ruma-identifiers",
|
||||
"ruma-serde",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -1629,7 +1629,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events-macros"
|
||||
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 = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1639,13 +1639,13 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
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 = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
"ruma-common",
|
||||
"ruma-events",
|
||||
"ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
|
||||
"ruma-identifiers",
|
||||
"ruma-serde",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -1653,39 +1653,29 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ruma-identifiers"
|
||||
version = "0.17.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"serde",
|
||||
"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]]
|
||||
name = "ruma-identifiers-macros"
|
||||
version = "0.17.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"ruma-identifiers 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ruma-identifiers",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-serde"
|
||||
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 = [
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
|
@ -1697,7 +1687,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
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 = [
|
||||
"base64 0.12.3",
|
||||
"ring",
|
||||
|
|
|
@ -27,4 +27,4 @@ reqwest = "0.10.6"
|
|||
base64 = "0.12.1"
|
||||
thiserror = "1.0.19"
|
||||
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" }
|
||||
|
|
|
@ -64,10 +64,9 @@ use ruma::{
|
|||
canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction,
|
||||
topic,
|
||||
},
|
||||
AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventJson,
|
||||
EventType,
|
||||
AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventType,
|
||||
},
|
||||
identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId},
|
||||
Raw, RoomAliasId, RoomId, RoomVersionId, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -624,7 +623,7 @@ pub fn set_displayname_route(
|
|||
EventType::RoomMember,
|
||||
serde_json::to_value(ruma::events::room::member::MemberEventContent {
|
||||
displayname: body.displayname.clone(),
|
||||
..serde_json::from_value::<EventJson<_>>(
|
||||
..serde_json::from_value::<Raw<_>>(
|
||||
db.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or_else(|| {
|
||||
|
@ -659,7 +658,7 @@ pub fn set_displayname_route(
|
|||
.try_into()
|
||||
.expect("time is valid"),
|
||||
),
|
||||
presence: ruma::events::presence::PresenceState::Online,
|
||||
presence: ruma::presence::PresenceState::Online,
|
||||
status_msg: None,
|
||||
},
|
||||
sender: user_id.clone(),
|
||||
|
@ -714,7 +713,7 @@ pub fn set_avatar_url_route(
|
|||
EventType::RoomMember,
|
||||
serde_json::to_value(ruma::events::room::member::MemberEventContent {
|
||||
avatar_url: body.avatar_url.clone(),
|
||||
..serde_json::from_value::<EventJson<_>>(
|
||||
..serde_json::from_value::<Raw<_>>(
|
||||
db.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or_else(|| {
|
||||
|
@ -749,7 +748,7 @@ pub fn set_avatar_url_route(
|
|||
.try_into()
|
||||
.expect("time is valid"),
|
||||
),
|
||||
presence: ruma::events::presence::PresenceState::Online,
|
||||
presence: ruma::presence::PresenceState::Online,
|
||||
status_msg: None,
|
||||
},
|
||||
sender: user_id.clone(),
|
||||
|
@ -1605,7 +1604,7 @@ pub fn leave_room_route(
|
|||
) -> ConduitResult<leave_room::Response> {
|
||||
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
|
||||
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or(Error::BadRequest(
|
||||
|
@ -1643,20 +1642,19 @@ pub fn kick_user_route(
|
|||
) -> ConduitResult<kick_user::Response> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
|
||||
let mut event =
|
||||
serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
|
||||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::BadState,
|
||||
"Cannot kick member that's not in the room.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
|
||||
let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
||||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::BadState,
|
||||
"Cannot kick member that's not in the room.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
|
||||
|
||||
event.membership = ruma::events::room::member::MembershipState::Leave;
|
||||
// TODO: reason
|
||||
|
@ -1697,7 +1695,7 @@ pub fn ban_user_route(
|
|||
third_party_invite: None,
|
||||
}),
|
||||
|event| {
|
||||
let mut event = serde_json::from_value::<EventJson<member::MemberEventContent>>(
|
||||
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
event.content.clone(),
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?
|
||||
|
@ -1730,20 +1728,19 @@ pub fn unban_user_route(
|
|||
) -> ConduitResult<unban_user::Response> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
|
||||
let mut event =
|
||||
serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
|
||||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::BadState,
|
||||
"Cannot unban a user who is not banned.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
|
||||
let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
||||
db.rooms
|
||||
.room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::BadState,
|
||||
"Cannot unban a user who is not banned.",
|
||||
))?
|
||||
.content
|
||||
.clone(),
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?;
|
||||
|
||||
event.membership = ruma::events::room::member::MembershipState::Leave;
|
||||
|
||||
|
@ -1902,7 +1899,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
aliases: Vec::new(),
|
||||
canonical_alias: state.get(&(EventType::RoomCanonicalAlias, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(serde_json::from_value::<
|
||||
EventJson<ruma::events::room::canonical_alias::CanonicalAliasEventContent>,
|
||||
Raw<ruma::events::room::canonical_alias::CanonicalAliasEventContent>,
|
||||
>(s.content.clone())
|
||||
.map_err(|_| Error::bad_database("Invalid canonical alias event in database."))?
|
||||
.deserialize()
|
||||
|
@ -1910,7 +1907,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
.alias)
|
||||
})?,
|
||||
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(),
|
||||
)
|
||||
.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,
|
||||
topic: state.get(&(EventType::RoomTopic, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(Some(serde_json::from_value::<
|
||||
EventJson<ruma::events::room::topic::TopicEventContent>,
|
||||
Raw<ruma::events::room::topic::TopicEventContent>,
|
||||
>(s.content.clone())
|
||||
.map_err(|_| Error::bad_database("Invalid room topic event in database."))?
|
||||
.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| {
|
||||
Ok(serde_json::from_value::<
|
||||
EventJson<ruma::events::room::history_visibility::HistoryVisibilityEventContent>,
|
||||
Raw<ruma::events::room::history_visibility::HistoryVisibilityEventContent>,
|
||||
>(s.content.clone())
|
||||
.map_err(|_| Error::bad_database("Invalid room history visibility event in database."))?
|
||||
.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| {
|
||||
Ok(serde_json::from_value::<
|
||||
EventJson<ruma::events::room::guest_access::GuestAccessEventContent>,
|
||||
Raw<ruma::events::room::guest_access::GuestAccessEventContent>,
|
||||
>(s.content.clone())
|
||||
.map_err(|_| Error::bad_database("Invalid room guest access event in database."))?
|
||||
.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| {
|
||||
Ok(Some(serde_json::from_value::<
|
||||
EventJson<ruma::events::room::avatar::AvatarEventContent>,
|
||||
Raw<ruma::events::room::avatar::AvatarEventContent>,
|
||||
>(s.content.clone())
|
||||
.map_err(|_| Error::bad_database("Invalid room avatar event in database."))?
|
||||
.deserialize()
|
||||
|
@ -2158,7 +2155,7 @@ pub fn create_state_event_for_key_route(
|
|||
|
||||
if body.event_type == EventType::RoomCanonicalAlias {
|
||||
let canonical_alias = serde_json::from_value::<
|
||||
EventJson<canonical_alias::CanonicalAliasEventContent>,
|
||||
Raw<canonical_alias::CanonicalAliasEventContent>,
|
||||
>(content.clone())
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid canonical alias."))?
|
||||
.deserialize()
|
||||
|
@ -2375,9 +2372,9 @@ pub fn sync_route(
|
|||
send_member_count = true;
|
||||
if !joined_since_last_sync && pdu.state_key == Some(user_id.to_string()) {
|
||||
let content = serde_json::from_value::<
|
||||
EventJson<ruma::events::room::member::MemberEventContent>,
|
||||
Raw<ruma::events::room::member::MemberEventContent>,
|
||||
>(pdu.content.clone())
|
||||
.expect("EventJson::from_value always works")
|
||||
.expect("Raw::from_value always works")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid PDU in database."))?;
|
||||
if content.membership == ruma::events::room::member::MembershipState::Join {
|
||||
|
@ -2410,7 +2407,7 @@ pub fn sync_route(
|
|||
.filter(|pdu| pdu.kind == EventType::RoomMember)
|
||||
.map(|pdu| {
|
||||
let content = serde_json::from_value::<
|
||||
EventJson<ruma::events::room::member::MemberEventContent>,
|
||||
Raw<ruma::events::room::member::MemberEventContent>,
|
||||
>(pdu.content.clone())
|
||||
.map_err(|_| Error::bad_database("Invalid member event in database."))?
|
||||
.deserialize()
|
||||
|
@ -2418,7 +2415,7 @@ pub fn sync_route(
|
|||
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
let current_content = serde_json::from_value::<
|
||||
EventJson<ruma::events::room::member::MemberEventContent>,
|
||||
Raw<ruma::events::room::member::MemberEventContent>,
|
||||
>(
|
||||
members
|
||||
.get(state_key)
|
||||
|
@ -2660,7 +2657,8 @@ pub fn sync_route(
|
|||
}
|
||||
|
||||
// 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 {
|
||||
next_batch,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{utils, Error, Result};
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind,
|
||||
events::{AnyEvent as EduEvent, EventJson, EventType},
|
||||
identifiers::{RoomId, UserId},
|
||||
events::{AnyEvent as EduEvent, EventType},
|
||||
Raw, RoomId, UserId,
|
||||
};
|
||||
use std::{collections::HashMap, convert::TryFrom};
|
||||
|
||||
|
@ -81,7 +81,7 @@ impl AccountData {
|
|||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
kind: &EventType,
|
||||
) -> Result<Option<EventJson<EduEvent>>> {
|
||||
) -> Result<Option<Raw<EduEvent>>> {
|
||||
Ok(self.all(room_id, user_id)?.remove(kind))
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ impl AccountData {
|
|||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
since: u64,
|
||||
) -> Result<HashMap<EventType, EventJson<EduEvent>>> {
|
||||
) -> Result<HashMap<EventType, Raw<EduEvent>>> {
|
||||
let mut userdata = HashMap::new();
|
||||
|
||||
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."))?,
|
||||
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.")
|
||||
})?,
|
||||
))
|
||||
|
@ -139,7 +139,7 @@ impl AccountData {
|
|||
&self,
|
||||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<EventType, EventJson<EduEvent>>> {
|
||||
) -> Result<HashMap<EventType, Raw<EduEvent>>> {
|
||||
self.changes_since(room_id, user_id, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{Error, Result};
|
||||
use ruma::events::EventJson;
|
||||
use ruma::Raw;
|
||||
|
||||
pub struct GlobalEdus {
|
||||
//pub globalallid_globalall: sled::Tree, // ToDevice, GlobalAllId = UserId + Count
|
||||
|
@ -47,8 +47,7 @@ impl GlobalEdus {
|
|||
pub fn presence_since(
|
||||
&self,
|
||||
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
|
||||
|
||||
Ok(self
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::convert::TryInto;
|
||||
|
||||
use crate::{utils, Error, Result};
|
||||
use ruma::identifiers::ServerName;
|
||||
use ruma::ServerName;
|
||||
pub const COUNTER: &str = "c";
|
||||
|
||||
pub struct Globals {
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruma::{
|
|||
error::ErrorKind,
|
||||
r0::backup::{BackupAlgorithm, KeyData, Sessions},
|
||||
},
|
||||
identifiers::{RoomId, UserId},
|
||||
{RoomId, UserId},
|
||||
};
|
||||
use std::{collections::BTreeMap, convert::TryFrom};
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ use ruma::{
|
|||
power_levels::{self, PowerLevelsEventContent},
|
||||
redaction,
|
||||
},
|
||||
EventJson, EventType,
|
||||
EventType,
|
||||
},
|
||||
identifiers::{EventId, RoomAliasId, RoomId, UserId},
|
||||
EventId, Raw, RoomAliasId, RoomId, UserId,
|
||||
};
|
||||
use sled::IVec;
|
||||
use std::{
|
||||
|
@ -287,28 +287,24 @@ impl Rooms {
|
|||
})
|
||||
},
|
||||
|power_levels| {
|
||||
Ok(
|
||||
serde_json::from_value::<EventJson<PowerLevelsEventContent>>(
|
||||
power_levels.content.clone(),
|
||||
)
|
||||
.expect("EventJson::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?,
|
||||
Ok(serde_json::from_value::<Raw<PowerLevelsEventContent>>(
|
||||
power_levels.content.clone(),
|
||||
)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?)
|
||||
},
|
||||
)?;
|
||||
let sender_membership = self
|
||||
.room_state_get(&room_id, &EventType::RoomMember, &sender.to_string())?
|
||||
.map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
|
||||
Ok(
|
||||
serde_json::from_value::<EventJson<member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
)
|
||||
.expect("EventJson::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
|
||||
.membership,
|
||||
Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
)
|
||||
.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(
|
||||
|
@ -339,24 +335,21 @@ impl Rooms {
|
|||
&target_user_id.to_string(),
|
||||
)?
|
||||
.map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
|
||||
Ok(
|
||||
serde_json::from_value::<EventJson<member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
)
|
||||
.expect("EventJson::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
|
||||
.membership,
|
||||
Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
)
|
||||
.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::<
|
||||
EventJson<member::MemberEventContent>,
|
||||
>(content.clone())
|
||||
.expect("EventJson::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
|
||||
.membership;
|
||||
let target_membership =
|
||||
serde_json::from_value::<Raw<member::MemberEventContent>>(content.clone())
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
|
||||
.membership;
|
||||
|
||||
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, "")?
|
||||
.map_or(Ok::<_, Error>(join_rules::JoinRule::Public), |pdu| {
|
||||
Ok(serde_json::from_value::<
|
||||
EventJson<join_rules::JoinRulesEventContent>,
|
||||
Raw<join_rules::JoinRulesEventContent>,
|
||||
>(pdu.content.clone())
|
||||
.expect("EventJson::from_value always works.")
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
Error::bad_database("Database contains invalid JoinRules event")
|
||||
|
@ -581,18 +574,17 @@ impl Rooms {
|
|||
EventType::RoomRedaction => {
|
||||
if let Some(redact_id) = &redacts {
|
||||
// TODO: Reason
|
||||
let _reason = serde_json::from_value::<
|
||||
EventJson<redaction::RedactionEventContent>,
|
||||
>(content)
|
||||
.expect("EventJson::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Invalid redaction event content.",
|
||||
)
|
||||
})?
|
||||
.reason;
|
||||
let _reason =
|
||||
serde_json::from_value::<Raw<redaction::RedactionEventContent>>(content)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Invalid redaction event content.",
|
||||
)
|
||||
})?
|
||||
.reason;
|
||||
|
||||
self.redact_pdu(&redact_id)?;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{utils, Error, Result};
|
||||
use ruma::{
|
||||
events::{AnyEvent as EduEvent, EventJson, SyncEphemeralRoomEvent},
|
||||
identifiers::{RoomId, UserId},
|
||||
events::{AnyEvent as EduEvent, SyncEphemeralRoomEvent},
|
||||
Raw, RoomId, UserId,
|
||||
};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
|
@ -61,8 +61,7 @@ impl RoomEdus {
|
|||
&self,
|
||||
room_id: &RoomId,
|
||||
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();
|
||||
prefix.push(0xff);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruma::{
|
|||
error::ErrorKind,
|
||||
r0::uiaa::{AuthData, UiaaInfo},
|
||||
},
|
||||
identifiers::{DeviceId, UserId},
|
||||
DeviceId, UserId,
|
||||
};
|
||||
|
||||
pub struct Uiaa {
|
||||
|
@ -149,7 +149,7 @@ impl Uiaa {
|
|||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
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 {
|
||||
self.userdeviceid_uiaainfo.insert(
|
||||
|
@ -171,7 +171,7 @@ impl Uiaa {
|
|||
) -> Result<UiaaInfo> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
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>(
|
||||
&self
|
||||
|
|
|
@ -8,8 +8,8 @@ use ruma::{
|
|||
keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
|
||||
},
|
||||
},
|
||||
events::{AnyToDeviceEvent, EventJson, EventType},
|
||||
identifiers::{DeviceId, UserId},
|
||||
events::{AnyToDeviceEvent, EventType},
|
||||
DeviceId, Raw, UserId,
|
||||
};
|
||||
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();
|
||||
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(
|
||||
userdeviceid,
|
||||
|
@ -200,7 +200,7 @@ impl Users {
|
|||
pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
|
||||
// Remove tokens
|
||||
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<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
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
|
||||
assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
|
||||
|
@ -273,7 +273,7 @@ impl Users {
|
|||
) -> Result<()> {
|
||||
let mut key = user_id.to_string().as_bytes().to_vec();
|
||||
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
|
||||
// Only existing devices should be able to call this.
|
||||
|
@ -305,7 +305,7 @@ impl Users {
|
|||
) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
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(b'"'); // Annoying quotation mark
|
||||
prefix.extend_from_slice(key_algorithm.to_string().as_bytes());
|
||||
|
@ -340,7 +340,7 @@ impl Users {
|
|||
) -> Result<BTreeMap<KeyAlgorithm, UInt>> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
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();
|
||||
|
||||
|
@ -375,7 +375,7 @@ impl Users {
|
|||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
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(
|
||||
&userdeviceid,
|
||||
|
@ -556,7 +556,7 @@ impl Users {
|
|||
) -> Result<Option<DeviceKeys>> {
|
||||
let mut key = user_id.to_string().as_bytes().to_vec();
|
||||
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| {
|
||||
Ok(Some(serde_json::from_slice(&bytes).map_err(|_| {
|
||||
|
@ -643,7 +643,7 @@ impl Users {
|
|||
) -> Result<()> {
|
||||
let mut key = target_user_id.to_string().as_bytes().to_vec();
|
||||
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.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
|
||||
|
@ -664,12 +664,12 @@ impl Users {
|
|||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
) -> Result<Vec<EventJson<AnyToDeviceEvent>>> {
|
||||
) -> Result<Vec<Raw<AnyToDeviceEvent>>> {
|
||||
let mut events = Vec::new();
|
||||
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(device_id.as_str().as_bytes());
|
||||
prefix.extend_from_slice(device_id.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
for value in self.todeviceid_events.scan_prefix(&prefix).values() {
|
||||
|
@ -690,7 +690,7 @@ impl Users {
|
|||
) -> Result<()> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(device_id.as_ref().as_bytes());
|
||||
prefix.extend_from_slice(device_id.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
let mut last = prefix.clone();
|
||||
|
@ -725,7 +725,7 @@ impl Users {
|
|||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
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.
|
||||
assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
|
||||
|
@ -748,7 +748,7 @@ impl Users {
|
|||
) -> Result<Option<Device>> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
|
||||
self.userdeviceid_metadata
|
||||
.get(&userdeviceid)?
|
||||
|
|
29
src/pdu.rs
29
src/pdu.rs
|
@ -3,10 +3,9 @@ use js_int::UInt;
|
|||
use ruma::{
|
||||
events::{
|
||||
pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent,
|
||||
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType,
|
||||
StateEvent,
|
||||
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
|
||||
},
|
||||
identifiers::{EventId, RoomId, ServerName, UserId},
|
||||
EventId, Raw, RoomId, ServerName, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
|
@ -79,40 +78,40 @@ impl PduEvent {
|
|||
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");
|
||||
serde_json::from_str::<AnySyncRoomEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.map(Raw::from)
|
||||
.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");
|
||||
serde_json::from_str::<AnyRoomEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.map(Raw::from)
|
||||
.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");
|
||||
serde_json::from_str::<AnyStateEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.map(Raw::from)
|
||||
.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");
|
||||
serde_json::from_str::<AnySyncStateEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.map(Raw::from)
|
||||
.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");
|
||||
serde_json::from_str::<AnyStrippedStateEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.map(Raw::from)
|
||||
.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");
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use js_int::uint;
|
||||
use ruma::{
|
||||
identifiers::UserId,
|
||||
UserId,
|
||||
push::{
|
||||
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
|
||||
PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak,
|
||||
|
|
|
@ -7,10 +7,7 @@ use rocket::{
|
|||
Outcome::*,
|
||||
Request, State,
|
||||
};
|
||||
use ruma::{
|
||||
api::Endpoint,
|
||||
identifiers::{DeviceId, UserId},
|
||||
};
|
||||
use ruma::{api::Endpoint, DeviceId, UserId};
|
||||
use std::{convert::TryInto, io::Cursor, ops::Deref};
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
|
|
Loading…
Reference in a new issue