From a87d224c50b8c92fd91aaf0e8399d18a359820c8 Mon Sep 17 00:00:00 2001 From: Waradu Date: Sat, 16 Nov 2024 18:35:50 +0100 Subject: [PATCH 1/2] fix: wanings --- src/discord/src/channel/mod.rs | 2 +- src/discord/src/message/mod.rs | 2 +- src/discord/src/snowflake.rs | 8 +++++--- src/ui/src/channel/message.rs | 8 ++++---- src/ui/src/channel/message_list.rs | 30 ++++++++++++++++++------------ src/ui/src/channel/mod.rs | 5 ++--- src/ui/src/main.rs | 4 ++-- 7 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/discord/src/channel/mod.rs b/src/discord/src/channel/mod.rs index 3c17de7..f8ee153 100644 --- a/src/discord/src/channel/mod.rs +++ b/src/discord/src/channel/mod.rs @@ -60,7 +60,7 @@ impl Channel for DiscordChannel { impl Clone for DiscordChannel { fn clone(&self) -> Self { Self { - channel_id: self.channel_id.clone(), + channel_id: self.channel_id, receiver: self.receiver.resubscribe(), client: self.client.clone(), } diff --git a/src/discord/src/message/mod.rs b/src/discord/src/message/mod.rs index caf41dd..36a8e20 100644 --- a/src/discord/src/message/mod.rs +++ b/src/discord/src/message/mod.rs @@ -37,6 +37,6 @@ impl Message for DiscordMessage { fn should_group(&self, previous: &Self) -> bool { const MAX_DISCORD_MESSAGE_GAP_SECS_FOR_GROUP: i64 = 5 * 60; - self.creation_time.signed_duration_since(&*previous.creation_time).num_seconds() <= MAX_DISCORD_MESSAGE_GAP_SECS_FOR_GROUP + self.creation_time.signed_duration_since(*previous.creation_time).num_seconds() <= MAX_DISCORD_MESSAGE_GAP_SECS_FOR_GROUP } } diff --git a/src/discord/src/snowflake.rs b/src/discord/src/snowflake.rs index 1a5db07..d493abb 100644 --- a/src/discord/src/snowflake.rs +++ b/src/discord/src/snowflake.rs @@ -1,10 +1,12 @@ +use std::fmt::{Display, Formatter, Result}; + #[derive(Clone, Hash, PartialEq, Eq, Copy, Debug)] pub struct Snowflake { pub content: u64, } -impl ToString for Snowflake { - fn to_string(&self) -> String { - self.content.to_string() +impl Display for Snowflake { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + write!(f, "{}", self.content) } } diff --git a/src/ui/src/channel/message.rs b/src/ui/src/channel/message.rs index 5485cd3..094a103 100644 --- a/src/ui/src/channel/message.rs +++ b/src/ui/src/channel/message.rs @@ -11,8 +11,8 @@ impl MessageGroup { MessageGroup { contents: vec![message] } } - pub fn get_author<'s>(&'s self) -> &'s (impl MessageAuthor + 's) { - self.contents.get(0).unwrap().get_author() + pub fn get_author(&self) -> &(impl MessageAuthor + '_) { + self.contents.first().unwrap().get_author() } pub fn add(&mut self, message: M) { @@ -24,7 +24,7 @@ impl MessageGroup { self.contents.push(message); } - pub fn contents<'s>(&'s self) -> impl IntoIterator { + pub fn contents(&self) -> impl IntoIterator { self.contents.iter().map(|v| v.get_content()) } @@ -35,7 +35,7 @@ impl MessageGroup { } } - return None; + None } pub fn size(&self) -> usize { diff --git a/src/ui/src/channel/message_list.rs b/src/ui/src/channel/message_list.rs index 6148d56..31216d3 100644 --- a/src/ui/src/channel/message_list.rs +++ b/src/ui/src/channel/message_list.rs @@ -9,6 +9,12 @@ pub struct MessageList { messages: Vec>, } +impl Default for MessageList { + fn default() -> Self { + Self::new() + } +} + impl MessageList { pub fn new() -> MessageList { Self { messages: Vec::default() } @@ -37,24 +43,24 @@ impl MessageList { let last = self.messages.last_mut(); - if last.is_some() - && last.as_ref().unwrap().get_author().get_id() == message.get_author().get_id() - && message.should_group(last.as_ref().unwrap().last()) - { - last.unwrap().add(message); + if let Some(last_group) = last { + if last_group.get_author().get_id() == message.get_author().get_id() && message.should_group(last_group.last()) { + last_group.add(message); + } else { + self.messages.push(MessageGroup::new(message)); + } } else { self.messages.push(MessageGroup::new(message)); } } pub fn add_pending_message(&mut self, pending_message: M) { - let last = self.messages.last_mut(); - - if last.is_some() - && last.as_ref().unwrap().get_author().get_id() == pending_message.get_author().get_id() - && pending_message.should_group(last.as_ref().unwrap().last()) - { - last.unwrap().add(pending_message); + if let Some(last) = self.messages.last_mut() { + if last.get_author().get_id() == pending_message.get_author().get_id() && pending_message.should_group(last.last()) { + last.add(pending_message); + } else { + self.messages.push(MessageGroup::new(pending_message)); + } } else { self.messages.push(MessageGroup::new(pending_message)); } diff --git a/src/ui/src/channel/mod.rs b/src/ui/src/channel/mod.rs index 8ebbb0d..77370e0 100644 --- a/src/ui/src/channel/mod.rs +++ b/src/ui/src/channel/mod.rs @@ -52,8 +52,8 @@ impl ChannelView { }); ctx - .subscribe(&message_input, move |channel_view, text_input, input_event, ctx| match input_event { - InputEvent::PressEnter => { + .subscribe(&message_input, move |channel_view, text_input, input_event, ctx| { + if let InputEvent::PressEnter = input_event { let content = text_input.read(ctx).text().to_string(); let channel_sender = channel.clone(); @@ -70,7 +70,6 @@ impl ChannelView { channel_view.list_state = channel_view.list_model.read(ctx).create_list_state(); ctx.notify(); } - _ => {} }) .detach(); diff --git a/src/ui/src/main.rs b/src/ui/src/main.rs index dd67808..f17eb2d 100644 --- a/src/ui/src/main.rs +++ b/src/ui/src/main.rs @@ -2,7 +2,7 @@ pub mod app; pub mod app_state; pub mod channel; -use std::{fs, path::PathBuf, sync::Arc}; +use std::sync::Arc; use app_state::AppState; use components::theme::Theme; @@ -59,6 +59,6 @@ async fn main() { ..Default::default() }; - cx.open_window(opts, |cx| cx.new_view(|cx| crate::app::App::new(cx))).unwrap(); + cx.open_window(opts, |cx| cx.new_view(crate::app::App::new)).unwrap(); }); } From 8fd232cb00ac479bf6b626052a5bc3fa24b6d18b Mon Sep 17 00:00:00 2001 From: Waradu Date: Sat, 16 Nov 2024 22:01:39 +0100 Subject: [PATCH 2/2] feat: allow to_string_trait_impl --- src/discord/src/snowflake.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/discord/src/snowflake.rs b/src/discord/src/snowflake.rs index d493abb..1d70ebd 100644 --- a/src/discord/src/snowflake.rs +++ b/src/discord/src/snowflake.rs @@ -1,12 +1,11 @@ -use std::fmt::{Display, Formatter, Result}; - #[derive(Clone, Hash, PartialEq, Eq, Copy, Debug)] pub struct Snowflake { pub content: u64, } -impl Display for Snowflake { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { - write!(f, "{}", self.content) +#[allow(clippy::to_string_trait_impl)] +impl ToString for Snowflake { + fn to_string(&self) -> String { + self.content.to_string() } }