Store list of members in channel and fix topic display
This commit is contained in:
parent
9fc8620176
commit
4238210403
2 changed files with 39 additions and 11 deletions
33
src/main.rs
33
src/main.rs
|
@ -92,10 +92,11 @@ impl Cri {
|
|||
|
||||
let command = tokens.next().unwrap();
|
||||
match command {
|
||||
"/join" => self.handle_join_command(&mut tokens),
|
||||
"/part" => self.handle_part_command(&mut tokens),
|
||||
"/query" => self.handle_query_command(tokens),
|
||||
_ => todo!(),
|
||||
"/join" | "/j" => self.handle_join_command(&mut tokens),
|
||||
"/part" | "/p" => self.handle_part_command(&mut tokens),
|
||||
"/query" | "/q" => self.handle_query_command(tokens),
|
||||
"/list" => self.handle_list_command(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +156,13 @@ impl Cri {
|
|||
self.message_log
|
||||
.set_active(Some(tokens.next().unwrap().to_string()));
|
||||
}
|
||||
|
||||
fn handle_list_command(&self) {
|
||||
self.input_tx
|
||||
.borrow()
|
||||
.send(IrcCommand::LIST(None, None).into())
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Application for Cri {
|
||||
|
@ -266,10 +274,6 @@ impl Application for Cri {
|
|||
);
|
||||
}
|
||||
|
||||
IrcCommand::TOPIC(channel, topic) => {
|
||||
self.message_log.on_topic(channel, topic.clone());
|
||||
}
|
||||
|
||||
IrcCommand::PRIVMSG(msgtarget, content)
|
||||
| IrcCommand::NOTICE(msgtarget, content) => {
|
||||
let channel = message.response_target().unwrap_or(msgtarget).to_string();
|
||||
|
@ -282,9 +286,21 @@ impl Application for Cri {
|
|||
×tamp,
|
||||
);
|
||||
}
|
||||
|
||||
IrcCommand::Response(Response::RPL_WELCOME, args) => {
|
||||
self.nickname = args[0].clone()
|
||||
}
|
||||
IrcCommand::Response(Response::RPL_NAMREPLY, args) => {
|
||||
let channel = &args[2];
|
||||
let names: Vec<_> = args[3].split_ascii_whitespace().collect();
|
||||
self.message_log.on_names_reply(channel, names);
|
||||
}
|
||||
IrcCommand::Response(Response::RPL_TOPIC, args) => {
|
||||
let channel = &args[1];
|
||||
let topic = &args[2];
|
||||
self.message_log.on_topic(channel, topic);
|
||||
}
|
||||
|
||||
IrcCommand::BATCH(tag, subcommand, params) => {
|
||||
self.message_log.on_batch(
|
||||
&self.nickname,
|
||||
|
@ -294,6 +310,7 @@ impl Application for Cri {
|
|||
×tamp,
|
||||
);
|
||||
}
|
||||
|
||||
_ => self.message_log.on_other(&message.to_string()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use std::collections::{HashMap, HashSet};
|
|||
pub struct Channel {
|
||||
pub messages: Vec<IrcMessage>,
|
||||
pub message_ids: HashSet<String>,
|
||||
pub names: Vec<String>,
|
||||
|
||||
pub topic: Option<String>,
|
||||
pub unread_messages: i32,
|
||||
|
@ -324,7 +325,11 @@ impl<'a> MessageLog {
|
|||
.clone()
|
||||
.unwrap_or("Server messages".to_string())
|
||||
),
|
||||
text(channel.topic.clone().unwrap_or_default())
|
||||
text(format!(
|
||||
"{} members - {}",
|
||||
channel.names.len(),
|
||||
channel.topic.as_deref().unwrap_or_default()
|
||||
))
|
||||
]);
|
||||
|
||||
let messages = channel
|
||||
|
@ -456,7 +461,13 @@ impl<'a> MessageLog {
|
|||
.width(Length::Fill)
|
||||
}
|
||||
|
||||
pub fn on_topic(&mut self, channel: &str, topic: Option<String>) {
|
||||
self.get_mut(Some(channel.to_string())).topic = topic;
|
||||
pub fn on_topic(&mut self, channel: &str, topic: &str) {
|
||||
self.get_mut(Some(channel.to_string())).topic = Some(topic.to_owned());
|
||||
}
|
||||
|
||||
pub fn on_names_reply(&mut self, channel: &str, names: Vec<&str>) {
|
||||
self.get_mut(Some(channel.to_string()))
|
||||
.names
|
||||
.extend(names.iter().map(|&n| str::to_string(n)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue