aboutsummaryrefslogtreecommitdiff
path: root/src/message/signalproxy
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2025-02-23 13:18:30 +0100
committerMax Audron <audron@cocaine.farm>2025-02-23 13:18:30 +0100
commit9e305eaebeeaba64649d3c39b22003ba9be1a407 (patch)
treeb9d8665058f3dcac2d4d4c8c4c697a71d1bc2935 /src/message/signalproxy
parentreplace deprecated failure crate with thiserror (diff)
fix ircchannel and maplist network representation
Diffstat (limited to '')
-rw-r--r--src/message/signalproxy/objects/aliasmanager.rs4
-rw-r--r--src/message/signalproxy/objects/highlightrulemanager.rs24
-rw-r--r--src/message/signalproxy/objects/ignorelistmanager.rs4
-rw-r--r--src/message/signalproxy/objects/ircchannel.rs44
-rw-r--r--src/message/signalproxy/objects/mod.rs31
-rw-r--r--src/message/signalproxy/objects/network.rs87
6 files changed, 93 insertions, 101 deletions
diff --git a/src/message/signalproxy/objects/aliasmanager.rs b/src/message/signalproxy/objects/aliasmanager.rs
index 6d6b63c..d35f145 100644
--- a/src/message/signalproxy/objects/aliasmanager.rs
+++ b/src/message/signalproxy/objects/aliasmanager.rs
@@ -60,9 +60,9 @@ impl Syncable for AliasManager {
#[derive(Clone, Debug, std::cmp::PartialEq, NetworkMap)]
#[network(repr = "maplist")]
pub struct Alias {
- #[network(rename = "names", variant = "StringList")]
+ #[network(rename = "names", stringlist)]
pub name: String,
- #[network(rename = "expansions", variant = "StringList")]
+ #[network(rename = "expansions", stringlist)]
pub expansion: String,
}
diff --git a/src/message/signalproxy/objects/highlightrulemanager.rs b/src/message/signalproxy/objects/highlightrulemanager.rs
index 1a2b58f..8d2b4ee 100644
--- a/src/message/signalproxy/objects/highlightrulemanager.rs
+++ b/src/message/signalproxy/objects/highlightrulemanager.rs
@@ -23,11 +23,7 @@ pub struct HighlightRuleManager {
impl HighlightRuleManager {
/// Get a reference to a specific highlight rule by ID.
pub fn highlight_rule(&self, id: i32) -> Option<&HighlightRule> {
- if let Some(position) = self
- .highlight_rule_list
- .iter()
- .position(|rule| rule.id == id)
- {
+ if let Some(position) = self.highlight_rule_list.iter().position(|rule| rule.id == id) {
self.highlight_rule_list.get(position)
} else {
None
@@ -36,11 +32,7 @@ impl HighlightRuleManager {
/// Get a mutable reference to a specific highlight rule by ID.
pub fn highlight_rule_mut(&mut self, id: i32) -> Option<&mut HighlightRule> {
- if let Some(position) = self
- .highlight_rule_list
- .iter()
- .position(|rule| rule.id == id)
- {
+ if let Some(position) = self.highlight_rule_list.iter().position(|rule| rule.id == id) {
self.highlight_rule_list.get_mut(position)
} else {
None
@@ -90,11 +82,7 @@ impl HighlightRuleManager {
}
pub fn remove_highlight_rule(&mut self, id: i32) {
- if let Some(position) = self
- .highlight_rule_list
- .iter()
- .position(|rule| rule.id == id)
- {
+ if let Some(position) = self.highlight_rule_list.iter().position(|rule| rule.id == id) {
self.highlight_rule_list.remove(position);
}
@@ -205,7 +193,7 @@ impl Syncable for HighlightRuleManager {
#[network(repr = "maplist")]
pub struct HighlightRule {
pub id: i32,
- #[network(variant = "StringList")]
+ #[network(stringlist)]
pub name: String,
#[quassel(name = "isRegEx")]
pub is_regex: bool,
@@ -215,9 +203,9 @@ pub struct HighlightRule {
pub is_enabled: bool,
#[quassel(name = "isInverse")]
pub is_inverse: bool,
- #[network(variant = "StringList")]
+ #[network(stringlist)]
pub sender: String,
- #[network(variant = "StringList")]
+ #[network(stringlist)]
pub channel: String,
}
diff --git a/src/message/signalproxy/objects/ignorelistmanager.rs b/src/message/signalproxy/objects/ignorelistmanager.rs
index ce4ad43..ca287e8 100644
--- a/src/message/signalproxy/objects/ignorelistmanager.rs
+++ b/src/message/signalproxy/objects/ignorelistmanager.rs
@@ -184,7 +184,7 @@ impl Syncable for IgnoreListManager {
pub struct IgnoreListItem {
#[network(rename = "ignoreType", type = "i32")]
pub ignore_type: IgnoreType,
- #[network(rename = "ignoreRule", variant = "StringList")]
+ #[network(rename = "ignoreRule", stringlist)]
pub ignore_rule: String,
#[network(rename = "isRegEx")]
pub is_regex: bool,
@@ -192,7 +192,7 @@ pub struct IgnoreListItem {
pub strictness: StrictnessType,
#[network(rename = "scope", type = "i32")]
pub scope: ScopeType,
- #[network(rename = "scopeRule", variant = "StringList")]
+ #[network(rename = "scopeRule", stringlist)]
pub scope_rule: String,
#[network(rename = "isActive")]
pub is_active: bool,
diff --git a/src/message/signalproxy/objects/ircchannel.rs b/src/message/signalproxy/objects/ircchannel.rs
index 105f318..15ed5f3 100644
--- a/src/message/signalproxy/objects/ircchannel.rs
+++ b/src/message/signalproxy/objects/ircchannel.rs
@@ -2,7 +2,7 @@ use std::collections::HashMap;
#[cfg(feature = "server")]
use libquassel_derive::sync;
-use libquassel_derive::{NetworkMap, Setters};
+use libquassel_derive::{NetworkList, NetworkMap, Setters};
use log::{error, warn};
use crate::message::{Class, Syncable};
@@ -11,15 +11,15 @@ use crate::primitive::StringList;
use super::{ChanModes, ChannelModeType};
#[allow(dead_code)]
-#[derive(Debug, Clone, PartialEq, Setters, NetworkMap)]
+#[derive(Debug, Clone, PartialEq, Setters, NetworkList, NetworkMap)]
#[network(repr = "maplist")]
pub struct IrcChannel {
- #[network(rename = "ChanModes", network = "map")]
+ #[network(rename = "ChanModes", variant = "VariantMap", network = "map")]
pub chan_modes: ChanModes,
// pub channel_modes: HashMap<char, ChannelMode>,
#[setter(skip)]
- #[network(rename = "UserModes", network = "map")]
+ #[network(rename = "UserModes", variant = "VariantMap", network = "map")]
pub user_modes: HashMap<String, String>,
#[setter(skip)]
pub name: String,
@@ -180,6 +180,7 @@ impl crate::message::StatefulSyncableClient for IrcChannel {
where
Self: Sized,
{
+ unimplemented!()
}
}
@@ -190,6 +191,7 @@ impl crate::message::StatefulSyncableServer for IrcChannel {
where
Self: Sized,
{
+ unimplemented!()
}
}
@@ -201,24 +203,24 @@ impl Syncable for IrcChannel {
mod tests {
use super::*;
- use crate::primitive::{Variant, VariantMap};
use crate::message::NetworkMap;
+ use crate::primitive::{Variant, VariantMap};
fn get_network() -> VariantMap {
map! {
s!("encrypted") =>
- Variant::bool(
+ Variant::VariantList(vec![Variant::bool(
false,
- ),
+ )]),
s!("topic") =>
- Variant::String(
+ Variant::VariantList(vec![Variant::String(
s!(""),
- ),
+ )]),
s!("password") =>
- Variant::String(
+ Variant::VariantList(vec![Variant::String(
s!(""),
- ),
- s!("ChanModes") => Variant::VariantMap(map!
+ )]),
+ s!("ChanModes") => Variant::VariantList(vec![Variant::VariantMap(map!
{
s!("B") => Variant::VariantMap(map!
{},
@@ -246,9 +248,9 @@ mod tests {
s!("b") => Variant::StringList(vec![s!("*!*@test"), s!("*!*@test2")]),
}),
},
- ),
+ )]),
s!("UserModes") =>
- Variant::VariantMap(map!
+ Variant::VariantList(vec![Variant::VariantMap(map!
{
s!("audron") => Variant::String(
s!("o"),
@@ -257,11 +259,11 @@ mod tests {
s!(""),
),
},
- ),
+ )]),
s!("name") =>
- Variant::String(
+ Variant::VariantList(vec![Variant::String(
s!("#audron-test"),
- ),
+ )]),
}
}
fn get_runtime() -> IrcChannel {
@@ -287,10 +289,7 @@ mod tests {
#[test]
fn ircchannel_from_network() {
- assert_eq!(
- IrcChannel::from_network_map(&mut get_network()),
- get_runtime()
- )
+ assert_eq!(IrcChannel::from_network_map(&mut get_network()), get_runtime())
}
#[test]
@@ -304,8 +303,7 @@ mod tests {
base.add_user_mode(s!("audron"), s!("o"));
assert_eq!(res, base);
- res.user_modes =
- map! { s!("audron") => s!("oh"), s!("audron_") => s!(""), s!("test") => s!("h") };
+ res.user_modes = map! { s!("audron") => s!("oh"), s!("audron_") => s!(""), s!("test") => s!("h") };
base.add_user_mode(s!("test"), s!("h"));
assert_eq!(res, base);
}
diff --git a/src/message/signalproxy/objects/mod.rs b/src/message/signalproxy/objects/mod.rs
index de5bf35..b3b2858 100644
--- a/src/message/signalproxy/objects/mod.rs
+++ b/src/message/signalproxy/objects/mod.rs
@@ -1,31 +1,31 @@
mod aliasmanager;
-mod buffersyncer;
mod backlogmanager;
-mod bufferviewmanager;
+mod buffersyncer;
mod bufferviewconfig;
+mod bufferviewmanager;
mod certmanager;
+mod chanmodes;
mod coreinfo;
mod highlightrulemanager;
mod identity;
mod ignorelistmanager;
mod ircchannel;
-mod chanmodes;
mod ircuser;
mod network;
mod networkinfo;
pub use aliasmanager::*;
-pub use buffersyncer::*;
pub use backlogmanager::*;
-pub use bufferviewmanager::*;
+pub use buffersyncer::*;
pub use bufferviewconfig::*;
+pub use bufferviewmanager::*;
pub use certmanager::*;
+pub use chanmodes::*;
pub use coreinfo::*;
pub use highlightrulemanager::*;
pub use identity::*;
pub use ignorelistmanager::*;
pub use ircchannel::*;
-pub use chanmodes::*;
pub use ircuser::*;
pub use network::*;
pub use networkinfo::*;
@@ -70,7 +70,7 @@ pub enum Types {
Network(network::Network),
NetworkInfo(NetworkInfo),
NetworkConfig(NetworkConfig),
- // IrcChannel(IrcChannel),
+ IrcChannel(IrcChannel),
Unknown(VariantList),
}
@@ -90,16 +90,13 @@ impl Types {
Types::Network(val) => val.to_network_list(),
Types::NetworkInfo(val) => val.to_network_list(),
Types::NetworkConfig(val) => val.to_network_list(),
- // Types::IrcChannel(val) => todo!(),
+ Types::IrcChannel(val) => val.to_network_list(),
Types::Unknown(val) => val.clone(),
}
}
pub fn from_network(class_name: &str, object_name: &str, input: &mut VariantList) -> Self {
- debug!(
- "converting {} from network object: {:#?}",
- class_name, input
- );
+ debug!("converting {} from network object: {:#?}", class_name, input);
match class_name {
"AliasManager" => Types::AliasManager(AliasManager::from_network_list(input)),
"BufferSyncer" => Types::BufferSyncer(BufferSyncer::from_network_list(input)),
@@ -108,9 +105,7 @@ impl Types {
config.buffer_view_id = object_name.parse().unwrap();
Types::BufferViewConfig(config)
}
- "BufferViewManager" => {
- Types::BufferViewManager(BufferViewManager::from_network_list(input))
- }
+ "BufferViewManager" => Types::BufferViewManager(BufferViewManager::from_network_list(input)),
// "CoreInfo" => Types::CoreInfo(CoreInfo::from_network_map(
// &mut input.remove(0).try_into().unwrap(),
// )),
@@ -120,14 +115,12 @@ impl Types {
"HighlightRuleManager" => {
Types::HighlightRuleManager(HighlightRuleManager::from_network_list(input))
}
- "IgnoreListManager" => {
- Types::IgnoreListManager(IgnoreListManager::from_network_list(input))
- }
+ "IgnoreListManager" => Types::IgnoreListManager(IgnoreListManager::from_network_list(input)),
"CertManager" => Types::CertManager(CertManager::from_network_list(input)),
"Network" => Types::Network(Network::from_network_list(input)),
"NetworkInfo" => Types::NetworkInfo(NetworkInfo::from_network_list(input)),
"NetworkConfig" => Types::NetworkConfig(NetworkConfig::from_network_list(input)),
- // "IrcChannel" => Types::IrcChannel(IrcChannel::from_network_list(input)),
+ "IrcChannel" => Types::IrcChannel(IrcChannel::from_network_list(input)),
_ => Types::Unknown(input.to_owned()),
}
}
diff --git a/src/message/signalproxy/objects/network.rs b/src/message/signalproxy/objects/network.rs
index d944b17..33d2b33 100644
--- a/src/message/signalproxy/objects/network.rs
+++ b/src/message/signalproxy/objects/network.rs
@@ -42,10 +42,14 @@ impl Network {
fn determine_channel_mode_types(&mut self) {
let mut modes: Vec<&str> = self.supports.get("CHANMODES").unwrap().split(',').collect();
- self.channel_modes.insert(ChannelModeType::DChanmode, modes.pop().unwrap().to_owned());
- self.channel_modes.insert(ChannelModeType::CChanmode, modes.pop().unwrap().to_owned());
- self.channel_modes.insert(ChannelModeType::BChanmode, modes.pop().unwrap().to_owned());
- self.channel_modes.insert(ChannelModeType::AChanmode, modes.pop().unwrap().to_owned());
+ self.channel_modes
+ .insert(ChannelModeType::DChanmode, modes.pop().unwrap().to_owned());
+ self.channel_modes
+ .insert(ChannelModeType::CChanmode, modes.pop().unwrap().to_owned());
+ self.channel_modes
+ .insert(ChannelModeType::BChanmode, modes.pop().unwrap().to_owned());
+ self.channel_modes
+ .insert(ChannelModeType::AChanmode, modes.pop().unwrap().to_owned());
}
fn determine_prefixes(&mut self) {
@@ -63,13 +67,17 @@ impl Network {
self.prefixes = default_prefixes;
self.prefix_modes = default_prefix_modes;
}
- },
+ }
None => {
self.prefixes = default_prefixes;
self.prefix_modes = default_prefix_modes;
- },
+ }
}
}
+
+ pub fn add_channel(&mut self, name: &str, channel: IrcChannel) {
+ self.irc_channels.insert(name.to_owned(), channel);
+ }
}
impl crate::message::signalproxy::NetworkList for Network {
@@ -116,24 +124,18 @@ impl crate::message::signalproxy::NetworkList for Network {
map.insert(
s!("Users"),
- Variant::VariantMap(self.irc_users.iter().fold(
- HashMap::new(),
- |mut res, (_, v)| {
- res.extend(v.to_network_map());
-
- res
- },
- )),
- );
-
- let channels = self
- .irc_channels
- .iter()
- .fold(HashMap::new(), |mut res, (_, v)| {
+ Variant::VariantMap(self.irc_users.iter().fold(HashMap::new(), |mut res, (_, v)| {
res.extend(v.to_network_map());
res
- });
+ })),
+ );
+
+ let channels = self.irc_channels.iter().fold(HashMap::new(), |mut res, (_, v)| {
+ res.extend(v.to_network_map());
+
+ res
+ });
map.insert(s!("Channels"), Variant::VariantMap(channels));
@@ -200,10 +202,7 @@ impl crate::message::signalproxy::NetworkList for Network {
&mut users.try_into().expect("failed to convert Users"),
);
- users
- .into_iter()
- .map(|user| (user.nick.clone(), user))
- .collect()
+ users.into_iter().map(|user| (user.nick.clone(), user)).collect()
}
None => HashMap::new(),
}
@@ -227,9 +226,7 @@ impl crate::message::signalproxy::NetworkList for Network {
let var: VariantMap = i.next().unwrap().try_into().unwrap();
- var.into_iter()
- .map(|(k, v)| (k, v.try_into().unwrap()))
- .collect()
+ var.into_iter().map(|(k, v)| (k, v.try_into().unwrap())).collect()
},
caps: {
i.position(|x| *x == Variant::ByteArray(String::from("Caps")))
@@ -237,9 +234,7 @@ impl crate::message::signalproxy::NetworkList for Network {
let var: VariantMap = i.next().unwrap().try_into().unwrap();
- var.into_iter()
- .map(|(k, v)| (k, v.try_into().unwrap()))
- .collect()
+ var.into_iter().map(|(k, v)| (k, v.try_into().unwrap())).collect()
},
caps_enabled: {
i.position(|x| *x == Variant::ByteArray(String::from("CapsEnabled")))
@@ -380,21 +375,39 @@ mod tests {
fn network_determine_channel_modes() {
let mut network = Network::default();
- network.supports.insert(s!("CHANMODES"), s!("IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz"));
+ network.supports.insert(
+ s!("CHANMODES"),
+ s!("IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz"),
+ );
network.determine_channel_mode_types();
- assert_eq!(network.channel_modes.get(&ChannelModeType::AChanmode).unwrap(), "IXZbegw");
- assert_eq!(network.channel_modes.get(&ChannelModeType::BChanmode).unwrap(), "k");
- assert_eq!(network.channel_modes.get(&ChannelModeType::CChanmode).unwrap(), "FHJLWdfjlx");
- assert_eq!(network.channel_modes.get(&ChannelModeType::DChanmode).unwrap(), "ABCDKMNOPQRSTcimnprstuz");
+ assert_eq!(
+ network.channel_modes.get(&ChannelModeType::AChanmode).unwrap(),
+ "IXZbegw"
+ );
+ assert_eq!(
+ network.channel_modes.get(&ChannelModeType::BChanmode).unwrap(),
+ "k"
+ );
+ assert_eq!(
+ network.channel_modes.get(&ChannelModeType::CChanmode).unwrap(),
+ "FHJLWdfjlx"
+ );
+ assert_eq!(
+ network.channel_modes.get(&ChannelModeType::DChanmode).unwrap(),
+ "ABCDKMNOPQRSTcimnprstuz"
+ );
}
#[test]
fn network_get_channel_mode_type() {
let mut network = Network::default();
- network.supports.insert(s!("CHANMODES"), s!("IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz"));
+ network.supports.insert(
+ s!("CHANMODES"),
+ s!("IXZbegw,k,FHJLWdfjlx,ABCDKMNOPQRSTcimnprstuz"),
+ );
network.determine_channel_mode_types();
assert_eq!(network.get_channel_mode_type('b'), ChannelModeType::AChanmode);