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"
10581058[[package]]
10591059name = "matrix-sdk"
10601060version = "0.2.0"
1061source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377"
1061source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f"
10621062dependencies = [
10631063 "dashmap",
10641064 "futures",
@@ -1080,7 +1080,7 @@ dependencies = [
10801080[[package]]
10811081name = "matrix-sdk-base"
10821082version = "0.2.0"
1083source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377"
1083source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f"
10841084dependencies = [
10851085 "chacha20poly1305",
10861086 "dashmap",
@@ -1103,7 +1103,7 @@ dependencies = [
11031103[[package]]
11041104name = "matrix-sdk-common"
11051105version = "0.2.0"
1106source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377"
1106source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f"
11071107dependencies = [
11081108 "async-trait",
11091109 "futures-locks",
@@ -1117,7 +1117,7 @@ dependencies = [
11171117[[package]]
11181118name = "matrix-sdk-crypto"
11191119version = "0.2.0"
1120source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#c034de470b02fa9659f0d65c25579739b702e377"
1120source = "git+https://github.com/matrix-org/matrix-rust-sdk/?branch=new-state-store#44974982e12bb9da79062db84e1e5f882fb9873f"
11211121dependencies = [
11221122 "aes-ctr",
11231123 "aes-gcm",
src/connection.rs +2 −2
@@ -108,8 +108,8 @@ pub struct Connection {
108108}
109109
110110impl Connection {
111 pub fn client(&self) -> Client {
112 self.client.clone()
111 pub fn client(&self) -> &Client {
112 &self.client
113113 }
114114
115115 pub async fn spawn<F>(&self, future: F) -> F::Output
src/server.rs +18 −3
@@ -58,6 +58,7 @@ use chrono::{offset::Utc, DateTime};
5858use indoc::indoc;
5959use std::{
6060 cell::{Ref, RefCell, RefMut},
61 cmp::Reverse,
6162 collections::HashMap,
6263 path::PathBuf,
6364 rc::{Rc, Weak},
@@ -325,7 +326,7 @@ impl MatrixServer {
325326
326327 pub async fn devices(&self) {
327328 if let Some(c) = self.connection() {
328 let response = match c.devices().await {
329 let mut response = match c.devices().await {
329330 Ok(r) => r,
330331 Err(e) => {
331332 self.print_error(&format!(
@@ -353,6 +354,9 @@ impl MatrixServer {
353354 Weechat::color("reset")
354355 ));
355356
357 response.devices.sort_by_key(|d| Reverse(d.last_seen_ts));
358 let own_device_id = c.client().device_id().await;
359
356360 let lines: Vec<String> = response
357361 .devices
358362 .iter()
@@ -375,11 +379,22 @@ impl MatrixServer {
375379 last_seen_date
376380 );
377381
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
378392 format!(
379 " {}{:<15}{}{:<30}{:<}",
380 Weechat::color(&device_color),
393 " {}{:<15}{}{}{:<30}{:<}",
394 Weechat::color(&color),
381395 d.device_id.as_str(),
382396 Weechat::color("reset"),
397 bold,
383398 d.display_name.as_deref().unwrap_or(""),
384399 last_seen,
385400 )