Skip to content

Commit

Permalink
Rename KeyModeType and ListModeType methods to be consistent with flags
Browse files Browse the repository at this point in the history
  • Loading branch information
progval authored and spb committed May 4, 2024
1 parent 5e4efa6 commit 3117454
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions sable_ircd/src/command/handlers/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async fn handle_channel_mode(
removed: perm_removed,
};
cmd.new_event_with_response(membership.id(), detail).await;
} else if let Some(list_type) = ListModeType::from_char(c) {
} else if let Some(list_type) = ListModeType::from_mode_char(c) {
let list = chan.list(list_type);

if dir == Direction::Query || args.is_empty() {
Expand Down Expand Up @@ -202,7 +202,7 @@ async fn handle_channel_mode(
}
}
}
} else if let Some(_key_type) = KeyModeType::from_char(c) {
} else if let Some(_key_type) = KeyModeType::from_mode_char(c) {
match dir {
// Can't query keys
Direction::Query => (),
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/messages/send_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl SendHistoryItem for update::ChannelTopicChange {

impl SendHistoryItem for update::ListModeAdded {
fn send_to(&self, conn: impl MessageSink, from_entry: &HistoryLogEntry) -> HandleResult {
let text = format!("+{} {}", self.list_type.mode_letter(), self.pattern);
let text = format!("+{} {}", self.list_type.mode_char(), self.pattern);
let message =
message::Mode::new(&self.set_by, &self.channel, &text).with_tags_from(from_entry);
conn.send(message);
Expand All @@ -168,7 +168,7 @@ impl SendHistoryItem for update::ListModeAdded {

impl SendHistoryItem for update::ListModeRemoved {
fn send_to(&self, conn: impl MessageSink, from_entry: &HistoryLogEntry) -> HandleResult {
let text = format!("-{} {}", self.list_type.mode_letter(), self.pattern);
let text = format!("-{} {}", self.list_type.mode_char(), self.pattern);
let message =
message::Mode::new(&self.removed_by, &self.channel, &text).with_tags_from(from_entry);
conn.send(message);
Expand Down
8 changes: 4 additions & 4 deletions sable_ircd/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ impl ClientServer {
.iter()
.collect(),
chan_modes_with_a_parameter: ListModeType::iter()
.map(|t| t.mode_letter())
.chain(KeyModeType::iter().map(|t| t.mode_letter()))
.map(|t| t.mode_char())
.chain(KeyModeType::iter().map(|t| t.mode_char()))
.chain(MembershipFlagSet::all().map(|m| m.mode_char()).into_iter())
.collect(),
}
Expand Down Expand Up @@ -198,8 +198,8 @@ impl ClientServer {
Username::LENGTH.try_into().unwrap(),
));

let list_modes: String = ListModeType::iter().map(|t| t.mode_letter()).collect();
let key_modes: String = KeyModeType::iter().map(|t| t.mode_letter()).collect();
let list_modes: String = ListModeType::iter().map(|t| t.mode_char()).collect();
let key_modes: String = KeyModeType::iter().map(|t| t.mode_char()).collect();
let param_modes = "";
let simple_modes: String = ChannelModeSet::all()
.map(|m| m.mode_char())
Expand Down
4 changes: 2 additions & 2 deletions sable_network/src/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ macro_rules! define_mode_type {

impl $typename
{
pub fn mode_letter(&self) -> char
pub fn mode_char(&self) -> char
{
match self {
$( Self:: $var => $val ),*
}
}

pub fn from_char(c: char) -> Option<Self>
pub fn from_mode_char(c: char) -> Option<Self>
{
match c {
$( $val => Some(Self::$var) ),+,
Expand Down
2 changes: 1 addition & 1 deletion sable_network/src/network/wrapper/channel_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl ChannelMode<'_> {
pub fn format(&self) -> String {
let mut ret = format!("+{}", self.data.modes.to_chars());
if self.data.key.is_some() {
ret.push(KeyModeType::Key.mode_letter());
ret.push(KeyModeType::Key.mode_char());
}
ret
}
Expand Down
4 changes: 2 additions & 2 deletions sable_network/src/utils/channel_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub fn format_cmode_changes(detail: &ChannelModeChange) -> (String, Vec<String>)
changes += "+";
changes += &detail.added.to_chars();
if let OptionChange::Set(new_key) = detail.key_change {
changes.push(KeyModeType::Key.mode_letter());
changes.push(KeyModeType::Key.mode_char());
params.push(new_key.to_string());
}
}
if has_minus(detail) {
changes += "-";
changes += &detail.removed.to_chars();
if detail.key_change.is_unset() {
changes.push(KeyModeType::Key.mode_letter());
changes.push(KeyModeType::Key.mode_char());
params.push("*".to_string());
}
}
Expand Down

0 comments on commit 3117454

Please sign in to comment.