Commit d00ecd4d6b
Unsigned
Layout: unified · split
src/server.rs +76 −15
| @@ -874,6 +874,12 @@ impl InnerServer { | ||
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | pub async fn devices(&self) { |
| 877 | enum DeviceTrust { | |
| 878 | Verified, | |
| 879 | Unverified, | |
| 880 | Unsupported, | |
| 881 | } | |
| 882 | ||
| 877 | 883 | if let Some(c) = self.connection() { |
| 878 | 884 | let mut response = match c.devices().await { |
| 879 | 885 | Ok(r) => r, |
| @@ -949,32 +955,87 @@ impl InnerServer { | ||
| 949 | 955 | d.get_key(DeviceKeyAlgorithm::Ed25519).cloned() |
| 950 | 956 | }) |
| 951 | 957 | .flatten() |
| 952 | } | |
| 953 | .unwrap_or_else(|| "-".to_owned()); | |
| 958 | }; | |
| 959 | ||
| 960 | let verified = if is_own_device { | |
| 961 | DeviceTrust::Verified | |
| 962 | } else { | |
| 963 | c.client() | |
| 964 | .get_device(&own_user_id, &device_info.device_id) | |
| 965 | .await | |
| 966 | .unwrap() | |
| 967 | .map(|d| { | |
| 968 | if d.is_trusted() { | |
| 969 | DeviceTrust::Verified | |
| 970 | } else { | |
| 971 | DeviceTrust::Unverified | |
| 972 | } | |
| 973 | }) | |
| 974 | .unwrap_or(DeviceTrust::Unsupported) | |
| 975 | }; | |
| 976 | ||
| 977 | let verified = match verified { | |
| 978 | DeviceTrust::Verified => { | |
| 979 | format!( | |
| 980 | "{}Trusted{}", | |
| 981 | Weechat::color("green"), | |
| 982 | Weechat::color("reset") | |
| 983 | ) | |
| 984 | } | |
| 985 | DeviceTrust::Unverified => { | |
| 986 | format!( | |
| 987 | "{}Not trusted{}", | |
| 988 | Weechat::color("red"), | |
| 989 | Weechat::color("reset") | |
| 990 | ) | |
| 991 | } | |
| 992 | DeviceTrust::Unsupported => { | |
| 993 | format!( | |
| 994 | "{}No encryption support{}", | |
| 995 | Weechat::color("darkgray"), | |
| 996 | Weechat::color("reset") | |
| 997 | ) | |
| 998 | } | |
| 999 | }; | |
| 954 | 1000 | |
| 955 | let fingerprint = fingerprint | |
| 956 | .chars() | |
| 957 | .collect::<Vec<char>>() | |
| 958 | .chunks(4) | |
| 959 | .map(|c| c.iter().collect::<String>()) | |
| 960 | .collect::<Vec<String>>() | |
| 961 | .join(" "); | |
| 1001 | let fingerprint = if let Some(fingerprint) = fingerprint { | |
| 1002 | let fingerprint = fingerprint | |
| 1003 | .chars() | |
| 1004 | .collect::<Vec<char>>() | |
| 1005 | .chunks(4) | |
| 1006 | .map(|c| c.iter().collect::<String>()) | |
| 1007 | .collect::<Vec<String>>() | |
| 1008 | .join(" "); | |
| 1009 | ||
| 1010 | format!( | |
| 1011 | "{}{}{}", | |
| 1012 | Weechat::color("magenta"), | |
| 1013 | fingerprint, | |
| 1014 | Weechat::color("reset") | |
| 1015 | ) | |
| 1016 | } else { | |
| 1017 | format!( | |
| 1018 | "{}-{}", | |
| 1019 | Weechat::color("darkgray"), | |
| 1020 | Weechat::color("reset") | |
| 1021 | ) | |
| 1022 | }; | |
| 962 | 1023 | |
| 963 | 1024 | let info = format!( |
| 964 | 1025 | " \ |
| 965 | 1026 | Name: {}{}\n \ |
| 966 | Device ID: {}{}{}\n \ | |
| 967 | Last seen: {}\n\ | |
| 968 | Fingerprint: {}{}{}\n", | |
| 1027 | Device ID: {}{}{}\n \ | |
| 1028 | Security: {}\n\ | |
| 1029 | Fingerprint: {}\n \ | |
| 1030 | Last seen: {}\n", | |
| 969 | 1031 | bold, |
| 970 | 1032 | device_info.display_name.as_deref().unwrap_or(""), |
| 971 | 1033 | Weechat::color(&color), |
| 972 | 1034 | device_info.device_id.as_str(), |
| 973 | 1035 | Weechat::color("reset"), |
| 974 | last_seen, | |
| 975 | Weechat::color("magenta"), | |
| 1036 | verified, | |
| 976 | 1037 | fingerprint, |
| 977 | Weechat::color("reset"), | |
| 1038 | last_seen, | |
| 978 | 1039 | ); |
| 979 | 1040 | |
| 980 | 1041 | lines.push(info); |