diff --git a/src/cri.rs b/src/cri.rs index 8a724e0..8f5818e 100644 --- a/src/cri.rs +++ b/src/cri.rs @@ -7,7 +7,9 @@ use iced::{ widget::{column, container, mouse_area, row, text, text_input}, Application, Background, Element, Length, Theme, }; -use irc::proto::{message::Tag, CapSubCommand, Capability, Command as IrcCommand, Response}; +use irc::proto::{ + message::Tag, CapSubCommand, Capability, ChannelExt, Command as IrcCommand, Response, +}; use once_cell::sync::Lazy; use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; @@ -190,7 +192,6 @@ impl Application for Cri { fn update(&mut self, message: Self::Message) -> iced::Command { match message { ui_message::UiMessage::IrcMessageReceived(message) => { - // TODO use actual nickname let source_nickname: String = message.source_nickname().unwrap_or(&self.nickname).into(); @@ -252,11 +253,19 @@ impl Application for Cri { IrcCommand::PRIVMSG(msgtarget, content) | IrcCommand::NOTICE(msgtarget, content) => { - let channel: String = message.response_target().unwrap_or(msgtarget).into(); + let source_nickname = message.source_nickname(); + let target_name = if msgtarget.is_channel_name() + || source_nickname == Some(&self.nickname) + { + msgtarget + } else { + source_nickname.unwrap_or(msgtarget) + }; + self.message_log.on_privmsg( &self.nickname, - &channel, - &source_nickname, + target_name, + source_nickname.unwrap(), content, message_id, ×tamp, diff --git a/src/message_log.rs b/src/message_log.rs index aa5eac3..36c0c1b 100644 --- a/src/message_log.rs +++ b/src/message_log.rs @@ -287,14 +287,14 @@ impl<'a> MessageLog { pub fn on_privmsg( &mut self, current_nickname: &str, - channel_name: &str, + target_name: &str, nickname: &str, message: &str, message_id: Option<&str>, timestamp: &DateTime, ) { - let is_active = self.active_channel.as_deref() == Some(channel_name); - let channel = self.get_mut(Some(channel_name)); + let is_active = self.active_channel.as_deref() == Some(target_name); + let channel = self.get_mut(Some(target_name)); if channel.is_multiline { Self::handle_multiline_message(channel, nickname, message, message_id);