diff --git a/src/main.rs b/src/main.rs index 9d2420c..a040903 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,6 +163,39 @@ impl Cri { .send(IrcCommand::LIST(None, None).into()) .unwrap() } + + fn on_join( + &mut self, + chanlist: &str, + source_nickname: &String, + timestamp: DateTime, + message_id: Option<&str>, + ) { + let already_joined = self.message_log.has_channel(dbg!(chanlist)); + self.message_log + .on_join(chanlist, source_nickname, ×tamp, message_id); + + if !already_joined + && source_nickname == &self.nickname + && self.capabilities.contains(&"draft/chathistory".into()) + { + self.input_tx + .borrow() + .send( + IrcCommand::Raw( + "CHATHISTORY".into(), + vec![ + "LATEST".into(), + chanlist.into(), + "*".into(), + 100.to_string(), + ], + ) + .into(), + ) + .unwrap(); + } + } } impl Application for Cri { @@ -220,32 +253,9 @@ impl Application for Cri { let capability = capability.as_ref().unwrap(); self.capabilities.push(capability.clone()); } - IrcCommand::JOIN(chanlist, _, _) => { - let already_joined = self.message_log.has_channel(chanlist); - self.message_log.on_join( - chanlist, - &source_nickname, - ×tamp, - message_id, - ); - if !already_joined && source_nickname == self.nickname { - self.input_tx - .borrow() - .send( - IrcCommand::Raw( - "CHATHISTORY".into(), - vec![ - "LATEST".into(), - chanlist.clone(), - "*".into(), - 100.to_string(), - ], - ) - .into(), - ) - .unwrap(); - } + IrcCommand::JOIN(chanlist, _, _) => { + self.on_join(chanlist, &source_nickname, timestamp, message_id); } IrcCommand::PART(chanlist, comment) => {