Move join handling to separate function
This commit is contained in:
parent
7fd71c8f07
commit
8d2e832671
1 changed files with 35 additions and 25 deletions
60
src/main.rs
60
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<Local>,
|
||||
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) => {
|
||||
|
|
Loading…
Reference in a new issue