From 0e2854fe885178764b2675acf63d8dd20fbc1e4f Mon Sep 17 00:00:00 2001 From: Max Audron Date: Mon, 18 Dec 2023 22:54:23 +0100 Subject: implement sync for IrcUser --- src/message/signalproxy/objects/ircuser.rs | 101 +++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 12 deletions(-) (limited to 'src/message/signalproxy/objects/ircuser.rs') diff --git a/src/message/signalproxy/objects/ircuser.rs b/src/message/signalproxy/objects/ircuser.rs index 6b14c70..833a162 100644 --- a/src/message/signalproxy/objects/ircuser.rs +++ b/src/message/signalproxy/objects/ircuser.rs @@ -1,41 +1,117 @@ -use crate::primitive::{DateTime, StringList}; +use crate::{ + message::{Syncable, Class}, + primitive::{DateTime, StringList}, +}; #[allow(unused_imports)] use crate::message::signalproxy::Network; -use libquassel_derive::NetworkMap; + +use itertools::Itertools; +#[cfg(feature = "server")] +use libquassel_derive::sync; +use libquassel_derive::{NetworkMap, Setters}; #[allow(dead_code)] -#[derive(Debug, Clone, PartialEq, NetworkMap)] +#[derive(Debug, Clone, PartialEq, NetworkMap, Setters)] #[network(repr = "maplist")] pub struct IrcUser { pub user: String, pub host: String, pub nick: String, - #[network(rename = "realName")] + #[quassel(name = "realName")] pub real_name: String, pub account: String, pub away: bool, - #[network(rename = "awayMessage")] + #[quassel(name = "awayMessage")] pub away_message: String, - #[network(rename = "idleTime")] + #[quassel(name = "idleTime")] pub idle_time: DateTime, - #[network(rename = "loginTime")] + #[quassel(name = "loginTime")] pub login_time: DateTime, pub server: String, - #[network(rename = "ircOperator")] + #[quassel(name = "ircOperator")] pub irc_operator: String, - #[network(rename = "lastAwayMessageTime")] + // #[quassel(name = "lastAwayMessage")] + // pub last_away_message: i32, + #[quassel(name = "lastAwayMessageTime")] pub last_away_message_time: DateTime, - #[network(rename = "whoisServiceReply")] + #[quassel(name = "whoisServiceReply")] pub whois_service_reply: String, - #[network(rename = "suserHost")] + #[quassel(name = "suserHost")] pub suser_host: String, pub encrypted: bool, pub channels: StringList, - #[network(rename = "userModes")] + #[quassel(name = "userModes")] pub user_modes: String, } +impl IrcUser { + pub fn add_user_modes(&mut self, modes: String) { + for mode in modes.chars() { + if ! self.user_modes.contains(mode) { + self.user_modes.push(mode); + } + } + + #[cfg(feature = "server")] + sync!("addUserModes", [modes]); + } + + pub fn remove_user_modes(&mut self, modes: String) { + for mode in modes.chars() { + if self.user_modes.contains(mode) { + self.user_modes = self.user_modes.chars().filter(|c| *c != mode).collect(); + } + } + + #[cfg(feature = "server")] + sync!("removeUserModes", [modes]); + } + + pub fn update_hostmask(&mut self, mask: String) { + + } + + pub fn join_channel(&mut self, channel: String) { + if ! self.channels.contains(&channel) { + self.channels.push(channel.clone()) + } + + #[cfg(feature = "server")] + sync!("partChannel", [channel]); + } + + pub fn part_channel(&mut self, channel: String) { + if let Some((i, _)) = self.channels.iter().find_position(|c| **c == channel) { + self.channels.remove(i); + } + + #[cfg(feature = "server")] + sync!("partChannel", [channel]); + } + + pub fn quit(&mut self) {} +} + +#[cfg(feature = "client")] +impl crate::message::StatefulSyncableClient for IrcUser {} + +#[cfg(feature = "server")] +impl crate::message::StatefulSyncableServer for IrcUser {} + +impl Syncable for IrcUser { + const CLASS: Class = Class::IrcUser; + + fn send_sync(&self, function: &str, params: crate::primitive::VariantList) { + crate::message::signalproxy::SYNC_PROXY.get().unwrap().sync( + Self::CLASS, + None, + function, + params, + ); + } +} + #[cfg(test)] mod tests { use crate::message::signalproxy::NetworkMap; @@ -57,6 +133,7 @@ mod tests { login_time: OffsetDateTime::unix_epoch(), server: s!(""), irc_operator: s!(""), + // last_away_message: 0, last_away_message_time: OffsetDateTime::unix_epoch(), whois_service_reply: s!(""), suser_host: s!(""), -- cgit v1.2.3 github.com/jsonnet-libs/k8s-alpha/1.19/_gen/storage/v1alpha1/volumeAttachmentStatus.libsonnet?h=1.2.0&follow=1'>Collapse)AuthorLines 2021-06-06make pet more compactR0flcopt3r/catinator-pet-commandMax Audron-5/+5 2021-06-05feat: adds pet command.R0flcopt3r-0/+90 When petting the cat it will reply with some random action. 2021-06-05feat: send actionR0flcopt3r-1/+9 2021-06-05release version 1.1.0Max Audron-2/+2 2021-06-05document proc macrosMax Audron-4/+97 2021-06-05add intensifyMax Audron-3/+27 2021-06-05add privmsg macroMax Audron-2/+40 2021-06-05fix jb remote urlsMax Audron-4/+4 2021-06-05remove egress gateway configMax Audron-10/+0 2021-06-05update tanka dependenciesMax Audron-8/+8 2021-06-05fix init container nameMax Audron-1/+1 2021-06-05fix tanka dependency pathMax Audron-8/+8 2021-06-05switch to https url for tanka util libMax Audron-2/+2 2021-06-05bump version to 1.0.2Max Audron-2/+2 2021-06-05add tanka ci configurationMax Audron-1/+1 2021-06-05ready tanka deploy for CIMax Audron-32/+69 2021-06-05remove tanka vendoringMax Audron-27651/+0 2021-05-26Release 1.0.1Max Audron-3/+3 2021-05-26fix log breaking once buffer fullMax Audron-2/+33 the log_msg function was poping the newest message and replacing it with the newest message, it should be poping the oldest messages. 2021-05-16add deployment stuffMax Audron-6/+27786 2021-05-15add container buildMax Audron-2/+35