Commit cb7615350d

cb7615350d327105ac1c15311ceed0f992417a03

parent: f41c0519f9

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2021-02-09 19:52 UTC

server: WIP better device list rendering.

Layout: unified · split

Cargo.lock +18 −17
@@ -1026,7 +1026,7 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
10261026[[package]]
10271027name = "matrix-sdk"
10281028version = "0.2.0"
1029source = "git+https://github.com/matrix-org/matrix-rust-sdk/#e7e43a8bf0c0195444abefd0dafd3d5432065b72"
1029source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=encryption-info#6930f7af6b77235e0d4a735acb90b442969d2de7"
10301030dependencies = [
10311031 "backoff",
10321032 "dashmap",
@@ -1049,7 +1049,7 @@ dependencies = [
10491049[[package]]
10501050name = "matrix-sdk-base"
10511051version = "0.2.0"
1052source = "git+https://github.com/matrix-org/matrix-rust-sdk/#e7e43a8bf0c0195444abefd0dafd3d5432065b72"
1052source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=encryption-info#6930f7af6b77235e0d4a735acb90b442969d2de7"
10531053dependencies = [
10541054 "chacha20poly1305",
10551055 "dashmap",
@@ -1072,13 +1072,14 @@ dependencies = [
10721072[[package]]
10731073name = "matrix-sdk-common"
10741074version = "0.2.0"
1075source = "git+https://github.com/matrix-org/matrix-rust-sdk/#e7e43a8bf0c0195444abefd0dafd3d5432065b72"
1075source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=encryption-info#6930f7af6b77235e0d4a735acb90b442969d2de7"
10761076dependencies = [
10771077 "async-trait",
10781078 "futures-locks",
10791079 "instant",
10801080 "ruma",
10811081 "serde",
1082 "serde_json",
10821083 "tokio",
10831084 "uuid",
10841085]
@@ -1086,7 +1087,7 @@ dependencies = [
10861087[[package]]
10871088name = "matrix-sdk-crypto"
10881089version = "0.2.0"
1089source = "git+https://github.com/matrix-org/matrix-rust-sdk/#e7e43a8bf0c0195444abefd0dafd3d5432065b72"
1090source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=encryption-info#6930f7af6b77235e0d4a735acb90b442969d2de7"
10901091dependencies = [
10911092 "aes-ctr",
10921093 "aes-gcm",
@@ -1676,7 +1677,7 @@ dependencies = [
16761677[[package]]
16771678name = "ruma"
16781679version = "0.0.2"
1679source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1680source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
16801681dependencies = [
16811682 "assign",
16821683 "js_int",
@@ -1692,7 +1693,7 @@ dependencies = [
16921693[[package]]
16931694name = "ruma-api"
16941695version = "0.17.0-alpha.2"
1695source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1696source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
16961697dependencies = [
16971698 "http",
16981699 "percent-encoding",
@@ -1707,7 +1708,7 @@ dependencies = [
17071708[[package]]
17081709name = "ruma-api-macros"
17091710version = "0.17.0-alpha.2"
1710source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1711source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17111712dependencies = [
17121713 "proc-macro-crate",
17131714 "proc-macro2",
@@ -1718,7 +1719,7 @@ dependencies = [
17181719[[package]]
17191720name = "ruma-client-api"
17201721version = "0.10.0-alpha.2"
1721source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1722source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17221723dependencies = [
17231724 "assign",
17241725 "http",
@@ -1737,7 +1738,7 @@ dependencies = [
17371738[[package]]
17381739name = "ruma-common"
17391740version = "0.3.0-alpha.1"
1740source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1741source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17411742dependencies = [
17421743 "js_int",
17431744 "maplit",
@@ -1750,7 +1751,7 @@ dependencies = [
17501751[[package]]
17511752name = "ruma-events"
17521753version = "0.22.0-alpha.2"
1753source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1754source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17541755dependencies = [
17551756 "js_int",
17561757 "pulldown-cmark",
@@ -1765,7 +1766,7 @@ dependencies = [
17651766[[package]]
17661767name = "ruma-events-macros"
17671768version = "0.22.0-alpha.2"
1768source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1769source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17691770dependencies = [
17701771 "proc-macro-crate",
17711772 "proc-macro2",
@@ -1776,7 +1777,7 @@ dependencies = [
17761777[[package]]
17771778name = "ruma-federation-api"
17781779version = "0.1.0-alpha.1"
1779source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1780source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17801781dependencies = [
17811782 "js_int",
17821783 "ruma-api",
@@ -1791,7 +1792,7 @@ dependencies = [
17911792[[package]]
17921793name = "ruma-identifiers"
17931794version = "0.18.0-alpha.1"
1794source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1795source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
17951796dependencies = [
17961797 "paste",
17971798 "ruma-identifiers-macros",
@@ -1804,7 +1805,7 @@ dependencies = [
18041805[[package]]
18051806name = "ruma-identifiers-macros"
18061807version = "0.18.0-alpha.1"
1807source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1808source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
18081809dependencies = [
18091810 "proc-macro2",
18101811 "quote",
@@ -1815,12 +1816,12 @@ dependencies = [
18151816[[package]]
18161817name = "ruma-identifiers-validation"
18171818version = "0.2.0"
1818source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1819source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
18191820
18201821[[package]]
18211822name = "ruma-serde"
18221823version = "0.3.0"
1823source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1824source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
18241825dependencies = [
18251826 "form_urlencoded",
18261827 "itoa",
@@ -1833,7 +1834,7 @@ dependencies = [
18331834[[package]]
18341835name = "ruma-serde-macros"
18351836version = "0.3.0"
1836source = "git+https://github.com/ruma/ruma?rev=8c109d3c0a7ec66b352dc82677d30db7cb0723eb#8c109d3c0a7ec66b352dc82677d30db7cb0723eb"
1837source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7"
18371838dependencies = [
18381839 "proc-macro-crate",
18391840 "proc-macro2",
Cargo.toml +1
@@ -32,4 +32,5 @@ features = ["async", "config_macro"]
3232
3333[dependencies.matrix-sdk]
3434git = "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::{events::AnySyncRoomEvent, AmbiguityChange},
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 +16 −4
@@ -48,16 +48,20 @@ use url::Url;
4848
4949use matrix_sdk::{
5050 async_trait,
51 deserialized_responses::AmbiguityChange,
51 deserialized_responses::{
52 events::{
53 AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
54 SyncRedactionEvent,
55 },
56 AmbiguityChange,
57 },
5258 events::{
5359 room::{
5460 member::MemberEventContent,
5561 message::{MessageEventContent, TextMessageEventContent},
56 redaction::SyncRedactionEvent,
5762 },
5863 AnyMessageEventContent, AnyRedactedSyncMessageEvent, AnyRoomEvent,
59 AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
60 SyncMessageEvent, SyncStateEvent,
64 AnySyncStateEvent, SyncStateEvent,
6165 },
6266 identifiers::{EventId, RoomAliasId, RoomId, UserId},
6367 uuid::Uuid,
@@ -878,6 +882,9 @@ impl MatrixRoom {
878882 event_id: event_id.clone(),
879883 content,
880884 unsigned: Default::default(),
885 // TODO this is our own message, we're trusting it, set a trust
886 // state if the room is encrypted.
887 encryption_info: None,
881888 };
882889
883890 let event = AnySyncMessageEvent::RoomMessage(event);
@@ -1005,6 +1012,11 @@ impl MatrixRoom {
10051012 }
10061013 }
10071014
1015 Weechat::print(&format!(
1016 "HELLO VERIFIED {:#?}",
1017 event.encryption_info()
1018 ));
1019
10081020 if let AnySyncMessageEvent::RoomRedaction(r) = event {
10091021 self.redact_event(r).await;
10101022 } else if event.is_edit() {
src/server.rs +71 −46
@@ -69,12 +69,11 @@ use url::Url;
6969use matrix_sdk::{
7070 self,
7171 api::r0::session::login::Response as LoginResponse,
72 deserialized_responses::AmbiguityChange,
72 deserialized_responses::{events::AnySyncRoomEvent, AmbiguityChange},
7373 events::{
74 room::member::MemberEventContent, AnySyncRoomEvent, AnySyncStateEvent,
75 SyncStateEvent,
74 room::member::MemberEventContent, AnySyncStateEvent, SyncStateEvent,
7675 },
77 identifiers::{DeviceIdBox, RoomId, UserId},
76 identifiers::{DeviceIdBox, DeviceKeyAlgorithm, RoomId, UserId},
7877 Client, ClientConfig, JoinedRoom,
7978};
8079
@@ -901,52 +900,78 @@ impl InnerServer {
901900
902901 response.devices.sort_by_key(|d| Reverse(d.last_seen_ts));
903902 let own_device_id = c.client().device_id().await;
903 let own_user_id = c.client().user_id().await.unwrap();
904904
905 let lines: Vec<String> = response
906 .devices
907 .iter()
908 .map(|d| {
909 let device_color = Weechat::info_get(
910 "nick_color_name",
911 d.device_id.as_str(),
912 )
913 .expect("Can't get device color");
914
915 let last_seen_date =
916 d.last_seen_ts.map_or("?".to_owned(), |d| {
917 let date: DateTime<Utc> = d.into();
918 date.format("%Y/%m/%d %H:%M").to_string()
919 });
920
921 let last_seen = format!(
922 "{} @ {}",
923 d.last_seen_ip.as_deref().unwrap_or("-"),
924 last_seen_date
925 );
905 let mut lines: Vec<String> = Vec::new();
926906
927 let (bold, color) = if own_device_id
928 .as_ref()
929 .map(|o| o == &d.device_id)
930 .unwrap_or(false)
931 {
932 (Weechat::color("bold"), format!("*{}", device_color))
933 } else {
934 ("", device_color)
935 };
907 for device_info in response.devices {
908 let device_color = Weechat::info_get(
909 "nick_color_name",
910 device_info.device_id.as_str(),
911 )
912 .expect("Can't get device color");
913
914 let last_seen_date =
915 device_info.last_seen_ts.map_or("?".to_owned(), |d| {
916 let date: DateTime<Utc> = d.into();
917 date.format("%Y/%m/%d %H:%M").to_string()
918 });
919
920 let last_seen = format!(
921 "{} @ {}",
922 device_info.last_seen_ip.as_deref().unwrap_or("-"),
923 last_seen_date
924 );
925
926 let (bold, color) = if own_device_id
927 .as_ref()
928 .map(|o| o == &device_info.device_id)
929 .unwrap_or(false)
930 {
931 (Weechat::color("bold"), format!("*{}", device_color))
932 } else {
933 ("", device_color)
934 };
936935
937 format!(
938 " {}{:<15}{}{}{:<30}{:<}",
939 Weechat::color(&color),
940 d.device_id.as_str(),
941 Weechat::color("reset"),
942 bold,
943 d.display_name.as_deref().unwrap_or(""),
944 last_seen,
945 )
946 })
947 .collect();
936 let fingerprint = c
937 .client()
938 .get_device(&own_user_id, &device_info.device_id)
939 .await
940 .unwrap()
941 .map(|d| d.get_key(DeviceKeyAlgorithm::Ed25519).cloned())
942 .flatten()
943 .unwrap_or("-".to_owned());
944
945 let info = format!(
946 "Device: {}{}{}\n \
947 Name: {}{}\n \
948 Fingerprint: {}{}\n",
949 Weechat::color(&color),
950 device_info.device_id.as_str(),
951 Weechat::color("reset"),
952 bold,
953 device_info.display_name.as_deref().unwrap_or(""),
954 Weechat::color("magenta"),
955 fingerprint,
956 );
957
958 // let info = format!(
959 // " Device: {}{:<15}{}{}{:<30}{:<}\n \
960 // Fingerprint: {}{}",
961 // Weechat::color(&color),
962 // device_info.device_id.as_str(),
963 // Weechat::color("reset"),
964 // bold,
965 // device_info.display_name.as_deref().unwrap_or(""),
966 // last_seen,
967 // Weechat::color("magenta"),
968 // fingerprint,
969 // );
970
971 lines.push(info);
972 }
948973
949 let line = lines.join("\n");
974 let line = lines.join("\n\n");
950975 self.print(&line);
951976 };
952977 }
src/utils.rs +2 −1
@@ -1,10 +1,11 @@
11use matrix_sdk::{
2 deserialized_responses::events::AnySyncMessageEvent,
23 events::{
34 room::message::{
45 MessageEventContent, NoticeMessageEventContent, Relation,
56 TextMessageEventContent,
67 },
7 AnyMessageEvent, AnySyncMessageEvent,
8 AnyMessageEvent,
89 },
910 identifiers::EventId,
1011};