From e40c337a28c4507a043973bdd1f06bca6cce0269 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sun, 25 Jul 2021 17:43:15 +0200 Subject: add Traits for syncable objects --- src/message/signalproxy/objects/aliasmanager.rs | 57 ++++++++++--------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'src/message/signalproxy/objects/aliasmanager.rs') diff --git a/src/message/signalproxy/objects/aliasmanager.rs b/src/message/signalproxy/objects/aliasmanager.rs index b536cde..d0e5d5b 100644 --- a/src/message/signalproxy/objects/aliasmanager.rs +++ b/src/message/signalproxy/objects/aliasmanager.rs @@ -1,5 +1,10 @@ use libquassel_derive::Network; +use crate::message::{StatefulSyncable, SyncProxy, Syncable}; + +/// AliasManager +/// keeps a list of all registered aliases +/// syncable #[derive(Clone, Debug, std::cmp::PartialEq, Network)] #[network(repr = "list")] pub struct AliasManager { @@ -7,6 +12,24 @@ pub struct AliasManager { pub aliases: Vec, } +impl AliasManager { + pub fn add_alias(&mut self, alias: Alias) { + // TODO check if name is equal + if !self.aliases.contains(&alias) { + self.aliases.push(alias) + } + } +} + +impl StatefulSyncable for AliasManager {} +impl Syncable for AliasManager { + fn sync(&self, session: impl SyncProxy, function: &str, params: crate::primitive::VariantList) { + session.sync("AliasManager", None, function, params) + } +} + +/// Alias +/// Represents a signle alias #[derive(Clone, Debug, std::cmp::PartialEq, Network)] #[network(repr = "maplist")] pub struct Alias { @@ -78,37 +101,3 @@ mod tests { assert_eq!(AliasManager::from_network(&mut get_dest()), get_src()) } } - -// impl AliasManager { -// /// Client to Server -// /// -// /// Replaces all properties of the object with the content of the -// /// "properties" parameter. This parameter is in network representation. -// /// -// fn request_update(self: &mut Self, properties: VariantMap) { -// self.update(properties); -// } - -// /// Server to Client -// fn add_alias(self: &mut Self, name: String, expansion: String) { -// self.aliases.push(Alias { name, expansion }); -// } - -// /// Server to Client -// /// -// /// Replaces all properties of the object with the content of the -// /// "properties" parameter. This parameter is in network representation. -// /// -// fn update(self: &mut Self, properties: VariantMap) { -// let mut alias: Vec = Vec::new(); - -// // for (i, name) in match_variant!(properties[&"Aliases".to_string()], Variant::String) { -// // alias.push(Alias { -// // name, -// // expansion: match_variant!(properties["Aliases"], Variant::String)["expansions"][i], -// // }) -// // } - -// self.aliases = alias -// } -// } -- cgit v1.2.3