Commit eaa25fa955
Unsigned
Layout: unified · split
src/render.rs +37 −23
| @@ -1,7 +1,7 @@ | |||
| 1 | use url::Url; | 1 | use url::Url; |
| 2 | 2 | ||
| 3 | use matrix_sdk::{ | 3 | use matrix_sdk::{ |
| 4 | encryption::verification::{SasVerification, Verification}, | 4 | encryption::verification::{format_emojis, SasVerification, Verification}, |
| 5 | ruma::{ | 5 | ruma::{ |
| 6 | events::{ | 6 | events::{ |
| 7 | key::verification::{ | 7 | key::verification::{ |
| @@ -598,8 +598,8 @@ macro_rules! render_start_content { | |||
| 598 | } else { | 598 | } else { |
| 599 | if sas.started_from_request() { | 599 | if sas.started_from_request() { |
| 600 | format!( | 600 | format!( |
| 601 | "{} has started an interactive emoji verifiaction \ | 601 | "{} has started an interactive emoji verification \ |
| 602 | with you, accept with TODO", | 602 | with you, waiting for emojis", |
| 603 | sas.other_device().user_id() | 603 | sas.other_device().user_id() |
| 604 | ) | 604 | ) |
| 605 | } else { | 605 | } else { |
| @@ -640,7 +640,10 @@ render_start_content!(KeyVerificationStartEventContent); | |||
| 640 | render_start_content!(ToDeviceKeyVerificationStartEventContent); | 640 | render_start_content!(ToDeviceKeyVerificationStartEventContent); |
| 641 | 641 | ||
| 642 | pub enum VerificationContext { | 642 | pub enum VerificationContext { |
| 643 | Room(WeechatRoomMember, WeechatRoomMember), | 643 | Room { |
| 644 | own_member: WeechatRoomMember, | ||
| 645 | sender: WeechatRoomMember, | ||
| 646 | }, | ||
| 644 | ToDevice, | 647 | ToDevice, |
| 645 | } | 648 | } |
| 646 | 649 | ||
| @@ -657,7 +660,7 @@ macro_rules! render_request_content { | |||
| 657 | 660 | ||
| 658 | fn render(&self, context: &Self::RenderContext) -> RenderedContent { | 661 | fn render(&self, context: &Self::RenderContext) -> RenderedContent { |
| 659 | let message = match context { | 662 | let message = match context { |
| 660 | VerificationContext::Room(own_member, sender) => { | 663 | VerificationContext::Room { own_member, sender } => { |
| 661 | if own_member == sender { | 664 | if own_member == sender { |
| 662 | "You sent a verification request".to_string() | 665 | "You sent a verification request".to_string() |
| 663 | } else { | 666 | } else { |
| @@ -723,6 +726,23 @@ macro_rules! render_ready_content { | |||
| 723 | render_ready_content!(KeyVerificationReadyEventContent); | 726 | render_ready_content!(KeyVerificationReadyEventContent); |
| 724 | render_ready_content!(ToDeviceKeyVerificationReadyEventContent); | 727 | render_ready_content!(ToDeviceKeyVerificationReadyEventContent); |
| 725 | 728 | ||
| 729 | fn render_sas_short_auth_string(sas: &SasVerification) -> Vec<String> { | ||
| 730 | if sas.supports_emoji() { | ||
| 731 | if let Some(emojis) = sas.emoji() { | ||
| 732 | return format_emojis(emojis) | ||
| 733 | .lines() | ||
| 734 | .map(ToOwned::to_owned) | ||
| 735 | .collect(); | ||
| 736 | } | ||
| 737 | } | ||
| 738 | |||
| 739 | if let Some((first, second, third)) = sas.decimals() { | ||
| 740 | return vec![format!("{first:04} {second:04} {third:04}")]; | ||
| 741 | } | ||
| 742 | |||
| 743 | vec!["Short authentication string is not ready yet".to_owned()] | ||
| 744 | } | ||
| 745 | |||
| 726 | macro_rules! render_key_content { | 746 | macro_rules! render_key_content { |
| 727 | ($type: ident) => { | 747 | ($type: ident) => { |
| 728 | impl Render for $type { | 748 | impl Render for $type { |
| @@ -735,29 +755,23 @@ macro_rules! render_key_content { | |||
| 735 | 755 | ||
| 736 | fn render(&self, sas: &Self::RenderContext) -> RenderedContent { | 756 | fn render(&self, sas: &Self::RenderContext) -> RenderedContent { |
| 737 | let (message, short_auth_string) = if sas.supports_emoji() { | 757 | let (message, short_auth_string) = if sas.supports_emoji() { |
| 738 | ( | 758 | ("Do the emojis match?", render_sas_short_auth_string(sas)) |
| 739 | "Do the emojis match?".to_string(), | ||
| 740 | format!("{:?}", sas.emoji()), | ||
| 741 | ) | ||
| 742 | } else { | 759 | } else { |
| 743 | ( | 760 | ( |
| 744 | "Do the decimals match".to_string(), | 761 | "Do the decimals match?", |
| 745 | format!("{:?}", sas.decimals()), | 762 | render_sas_short_auth_string(sas), |
| 746 | ) | 763 | ) |
| 747 | }; | 764 | }; |
| 748 | 765 | ||
| 749 | RenderedContent { | 766 | let lines = std::iter::once(message.to_owned()) |
| 750 | lines: vec![ | 767 | .chain(short_auth_string) |
| 751 | RenderedLine { | 768 | .map(|message| RenderedLine { |
| 752 | message, | 769 | message, |
| 753 | tags: self.tags(), | 770 | tags: self.tags(), |
| 754 | }, | 771 | }) |
| 755 | RenderedLine { | 772 | .collect(); |
| 756 | message: short_auth_string, | 773 | |
| 757 | tags: self.tags(), | 774 | RenderedContent { lines } |
| 758 | }, | ||
| 759 | ], | ||
| 760 | } | ||
| 761 | } | 775 | } |
| 762 | } | 776 | } |
| 763 | }; | 777 | }; |
src/room/verification.rs +1 −1
| @@ -204,7 +204,7 @@ impl Verification { | |||
| 204 | send_time, | 204 | send_time, |
| 205 | &e.event_id, | 205 | &e.event_id, |
| 206 | &sender.clone(), | 206 | &sender.clone(), |
| 207 | &VerificationContext::Room(sender, own_member), | 207 | &VerificationContext::Room { own_member, sender }, |
| 208 | ); | 208 | ); |
| 209 | self.buffer.print_rendered_event(rendered); | 209 | self.buffer.print_rendered_event(rendered); |
| 210 | 210 | ||