Commit ef6b74a150
Unsigned
Layout: unified · split
src/render.rs +3 −51
| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | use url::Url; |
| 2 | 2 | |
| 3 | 3 | use matrix_sdk::{ |
| 4 | encryption::verification::{ | |
| 5 | SasVerification, Verification, VerificationRequest, | |
| 6 | }, | |
| 4 | encryption::verification::{SasVerification, Verification}, | |
| 7 | 5 | ruma::{ |
| 8 | 6 | events::{ |
| 9 | 7 | key::verification::{ |
| @@ -644,7 +642,7 @@ render_start_content!(ToDeviceKeyVerificationStartEventContent); | ||
| 644 | 642 | |
| 645 | 643 | pub enum VerificationContext { |
| 646 | 644 | Room(WeechatRoomMember, WeechatRoomMember), |
| 647 | ToDevice(VerificationRequest), | |
| 645 | ToDevice, | |
| 648 | 646 | } |
| 649 | 647 | |
| 650 | 648 | macro_rules! render_request_content { |
| @@ -670,7 +668,7 @@ macro_rules! render_request_content { | ||
| 670 | 668 | ) |
| 671 | 669 | } |
| 672 | 670 | } |
| 673 | VerificationContext::ToDevice(_) => { | |
| 671 | VerificationContext::ToDevice => { | |
| 674 | 672 | format!("You have requested this device to be verified") |
| 675 | 673 | } |
| 676 | 674 | }; |
| @@ -769,42 +767,9 @@ macro_rules! render_key_content { | ||
| 769 | 767 | render_key_content!(KeyVerificationKeyEventContent); |
| 770 | 768 | render_key_content!(ToDeviceKeyVerificationKeyEventContent); |
| 771 | 769 | |
| 772 | /// Trait for message event types that contain an optional formatted body. | |
| 773 | /// `resolve_body` will return the formatted body if present, else fallback to | |
| 774 | /// the regular body. | |
| 775 | trait HasFormattedBody { | |
| 776 | fn body(&self) -> &str; | |
| 777 | fn formatted_body(&self) -> Option<&str>; | |
| 778 | #[inline] | |
| 779 | fn resolve_body(&self) -> &str { | |
| 780 | self.formatted_body().unwrap_or_else(|| self.body()) | |
| 781 | } | |
| 782 | } | |
| 783 | ||
| 784 | // Repeating this for each event type would get boring fast so lets use a simple | |
| 785 | // macro to implement the trait for a struct that has a `body` and | |
| 786 | // `formatted_body` field | |
| 787 | macro_rules! has_formatted_body { | |
| 788 | ($content: ident) => { | |
| 789 | impl HasFormattedBody for $content { | |
| 790 | #[inline] | |
| 791 | fn body(&self) -> &str { | |
| 792 | &self.body | |
| 793 | } | |
| 794 | ||
| 795 | #[inline] | |
| 796 | fn formatted_body(&self) -> Option<&str> { | |
| 797 | self.formatted.as_ref().map(|f| f.body.as_ref()) | |
| 798 | } | |
| 799 | } | |
| 800 | }; | |
| 801 | } | |
| 802 | ||
| 803 | 770 | /// This trait is implemented for message types that can contain either an URL |
| 804 | 771 | /// or an encrypted file. One of these _must_ be present. |
| 805 | 772 | pub trait HasUrlOrFile { |
| 806 | fn url(&self) -> Option<&MxcUri>; | |
| 807 | ||
| 808 | 773 | fn body(&self) -> &str; |
| 809 | 774 | |
| 810 | 775 | #[inline] |
| @@ -829,14 +794,6 @@ macro_rules! has_url_or_file { | ||
| 829 | 794 | &self.body |
| 830 | 795 | } |
| 831 | 796 | |
| 832 | #[inline] | |
| 833 | fn url(&self) -> Option<&MxcUri> { | |
| 834 | match &self.source { | |
| 835 | MediaSource::Plain(url) => Some(url), | |
| 836 | _ => None, | |
| 837 | } | |
| 838 | } | |
| 839 | ||
| 840 | 797 | fn source(&self) -> &MediaSource { |
| 841 | 798 | &self.source |
| 842 | 799 | } |
| @@ -851,11 +808,6 @@ macro_rules! has_url_or_file { | ||
| 851 | 808 | }; |
| 852 | 809 | } |
| 853 | 810 | |
| 854 | // this actually implements the trait for different event types | |
| 855 | has_formatted_body!(EmoteMessageEventContent); | |
| 856 | has_formatted_body!(NoticeMessageEventContent); | |
| 857 | has_formatted_body!(TextMessageEventContent); | |
| 858 | ||
| 859 | 811 | has_url_or_file!(AudioMessageEventContent); |
| 860 | 812 | has_url_or_file!(FileMessageEventContent); |
| 861 | 813 | has_url_or_file!(ImageMessageEventContent); |
src/room/members.rs −4
| @@ -242,10 +242,6 @@ impl Members { | ||
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | fn room(&self) -> &Room { | |
| 246 | &self.room | |
| 247 | } | |
| 248 | ||
| 249 | 245 | pub fn mark_active( |
| 250 | 246 | &self, |
| 251 | 247 | user_id: &UserId, |
src/room/verification.rs +3 −3
| @@ -68,7 +68,7 @@ impl Verification { | ||
| 68 | 68 | if let Some(ActiveVerification::Sas(verification)) = |
| 69 | 69 | self.inner.borrow().clone() |
| 70 | 70 | { |
| 71 | let ret = | |
| 71 | let _ret = | |
| 72 | 72 | c.spawn(async move { verification.confirm().await }).await; |
| 73 | 73 | } |
| 74 | 74 | } |
| @@ -84,7 +84,7 @@ impl Verification { | ||
| 84 | 84 | { |
| 85 | 85 | let verification_clone = verification.clone(); |
| 86 | 86 | |
| 87 | let ret = c | |
| 87 | let _ret = c | |
| 88 | 88 | .spawn(async move { |
| 89 | 89 | verification |
| 90 | 90 | .accept_with_methods(vec![ |
| @@ -158,7 +158,7 @@ impl Verification { | ||
| 158 | 158 | |
| 159 | 159 | // We accept here automatically since the only method |
| 160 | 160 | // we're supporting is SAS verification |
| 161 | let ret = connection | |
| 161 | let _ret = connection | |
| 162 | 162 | .spawn(async move { sas.accept().await }) |
| 163 | 163 | .await; |
| 164 | 164 | } |
src/server.rs +2 −2
| @@ -727,7 +727,7 @@ impl InnerServer { | ||
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /// Borrow the server buffer handle. |
| 730 | pub fn server_buffer(&self) -> Ref<Option<BufferHandle>> { | |
| 730 | pub fn server_buffer(&self) -> Ref<'_, Option<BufferHandle>> { | |
| 731 | 731 | self.server_buffer.borrow() |
| 732 | 732 | } |
| 733 | 733 | |
| @@ -849,7 +849,7 @@ impl InnerServer { | ||
| 849 | 849 | .cloned(); |
| 850 | 850 | |
| 851 | 851 | if let Some(mut buffer) = buffer { |
| 852 | buffer.update(sas).await; | |
| 852 | let _ = buffer.update(sas).await; | |
| 853 | 853 | buffer.handle_event(&event).await; |
| 854 | 854 | } else { |
| 855 | 855 | let buffer = VerificationBuffer::new( |
src/verification_buffer.rs +5 −14
| @@ -87,14 +87,6 @@ impl Verification { | ||
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | async fn generate_qr_code(&self) -> Option<QrVerification> { | |
| 91 | match self { | |
| 92 | Verification::Request(r) => r.generate_qr_code().await.unwrap(), | |
| 93 | Verification::Sas(_) => None, | |
| 94 | Verification::Qr(_) => None, | |
| 95 | } | |
| 96 | } | |
| 97 | ||
| 98 | 90 | async fn cancel(&self) -> Result<(), Error> { |
| 99 | 91 | match self { |
| 100 | 92 | Verification::Request(r) => r.cancel().await, |
| @@ -111,7 +103,7 @@ struct InnerVerificationBuffer { | ||
| 111 | 103 | } |
| 112 | 104 | |
| 113 | 105 | impl InnerVerificationBuffer { |
| 114 | fn print_done(&self, buffer: BufferHandle) {} | |
| 106 | fn print_done(&self, _buffer: BufferHandle) {} | |
| 115 | 107 | |
| 116 | 108 | pub async fn accept(&self, buffer: BufferHandle) -> Result<(), Error> { |
| 117 | 109 | if let Some(c) = self.connection.borrow().clone() { |
| @@ -227,7 +219,7 @@ impl BufferCloseCallback for InnerVerificationBuffer { | ||
| 227 | 219 | impl VerificationBuffer { |
| 228 | 220 | pub fn new( |
| 229 | 221 | server_name: &str, |
| 230 | sender: &UserId, | |
| 222 | _sender: &UserId, | |
| 231 | 223 | verification: impl Into<Verification>, |
| 232 | 224 | connection: Rc<RefCell<Option<Connection>>>, |
| 233 | 225 | ) -> Self { |
| @@ -305,12 +297,11 @@ impl VerificationBuffer { | ||
| 305 | 297 | pub async fn handle_event(&self, event: &AnyToDeviceEvent) { |
| 306 | 298 | match event { |
| 307 | 299 | AnyToDeviceEvent::KeyVerificationRequest(e) => { |
| 308 | if let Verification::Request(request) = | |
| 300 | if let Verification::Request(_) = | |
| 309 | 301 | self.inner.verification.borrow().clone() |
| 310 | 302 | { |
| 311 | let content = e | |
| 312 | .content | |
| 313 | .render(&VerificationContext::ToDevice(request)); | |
| 303 | let content = | |
| 304 | e.content.render(&VerificationContext::ToDevice); | |
| 314 | 305 | |
| 315 | 306 | self.print(&content); |
| 316 | 307 | } |