feat: implement NAMES
All checks were successful
build / test-alpine (push) Successful in 50s
build / test-debian (push) Successful in 1m0s

This commit is contained in:
user0-07161 2026-02-16 12:24:38 +01:00
parent 112e20a9f7
commit 400f9b14da
3 changed files with 61 additions and 1 deletions

View file

@ -12,6 +12,7 @@ use super::commands::{
use crate::{
SENDER,
channels::Channel,
client::commands::names::Names,
config::ServerInfo,
error_structs::CommandExecError,
messages::{ChanJoinMessage, Message},
@ -21,6 +22,7 @@ use crate::{
mod cap;
mod join;
mod names;
mod nick;
mod pass;
mod ping;
@ -45,6 +47,7 @@ pub enum ClientAction {
JoinChannels(Vec<Channel>),
UpgradeToServerConn,
ErrorAuthenticateFirst,
ListNames(Channel),
DoNothing,
}
@ -126,6 +129,7 @@ impl ClientCommand {
command_map.insert("JOIN".to_owned(), &Join);
command_map.insert("WHO".to_owned(), &Who);
command_map.insert("PASS".to_owned(), &Pass);
command_map.insert("NAMES".to_owned(), &Names);
debug!("executing IrcCommand: {self:?}");
@ -190,6 +194,13 @@ impl ClientAction {
return ReturnAction::ServerConn;
}
ClientAction::ListNames(channel) => {
channel
.names_list_send(user_state.clone().unwrap_all(), channel, writer, hostname)
.await
.unwrap();
}
_ => {}
}

View 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
}
}

View file

@ -21,7 +21,7 @@ pub struct User {
// pub hostname: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Clone, Debug, Hash, PartialOrd, Ord)]
pub struct UserUnwrapped {
pub nickname: String,
pub username: String,
@ -35,6 +35,18 @@ pub struct UserUnwrapped {
// 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 {
pub fn is_populated_without_uid(&self) -> bool {
self.realname.is_some() && self.username.is_some() && self.nickname.is_some()