Skip to content

Commit

Permalink
Merge branch 'master' into history
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Jun 27, 2024
2 parents 466a0e4 + e9701e5 commit 6fc79e7
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 154 deletions.
51 changes: 29 additions & 22 deletions sable_ircd/src/messages/send_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl SendHistoryItem<update::ChannelModeChange> for ClientServer {
) -> HandleResult {
let net = self.network();
let source = net.message_source(&item.changed_by)?;
let channel = net.channel(item.channel)?;
let (mut changes, params) = format_cmode_changes(item);

for p in params {
Expand All @@ -196,7 +197,7 @@ impl SendHistoryItem<update::ChannelModeChange> for ClientServer {
}

let message =
message::Mode::new(&source, &item.channel, &changes).with_tags_from(from_entry, &net);
message::Mode::new(&source, &channel, &changes).with_tags_from(from_entry, &net);

conn.send(message);

Expand All @@ -213,8 +214,9 @@ impl SendHistoryItem<update::ChannelTopicChange> for ClientServer {
) -> HandleResult {
let net = self.network();
let source = net.message_source(&item.setter)?;
let channel = net.channel(item.channel)?;

let message = message::Topic::new(&source, &item.channel.name, &item.new_text)
let message = message::Topic::new(&source, &channel.name(), &item.new_text)
.with_tags_from(from_entry, &net);

conn.send(message);
Expand All @@ -232,10 +234,10 @@ impl SendHistoryItem<update::ListModeAdded> for ClientServer {
) -> HandleResult {
let net = self.network();
let source = net.message_source(&item.set_by)?;
let channel = net.channel(item.channel)?;

let text = format!("+{} {}", item.list_type.mode_char(), item.pattern);
let message =
message::Mode::new(&source, &item.channel, &text).with_tags_from(from_entry, &net);
let message = message::Mode::new(&source, &channel, &text).with_tags_from(from_entry, &net);
conn.send(message);
Ok(())
}
Expand All @@ -250,10 +252,10 @@ impl SendHistoryItem<update::ListModeRemoved> for ClientServer {
) -> HandleResult {
let net = self.network();
let source = net.message_source(&item.removed_by)?;
let channel = net.channel(item.channel)?;

let text = format!("-{} {}", item.list_type.mode_char(), item.pattern);
let message =
message::Mode::new(&source, &item.channel, &text).with_tags_from(from_entry, &net);
let message = message::Mode::new(&source, &channel, &text).with_tags_from(from_entry, &net);
conn.send(message);
Ok(())
}
Expand All @@ -269,6 +271,7 @@ impl SendHistoryItem<update::MembershipFlagChange> for ClientServer {
let net = self.network();
let source = net.message_source(&item.changed_by)?;
let user = net.historic_user(item.user)?;
let channel = net.channel(item.membership.channel())?;

let (mut changes, args) =
format_channel_perm_changes(&user.nickname, &item.added, &item.removed);
Expand All @@ -277,7 +280,7 @@ impl SendHistoryItem<update::MembershipFlagChange> for ClientServer {
changes += &args.join(" ");

let message =
message::Mode::new(&source, &item.channel, &changes).with_tags_from(from_entry, &net);
message::Mode::new(&source, &channel, &changes).with_tags_from(from_entry, &net);

conn.send(message);

Expand All @@ -294,22 +297,24 @@ impl SendHistoryItem<update::ChannelJoin> for ClientServer {
) -> HandleResult {
let net = self.network();
let user = net.historic_user(item.user)?;
let membership = net.membership(item.membership)?;
let channel = membership.channel()?;

let message = message::Join::new(user, &item.channel.name).with_tags_from(from_entry, &net);
let message = message::Join::new(user, &channel.name()).with_tags_from(from_entry, &net);

conn.send(message);

if !item.membership.permissions.is_empty() {
if !membership.permissions().is_empty() {
let (mut changes, args) = format_channel_perm_changes(
&user.nickname,
&item.membership.permissions,
&membership.permissions(),
&MembershipFlagSet::new(),
);

changes += " ";
changes += &args.join(" ");

let msg = message::Mode::new(user, &item.channel, &changes);
let msg = message::Mode::new(user, &channel, &changes);
conn.send(msg);
}

Expand All @@ -334,8 +339,9 @@ impl SendHistoryItem<update::ChannelKick> for ClientServer {
let net = self.network();
let source = net.message_source(&item.source)?;
let user = net.historic_user(item.user)?;
let channel = net.channel(item.membership.channel)?;

let message = message::Kick::new(&source, user, &item.channel.name, &item.message)
let message = message::Kick::new(&source, user, &channel.name(), &item.message)
.with_tags_from(from_entry, &net);

conn.send(message);
Expand All @@ -353,8 +359,11 @@ impl SendHistoryItem<update::ChannelPart> for ClientServer {
) -> HandleResult {
let net = self.network();
let user = net.historic_user(item.user)?;
let channel = net.channel(item.membership.channel)?;

let message = message::Part::new(user, &item.channel.name, &item.message)
// If editing this behaviour, make sure that the faked version in the channel rename
// handler stays in sync
let message = message::Part::new(user, &channel.name(), &item.message)
.with_tags_from(from_entry, &net);

conn.send(message);
Expand All @@ -373,9 +382,10 @@ impl SendHistoryItem<update::ChannelInvite> for ClientServer {
let net = self.network();
let source = net.message_source(&item.source)?;
let user = net.historic_user(item.user)?;
let channel = net.channel(item.invite.channel())?;

let message = message::Invite::new(&source, user, &item.channel.name)
.with_tags_from(from_entry, &net);
let message =
message::Invite::new(&source, user, &channel.name()).with_tags_from(from_entry, &net);

conn.send(message);

Expand Down Expand Up @@ -406,14 +416,11 @@ impl SendHistoryItem<update::NewMessage> for ClientServer {
let net = self.network();
let source = net.message_source(&item.source)?;
let target = net.message_target(&item.target)?;
let message = net.message(item.message)?;

let message = message::Message::new(
&source,
&target,
item.message.message_type,
&item.message.text,
)
.with_tags_from(from_entry, &net);
let message =
message::Message::new(&source, &target, message.message_type(), message.text())
.with_tags_from(from_entry, &net);

// Users should only see their own message echoed if they've asked for it,
// unless it's sent to themself
Expand Down
35 changes: 10 additions & 25 deletions sable_ircd/src/messages/send_realtime.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::errors::HandleResult;
use crate::messages::MessageSink;
use crate::ClientServer;
use sable_network::network::state;
use sable_network::network::state::HistoricUser;
use sable_network::prelude::wrapper::ObjectWrapper;
use sable_network::prelude::*;
use sable_network::rpc::NetworkHistoryUpdate;

Expand Down Expand Up @@ -55,7 +52,7 @@ impl SendRealtimeItem<update::ChannelJoin> for ClientServer {

// If we get here, the user we're notifying is the joining user
let network = self.network();
let channel = network.channel(item.channel.id)?;
let channel = network.channel(item.membership.channel())?;
let user = network.user(*item.user.user())?;

if let Some(topic) = channel.topic() {
Expand All @@ -79,13 +76,13 @@ impl SendRealtimeItem<update::ChannelRename> for ClientServer {
conn: &impl MessageSink,
from_entry: &NetworkHistoryUpdate,
) -> HandleResult {
let net = self.network();
let source = net.message_source(&item.source)?;
let network = self.network();
let source = network.message_source(&item.source)?;

if conn.capabilities().has(ClientCapability::ChannelRename) {
conn.send(
message::Rename::new(&source, &item.old_name, &item.new_name, &item.message)
.with_tags_from(from_entry, &net)
.with_tags_from(from_entry, &network)
.with_required_capabilities(ClientCapability::ChannelRename),
);

Expand All @@ -98,8 +95,7 @@ impl SendRealtimeItem<update::ChannelRename> for ClientServer {
return Ok(());
};

let network = self.network();
let channel = network.channel(item.channel.id)?;
let channel = network.channel(item.channel)?;
let Some(membership) = channel.has_member(user_id) else {
tracing::warn!("Cannot send ChannelRename to non-member {:?}", user_id);
return Ok(());
Expand All @@ -109,22 +105,8 @@ impl SendRealtimeItem<update::ChannelRename> for ClientServer {

// Construct fake join/part updates so that we can fake the log entry as well

let fake_part = update::ChannelPart {
channel: state::Channel {
name: item.old_name,
..item.channel.clone()
},
membership: membership.raw().clone(),
user: user.historic_id(),
message: format!("Channel renamed to {}: {}", &item.new_name, &item.message),
};

let fake_join = update::ChannelJoin {
channel: state::Channel {
name: item.new_name,
..item.channel.clone()
},
membership: membership.raw().clone(),
membership: membership.id(),
user: user.historic_id(),
};

Expand All @@ -135,7 +117,10 @@ impl SendRealtimeItem<update::ChannelRename> for ClientServer {
users_to_notify: vec![],
};

self.send_item(&fake_part, conn, &fake_log_entry)?;
let fake_part = message::Part::new(&user, &item.old_name, &item.message)
.with_tags_from(&fake_log_entry, &network);
conn.send(fake_part);

// fake_join was moved into fake_log_entry
self.send_now(&fake_log_entry, conn, &fake_log_entry)
}
Expand Down
21 changes: 13 additions & 8 deletions sable_ircd/src/server/update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,23 @@ impl ClientServer {
// without. This is called out explicitly in the labeled-response spec, and appears
// to exist solely to make my life difficult.

let net = self.network();
let message = net.message(msg.message)?;

if let HistoricMessageSourceId::User(source) = &msg.source {
if let HistoricMessageTargetId::User(target) = &msg.target {
// Source and target are both users. Check for self-message with the awkward caps
if source == target {
// We handle this as a special case.

let net = self.network();
let source = net.historic_user(*source)?;
let target = net.historic_user(*target)?;

let message = message::Message::new(
source,
target,
msg.message.message_type,
&msg.message.text,
message.message_type(),
message.text(),
)
.with_tags_from(update, &net);

Expand Down Expand Up @@ -121,11 +123,11 @@ impl ClientServer {
if let Ok(connection) = self
.connections
.read()
.get_user_connection(detail.connection.id)
.get_user_connection(detail.connection)
{
// `register_new_user` doesn't set the user ID on the connection; it remains a pre-client until
// we see the registration events come back through (i.e. here)
connection.set_user(user.id(), detail.connection.id);
connection.set_user(user.id(), detail.connection);

connection.send(numeric::Numeric001::new_for(
&self.node.name().to_string(),
Expand Down Expand Up @@ -178,10 +180,13 @@ impl ClientServer {
Ok(())
}

fn handle_services_update(&self, detail: &update::ServicesUpdate) -> HandleResult {
match &detail.new_state {
fn handle_services_update(&self, _detail: &update::ServicesUpdate) -> HandleResult {
let net = self.network();
let new_state = net.current_services();

match new_state {
Some(state) => {
let mut mechanisms = state.sasl_mechanisms.clone();
let mut mechanisms = state.sasl_mechanisms().clone();
mechanisms.push("EXTERNAL".to_string());
self.client_caps
.enable_with_values(ClientCapability::Sasl, &mechanisms);
Expand Down
20 changes: 10 additions & 10 deletions sable_network/src/network/network/account_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ impl Network {
sasl_mechanisms: update.sasl_mechanisms.clone(),
});

updates.notify(
update::ServicesUpdate {
new_state: self.current_services.clone(),
},
event,
);
updates.notify(update::ServicesUpdate {}, event);
}

pub(super) fn update_account(
Expand Down Expand Up @@ -113,13 +108,18 @@ impl Network {
return;
};

let old_account = user.account.and_then(|id| accounts.get(&id)).cloned();
let new_account = update.account.and_then(|id| accounts.get(&id)).cloned();
let old_account = user.account;
let new_account = update.account;

user.account = update.account;

self.historic_users
.update_account(user, new_account.as_ref().map(|a| a.name));
self.historic_users.update_account(
user,
event.timestamp,
new_account
.as_ref()
.and_then(|id| accounts.get(id).map(|a| a.name)),
);

let user = user.clone();

Expand Down
4 changes: 1 addition & 3 deletions sable_network/src/network/network/audit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ impl Network {
) {
self.audit_log.insert(target, details.entry.clone());

let update = update::NewAuditLogEntry {
entry: details.entry.clone(),
};
let update = update::NewAuditLogEntry { entry: target };
updates.notify(update, event);
}
}
Loading

0 comments on commit 6fc79e7

Please sign in to comment.