Commit d00ecd4d6b
Unsigned
Layout: unified · split
src/server.rs +76 −15
| @@ -874,6 +874,12 @@ impl InnerServer { | |||
| 874 | } | 874 | } |
| 875 | 875 | ||
| 876 | pub async fn devices(&self) { | 876 | pub async fn devices(&self) { |
| 877 | enum DeviceTrust { | ||
| 878 | Verified, | ||
| 879 | Unverified, | ||
| 880 | Unsupported, | ||
| 881 | } | ||
| 882 | |||
| 877 | if let Some(c) = self.connection() { | 883 | if let Some(c) = self.connection() { |
| 878 | let mut response = match c.devices().await { | 884 | let mut response = match c.devices().await { |
| 879 | Ok(r) => r, | 885 | Ok(r) => r, |
| @@ -949,32 +955,87 @@ impl InnerServer { | |||
| 949 | d.get_key(DeviceKeyAlgorithm::Ed25519).cloned() | 955 | d.get_key(DeviceKeyAlgorithm::Ed25519).cloned() |
| 950 | }) | 956 | }) |
| 951 | .flatten() | 957 | .flatten() |
| 952 | } | 958 | }; |
| 953 | .unwrap_or_else(|| "-".to_owned()); | 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 | 1001 | let fingerprint = if let Some(fingerprint) = fingerprint { |
| 956 | .chars() | 1002 | let fingerprint = fingerprint |
| 957 | .collect::<Vec<char>>() | 1003 | .chars() |
| 958 | .chunks(4) | 1004 | .collect::<Vec<char>>() |
| 959 | .map(|c| c.iter().collect::<String>()) | 1005 | .chunks(4) |
| 960 | .collect::<Vec<String>>() | 1006 | .map(|c| c.iter().collect::<String>()) |
| 961 | .join(" "); | 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 | let info = format!( | 1024 | let info = format!( |
| 964 | " \ | 1025 | " \ |
| 965 | Name: {}{}\n \ | 1026 | Name: {}{}\n \ |
| 966 | Device ID: {}{}{}\n \ | 1027 | Device ID: {}{}{}\n \ |
| 967 | Last seen: {}\n\ | 1028 | Security: {}\n\ |
| 968 | Fingerprint: {}{}{}\n", | 1029 | Fingerprint: {}\n \ |
| 1030 | Last seen: {}\n", | ||
| 969 | bold, | 1031 | bold, |
| 970 | device_info.display_name.as_deref().unwrap_or(""), | 1032 | device_info.display_name.as_deref().unwrap_or(""), |
| 971 | Weechat::color(&color), | 1033 | Weechat::color(&color), |
| 972 | device_info.device_id.as_str(), | 1034 | device_info.device_id.as_str(), |
| 973 | Weechat::color("reset"), | 1035 | Weechat::color("reset"), |
| 974 | last_seen, | 1036 | verified, |
| 975 | Weechat::color("magenta"), | ||
| 976 | fingerprint, | 1037 | fingerprint, |
| 977 | Weechat::color("reset"), | 1038 | last_seen, |
| 978 | ); | 1039 | ); |
| 979 | 1040 | ||
| 980 | lines.push(info); | 1041 | lines.push(info); |