aboutsummaryrefslogtreecommitdiff
path: root/src/message/signalproxy/rpccall/message.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2025-03-01 20:00:36 +0100
committerMax Audron <audron@cocaine.farm>2025-03-01 20:02:12 +0100
commit09bdd93113e46a5ee909190d23a2638c5f4f010b (patch)
tree8bf27da0c09317302e6c3b2d2020ac2b7403b650 /src/message/signalproxy/rpccall/message.rs
parentadd UserType implementation for required signalproxy objects (diff)
implement rpc calls
Diffstat (limited to 'src/message/signalproxy/rpccall/message.rs')
-rw-r--r--src/message/signalproxy/rpccall/message.rs109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/message/signalproxy/rpccall/message.rs b/src/message/signalproxy/rpccall/message.rs
new file mode 100644
index 0000000..93888b5
--- /dev/null
+++ b/src/message/signalproxy/rpccall/message.rs
@@ -0,0 +1,109 @@
+use crate::primitive::{BufferInfo, Message, Variant};
+
+use super::{Direction, RpcCall, RpcCallType};
+
+/// Called when a new IRC message has been received, and the client should display or store it.
+#[derive(Clone, Debug, std::cmp::PartialEq)]
+pub struct DisplayMessage {
+ pub message: Message,
+}
+
+impl RpcCallType for DisplayMessage {
+ const NAME: &str = "2displayMessage(Message)";
+ const DIRECTION: Direction = Direction::ServerToClient;
+
+ fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
+ Ok(vec![
+ Variant::ByteArray(Self::NAME.to_string()),
+ self.message.clone().into(),
+ ])
+ }
+
+ fn from_network(
+ size: usize,
+ input: &mut crate::primitive::VariantList,
+ ) -> Result<(usize, RpcCall), crate::ProtocolError>
+ where
+ Self: Sized,
+ {
+ Ok((
+ size,
+ RpcCall::DisplayMessage(DisplayMessage {
+ message: match_variant!(input.remove(0), Variant::Message),
+ }),
+ ))
+ }
+}
+
+/// Status message for an IRC network to be shown in the client’s status bar (if available).
+#[derive(Clone, Debug, std::cmp::PartialEq)]
+pub struct DisplayStatusMessage {
+ pub network: String,
+ pub message: String,
+}
+
+impl RpcCallType for DisplayStatusMessage {
+ const NAME: &str = "2displayStatusMsg(QString,QString)";
+ const DIRECTION: Direction = Direction::ServerToClient;
+
+ fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
+ Ok(vec![
+ Variant::ByteArray(Self::NAME.to_string()),
+ self.network.clone().into(),
+ self.message.clone().into(),
+ ])
+ }
+
+ fn from_network(
+ size: usize,
+ input: &mut crate::primitive::VariantList,
+ ) -> Result<(usize, RpcCall), crate::ProtocolError>
+ where
+ Self: Sized,
+ {
+ Ok((
+ size,
+ DisplayStatusMessage {
+ network: match_variant!(input.remove(0), Variant::String),
+ message: match_variant!(input.remove(0), Variant::String),
+ }
+ .into(),
+ ))
+ }
+}
+
+#[derive(Clone, Debug, std::cmp::PartialEq)]
+pub struct SendInput {
+ buffer: BufferInfo,
+ message: String,
+}
+
+impl RpcCallType for SendInput {
+ const NAME: &str = "2sendInput(BufferInfo,QString)";
+ const DIRECTION: Direction = Direction::ClientToServer;
+
+ fn to_network(&self) -> Result<Vec<Variant>, crate::ProtocolError> {
+ Ok(vec![
+ Variant::ByteArray(Self::NAME.to_string()),
+ self.buffer.clone().into(),
+ self.message.clone().into(),
+ ])
+ }
+
+ fn from_network(
+ size: usize,
+ input: &mut crate::primitive::VariantList,
+ ) -> Result<(usize, RpcCall), crate::ProtocolError>
+ where
+ Self: Sized,
+ {
+ Ok((
+ size,
+ Self {
+ buffer: match_variant!(input.remove(0), Variant::BufferInfo),
+ message: match_variant!(input.remove(0), Variant::String),
+ }
+ .into(),
+ ))
+ }
+}