Skip to content

Automatically attach preclients to an existing session of the account, if any #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sable_ircd/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,17 @@ impl PreClient {
pub fn can_register(&self) -> bool {
let can_register_new = self.can_register_new_user();
let can_attach = self.can_attach_to_user().is_some();
let is_negotiating_caps =
self.progress_flags.load(Ordering::Relaxed) & ProgressFlag::CapNegotiation as u32 != 0;

tracing::trace!(
?self,
can_register_new,
can_attach,
is_negotiating_caps,
"PreClient::can_register"
);
can_register_new || can_attach
(can_register_new || can_attach) && !is_negotiating_caps
}

/// Determine whether this connection is ready to register as a new user
Expand Down
35 changes: 35 additions & 0 deletions sable_ircd/src/server/update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use sable_network::prelude::state::{HistoricMessageSourceId, HistoricMessageTarg
use super::*;
use crate::errors::HandleResult;
use crate::monitor::MonitoredItem;
use sable_network::network::update::UserAwayChange;

impl ClientServer {
pub(super) fn handle_history_update(&self, update: NetworkHistoryUpdate) -> HandleResult {
Expand Down Expand Up @@ -169,6 +170,40 @@ impl ClientServer {

connection.send(message::Notice::new(&self.node.name().to_string(), &user,
"The network is currently running in debug mode. Do not send any sensitive information such as passwords."));

if let Some(&away_reason) = user.away_reason() {
let fake_log_entry = NetworkHistoryUpdate {
timestamp: 0, // XXX
event: EventId::new(Snowflake::from_parts(self.node().id(), 0, 0)), // XXX
change: NetworkStateChange::UserAwayChange(UserAwayChange {
user: user.historic_id(),
old_reason: None,
new_reason: Some(away_reason),
}),
users_to_notify: vec![],
};

// Set away status if user has away-notify capability
// FIXME: suffers from https://github.com/Libera-Chat/sable/issues/155
self.send_now(&fake_log_entry, &connection, &fake_log_entry)?;
}

for membership in user.channels() {
let fake_join = update::ChannelJoin {
membership: membership.id(),
user: user.historic_id(),
};

let fake_log_entry = NetworkHistoryUpdate {
timestamp: 0, // XXX
event: EventId::new(Snowflake::from_parts(self.node().id(), 0, 0)), // XXX
change: NetworkStateChange::ChannelJoin(fake_join),
users_to_notify: vec![],
};

// Send join + topic + names
self.send_now(&fake_log_entry, &connection, &fake_log_entry)?;
}
}
Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions sable_network/src/policy/standard_user_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ impl UserPolicyService for StandardUserPolicy {

Err(PermissionError::User(Invisible))
}

fn auto_attach_session(&self, _user: &wrapper::User) -> bool {
true
}
}
6 changes: 6 additions & 0 deletions sable_network/src/policy/user_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ use super::*;
pub trait UserPolicyService {
/// Determine whether a given user can set a given user mode on themselves
fn can_set_umode(&self, user: &wrapper::User, mode: UserModeFlag) -> PermissionResult;

/// Determine whether a given user can unset a given user mode on themselves
fn can_unset_umode(&self, user: &wrapper::User, mode: UserModeFlag) -> PermissionResult;

/// Determine whether `to_user` can discover `user` without knowing their nick
/// (eg. with `WHO *`)
fn can_list_user(&self, to_user: &User, user: &User) -> PermissionResult;

/// Determine whether a new connection of the given `user` will join an existing
/// session if there is any
fn auto_attach_session(&self, user: &wrapper::User) -> bool;
}
Loading