From 70214da3a8c95e19088a01f6ef0d89dde24475ba Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 9 Dec 2024 20:06:37 +0100 Subject: [PATCH 1/2] custom message for publish --- README.md | 4 ++-- examples/crypto.rs | 2 +- examples/custom_origin.rs | 2 +- examples/no_std/src/publish.rs | 2 +- examples/publish.rs | 8 ++++---- examples/publish_blocking.rs | 2 +- src/dx/publish/builders.rs | 2 +- src/dx/publish/mod.rs | 13 ++++++++----- src/lib.rs | 4 ++-- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c125e259..e5a96306 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ async fn main() -> Result<(), Box> { client .publish_message("hello world!") .channel("my_channel") - .r#type("text-message") + .custom_message_type("text-message") .execute() .await?; @@ -144,7 +144,7 @@ async fn main() -> Result<(), Box> { client .publish_message("hello world on the other channel!") .channel("my_channel_2") - .r#type("text-message") + .custom_message_type("text-message") .execute() .await?; diff --git a/examples/crypto.rs b/examples/crypto.rs index 9584b6e8..cda590cc 100644 --- a/examples/crypto.rs +++ b/examples/crypto.rs @@ -65,7 +65,7 @@ async fn main() -> Result<(), Box> { let result = client .publish_message("hello world!") .channel("my_channel") - .r#type("text-message") + .custom_message_type("text-message") .execute() .await?; diff --git a/examples/custom_origin.rs b/examples/custom_origin.rs index ae36bb5b..a8129e1b 100644 --- a/examples/custom_origin.rs +++ b/examples/custom_origin.rs @@ -28,7 +28,7 @@ async fn main() -> Result<(), Box> { let result = client .publish_message("hello world!") .channel("my_channel") - .r#type("text-message") + .custom_message_type("text-message") .execute() .await?; diff --git a/examples/no_std/src/publish.rs b/examples/no_std/src/publish.rs index fae7a88b..86beebcd 100644 --- a/examples/no_std/src/publish.rs +++ b/examples/no_std/src/publish.rs @@ -140,7 +140,7 @@ fn publish_example() -> Result<(), PubNubError> { .use_post(true) .ttl(10) .space_id("my_space") - .r#type("my_type") + .custom_message_type("my_type") .execute_blocking()?; Ok(()) diff --git a/examples/publish.rs b/examples/publish.rs index 1716f19f..6184a437 100644 --- a/examples/publish.rs +++ b/examples/publish.rs @@ -26,7 +26,7 @@ async fn main() -> Result<(), Box> { let result = client .publish_message("hello world!") .channel("my_channel") - .r#type("text-message") + .custom_message_type("text-message") .execute() .await?; @@ -37,7 +37,7 @@ async fn main() -> Result<(), Box> { client .publish_message("hello async world!") .channel("my_channel") - .r#type("text-message") + .custom_message_type("text-message") .execute(), ); @@ -48,7 +48,7 @@ async fn main() -> Result<(), Box> { description: "Check out this awesome playlist I made!".into(), }) .channel("my_channel") - .r#type("url-with-description") + .custom_message_type("url-with-description") .execute() .await?; @@ -64,7 +64,7 @@ async fn main() -> Result<(), Box> { .use_post(true) .ttl(10) .space_id("my_space") - .r#type("text-message") + .custom_message_type("text-message") .execute() .await?; diff --git a/examples/publish_blocking.rs b/examples/publish_blocking.rs index d8a1082c..93185b75 100644 --- a/examples/publish_blocking.rs +++ b/examples/publish_blocking.rs @@ -59,7 +59,7 @@ fn main() -> Result<(), Box> { .use_post(true) .ttl(10) .space_id("my_space") - .r#type("my_type") + .custom_message_type("my_type") .execute_blocking()?; println!("result: {:?}", result); diff --git a/src/dx/publish/builders.rs b/src/dx/publish/builders.rs index 614fa0dd..09f29575 100644 --- a/src/dx/publish/builders.rs +++ b/src/dx/publish/builders.rs @@ -169,5 +169,5 @@ where /// Message type to publish. #[builder(setter(strip_option, into), default = "None")] - pub(super) r#type: Option, + pub(super) custom_message_type: Option, } diff --git a/src/dx/publish/mod.rs b/src/dx/publish/mod.rs index 28378ad7..bd59da86 100644 --- a/src/dx/publish/mod.rs +++ b/src/dx/publish/mod.rs @@ -257,8 +257,11 @@ where query_params.insert("space-id".to_string(), space_id.clone()); } - if let Some(r#type) = &self.r#type { - query_params.insert("type".to_string(), r#type.clone()); + if let Some(custom_message_type) = &self.custom_message_type { + query_params.insert( + "custom_message_type".to_string(), + custom_message_type.clone(), + ); } query_params.insert("seqn".to_string(), self.seqn.to_string()); @@ -351,7 +354,7 @@ where replicate: value.replicate, use_post: value.use_post, space_id: value.space_id, - r#type: value.r#type, + custom_message_type: value.custom_message_type, }, } } @@ -386,7 +389,7 @@ struct PublishMessageParams { use_post: bool, meta: Option>, space_id: Option, - r#type: Option, + custom_message_type: Option, } fn bool_to_numeric(value: bool) -> String { @@ -486,7 +489,7 @@ mod should { .ttl(50) .store(true) .space_id("space_id") - .r#type("message_type") + .custom_message_type("message_type") .meta(HashMap::from([("k".to_string(), "v".to_string())])) .prepare_context_with_request() .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 0b9a37f7..1f689d95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,7 +139,7 @@ //! client //! .publish_message("hello world!") //! .channel("my_channel") -//! .r#type("text-message") +//! .custom_message_type("text-message") //! .execute() //! .await?; //! @@ -147,7 +147,7 @@ //! client //! .publish_message("hello world on the other channel!") //! .channel("my_channel_2") -//! .r#type("text-message") +//! .custom_message_type("text-message") //! .execute() //! .await?; //! From 48adb72f3d988baf58fdf6ed7143a40e309a6f87 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 9 Dec 2024 20:22:55 +0100 Subject: [PATCH 2/2] rest of the functions --- src/dx/publish/mod.rs | 7 +++++-- src/dx/subscribe/event_dispatcher.rs | 6 +++--- src/dx/subscribe/event_engine/effects/emit_messages.rs | 2 +- src/dx/subscribe/result.rs | 6 +++--- src/dx/subscribe/types.rs | 6 +++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/dx/publish/mod.rs b/src/dx/publish/mod.rs index bd59da86..e085974d 100644 --- a/src/dx/publish/mod.rs +++ b/src/dx/publish/mod.rs @@ -499,10 +499,13 @@ mod should { ("norep".to_string(), "true".to_string()), ("store".to_string(), "1".to_string()), ("space-id".to_string(), "space_id".to_string()), - ("type".to_string(), "message_type".to_string()), + ( + "custom_message_type".to_string(), + "message_type".to_string() + ), ("meta".to_string(), "{\"k\":\"v\"}".to_string()), ("ttl".to_string(), "50".to_string()), - ("seqn".to_string(), "1".to_string()) + ("seqn".to_string(), "1".to_string()), ]), result.data.query_parameters ); diff --git a/src/dx/subscribe/event_dispatcher.rs b/src/dx/subscribe/event_dispatcher.rs index bb2007a5..7aee1b18 100644 --- a/src/dx/subscribe/event_dispatcher.rs +++ b/src/dx/subscribe/event_dispatcher.rs @@ -430,7 +430,7 @@ mod it_should { channel: "test-channel".to_string(), subscription: "test-channel".to_string(), data: "Test message 1".to_string().into_bytes(), - r#type: None, + custom_message_type: None, space_id: None, decryption_error: None, }), @@ -440,7 +440,7 @@ mod it_should { channel: "test-channel".to_string(), subscription: "test-channel".to_string(), data: "Test signal 1".to_string().into_bytes(), - r#type: None, + custom_message_type: None, space_id: None, decryption_error: None, }), @@ -459,7 +459,7 @@ mod it_should { channel: "test-channel".to_string(), subscription: "test-channel".to_string(), data: "Test message 2".to_string().into_bytes(), - r#type: None, + custom_message_type: None, space_id: None, decryption_error: None, }), diff --git a/src/dx/subscribe/event_engine/effects/emit_messages.rs b/src/dx/subscribe/event_engine/effects/emit_messages.rs index a8c542c6..b3a2e6ed 100644 --- a/src/dx/subscribe/event_engine/effects/emit_messages.rs +++ b/src/dx/subscribe/event_engine/effects/emit_messages.rs @@ -34,7 +34,7 @@ mod should { channel: "test".to_string(), subscription: "test-group".to_string(), data: vec![], - r#type: None, + custom_message_type: None, space_id: None, decryption_error: None, }; diff --git a/src/dx/subscribe/result.rs b/src/dx/subscribe/result.rs index a393d901..6930fe94 100644 --- a/src/dx/subscribe/result.rs +++ b/src/dx/subscribe/result.rs @@ -257,11 +257,11 @@ pub struct Envelope { pub subscription: Option, /// User provided message type (set only when [`publish`] called with - /// `r#type`). + /// `custom_message_type`). /// /// [`publish`]: crate::dx::publish - #[cfg_attr(feature = "serde", serde(rename = "mt"), serde(default))] - pub r#type: Option, + #[cfg_attr(feature = "serde", serde(rename = "cmt"), serde(default))] + pub custom_message_type: Option, /// Identifier of space into which message has been published (set only when /// [`publish`] called with `space_id`). diff --git a/src/dx/subscribe/types.rs b/src/dx/subscribe/types.rs index a44a8a6a..f3cb0aaf 100644 --- a/src/dx/subscribe/types.rs +++ b/src/dx/subscribe/types.rs @@ -470,10 +470,10 @@ pub struct Message { pub data: Vec, /// User provided message type (set only when [`publish`] called with - /// `r#type`). + /// `custom_message_type`). /// /// [`publish`]: crate::dx::publish - pub r#type: Option, + pub custom_message_type: Option, /// Identifier of space into which message has been published (set only when /// [`publish`] called with `space_id`). @@ -1097,7 +1097,7 @@ impl TryFrom for Message { channel: value.channel, subscription, data: value.payload.into(), - r#type: value.r#type, + custom_message_type: value.custom_message_type, space_id: value.space_id, decryption_error: None, })