From 23d734c65dd1a8632fb4db3d730d67eb73340e33 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Sun, 26 Apr 2026 09:48:43 +0200 Subject: [PATCH] Also remove the From<&str> implementation for Reaction --- src/reaction.rs | 42 +++++++++++++++++++----------------------- src/receive_imf.rs | 2 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/reaction.rs b/src/reaction.rs index 515a468e3..22ad5adf1 100644 --- a/src/reaction.rs +++ b/src/reaction.rs @@ -36,10 +36,7 @@ pub struct Reaction { reaction: String, } -// We implement From<&str> instead of std::str::FromStr, because -// FromStr requires error type and reaction parsing never returns an -// error. -impl From<&str> for Reaction { +impl Reaction { /// Convert a `&str` into a `Reaction`. /// Everything after the first whitespace is ignored. /// @@ -51,7 +48,7 @@ impl From<&str> for Reaction { /// reactions is not different from other kinds of spam attacks /// such as sending large numbers of large messages, and should be /// dealt with the same way, e.g. by blocking the user. - fn from(reaction: &str) -> Self { + pub fn from_str(reaction: &str) -> Self { let reaction: &str = reaction .split_ascii_whitespace() .next() @@ -61,9 +58,7 @@ impl From<&str> for Reaction { reaction: reaction.to_string(), } } -} -impl Reaction { /// Returns true if reaction contains no emoji. pub fn is_empty(&self) -> bool { self.reaction.is_empty() @@ -212,7 +207,7 @@ pub async fn send_reaction(context: &Context, msg_id: MsgId, reaction: &str) -> let msg = Message::load_from_db(context, msg_id).await?; let chat_id = msg.chat_id; - let reaction: Reaction = reaction.into(); + let reaction = Reaction::from_str(reaction); let mut reaction_msg = Message::new_text(reaction.as_str().to_string()); reaction_msg.set_reaction(); reaction_msg.in_reply_to = Some(msg.rfc724_mid); @@ -282,7 +277,7 @@ pub async fn get_msg_reactions(context: &Context, msg_id: MsgId) -> Result panic!("Unexpected event {event:?}."), } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 195fc0cdc..b1c9151f2 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -2151,7 +2151,7 @@ async fn add_parts( chat_id, from_id, sort_timestamp, - Reaction::from(reaction_str.as_str()), + Reaction::from_str(reaction_str.as_str()), is_incoming_fresh, ) .await?;