aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2023-12-18 22:55:09 +0100
committerMax Audron <audron@cocaine.farm>2023-12-18 22:55:09 +0100
commitabd2dcdb60eea52cafb1d7d83c2b1e2dbb385f80 (patch)
treedb3134df8fbfb98fd75f2de353049f01c9a3c848 /src
parentimplement sync for IrcUser (diff)
add identity and network to SessionManager
Diffstat (limited to '')
-rw-r--r--src/session/mod.rs55
1 files changed, 46 insertions, 9 deletions
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 0a305c7..531f4f0 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -1,4 +1,13 @@
-use crate::message::{objects::{*, Types}, InitData, StatefulSyncableClient, SyncMessage, Syncable, Class};
+use std::collections::HashMap;
+
+use crate::message::StatefulSyncableServer;
+
+use log::{debug, warn};
+
+use crate::message::{
+ objects::{Types, *},
+ Class, InitData, SessionInit, StatefulSyncableClient, SyncMessage, Syncable,
+};
// TODO implement nested types init and sync like BufferViewConfig in BufferViewManager
@@ -11,8 +20,9 @@ pub struct Session {
pub cert_manager: CertManager,
pub core_info: CoreInfo,
pub highlight_rule_manager: HighlightRuleManager,
- pub identity: Identity,
+ pub identities: Vec<Identity>,
pub ignore_list_manager: IgnoreListManager,
+ pub networks: HashMap<i32, Network>,
}
/// The Session Trait is the main point of entry and implements the basic logic
@@ -24,8 +34,11 @@ pub trait SessionManager {
fn cert_manager(&mut self) -> &mut CertManager;
fn core_info(&mut self) -> &mut CoreInfo;
fn highlight_rule_manager(&mut self) -> &mut HighlightRuleManager;
- fn identity(&mut self) -> &mut Identity;
+ fn identities(&mut self) -> &mut Vec<Identity>;
+ fn identity(&mut self, id: usize) -> Option<&mut Identity>;
fn ignore_list_manager(&mut self) -> &mut IgnoreListManager;
+ fn networks(&mut self) -> &mut HashMap<i32, Network>;
+ fn network(&mut self, id: i32) -> Option<&mut Network>;
fn sync(&mut self, msg: SyncMessage)
where
@@ -39,10 +52,15 @@ pub trait SessionManager {
Class::CoreInfo => self.core_info().sync(msg),
Class::CoreData => (),
Class::HighlightRuleManager => self.highlight_rule_manager().sync(msg),
- Class::Identity => self.identity().sync(msg),
+ Class::Identity => (),
Class::IgnoreListManager => self.ignore_list_manager().sync(msg),
Class::CertManager => self.cert_manager().sync(msg),
- Class::Network => (),
+ Class::Network => {
+ let id: i32 = msg.object_name.parse().unwrap();
+ if let Some(network) = self.network(id) {
+ // network.sync()
+ }
+ }
Class::NetworkInfo => (),
Class::NetworkConfig => (),
Class::IrcChannel => {
@@ -100,9 +118,13 @@ pub trait SessionManager {
}
}
+ fn session_init(&mut self, data: SessionInit) {
+ *self.identities() = data.identities;
+ }
+
fn init(&mut self, data: InitData) {
match data.init_data {
- Types::AliasManager(data) => {self.alias_manager().init(data)}
+ Types::AliasManager(data) => self.alias_manager().init(data),
Types::BufferSyncer(data) => self.buffer_syncer().init(data),
Types::BufferViewConfig(_) => (),
Types::BufferViewManager(data) => self.buffer_view_manager().init(data),
@@ -110,7 +132,10 @@ pub trait SessionManager {
Types::HighlightRuleManager(data) => self.highlight_rule_manager().init(data),
Types::IgnoreListManager(data) => self.ignore_list_manager().init(data),
Types::CertManager(data) => self.cert_manager().init(data),
- Types::Network(_) => (),
+ Types::Network(network) => {
+ let id: i32 = data.object_name.parse().unwrap();
+ self.networks().insert(id, network);
+ }
Types::NetworkInfo(_) => (),
Types::NetworkConfig(_) => (),
Types::Unknown(_) => (),
@@ -147,11 +172,23 @@ impl SessionManager for Session {
&mut self.highlight_rule_manager
}
- fn identity(&mut self) -> &mut Identity {
- &mut self.identity
+ fn identities(&mut self) -> &mut Vec<Identity> {
+ &mut self.identities
+ }
+
+ fn identity(&mut self, id: usize) -> Option<&mut Identity> {
+ self.identities.get_mut(id)
}
fn ignore_list_manager(&mut self) -> &mut IgnoreListManager {
&mut self.ignore_list_manager
}
+
+ fn networks(&mut self) -> &mut HashMap<i32, Network> {
+ &mut self.networks
+ }
+
+ fn network(&mut self, id: i32) -> Option<&mut Network> {
+ self.networks.get_mut(&id)
+ }
}
2021-10-22write tons of documentation and reorganize some modulesMax Audron-65/+300 2021-10-22remove wolfram alpha url shorteningMax Audron-1/+2 2021-10-20remove failing wolfram alpha test casesMax Audron-105/+55 this is due to the url shorterner dying randomly and also just generally bad idea to call external services during unit tests. 2021-10-20bump version to 1.6.2Max Audron-3/+2 2021-10-20prepare for release on crates.ioMax Audron-39/+65 2021-10-20add async docs to macro crate and bump versionMax Audron-9/+10 2021-10-20change hook errors to be logged as warningsMax Audron-3/+3 they in nearly all cases aren't critical enough to warrant an actual error messages 2021-10-20fix configuration not loading correctly on release buildsMax Audron-8/+23 2021-10-19replace sedregex crate8-rework-sedMax Audron-20/+358 This replaces the sedregex crate with our own implementation for multiple reasons: 1. We required to access the parsed regex, this required a patch to the sedregex crate which did not get merged due to an inactive dev, blocking us from publishing on crates.Io 2. We wanted to highlight the changes done in bold 3. We want to add execution of multiple chained sed commands in the future which would require more modification 2021-10-19add formatting trait for irc codesMax Audron-0/+129 add an impl off the formatting trait on String to format Strings with the typical irc formatting codes for bold, italic etc 2021-10-17fix links in readmeMax Audron-2/+2