feat: implement NAMES
This commit is contained in:
parent
112e20a9f7
commit
400f9b14da
3 changed files with 61 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ use super::commands::{
|
||||||
use crate::{
|
use crate::{
|
||||||
SENDER,
|
SENDER,
|
||||||
channels::Channel,
|
channels::Channel,
|
||||||
|
client::commands::names::Names,
|
||||||
config::ServerInfo,
|
config::ServerInfo,
|
||||||
error_structs::CommandExecError,
|
error_structs::CommandExecError,
|
||||||
messages::{ChanJoinMessage, Message},
|
messages::{ChanJoinMessage, Message},
|
||||||
|
|
@ -21,6 +22,7 @@ use crate::{
|
||||||
|
|
||||||
mod cap;
|
mod cap;
|
||||||
mod join;
|
mod join;
|
||||||
|
mod names;
|
||||||
mod nick;
|
mod nick;
|
||||||
mod pass;
|
mod pass;
|
||||||
mod ping;
|
mod ping;
|
||||||
|
|
@ -45,6 +47,7 @@ pub enum ClientAction {
|
||||||
JoinChannels(Vec<Channel>),
|
JoinChannels(Vec<Channel>),
|
||||||
UpgradeToServerConn,
|
UpgradeToServerConn,
|
||||||
ErrorAuthenticateFirst,
|
ErrorAuthenticateFirst,
|
||||||
|
ListNames(Channel),
|
||||||
DoNothing,
|
DoNothing,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,6 +129,7 @@ impl ClientCommand {
|
||||||
command_map.insert("JOIN".to_owned(), &Join);
|
command_map.insert("JOIN".to_owned(), &Join);
|
||||||
command_map.insert("WHO".to_owned(), &Who);
|
command_map.insert("WHO".to_owned(), &Who);
|
||||||
command_map.insert("PASS".to_owned(), &Pass);
|
command_map.insert("PASS".to_owned(), &Pass);
|
||||||
|
command_map.insert("NAMES".to_owned(), &Names);
|
||||||
|
|
||||||
debug!("executing IrcCommand: {self:?}");
|
debug!("executing IrcCommand: {self:?}");
|
||||||
|
|
||||||
|
|
@ -190,6 +194,13 @@ impl ClientAction {
|
||||||
return ReturnAction::ServerConn;
|
return ReturnAction::ServerConn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClientAction::ListNames(channel) => {
|
||||||
|
channel
|
||||||
|
.names_list_send(user_state.clone().unwrap_all(), channel, writer, hostname)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
37
src/client/commands/names.rs
Normal file
37
src/client/commands/names.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
use super::{ClientAction, ClientHandler};
|
||||||
|
use crate::{JOINED_CHANNELS, user::User};
|
||||||
|
|
||||||
|
pub struct Names;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ClientHandler for Names {
|
||||||
|
async fn handle(
|
||||||
|
&self,
|
||||||
|
arguments: Vec<String>,
|
||||||
|
_authenticated: bool,
|
||||||
|
_user_state: &mut User,
|
||||||
|
_server_outgoing_password: String,
|
||||||
|
_server_incoming_passwords: Vec<String>,
|
||||||
|
_user_passwords: Vec<String>,
|
||||||
|
) -> Vec<super::ClientAction> {
|
||||||
|
let mut actions = Vec::new();
|
||||||
|
|
||||||
|
let channels_lock = JOINED_CHANNELS.lock().await;
|
||||||
|
let channel_names = arguments[0]
|
||||||
|
.split(',')
|
||||||
|
.map(|x| x.to_owned())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
for channel in channel_names {
|
||||||
|
for channel_lock in channels_lock.iter() {
|
||||||
|
if channel == channel_lock.name {
|
||||||
|
actions.push(super::ClientAction::ListNames(channel_lock.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/user.rs
14
src/user.rs
|
|
@ -21,7 +21,7 @@ pub struct User {
|
||||||
// pub hostname: Option<String>,
|
// pub hostname: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Debug, Hash, PartialOrd, Ord)]
|
||||||
pub struct UserUnwrapped {
|
pub struct UserUnwrapped {
|
||||||
pub nickname: String,
|
pub nickname: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
|
@ -35,6 +35,18 @@ pub struct UserUnwrapped {
|
||||||
// pub hostname: Option<String>,
|
// pub hostname: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for UserUnwrapped {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.nickname == other.nickname && self.username == other.username
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ne(&self, other: &Self) -> bool {
|
||||||
|
!self.eq(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eq for UserUnwrapped {}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
pub fn is_populated_without_uid(&self) -> bool {
|
pub fn is_populated_without_uid(&self) -> bool {
|
||||||
self.realname.is_some() && self.username.is_some() && self.nickname.is_some()
|
self.realname.is_some() && self.username.is_some() && self.nickname.is_some()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue