aboutsummaryrefslogtreecommitdiff
path: root/src/session/mod.rs
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/session/mod.rs
parentimplement sync for IrcUser (diff)
add identity and network to SessionManager
Diffstat (limited to 'src/session/mod.rs')
-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)
+ }
}
:08 +0100'>2025-02-26refactor variant serialization codeMax Audron-256/+405 Factored out a lot of the serialization of variants into trait's that have auto impl so code duplication is much reduced 2025-02-26add MsgId and BufferId to objects where neededMax Audron-141/+157 some objects where still handling BufferId or MsgId as their raw types which lead to errors now that the Types are properly parsed in the varinats 2025-02-25enable transparent repr for msgid and bufferidMax Audron-0/+2 2025-02-25Implement BacklogManagerTobias Deiminger-59/+113 2025-02-25Use BufferId in BufferInfoTobias Deiminger-10/+11 2025-02-25Use BufferId in VariantTobias Deiminger-2/+33 2025-02-25Add BufferId as Rust typeTobias Deiminger-0/+39 Up to now it was represented as i32. If we introduce a newtype for it, we can handle it idiomatically as dedicated Variant::BufferId variant (instead of having it mashed into Variant::UserType). 2025-02-25Use MsgId in MessageTobias Deiminger-18/+6 2025-02-25Use MsgId in VariantTobias Deiminger-20/+37 2025-02-25Add MsgId as Rust typeTobias Deiminger-0/+56 Up to now it was handled implicitely in Variant::UserType. Making it an explicit type allows to centralize the i32/i64 cfg dependency and to use the type for arguments in signalproxy::objects functions. 2025-02-24added session manager comments and log messageMax Audron-1/+3 2025-02-23add identity syncable to SessionManagerMax Audron-1/+8 2025-02-23add syncables for IrcUserMax Audron-2/+53 2025-02-23move network config to it's own file and impl it's syncMax Audron-23/+84 2025-02-23add basic network syncablesMax Audron-39/+420 2025-02-23clean up unused_import and unused_variables a bitMax Audron-2/+8 2025-02-23fix server feature errorsMax Audron-28/+23 2025-02-23fix ircchannel and maplist network representationMax Audron-154/+137 2025-02-22replace deprecated failure crate with thiserrorMax Audron-278/+194 this changes the public API in that all our methods now return a proper ProtocolError crate. Needed change anyways to properly deal with all our errors in the long run. Will still need to do a pass through the crate to remove all existing unwraps where it makes sense. 2025-02-22update dependencies and fix errorsMax Audron-508/+332 2025-02-22update flakeMax Audron-94/+117 2024-05-22add todos to readmeMax Audron-16/+35