Move join handling to separate function

This commit is contained in:
Sijmen 2023-11-23 11:47:01 +01:00
parent 7fd71c8f07
commit 8d2e832671
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48

View file

@ -163,6 +163,39 @@ impl Cri {
.send(IrcCommand::LIST(None, None).into()) .send(IrcCommand::LIST(None, None).into())
.unwrap() .unwrap()
} }
fn on_join(
&mut self,
chanlist: &str,
source_nickname: &String,
timestamp: DateTime<Local>,
message_id: Option<&str>,
) {
let already_joined = self.message_log.has_channel(dbg!(chanlist));
self.message_log
.on_join(chanlist, source_nickname, &timestamp, 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 { impl Application for Cri {
@ -220,32 +253,9 @@ impl Application for Cri {
let capability = capability.as_ref().unwrap(); let capability = capability.as_ref().unwrap();
self.capabilities.push(capability.clone()); 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,
&timestamp,
message_id,
);
if !already_joined && source_nickname == self.nickname { IrcCommand::JOIN(chanlist, _, _) => {
self.input_tx self.on_join(chanlist, &source_nickname, timestamp, message_id);
.borrow()
.send(
IrcCommand::Raw(
"CHATHISTORY".into(),
vec![
"LATEST".into(),
chanlist.clone(),
"*".into(),
100.to_string(),
],
)
.into(),
)
.unwrap();
}
} }
IrcCommand::PART(chanlist, comment) => { IrcCommand::PART(chanlist, comment) => {