diff options
| author | Max Audron <audron@cocaine.farm> | 2021-01-04 18:38:31 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-01-04 18:38:31 +0100 |
| commit | 0b7c6cf0b129799110d3ef0118e1f2b5697a2068 (patch) | |
| tree | 9bbb49c7af7feb6fc1aff497e0d577fe31ef11ed /src/message/signalproxy/objects | |
| parent | WIP: function api (diff) | |
| parent | add example program: quasselproxy (diff) | |
Merge branch 'client'
Diffstat (limited to 'src/message/signalproxy/objects')
| -rw-r--r-- | src/message/signalproxy/objects/aliasmanager.rs | 46 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/backlogmanager.rs | 161 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/buffersyncer.rs | 74 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/identity.rs | 119 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/mod.rs | 12 |
5 files changed, 412 insertions, 0 deletions
diff --git a/src/message/signalproxy/objects/aliasmanager.rs b/src/message/signalproxy/objects/aliasmanager.rs new file mode 100644 index 0000000..828caaa --- /dev/null +++ b/src/message/signalproxy/objects/aliasmanager.rs @@ -0,0 +1,46 @@ +use crate::primitive::{Variant, VariantMap}; + +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct AliasManager { + pub aliases: Vec<Alias>, +} + +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct Alias { + name: String, + expansion: String, +} + +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<Alias> = 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 + } +} diff --git a/src/message/signalproxy/objects/backlogmanager.rs b/src/message/signalproxy/objects/backlogmanager.rs new file mode 100644 index 0000000..86a7f61 --- /dev/null +++ b/src/message/signalproxy/objects/backlogmanager.rs @@ -0,0 +1,161 @@ +// interface BacklogManager { +// +// +// // C->S calls +// +// /** +// * Loads backlog for `bufferId`, starting at message `first`, up to `last` +// * (plus `additional` more messages after `last`) but at most `limit` +// * messages total. +// */ +// requestBacklog(bufferId: BufferId, first: MsgId, last: MsgId, limit: Int, additional: Int) +// /** +// * Same as `requestBacklog`, but only messages of a certain message `type` +// * with certain `flags` set. +// */ +// requestBacklogFiltered(bufferId: BufferId, first: MsgId, last: MsgId, limit: Int, additional: Int, type: Int, flags: Int) +// /** +// * Same as `requestBacklog`, but applied to all buffers. +// */ +// requestBacklogAll(first: MsgId, last: MsgId, limit: Int, additional: Int) +// /** +// * Same as `requestBacklogFiltered`, but applied to all buffers. +// */ +// requestBacklogAllFiltered(first: MsgId, last: MsgId, limit: Int, additional: Int, type: Int, flags: Int) +// +// +// // S->C calls +// +// /** +// * The response to `requestBacklog`, with the messages encoded as QVariants +// * in the `messages` parameter. +// */ +// receiveBacklog(bufferId: BufferId, first: MsgId, last: MsgId, limit: Int, additional: Int, messages: QVariantList) +// /** +// * The response to `requestBacklogFiltered`, with the messages encoded as +// * QVariants in the `messages` parameter. +// */ +// receiveBacklogFiltered(bufferId: BufferId, first: MsgId, last: MsgId, limit: Int, additional: Int, type: Int, flags: Int, messages: QVariantList) +// /** +// * The response to `requestBacklogAll`, with the messages encoded as +// * QVariants in the `messages` parameter. +// */ +// receiveBacklogAll(first: MsgId, last: MsgId, limit: Int, additional: Int, messages: QVariantList) +// /** +// * The response to `requestBacklogAllFiltered`, with the messages encoded as +// * QVariants in the `messages` parameter. +// */ +// receiveBacklogAllFiltered(first: MsgId, last: MsgId, limit: Int, additional: Int, type: Int, flags: Int, messages: QVariantList) +// } + +use crate::primitive::VariantList; + +/// Receive and Request Backlog +/// All "request" functions are Client to Server and all "receive" functions are Server to Client +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct BacklogManager {} + +impl BacklogManager { + /// Loads backlog for `bufferId`, starting at message `first`, up to `last` + /// (plus `additional` more messages after `last`) but at most `limit` + /// messages total. + fn requestBacklog( + self: Self, + buffer_id: u32, + first: u32, + last: u32, + limit: u32, + additional: u32, + ) { + unimplemented!() + } + + /// Same as `requestBacklog`, but only messages of a certain message `type` + /// with certain `flags` set. + fn requestBacklogFiltered( + self: Self, + buffer_id: u32, + first: u32, + last: u32, + limit: u32, + additional: u32, + msgtype: u32, + flags: u32, + ) { + unimplemented!() + } + + /// Same as `requestBacklog`, but applied to all buffers. + fn requestBacklogAll(self: Self, first: u32, last: u32, limit: u32, additional: u32) { + unimplemented!() + } + + /// Same as `requestBacklogFiltered`, but applied to all buffers. + fn requestBacklogAllFiltered( + self: Self, + first: u32, + last: u32, + limit: u32, + additional: u32, + msgtype: u32, + flags: u32, + ) { + unimplemented!() + } + + /// The response to `requestBacklog`, with the messages encoded as Variants + /// in the `messages` parameter. + fn receiveBacklog( + self: Self, + buffer_id: u32, + first: u32, + last: u32, + limit: u32, + additional: u32, + messages: VariantList, + ) { + unimplemented!() + } + + /// The response to `requestBacklogFiltered`, with the messages encoded as + /// Variants in the `messages` parameter. + fn receiveBacklogFiltered( + self: Self, + buffer_id: u32, + first: u32, + last: u32, + limit: u32, + additional: u32, + msgtype: u32, + flags: u32, + messages: VariantList, + ) { + unimplemented!() + } + + /// Same as `receiveBacklog`, but applied to all buffers. + fn receiveBacklogAll( + self: Self, + first: u32, + last: u32, + limit: u32, + additional: u32, + messages: VariantList, + ) { + unimplemented!() + } + + /// Same as `receiveBacklogFiltered`, but applied to all buffers. + fn receiveBacklogAllFiltered( + self: Self, + first: u32, + last: u32, + limit: u32, + additional: u32, + msgtype: u32, + flags: u32, + messages: VariantList, + ) { + unimplemented!() + } +} diff --git a/src/message/signalproxy/objects/buffersyncer.rs b/src/message/signalproxy/objects/buffersyncer.rs new file mode 100644 index 0000000..7ee4ca5 --- /dev/null +++ b/src/message/signalproxy/objects/buffersyncer.rs @@ -0,0 +1,74 @@ +use crate::message::signalproxy::MessageType; +use std::collections::HashMap; + +// use default_macro::default; +// #[default(crate::message::signalproxy::objects::BufferSyncerClient)] +pub struct BufferSyncer { + pub activities: HashMap<u32, MessageType>, + pub highlight_counts: HashMap<u32, u32>, + pub last_seen_msg: HashMap<u32, u32>, + pub marker_line: HashMap<u32, u32>, +} + +pub trait BufferSyncerServer { + fn activities(self: &Self) -> &HashMap<u32, MessageType>; + fn activities_mut(self: &mut Self) -> &mut HashMap<u32, MessageType>; + + fn highlight_counts(self: &Self) -> &HashMap<u32, u32>; + fn highlight_counts_mut(self: &mut Self) -> &mut HashMap<u32, u32>; + + fn last_seen_msg(self: &Self) -> &HashMap<u32, u32>; + fn last_seen_msg_mut(self: &mut Self) -> &mut HashMap<u32, u32>; + + fn marker_line(self: &Self) -> &HashMap<u32, u32>; + fn marker_line_mut(self: &mut Self) -> &mut HashMap<u32, u32>; + + fn request_mark_buffer_as_read(buffer: u32); + fn request_merge_buffers_permanently(buffer1: u32, buffer2: u32); + fn request_purge_buffer_ids(); + fn request_remove_buffer(buffer: u32); + fn request_rename_buffer(buffer: u32, new_name: String); + + fn request_set_last_seen_msg(self: &mut Self, buffer: u32, msgid: u32) { + self.last_seen_msg_mut().insert(buffer, msgid); + } + + fn request_set_marker_line(self: &mut Self, buffer: u32, msgid: u32) { + self.marker_line_mut().insert(buffer, msgid); + } +} + +pub trait BufferSyncerClient { + fn activities(self: &Self) -> &HashMap<u32, MessageType>; + fn activities_mut(self: &mut Self) -> &mut HashMap<u32, MessageType>; + + fn highlight_counts(self: &Self) -> &HashMap<u32, u32>; + fn highlight_counts_mut(self: &mut Self) -> &mut HashMap<u32, u32>; + + fn last_seen_msg(self: &Self) -> &HashMap<u32, u32>; + fn last_seen_msg_mut(self: &mut Self) -> &mut HashMap<u32, u32>; + + fn marker_line(self: &Self) -> &HashMap<u32, u32>; + fn marker_line_mut(self: &mut Self) -> &mut HashMap<u32, u32>; + + fn mark_buffer_as_read(buffer: u32); + fn merge_buffers_permanently(buffer1: u32, buffer2: u32); + fn remove_buffer(buffer: u32); + fn rename_buffer(buffer: u32, new_name: String); + + fn set_buffer_activity(self: &mut Self, buffer: u32, activity: MessageType) { + self.activities_mut().insert(buffer, activity); + } + + fn set_highlight_count(self: &mut Self, buffer: u32, count: u32) { + self.highlight_counts_mut().insert(buffer, count); + } + + fn set_last_seen_msg(self: &mut Self, buffer: u32, msgid: u32) { + self.last_seen_msg_mut().insert(buffer, msgid); + } + + fn set_marker_line(self: &mut Self, buffer: u32, msgid: u32) { + self.marker_line_mut().insert(buffer, msgid); + } +} diff --git a/src/message/signalproxy/objects/identity.rs b/src/message/signalproxy/objects/identity.rs new file mode 100644 index 0000000..a710e5d --- /dev/null +++ b/src/message/signalproxy/objects/identity.rs @@ -0,0 +1,119 @@ +use crate::primitive::{Variant, VariantMap}; + +#[derive(Debug, Clone)] +pub struct Identity { + identity_id: i32, + identity_name: String, + real_name: String, + nicks: Vec<String>, + away_nick: String, + away_nick_enabled: bool, + away_reason: String, + away_reason_enabled: bool, + auto_away_enabled: bool, + auto_away_time: i32, + auto_away_reason: String, + auto_away_reason_enabled: bool, + detach_away_enabled: bool, + detach_away_reason: String, + detach_away_reason_enabled: bool, + ident: String, + kick_reason: String, + part_reason: String, + quit_reason: String, +} + +impl From<VariantMap> for Identity { + fn from(input: VariantMap) -> Self { + Identity { + identity_id: match_variant!(input.get("identityId").unwrap(), Variant::i32), + identity_name: match_variant!(input.get("identityName").unwrap(), Variant::String), + real_name: match_variant!(input.get("realName").unwrap(), Variant::String), + nicks: match_variant!(input.get("nicks").unwrap(), Variant::StringList), + away_nick: match_variant!(input.get("awayNick").unwrap(), Variant::String), + away_nick_enabled: match_variant!(input.get("awayNickEnabled").unwrap(), Variant::bool), + away_reason: match_variant!(input.get("awayReason").unwrap(), Variant::String), + away_reason_enabled: match_variant!( + input.get("awayReasonEnabled").unwrap(), + Variant::bool + ), + auto_away_enabled: match_variant!(input.get("autoAwayEnabled").unwrap(), Variant::bool), + auto_away_time: match_variant!(input.get("autoAwayTime").unwrap(), Variant::i32), + auto_away_reason: match_variant!(input.get("autoAwayReason").unwrap(), Variant::String), + auto_away_reason_enabled: match_variant!( + input.get("autoAwayReasonEnabled").unwrap(), + Variant::bool + ), + detach_away_enabled: match_variant!( + input.get("detachAwayEnabled").unwrap(), + Variant::bool + ), + detach_away_reason: match_variant!( + input.get("detachAwayReason").unwrap(), + Variant::String + ), + detach_away_reason_enabled: match_variant!( + input.get("detachAwayReasonEnabled").unwrap(), + Variant::bool + ), + ident: match_variant!(input.get("ident").unwrap(), Variant::String), + kick_reason: match_variant!(input.get("kickReason").unwrap(), Variant::String), + part_reason: match_variant!(input.get("partReason").unwrap(), Variant::String), + quit_reason: match_variant!(input.get("quitReason").unwrap(), Variant::String), + } + } +} + +impl Into<std::collections::HashMap<String, Variant>> for Identity { + fn into(self) -> VariantMap { + let mut res = VariantMap::with_capacity(19); + + res.insert("identityId".to_string(), Variant::i32(self.identity_id)); + res.insert( + "identityName".to_string(), + Variant::String(self.identity_name), + ); + res.insert("realName".to_string(), Variant::String(self.real_name)); + res.insert("nicks".to_string(), Variant::StringList(self.nicks)); + res.insert("awayNick".to_string(), Variant::String(self.away_nick)); + res.insert( + "awayNickEnabled".to_string(), + Variant::bool(self.away_nick_enabled), + ); + res.insert("awayReason".to_string(), Variant::String(self.away_reason)); + res.insert( + "awayReasonEnabled".to_string(), + Variant::bool(self.away_reason_enabled), + ); + res.insert( + "autoAwayEnabled".to_string(), + Variant::bool(self.auto_away_enabled), + ); + res.insert( + "autoAwayTime".to_string(), + Variant::i32(self.auto_away_time), + ); + res.insert( + "autoAwayReason".to_string(), + Variant::String(self.auto_away_reason), + ); + res.insert( + "detachAwayEnabled".to_string(), + Variant::bool(self.detach_away_enabled), + ); + res.insert( + "detachAwayReason".to_string(), + Variant::String(self.detach_away_reason), + ); + res.insert( + "detachAwayReasonEnabled".to_string(), + Variant::bool(self.detach_away_reason_enabled), + ); + res.insert("ident".to_string(), Variant::String(self.ident)); + res.insert("kickReason".to_string(), Variant::String(self.kick_reason)); + res.insert("partReason".to_string(), Variant::String(self.part_reason)); + res.insert("quitReason".to_string(), Variant::String(self.quit_reason)); + + res + } +} diff --git a/src/message/signalproxy/objects/mod.rs b/src/message/signalproxy/objects/mod.rs new file mode 100644 index 0000000..a84f6fa --- /dev/null +++ b/src/message/signalproxy/objects/mod.rs @@ -0,0 +1,12 @@ +// mod aliasmanager; +// mod backlogmanager; + +mod buffersyncer; +mod identity; + +pub use buffersyncer::*; +pub use identity::*; + +pub trait Act { + fn act(self: Self); +} |
