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 | [[package]] |
1058 | [[package]] |
| 1059 | name = "matrix-sdk" |
1059 | name = "matrix-sdk" |
| 1060 | version = "0.2.0" |
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 | dependencies = [ |
1062 | dependencies = [ |
| 1063 | "dashmap", |
1063 | "dashmap", |
| 1064 | "futures", |
1064 | "futures", |
| @@ -1080,7 +1080,7 @@ dependencies = [ |
| 1080 | [[package]] |
1080 | [[package]] |
| 1081 | name = "matrix-sdk-base" |
1081 | name = "matrix-sdk-base" |
| 1082 | version = "0.2.0" |
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 | dependencies = [ |
1084 | dependencies = [ |
| 1085 | "chacha20poly1305", |
1085 | "chacha20poly1305", |
| 1086 | "dashmap", |
1086 | "dashmap", |
| @@ -1103,7 +1103,7 @@ dependencies = [ |
| 1103 | [[package]] |
1103 | [[package]] |
| 1104 | name = "matrix-sdk-common" |
1104 | name = "matrix-sdk-common" |
| 1105 | version = "0.2.0" |
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 | dependencies = [ |
1107 | dependencies = [ |
| 1108 | "async-trait", |
1108 | "async-trait", |
| 1109 | "futures-locks", |
1109 | "futures-locks", |
| @@ -1117,7 +1117,7 @@ dependencies = [ |
| 1117 | [[package]] |
1117 | [[package]] |
| 1118 | name = "matrix-sdk-crypto" |
1118 | name = "matrix-sdk-crypto" |
| 1119 | version = "0.2.0" |
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 | dependencies = [ |
1121 | dependencies = [ |
| 1122 | "aes-ctr", |
1122 | "aes-ctr", |
| 1123 | "aes-gcm", |
1123 | "aes-gcm", |
src/connection.rs
+2 −2
| @@ -108,8 +108,8 @@ pub struct Connection { |
| 108 | } |
108 | } |
| 109 | |
109 | |
| 110 | impl Connection { |
110 | impl Connection { |
| 111 | pub fn client(&self) -> Client { |
111 | pub fn client(&self) -> &Client { |
| 112 | self.client.clone() |
112 | &self.client |
| 113 | } |
113 | } |
| 114 | |
114 | |
| 115 | pub async fn spawn<F>(&self, future: F) -> F::Output |
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 | use indoc::indoc; |
58 | use indoc::indoc; |
| 59 | use std::{ |
59 | use std::{ |
| 60 | cell::{Ref, RefCell, RefMut}, |
60 | cell::{Ref, RefCell, RefMut}, |
| |
61 | cmp::Reverse, |
| 61 | collections::HashMap, |
62 | collections::HashMap, |
| 62 | path::PathBuf, |
63 | path::PathBuf, |
| 63 | rc::{Rc, Weak}, |
64 | rc::{Rc, Weak}, |
| @@ -325,7 +326,7 @@ impl MatrixServer { |
| 325 | |
326 | |
| 326 | pub async fn devices(&self) { |
327 | pub async fn devices(&self) { |
| 327 | if let Some(c) = self.connection() { |
328 | if let Some(c) = self.connection() { |
| 328 | let response = match c.devices().await { |
329 | let mut response = match c.devices().await { |
| 329 | Ok(r) => r, |
330 | Ok(r) => r, |
| 330 | Err(e) => { |
331 | Err(e) => { |
| 331 | self.print_error(&format!( |
332 | self.print_error(&format!( |
| @@ -353,6 +354,9 @@ impl MatrixServer { |
| 353 | Weechat::color("reset") |
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 | let lines: Vec<String> = response |
360 | let lines: Vec<String> = response |
| 357 | .devices |
361 | .devices |
| 358 | .iter() |
362 | .iter() |
| @@ -375,11 +379,22 @@ impl MatrixServer { |
| 375 | last_seen_date |
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 | format!( |
392 | format!( |
| 379 | " {}{:<15}{}{:<30}{:<}", |
393 | " {}{:<15}{}{}{:<30}{:<}", |
| 380 | Weechat::color(&device_color), |
394 | Weechat::color(&color), |
| 381 | d.device_id.as_str(), |
395 | d.device_id.as_str(), |
| 382 | Weechat::color("reset"), |
396 | Weechat::color("reset"), |
| |
397 | bold, |
| 383 | d.display_name.as_deref().unwrap_or(""), |
398 | d.display_name.as_deref().unwrap_or(""), |
| 384 | last_seen, |
399 | last_seen, |
| 385 | ) |
400 | ) |