From 33bc666859ccbe939684c9e908b17be37cf6a7ed Mon Sep 17 00:00:00 2001 From: Devin R Date: Tue, 21 Jul 2020 14:04:39 -0400 Subject: [PATCH] Use sync ephemeral events in sync Resposne (remove room_id) Bump ruma to latest master which also fixes some server name as String to now being of type Box. --- Cargo.lock | 124 ++++++++++++++++++++----------------- Cargo.toml | 2 +- src/client_server.rs | 11 ++-- src/database/rooms.rs | 2 +- src/database/rooms/edus.rs | 41 ++---------- src/pdu.rs | 4 +- 6 files changed, 82 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79973c0f..8800c5ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,9 +106,9 @@ version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -423,9 +423,9 @@ version = "0.3.0" source = "git+https://github.com/SergioBenitez/Devise.git?rev=e58b3ac9a#e58b3ac9afc3b6ff10a8aaf02a3e768a8f530089" dependencies = [ "bitflags", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -597,9 +597,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -716,6 +716,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +dependencies = [ + "autocfg", +] + [[package]] name = "heck" version = "0.3.1" @@ -847,11 +856,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" dependencies = [ "autocfg", + "hashbrown", ] [[package]] @@ -895,9 +905,9 @@ dependencies = [ [[package]] name = "js_int" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b2b63d60564122f2a7d6592c2f1d6c1c60e7a266b4d24715950a1ddad784f66" +checksum = "b96797f53235a1d6dc985f244a69de54b04c45b7e0e357a35c85a45a847d92f2" dependencies = [ "serde", ] @@ -920,9 +930,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" +checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" [[package]] name = "lock_api" @@ -1257,9 +1267,9 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -1282,9 +1292,9 @@ checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" [[package]] name = "png" -version = "0.16.6" +version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c150bf7479fafe3dd8740dbe48cc33b2a3efb7b0fe3483aced8bbc39f6d0238d" +checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970" dependencies = [ "bitflags", "crc32fast", @@ -1331,9 +1341,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid 0.2.1", ] @@ -1353,7 +1363,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", ] [[package]] @@ -1429,9 +1439,9 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d21b475ab879ef0e315ad99067fa25778c3b0377f57f1b00207448dac1a3144" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -1556,7 +1566,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.1.0" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "ruma-api", "ruma-client-api", @@ -1570,7 +1580,7 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.16.1" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "http", "percent-encoding 2.1.0", @@ -1585,18 +1595,18 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.16.1" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "matches", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] name = "ruma-client-api" version = "0.9.0" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "http", "js_int", @@ -1613,7 +1623,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.1.3" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "js_int", "matches", @@ -1626,7 +1636,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.21.3" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "js_int", "ruma-common", @@ -1641,18 +1651,18 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.21.3" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "matches", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] name = "ruma-federation-api" version = "0.0.2" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "js_int", "matches", @@ -1668,7 +1678,7 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.17.0-pre.1" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "matches", "rand", @@ -1679,7 +1689,7 @@ dependencies = [ [[package]] name = "ruma-serde" version = "0.2.2" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "form_urlencoded", "itoa", @@ -1691,7 +1701,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.6.0-dev.1" -source = "git+https://github.com/ruma/ruma?rev=848b225#848b22568106d05c5444f3fe46070d5aa16e422b" +source = "git+https://github.com/ruma/ruma?rev=b55f827#b55f82742c88ea6d8744f37bacac5cbfa17a9029" dependencies = [ "base64 0.12.3", "ring", @@ -1836,9 +1846,9 @@ version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -1975,11 +1985,11 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", "serde", "serde_derive", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -1989,13 +1999,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", "serde", "serde_derive", "serde_json", "sha1", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -2020,9 +2030,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" dependencies = [ "heck", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -2050,11 +2060,11 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", "unicode-xid 0.2.1", ] @@ -2088,9 +2098,9 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -2135,10 +2145,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", "standback", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -2176,9 +2186,9 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", ] [[package]] @@ -2385,9 +2395,9 @@ dependencies = [ "bumpalo", "lazy_static", "log", - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", "wasm-bindgen-shared", ] @@ -2419,9 +2429,9 @@ version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" dependencies = [ - "proc-macro2 1.0.18", + "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.34", + "syn 1.0.35", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 80785c87..adf7a985 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "848b225" } +ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "b55f827" } diff --git a/src/client_server.rs b/src/client_server.rs index c83f9e22..48c03c3a 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -64,7 +64,8 @@ use ruma::{ canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction, topic, }, - AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, EventJson, EventType, + AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventJson, + EventType, }, identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId}, }; @@ -284,7 +285,7 @@ pub fn login_route( Ok(login::Response { user_id, access_token: token, - home_server: Some(db.globals.server_name().to_string()), + home_server: Some(db.globals.server_name().to_owned()), device_id: device_id.into(), well_known: None, } @@ -2530,9 +2531,9 @@ pub fn sync_route( { edus.push( serde_json::from_str( - &serde_json::to_string(&AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Typing( + &serde_json::to_string(&AnySyncEphemeralRoomEvent::Typing( db.rooms.edus.roomactives_all(&room_id)?, - ))) + )) .expect("event is valid, we just created it"), ) .expect("event is valid, we just created it"), @@ -2613,7 +2614,7 @@ pub fn sync_route( { edus.push( serde_json::from_str( - &serde_json::to_string(&ruma::events::AnySyncEphemeralRoomEvent::Typing( + &serde_json::to_string(&AnySyncEphemeralRoomEvent::Typing( db.rooms.edus.roomactives_all(&room_id)?, )) .expect("event is valid, we just created it"), diff --git a/src/database/rooms.rs b/src/database/rooms.rs index d29ab427..7e6036dd 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -515,7 +515,7 @@ impl Rooms { event_id: EventId::try_from("$thiswillbefilledinlater").expect("we know this is valid"), room_id: room_id.clone(), sender: sender.clone(), - origin: globals.server_name().to_string(), + origin: globals.server_name().to_owned(), origin_server_ts: utils::millis_since_unix_epoch() .try_into() .expect("time is valid"), diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs index 3ee1e756..b96f1b10 100644 --- a/src/database/rooms/edus.rs +++ b/src/database/rooms/edus.rs @@ -209,8 +209,10 @@ impl RoomEdus { .unwrap_or(0)) } - /// Returns an iterator over all active events (e.g. typing notifications). - pub fn roomactives_all(&self, room_id: &RoomId) -> Result { + pub fn roomactives_all( + &self, + room_id: &RoomId, + ) -> Result> { let mut prefix = room_id.to_string().as_bytes().to_vec(); prefix.push(0xff); @@ -234,43 +236,10 @@ impl RoomEdus { user_ids.push(user_id?); } - Ok(ruma::events::typing::TypingEvent { + Ok(SyncEphemeralRoomEvent { content: ruma::events::typing::TypingEventContent { user_ids }, - room_id: room_id.clone(), }) } - // REMOVE the above method and uncomment the bottom when ruma/ruma PR #141 is merged - // pub fn roomactives_all( - // &self, - // room_id: &RoomId, - // ) -> Result> { - // let mut prefix = room_id.to_string().as_bytes().to_vec(); - // prefix.push(0xff); - - // let mut user_ids = Vec::new(); - - // for user_id in self - // .roomactiveid_userid - // .scan_prefix(prefix) - // .values() - // .map(|user_id| { - // Ok::<_, Error>( - // UserId::try_from(utils::string_from_bytes(&user_id?).map_err(|_| { - // Error::bad_database("User ID in roomactiveid_userid is invalid unicode.") - // })?) - // .map_err(|_| { - // Error::bad_database("User ID in roomactiveid_userid is invalid.") - // })?, - // ) - // }) - // { - // user_ids.push(user_id?); - // } - - // Ok(SyncEphemeralRoomEvent { - // content: ruma::events::typing::TypingEventContent { user_ids }, - // }) - // } /// Sets a private read marker at `count`. pub fn room_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { diff --git a/src/pdu.rs b/src/pdu.rs index f55acaf3..0db77a1a 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -6,7 +6,7 @@ use ruma::{ AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType, StateEvent, }, - identifiers::{EventId, RoomId, UserId}, + identifiers::{EventId, RoomId, ServerName, UserId}, }; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -17,7 +17,7 @@ pub struct PduEvent { pub event_id: EventId, pub room_id: RoomId, pub sender: UserId, - pub origin: String, + pub origin: Box, pub origin_server_ts: UInt, #[serde(rename = "type")] pub kind: EventType,