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