Commit 01e3a863fd
Unsigned
Layout: unified · split
src/server.rs +37 −37
| @@ -55,7 +55,6 @@ | |||
| 55 | //! that processing events will not block the Weechat mainloop for too long. | 55 | //! that processing events will not block the Weechat mainloop for too long. |
| 56 | 56 | ||
| 57 | use chrono::{offset::Utc, DateTime}; | 57 | use chrono::{offset::Utc, DateTime}; |
| 58 | use indoc::indoc; | ||
| 59 | use std::{ | 58 | use std::{ |
| 60 | cell::{Ref, RefCell, RefMut}, | 59 | cell::{Ref, RefCell, RefMut}, |
| 61 | cmp::Reverse, | 60 | cmp::Reverse, |
| @@ -889,12 +888,7 @@ impl InnerServer { | |||
| 889 | } | 888 | } |
| 890 | 889 | ||
| 891 | self.print_network(&format!( | 890 | self.print_network(&format!( |
| 892 | indoc!( | 891 | "Devices for server {}{}{}:", |
| 893 | " | ||
| 894 | Devices for server {}{}{}: | ||
| 895 | Device ID Device name Last seen | ||
| 896 | " | ||
| 897 | ), | ||
| 898 | Weechat::color("chat_server"), | 892 | Weechat::color("chat_server"), |
| 899 | self.name(), | 893 | self.name(), |
| 900 | Weechat::color("reset") | 894 | Weechat::color("reset") |
| @@ -925,55 +919,61 @@ impl InnerServer { | |||
| 925 | last_seen_date | 919 | last_seen_date |
| 926 | ); | 920 | ); |
| 927 | 921 | ||
| 928 | let (bold, color) = if own_device_id | 922 | let is_own_device = own_device_id |
| 929 | .as_ref() | 923 | .as_ref() |
| 930 | .map(|o| o == &device_info.device_id) | 924 | .map(|o| o == &device_info.device_id) |
| 931 | .unwrap_or(false) | 925 | .unwrap_or(false); |
| 932 | { | 926 | |
| 927 | let (bold, color) = if is_own_device { | ||
| 933 | (Weechat::color("bold"), format!("*{}", device_color)) | 928 | (Weechat::color("bold"), format!("*{}", device_color)) |
| 934 | } else { | 929 | } else { |
| 935 | ("", device_color) | 930 | ("", device_color) |
| 936 | }; | 931 | }; |
| 937 | 932 | ||
| 938 | let fingerprint = c | 933 | let fingerprint = if is_own_device { |
| 939 | .client() | 934 | // TODO we need to be able to fetch this |
| 940 | .get_device(&own_user_id, &device_info.device_id) | 935 | "TODO".to_owned() |
| 941 | .await | 936 | } else { |
| 942 | .unwrap() | 937 | c.client() |
| 943 | .map(|d| d.get_key(DeviceKeyAlgorithm::Ed25519).cloned()) | 938 | .get_device(&own_user_id, &device_info.device_id) |
| 944 | .flatten() | 939 | .await |
| 945 | .unwrap_or("-".to_owned()); | 940 | .unwrap() |
| 941 | .map(|d| { | ||
| 942 | d.get_key(DeviceKeyAlgorithm::Ed25519).cloned() | ||
| 943 | }) | ||
| 944 | .flatten() | ||
| 945 | .unwrap_or("-".to_owned()) | ||
| 946 | }; | ||
| 947 | |||
| 948 | let fingerprint = fingerprint | ||
| 949 | .chars() | ||
| 950 | .collect::<Vec<char>>() | ||
| 951 | .chunks(4) | ||
| 952 | .map(|c| c.iter().collect::<String>()) | ||
| 953 | .collect::<Vec<String>>() | ||
| 954 | .join(" "); | ||
| 946 | 955 | ||
| 947 | let info = format!( | 956 | let info = format!( |
| 948 | "Device: {}{}{}\n \ | 957 | " \ |
| 949 | Name: {}{}\n \ | 958 | Name: {}{}\n \ |
| 950 | Fingerprint: {}{}\n", | 959 | Device ID: {}{}{}\n \ |
| 960 | Last seen: {}\n\ | ||
| 961 | Fingerprint: {}{}{}\n", | ||
| 962 | bold, | ||
| 963 | device_info.display_name.as_deref().unwrap_or(""), | ||
| 951 | Weechat::color(&color), | 964 | Weechat::color(&color), |
| 952 | device_info.device_id.as_str(), | 965 | device_info.device_id.as_str(), |
| 953 | Weechat::color("reset"), | 966 | Weechat::color("reset"), |
| 954 | bold, | 967 | last_seen, |
| 955 | device_info.display_name.as_deref().unwrap_or(""), | ||
| 956 | Weechat::color("magenta"), | 968 | Weechat::color("magenta"), |
| 957 | fingerprint, | 969 | fingerprint, |
| 970 | Weechat::color("reset"), | ||
| 958 | ); | 971 | ); |
| 959 | 972 | ||
| 960 | // let info = format!( | ||
| 961 | // " Device: {}{:<15}{}{}{:<30}{:<}\n \ | ||
| 962 | // Fingerprint: {}{}", | ||
| 963 | // Weechat::color(&color), | ||
| 964 | // device_info.device_id.as_str(), | ||
| 965 | // Weechat::color("reset"), | ||
| 966 | // bold, | ||
| 967 | // device_info.display_name.as_deref().unwrap_or(""), | ||
| 968 | // last_seen, | ||
| 969 | // Weechat::color("magenta"), | ||
| 970 | // fingerprint, | ||
| 971 | // ); | ||
| 972 | |||
| 973 | lines.push(info); | 973 | lines.push(info); |
| 974 | } | 974 | } |
| 975 | 975 | ||
| 976 | let line = lines.join("\n\n"); | 976 | let line = lines.join("\n"); |
| 977 | self.print(&line); | 977 | self.print(&line); |
| 978 | }; | 978 | }; |
| 979 | } | 979 | } |