Commit ef6b74a150

ef6b74a150a67a65acf210bc9dfe40dc890c7357

parent: de3d9101bc

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-08 10:41 UTC
committer: <strk@kbt.io>

fix: clean up Rust 1.96 warnings

Layout: unified · split

src/render.rs +3 −51
@@ -1,9 +1,7 @@
1use url::Url; 1use url::Url;
2 2
3use matrix_sdk::{ 3use matrix_sdk::{
4 encryption::verification::{ 4 encryption::verification::{SasVerification, Verification},
5 SasVerification, Verification, VerificationRequest,
6 },
7 ruma::{ 5 ruma::{
8 events::{ 6 events::{
9 key::verification::{ 7 key::verification::{
@@ -644,7 +642,7 @@ render_start_content!(ToDeviceKeyVerificationStartEventContent);
644 642
645pub enum VerificationContext { 643pub enum VerificationContext {
646 Room(WeechatRoomMember, WeechatRoomMember), 644 Room(WeechatRoomMember, WeechatRoomMember),
647 ToDevice(VerificationRequest), 645 ToDevice,
648} 646}
649 647
650macro_rules! render_request_content { 648macro_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 format!("You have requested this device to be verified") 672 format!("You have requested this device to be verified")
675 } 673 }
676 }; 674 };
@@ -769,42 +767,9 @@ macro_rules! render_key_content {
769render_key_content!(KeyVerificationKeyEventContent); 767render_key_content!(KeyVerificationKeyEventContent);
770render_key_content!(ToDeviceKeyVerificationKeyEventContent); 768render_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.
775trait 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
787macro_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/// This trait is implemented for message types that can contain either an URL 770/// This trait is implemented for message types that can contain either an URL
804/// or an encrypted file. One of these _must_ be present. 771/// or an encrypted file. One of these _must_ be present.
805pub trait HasUrlOrFile { 772pub trait HasUrlOrFile {
806 fn url(&self) -> Option<&MxcUri>;
807
808 fn body(&self) -> &str; 773 fn body(&self) -> &str;
809 774
810 #[inline] 775 #[inline]
@@ -829,14 +794,6 @@ macro_rules! has_url_or_file {
829 &self.body 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 fn source(&self) -> &MediaSource { 797 fn source(&self) -> &MediaSource {
841 &self.source 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
855has_formatted_body!(EmoteMessageEventContent);
856has_formatted_body!(NoticeMessageEventContent);
857has_formatted_body!(TextMessageEventContent);
858
859has_url_or_file!(AudioMessageEventContent); 811has_url_or_file!(AudioMessageEventContent);
860has_url_or_file!(FileMessageEventContent); 812has_url_or_file!(FileMessageEventContent);
861has_url_or_file!(ImageMessageEventContent); 813has_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 pub fn mark_active( 245 pub fn mark_active(
250 &self, 246 &self,
251 user_id: &UserId, 247 user_id: &UserId,
src/room/verification.rs +3 −3
@@ -68,7 +68,7 @@ impl Verification {
68 if let Some(ActiveVerification::Sas(verification)) = 68 if let Some(ActiveVerification::Sas(verification)) =
69 self.inner.borrow().clone() 69 self.inner.borrow().clone()
70 { 70 {
71 let ret = 71 let _ret =
72 c.spawn(async move { verification.confirm().await }).await; 72 c.spawn(async move { verification.confirm().await }).await;
73 } 73 }
74 } 74 }
@@ -84,7 +84,7 @@ impl Verification {
84 { 84 {
85 let verification_clone = verification.clone(); 85 let verification_clone = verification.clone();
86 86
87 let ret = c 87 let _ret = c
88 .spawn(async move { 88 .spawn(async move {
89 verification 89 verification
90 .accept_with_methods(vec![ 90 .accept_with_methods(vec![
@@ -158,7 +158,7 @@ impl Verification {
158 158
159 // We accept here automatically since the only method 159 // We accept here automatically since the only method
160 // we're supporting is SAS verification 160 // we're supporting is SAS verification
161 let ret = connection 161 let _ret = connection
162 .spawn(async move { sas.accept().await }) 162 .spawn(async move { sas.accept().await })
163 .await; 163 .await;
164 } 164 }
src/server.rs +2 −2
@@ -727,7 +727,7 @@ impl InnerServer {
727 } 727 }
728 728
729 /// Borrow the server buffer handle. 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 self.server_buffer.borrow() 731 self.server_buffer.borrow()
732 } 732 }
733 733
@@ -849,7 +849,7 @@ impl InnerServer {
849 .cloned(); 849 .cloned();
850 850
851 if let Some(mut buffer) = buffer { 851 if let Some(mut buffer) = buffer {
852 buffer.update(sas).await; 852 let _ = buffer.update(sas).await;
853 buffer.handle_event(&event).await; 853 buffer.handle_event(&event).await;
854 } else { 854 } else {
855 let buffer = VerificationBuffer::new( 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 async fn cancel(&self) -> Result<(), Error> { 90 async fn cancel(&self) -> Result<(), Error> {
99 match self { 91 match self {
100 Verification::Request(r) => r.cancel().await, 92 Verification::Request(r) => r.cancel().await,
@@ -111,7 +103,7 @@ struct InnerVerificationBuffer {
111} 103}
112 104
113impl InnerVerificationBuffer { 105impl InnerVerificationBuffer {
114 fn print_done(&self, buffer: BufferHandle) {} 106 fn print_done(&self, _buffer: BufferHandle) {}
115 107
116 pub async fn accept(&self, buffer: BufferHandle) -> Result<(), Error> { 108 pub async fn accept(&self, buffer: BufferHandle) -> Result<(), Error> {
117 if let Some(c) = self.connection.borrow().clone() { 109 if let Some(c) = self.connection.borrow().clone() {
@@ -227,7 +219,7 @@ impl BufferCloseCallback for InnerVerificationBuffer {
227impl VerificationBuffer { 219impl VerificationBuffer {
228 pub fn new( 220 pub fn new(
229 server_name: &str, 221 server_name: &str,
230 sender: &UserId, 222 _sender: &UserId,
231 verification: impl Into<Verification>, 223 verification: impl Into<Verification>,
232 connection: Rc<RefCell<Option<Connection>>>, 224 connection: Rc<RefCell<Option<Connection>>>,
233 ) -> Self { 225 ) -> Self {
@@ -305,12 +297,11 @@ impl VerificationBuffer {
305 pub async fn handle_event(&self, event: &AnyToDeviceEvent) { 297 pub async fn handle_event(&self, event: &AnyToDeviceEvent) {
306 match event { 298 match event {
307 AnyToDeviceEvent::KeyVerificationRequest(e) => { 299 AnyToDeviceEvent::KeyVerificationRequest(e) => {
308 if let Verification::Request(request) = 300 if let Verification::Request(_) =
309 self.inner.verification.borrow().clone() 301 self.inner.verification.borrow().clone()
310 { 302 {
311 let content = e 303 let content =
312 .content 304 e.content.render(&VerificationContext::ToDevice);
313 .render(&VerificationContext::ToDevice(request));
314 305
315 self.print(&content); 306 self.print(&content);
316 } 307 }