Commit a37e09273c

a37e09273c4157b8d516d015d6f49eac0ee2ea61

parent: c7bfa47b05

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2021-03-02 16:58 UTC

weechat-matrix: Update to the encryption-info rust-sdk branch

Layout: unified · split

Cargo.lock +63 −19
@@ -157,6 +157,20 @@ version = "1.0.1"
157157source = "registry+https://github.com/rust-lang/crates.io-index"
158158checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
159159
160[[package]]
161name = "backoff"
162version = "0.3.0"
163source = "registry+https://github.com/rust-lang/crates.io-index"
164checksum = "9fe17f59a06fe8b87a6fc8bf53bb70b3aba76d7685f432487a68cd5552853625"
165dependencies = [
166 "futures-core",
167 "getrandom",
168 "instant",
169 "pin-project 1.0.4",
170 "rand",
171 "tokio",
172]
173
160174[[package]]
161175name = "backtrace"
162176version = "0.3.56"
@@ -900,6 +914,12 @@ dependencies = [
900914 "web-sys",
901915]
902916
917[[package]]
918name = "integer-encoding"
919version = "1.1.7"
920source = "registry+https://github.com/rust-lang/crates.io-index"
921checksum = "48dc51180a9b377fd75814d0cc02199c20f8e99433d6762f650d39cdbbd3b56f"
922
903923[[package]]
904924name = "ipnet"
905925version = "2.3.0"
@@ -1015,8 +1035,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
10151035[[package]]
10161036name = "matrix-sdk"
10171037version = "0.2.0"
1018source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b66c666997cbcf32071d24ffe2484a215de8d0e4"
1038source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=encryption-info#92f3eb256d7e878e2bf392153337a199cfd3dd09"
10191039dependencies = [
1040 "backoff",
10201041 "dashmap",
10211042 "futures",
10221043 "futures-timer",
@@ -1037,7 +1058,7 @@ dependencies = [
10371058[[package]]
10381059name = "matrix-sdk-base"
10391060version = "0.2.0"
1040source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b66c666997cbcf32071d24ffe2484a215de8d0e4"
1061source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=encryption-info#92f3eb256d7e878e2bf392153337a199cfd3dd09"
10411062dependencies = [
10421063 "chacha20poly1305",
10431064 "dashmap",
@@ -1060,13 +1081,14 @@ dependencies = [
10601081[[package]]
10611082name = "matrix-sdk-common"
10621083version = "0.2.0"
1063source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b66c666997cbcf32071d24ffe2484a215de8d0e4"
1084source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=encryption-info#92f3eb256d7e878e2bf392153337a199cfd3dd09"
10641085dependencies = [
10651086 "async-trait",
10661087 "futures-locks",
10671088 "instant",
10681089 "ruma",
10691090 "serde",
1091 "serde_json",
10701092 "tokio",
10711093 "uuid",
10721094]
@@ -1074,7 +1096,7 @@ dependencies = [
10741096[[package]]
10751097name = "matrix-sdk-crypto"
10761098version = "0.2.0"
1077source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b66c666997cbcf32071d24ffe2484a215de8d0e4"
1099source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=encryption-info#92f3eb256d7e878e2bf392153337a199cfd3dd09"
10781100dependencies = [
10791101 "aes-ctr",
10801102 "aes-gcm",
@@ -1664,7 +1686,7 @@ dependencies = [
16641686[[package]]
16651687name = "ruma"
16661688version = "0.0.2"
1667source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1689source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
16681690dependencies = [
16691691 "assign",
16701692 "js_int",
@@ -1680,7 +1702,7 @@ dependencies = [
16801702[[package]]
16811703name = "ruma-api"
16821704version = "0.17.0-alpha.2"
1683source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1705source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
16841706dependencies = [
16851707 "http",
16861708 "percent-encoding",
@@ -1695,7 +1717,7 @@ dependencies = [
16951717[[package]]
16961718name = "ruma-api-macros"
16971719version = "0.17.0-alpha.2"
1698source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1720source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
16991721dependencies = [
17001722 "proc-macro-crate",
17011723 "proc-macro2",
@@ -1706,7 +1728,7 @@ dependencies = [
17061728[[package]]
17071729name = "ruma-client-api"
17081730version = "0.10.0-alpha.2"
1709source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1731source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17101732dependencies = [
17111733 "assign",
17121734 "http",
@@ -1725,7 +1747,7 @@ dependencies = [
17251747[[package]]
17261748name = "ruma-common"
17271749version = "0.3.0-alpha.1"
1728source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1750source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17291751dependencies = [
17301752 "js_int",
17311753 "maplit",
@@ -1738,7 +1760,7 @@ dependencies = [
17381760[[package]]
17391761name = "ruma-events"
17401762version = "0.22.0-alpha.2"
1741source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1763source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17421764dependencies = [
17431765 "js_int",
17441766 "pulldown-cmark",
@@ -1753,7 +1775,7 @@ dependencies = [
17531775[[package]]
17541776name = "ruma-events-macros"
17551777version = "0.22.0-alpha.2"
1756source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1778source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17571779dependencies = [
17581780 "proc-macro-crate",
17591781 "proc-macro2",
@@ -1764,7 +1786,7 @@ dependencies = [
17641786[[package]]
17651787name = "ruma-federation-api"
17661788version = "0.1.0-alpha.1"
1767source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1789source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17681790dependencies = [
17691791 "js_int",
17701792 "ruma-api",
@@ -1779,7 +1801,7 @@ dependencies = [
17791801[[package]]
17801802name = "ruma-identifiers"
17811803version = "0.18.0-alpha.1"
1782source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1804source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17831805dependencies = [
17841806 "paste",
17851807 "ruma-identifiers-macros",
@@ -1792,7 +1814,7 @@ dependencies = [
17921814[[package]]
17931815name = "ruma-identifiers-macros"
17941816version = "0.18.0-alpha.1"
1795source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1817source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
17961818dependencies = [
17971819 "proc-macro2",
17981820 "quote",
@@ -1803,12 +1825,12 @@ dependencies = [
18031825[[package]]
18041826name = "ruma-identifiers-validation"
18051827version = "0.2.0"
1806source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1828source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
18071829
18081830[[package]]
18091831name = "ruma-serde"
18101832version = "0.3.0"
1811source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1833source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
18121834dependencies = [
18131835 "form_urlencoded",
18141836 "itoa",
@@ -1821,7 +1843,7 @@ dependencies = [
18211843[[package]]
18221844name = "ruma-serde-macros"
18231845version = "0.3.0"
1824source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1846source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d"
18251847dependencies = [
18261848 "proc-macro-crate",
18271849 "proc-macro2",
@@ -1953,9 +1975,9 @@ dependencies = [
19531975
19541976[[package]]
19551977name = "serde_json"
1956version = "1.0.61"
1978version = "1.0.62"
19571979source = "registry+https://github.com/rust-lang/crates.io-index"
1958checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a"
1980checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486"
19591981dependencies = [
19601982 "itoa",
19611983 "ryu",
@@ -2241,6 +2263,28 @@ dependencies = [
22412263 "once_cell",
22422264]
22432265
2266[[package]]
2267name = "threadpool"
2268version = "1.8.1"
2269source = "registry+https://github.com/rust-lang/crates.io-index"
2270checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
2271dependencies = [
2272 "num_cpus",
2273]
2274
2275[[package]]
2276name = "thrift"
2277version = "0.13.0"
2278source = "registry+https://github.com/rust-lang/crates.io-index"
2279checksum = "0c6d965454947cc7266d22716ebfd07b18d84ebaf35eec558586bbb2a8cb6b5b"
2280dependencies = [
2281 "byteorder",
2282 "integer-encoding",
2283 "log",
2284 "ordered-float",
2285 "threadpool",
2286]
2287
22442288[[package]]
22452289name = "time"
22462290version = "0.1.44"
Cargo.toml +6 −5
@@ -10,9 +10,9 @@ name = "matrix"
1010crate-type = ["cdylib"]
1111
1212[dependencies]
13url = "2.2.0"
14futures = "0.3.12"
15tokio = { version = "1.1.0", features = [ "rt-multi-thread", "sync" ] }
13url = "2.2.1"
14futures = "0.3.13"
15tokio = { version = "1.2.0", features = [ "rt-multi-thread", "sync" ] }
1616dashmap = "4.0.2"
1717tracing = "0.1.22"
1818tracing-subscriber = "0.2.15"
@@ -24,12 +24,13 @@ unicode-segmentation = "1.7.1"
2424strum = "0.20.0"
2525strum_macros = "0.20.1"
2626chrono = "0.4.19"
27serde_json = "1.0.61"
27serde_json = "1.0.64"
2828
2929[dependencies.weechat]
3030git = "https://github.com/poljar/rust-weechat"
3131features = ["async", "config_macro"]
3232
3333[dependencies.matrix-sdk]
34git = "https://github.com/matrix-org/matrix-rust-sdk/"
34git = "https://github.com/matrix-org/matrix-rust-sdk"
35branch = "encryption-info"
3536features = ["markdown"]
src/connection.rs +2 −2
@@ -36,10 +36,10 @@ use matrix_sdk::{
3636 typing::create_typing_event::{Response as TypingResponse, Typing},
3737 uiaa::AuthData,
3838 },
39 deserialized_responses::AmbiguityChange,
39 deserialized_responses::{AmbiguityChange, AnySyncRoomEvent},
4040 events::{
4141 room::member::MemberEventContent, AnyMessageEventContent,
42 AnySyncRoomEvent, AnySyncStateEvent, SyncStateEvent,
42 AnySyncStateEvent, SyncStateEvent,
4343 },
4444 identifiers::{DeviceIdBox, RoomId},
4545 Client, JoinedRoom, LoopCtrl, Result as MatrixResult, SyncSettings,
src/room/mod.rs +23 −13
@@ -32,6 +32,7 @@ use std::{
3232 borrow::Cow,
3333 cell::RefCell,
3434 collections::HashMap,
35 convert::TryInto,
3536 ops::Deref,
3637 rc::Rc,
3738 sync::{
@@ -48,16 +49,20 @@ use url::Url;
4849
4950use matrix_sdk::{
5051 async_trait,
51 deserialized_responses::AmbiguityChange,
52 deserialized_responses::{
53 events::{SyncMessageEvent, SyncRedactionEvent},
54 AmbiguityChange, AnyMessageEventContent, AnySyncMessageEvent,
55 AnySyncRoomEvent,
56 },
5257 events::{
5358 room::{
5459 member::MemberEventContent,
55 message::{MessageEventContent, TextMessageEventContent},
56 redaction::SyncRedactionEvent,
60 message::{
61 MessageEventContent, MessageType, TextMessageEventContent,
62 },
5763 },
58 AnyMessageEventContent, AnyRedactedSyncMessageEvent, AnyRoomEvent,
59 AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
60 SyncMessageEvent, SyncStateEvent,
64 AnyRedactedSyncMessageEvent, AnyRoomEvent, AnySyncStateEvent,
65 SyncStateEvent,
6166 },
6267 identifiers::{EventId, RoomAliasId, RoomId, UserId},
6368 uuid::Uuid,
@@ -338,8 +343,9 @@ impl RoomHandle {
338343impl BufferInputCallbackAsync for MatrixRoom {
339344 async fn callback(&mut self, _: BufferHandle, input: String) {
340345 // TODO parse the input here and produce a formatted body.
341 let content =
342 MessageEventContent::Text(TextMessageEventContent::markdown(input));
346 let content = MessageEventContent::new(MessageType::Text(
347 TextMessageEventContent::markdown(input),
348 ));
343349 self.send_message(content).await;
344350 }
345351}
@@ -488,13 +494,13 @@ impl MatrixRoom {
488494 content: &AnyMessageEventContent,
489495 ) -> Option<RenderedEvent> {
490496 use AnyMessageEventContent::*;
491 use MessageEventContent::*;
497 use MessageType::*;
492498
493499 let rendered = match content {
494500 RoomEncrypted(c) => {
495501 c.render_with_prefix(send_time, event_id, sender, &())
496502 }
497 RoomMessage(c) => match c {
503 RoomMessage(c) => match &c.msgtype {
498504 Text(c) => {
499505 c.render_with_prefix(send_time, event_id, sender, &())
500506 }
@@ -578,7 +584,7 @@ impl MatrixRoom {
578584 content: &MessageEventContent,
579585 ) {
580586 if self.config.borrow().look().local_echo() {
581 if let MessageEventContent::Text(c) = content {
587 if let MessageType::Text(c) = &content.msgtype {
582588 let sender =
583589 self.members.get(&self.own_user_id).await.unwrap_or_else(
584590 || panic!("No own member {}", self.own_user_id),
@@ -626,7 +632,9 @@ impl MatrixRoom {
626632 match c
627633 .send_message(
628634 &self.room_id,
629 AnyMessageEventContent::RoomMessage(content),
635 AnyMessageEventContent::RoomMessage(content)
636 .try_into()
637 .expect("Can't convert to ruma event"),
630638 Some(uuid),
631639 )
632640 .await
@@ -874,6 +882,7 @@ impl MatrixRoom {
874882 event_id: event_id.clone(),
875883 content,
876884 unsigned: Default::default(),
885 encryption_info: None,
877886 };
878887
879888 let event = AnySyncMessageEvent::RoomMessage(event);
@@ -1086,12 +1095,13 @@ impl MatrixRoom {
10861095 );
10871096
10881097 let send_time = event.origin_server_ts();
1098
10891099 if let Some(rendered) = self
10901100 .render_message_content(
10911101 event.event_id(),
10921102 send_time,
10931103 &sender,
1094 &event.content(),
1104 &event.content().into(),
10951105 )
10961106 .await
10971107 {
src/server.rs +2 −3
@@ -69,10 +69,9 @@ use url::Url;
6969use matrix_sdk::{
7070 self,
7171 api::r0::session::login::Response as LoginResponse,
72 deserialized_responses::AmbiguityChange,
72 deserialized_responses::{AmbiguityChange, AnySyncRoomEvent},
7373 events::{
74 room::member::MemberEventContent, AnySyncRoomEvent, AnySyncStateEvent,
75 SyncStateEvent,
74 room::member::MemberEventContent, AnySyncStateEvent, SyncStateEvent,
7675 },
7776 identifiers::{DeviceIdBox, RoomId, UserId},
7877 Client, ClientConfig, JoinedRoom,
src/utils.rs +16 −44
@@ -1,64 +1,36 @@
11use matrix_sdk::{
2 deserialized_responses::AnySyncMessageEvent,
23 events::{
3 room::message::{
4 MessageEventContent, NoticeMessageEventContent, Relation,
5 TextMessageEventContent,
6 },
7 AnyMessageEvent, AnySyncMessageEvent,
4 room::message::Relation,
5 AnyMessageEvent,
86 },
97 identifiers::EventId,
108};
9use matrix_sdk::events::room::message::MessageEventContent;
1110
1211pub trait Edit {
1312 fn is_edit(&self) -> bool;
1413 fn get_edit(&self) -> Option<(&EventId, &MessageEventContent)>;
1514}
1615
17macro_rules! impl_relation {
18 ($name:ident) => {
19 impl Edit for $name {
20 fn is_edit(&self) -> bool {
21 if let Some(Relation::Replacement(_)) = self.relates_to.as_ref()
22 {
23 self.new_content.is_some()
24 } else {
25 false
26 }
27 }
28
29 fn get_edit(&self) -> Option<(&EventId, &MessageEventContent)> {
30 if let Some(Relation::Replacement(r)) = self.relates_to.as_ref()
31 {
32 if let Some(content) = self.new_content.as_ref() {
33 Some((&r.event_id, &*content))
34 } else {
35 None
36 }
37 } else {
38 None
39 }
40 }
41 }
42 };
43}
44
45impl_relation!(TextMessageEventContent);
46impl_relation!(NoticeMessageEventContent);
47
4816impl Edit for MessageEventContent {
4917 fn is_edit(&self) -> bool {
50 match self {
51 MessageEventContent::Notice(n) => n.is_edit(),
52 MessageEventContent::Text(t) => t.is_edit(),
53 _ => false,
18 if let Some(Relation::Replacement(_)) = self.relates_to.as_ref() {
19 self.new_content.is_some()
20 } else {
21 false
5422 }
5523 }
5624
5725 fn get_edit(&self) -> Option<(&EventId, &MessageEventContent)> {
58 match self {
59 MessageEventContent::Notice(n) => n.get_edit(),
60 MessageEventContent::Text(t) => t.get_edit(),
61 _ => None,
26 if let Some(Relation::Replacement(r)) = self.relates_to.as_ref() {
27 if let Some(content) = self.new_content.as_ref() {
28 Some((&r.event_id, &*content))
29 } else {
30 None
31 }
32 } else {
33 None
6234 }
6335 }
6436}