Skip to content

add custom message type #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
client
.publish_message("hello world!")
.channel("my_channel")
.r#type("text-message")
.custom_message_type("text-message")
.execute()
.await?;

// Send a message to another channel
client
.publish_message("hello world on the other channel!")
.channel("my_channel_2")
.r#type("text-message")
.custom_message_type("text-message")
.execute()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
let result = client
.publish_message("hello world!")
.channel("my_channel")
.r#type("text-message")
.custom_message_type("text-message")
.execute()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
let result = client
.publish_message("hello world!")
.channel("my_channel")
.r#type("text-message")
.custom_message_type("text-message")
.execute()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/no_std/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
8 changes: 4 additions & 4 deletions examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
let result = client
.publish_message("hello world!")
.channel("my_channel")
.r#type("text-message")
.custom_message_type("text-message")
.execute()
.await?;

Expand All @@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
client
.publish_message("hello async world!")
.channel("my_channel")
.r#type("text-message")
.custom_message_type("text-message")
.execute(),
);

Expand All @@ -48,7 +48,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
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?;

Expand All @@ -64,7 +64,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
.use_post(true)
.ttl(10)
.space_id("my_space")
.r#type("text-message")
.custom_message_type("text-message")
.execute()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/publish_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.use_post(true)
.ttl(10)
.space_id("my_space")
.r#type("my_type")
.custom_message_type("my_type")
.execute_blocking()?;

println!("result: {:?}", result);
Expand Down
2 changes: 1 addition & 1 deletion src/dx/publish/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ where

/// Message type to publish.
#[builder(setter(strip_option, into), default = "None")]
pub(super) r#type: Option<String>,
pub(super) custom_message_type: Option<String>,
}
20 changes: 13 additions & 7 deletions src/dx/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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,
},
}
}
Expand Down Expand Up @@ -386,7 +389,7 @@ struct PublishMessageParams<M> {
use_post: bool,
meta: Option<HashMap<String, String>>,
space_id: Option<String>,
r#type: Option<String>,
custom_message_type: Option<String>,
}

fn bool_to_numeric(value: bool) -> String {
Expand Down Expand Up @@ -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();
Expand All @@ -496,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
);
Expand Down
6 changes: 3 additions & 3 deletions src/dx/subscribe/event_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand All @@ -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,
}),
Expand All @@ -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,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/dx/subscribe/event_engine/effects/emit_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
6 changes: 3 additions & 3 deletions src/dx/subscribe/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
/// PubNub defined event type.
#[cfg_attr(
feature = "serde",
serde(rename = "f"),

Check warning on line 212 in src/dx/subscribe/result.rs

View workflow job for this annotation

GitHub Actions / Check if `no_std` target compiles as expected

unreachable pattern

Check warning on line 212 in src/dx/subscribe/result.rs

View workflow job for this annotation

GitHub Actions / Check if `no_std` target compiles as expected

unreachable pattern

Check warning on line 212 in src/dx/subscribe/result.rs

View workflow job for this annotation

GitHub Actions / Check if Web Assembly target compiles as expected

unreachable pattern
serde(default = "Envelope::default_message_type")
)]
pub message_type: SubscribeMessageType,
Expand Down Expand Up @@ -257,11 +257,11 @@
pub subscription: Option<String>,

/// 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<String>,
#[cfg_attr(feature = "serde", serde(rename = "cmt"), serde(default))]
pub custom_message_type: Option<String>,

/// Identifier of space into which message has been published (set only when
/// [`publish`] called with `space_id`).
Expand Down
6 changes: 3 additions & 3 deletions src/dx/subscribe/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ pub struct Message {
pub data: Vec<u8>,

/// User provided message type (set only when [`publish`] called with
/// `r#type`).
/// `custom_message_type`).
///
/// [`publish`]: crate::dx::publish
pub r#type: Option<String>,
pub custom_message_type: Option<String>,

/// Identifier of space into which message has been published (set only when
/// [`publish`] called with `space_id`).
Expand Down Expand Up @@ -1097,7 +1097,7 @@ impl TryFrom<Envelope> 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,
})
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@
//! client
//! .publish_message("hello world!")
//! .channel("my_channel")
//! .r#type("text-message")
//! .custom_message_type("text-message")
//! .execute()
//! .await?;
//!
//! // Send a message to another channel
//! client
//! .publish_message("hello world on the other channel!")
//! .channel("my_channel_2")
//! .r#type("text-message")
//! .custom_message_type("text-message")
//! .execute()
//! .await?;
//!
Expand Down
Loading