Commit eaa25fa955

eaa25fa95554a02c65b9a8012df55e8b8dfa346c

parent: 6aead2bc6d

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-23 22:07 UTC
committer: <strk@kbt.io>

fix: render in-room SAS verification clearly

Layout: unified · split

src/render.rs +37 −23
@@ -1,7 +1,7 @@
11use url::Url;
22
33use matrix_sdk::{
4 encryption::verification::{SasVerification, Verification},
4 encryption::verification::{format_emojis, SasVerification, Verification},
55 ruma::{
66 events::{
77 key::verification::{
@@ -598,8 +598,8 @@ macro_rules! render_start_content {
598598 } else {
599599 if sas.started_from_request() {
600600 format!(
601 "{} has started an interactive emoji verifiaction \
602 with you, accept with TODO",
601 "{} has started an interactive emoji verification \
602 with you, waiting for emojis",
603603 sas.other_device().user_id()
604604 )
605605 } else {
@@ -640,7 +640,10 @@ render_start_content!(KeyVerificationStartEventContent);
640640render_start_content!(ToDeviceKeyVerificationStartEventContent);
641641
642642pub enum VerificationContext {
643 Room(WeechatRoomMember, WeechatRoomMember),
643 Room {
644 own_member: WeechatRoomMember,
645 sender: WeechatRoomMember,
646 },
644647 ToDevice,
645648}
646649
@@ -657,7 +660,7 @@ macro_rules! render_request_content {
657660
658661 fn render(&self, context: &Self::RenderContext) -> RenderedContent {
659662 let message = match context {
660 VerificationContext::Room(own_member, sender) => {
663 VerificationContext::Room { own_member, sender } => {
661664 if own_member == sender {
662665 "You sent a verification request".to_string()
663666 } else {
@@ -723,6 +726,23 @@ macro_rules! render_ready_content {
723726render_ready_content!(KeyVerificationReadyEventContent);
724727render_ready_content!(ToDeviceKeyVerificationReadyEventContent);
725728
729fn 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
726746macro_rules! render_key_content {
727747 ($type: ident) => {
728748 impl Render for $type {
@@ -735,29 +755,23 @@ macro_rules! render_key_content {
735755
736756 fn render(&self, sas: &Self::RenderContext) -> RenderedContent {
737757 let (message, short_auth_string) = if sas.supports_emoji() {
738 (
739 "Do the emojis match?".to_string(),
740 format!("{:?}", sas.emoji()),
741 )
758 ("Do the emojis match?", render_sas_short_auth_string(sas))
742759 } else {
743760 (
744 "Do the decimals match".to_string(),
745 format!("{:?}", sas.decimals()),
761 "Do the decimals match?",
762 render_sas_short_auth_string(sas),
746763 )
747764 };
748765
749 RenderedContent {
750 lines: vec![
751 RenderedLine {
752 message,
753 tags: self.tags(),
754 },
755 RenderedLine {
756 message: short_auth_string,
757 tags: self.tags(),
758 },
759 ],
760 }
766 let lines = std::iter::once(message.to_owned())
767 .chain(short_auth_string)
768 .map(|message| RenderedLine {
769 message,
770 tags: self.tags(),
771 })
772 .collect();
773
774 RenderedContent { lines }
761775 }
762776 }
763777 };
src/room/verification.rs +1 −1
@@ -204,7 +204,7 @@ impl Verification {
204204 send_time,
205205 &e.event_id,
206206 &sender.clone(),
207 &VerificationContext::Room(sender, own_member),
207 &VerificationContext::Room { own_member, sender },
208208 );
209209 self.buffer.print_rendered_event(rendered);
210210