Commit efc6555036
efc6555036d9bb99fdf877cd63fc10eaac913f0a
parent: e21e74f813
Unsigned
Damir Jelić <poljar@termina.org.uk> · 2021-01-23 15:04 UTC
server: Sort the device list and bold our own device
Layout: unified · split
Cargo.lock
+4 −4
| @@ -1058,7 +1058,7 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" |
| 1058 | 1058 | [[package]] |
| 1059 | 1059 | name = "matrix-sdk" |
| 1060 | 1060 | version = "0.2.0" |
| 1061 | | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377" |
| 1061 | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f" |
| 1062 | 1062 | dependencies = [ |
| 1063 | 1063 | "dashmap", |
| 1064 | 1064 | "futures", |
| @@ -1080,7 +1080,7 @@ dependencies = [ |
| 1080 | 1080 | [[package]] |
| 1081 | 1081 | name = "matrix-sdk-base" |
| 1082 | 1082 | version = "0.2.0" |
| 1083 | | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377" |
| 1083 | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f" |
| 1084 | 1084 | dependencies = [ |
| 1085 | 1085 | "chacha20poly1305", |
| 1086 | 1086 | "dashmap", |
| @@ -1103,7 +1103,7 @@ dependencies = [ |
| 1103 | 1103 | [[package]] |
| 1104 | 1104 | name = "matrix-sdk-common" |
| 1105 | 1105 | version = "0.2.0" |
| 1106 | | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377" |
| 1106 | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f" |
| 1107 | 1107 | dependencies = [ |
| 1108 | 1108 | "async-trait", |
| 1109 | 1109 | "futures-locks", |
| @@ -1117,7 +1117,7 @@ dependencies = [ |
| 1117 | 1117 | [[package]] |
| 1118 | 1118 | name = "matrix-sdk-crypto" |
| 1119 | 1119 | version = "0.2.0" |
| 1120 | | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377" |
| 1120 | source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f" |
| 1121 | 1121 | dependencies = [ |
| 1122 | 1122 | "aes-ctr", |
| 1123 | 1123 | "aes-gcm", |
src/connection.rs
+2 −2
| @@ -108,8 +108,8 @@ pub struct Connection { |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | impl Connection { |
| 111 | | pub fn client(&self) -> Client { |
| 112 | | self.client.clone() |
| 111 | pub fn client(&self) -> &Client { |
| 112 | &self.client |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | pub async fn spawn<F>(&self, future: F) -> F::Output |
src/server.rs
+18 −3
| @@ -58,6 +58,7 @@ use chrono::{offset::Utc, DateTime}; |
| 58 | 58 | use indoc::indoc; |
| 59 | 59 | use std::{ |
| 60 | 60 | cell::{Ref, RefCell, RefMut}, |
| 61 | cmp::Reverse, |
| 61 | 62 | collections::HashMap, |
| 62 | 63 | path::PathBuf, |
| 63 | 64 | rc::{Rc, Weak}, |
| @@ -325,7 +326,7 @@ impl MatrixServer { |
| 325 | 326 | |
| 326 | 327 | pub async fn devices(&self) { |
| 327 | 328 | if let Some(c) = self.connection() { |
| 328 | | let response = match c.devices().await { |
| 329 | let mut response = match c.devices().await { |
| 329 | 330 | Ok(r) => r, |
| 330 | 331 | Err(e) => { |
| 331 | 332 | self.print_error(&format!( |
| @@ -353,6 +354,9 @@ impl MatrixServer { |
| 353 | 354 | Weechat::color("reset") |
| 354 | 355 | )); |
| 355 | 356 | |
| 357 | response.devices.sort_by_key(|d| Reverse(d.last_seen_ts)); |
| 358 | let own_device_id = c.client().device_id().await; |
| 359 | |
| 356 | 360 | let lines: Vec<String> = response |
| 357 | 361 | .devices |
| 358 | 362 | .iter() |
| @@ -375,11 +379,22 @@ impl MatrixServer { |
| 375 | 379 | last_seen_date |
| 376 | 380 | ); |
| 377 | 381 | |
| 382 | let (bold, color) = if own_device_id |
| 383 | .as_ref() |
| 384 | .map(|o| o == &d.device_id) |
| 385 | .unwrap_or(false) |
| 386 | { |
| 387 | (Weechat::color("bold"), format!("*{}", device_color)) |
| 388 | } else { |
| 389 | ("", device_color) |
| 390 | }; |
| 391 | |
| 378 | 392 | format!( |
| 379 | | " {}{:<15}{}{:<30}{:<}", |
| 380 | | Weechat::color(&device_color), |
| 393 | " {}{:<15}{}{}{:<30}{:<}", |
| 394 | Weechat::color(&color), |
| 381 | 395 | d.device_id.as_str(), |
| 382 | 396 | Weechat::color("reset"), |
| 397 | bold, |
| 383 | 398 | d.display_name.as_deref().unwrap_or(""), |
| 384 | 399 | last_seen, |
| 385 | 400 | ) |