Skip to content

Commit

Permalink
Merge branch 'master' into feat/presence-api-state
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax authored Aug 30, 2023
2 parents fc14cd7 + 4d6c07f commit 11dacc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
7 changes: 0 additions & 7 deletions src/dx/presence/builders/here_now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! The [`HereNowRequestBuilder`] lets you make and execute a Here Now request
//! that will associate a user with a channel.
use core::ops::Deref;

use derive_builder::Builder;

use crate::{
Expand Down Expand Up @@ -119,11 +117,6 @@ impl<T, D> HereNowRequest<T, D> {
query.insert("disable_uuids".into(), "1".into());
});

query.insert(
"uuid".into(),
self.pubnub_client.config.user_id.deref().clone(),
);

Ok(TransportRequest {
path: format!(
"/v2/presence/sub-key/{sub_key}/channel/{}",
Expand Down
24 changes: 13 additions & 11 deletions src/dx/presence/builders/where_now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ pub struct WhereNowRequest<T, D> {
#[builder(field(vis = "pub(in crate::dx::presence)"), setter(custom))]
pub(in crate::dx::presence) pubnub_client: PubNubClientInstance<T, D>,

#[builder(field(vis = "pub(in crate::dx::presence)"), setter(strip_option, into))]
#[builder(
field(vis = "pub(in crate::dx::presence)"),
setter(strip_option, into),
default
)]
/// Identifier for which `state` should be associated for provided list of
/// channels and groups.
pub(in crate::dx::presence) user_id: String,
Expand All @@ -52,15 +56,7 @@ impl<T, D> WhereNowRequestBuilder<T, D> {
/// Validator ensure that list of provided data is enough to build valid
/// set state request instance.
fn validate(&self) -> Result<(), String> {
builders::validate_configuration(&self.pubnub_client).and_then(|_| {
self.user_id
.clone()
.is_some_and(|id| !id.is_empty())
.then_some(())
.ok_or_else(|| {
"User ID is empty. It should be provided and not empty string.".to_owned()
})
})
builders::validate_configuration(&self.pubnub_client)
}

/// Build [`SetStateRequest`] from builder.
Expand All @@ -77,10 +73,16 @@ impl<T, D> WhereNowRequest<T, D> {
) -> Result<TransportRequest, PubNubError> {
let sub_key = &self.pubnub_client.config.subscribe_key;

let user_id = if self.user_id.is_empty() {
&*self.pubnub_client.config.user_id
} else {
&self.user_id
};

Ok(TransportRequest {
path: format!(
"/v2/presence/sub-key/{sub_key}/uuid/{}",
url_encode_extended(self.user_id.as_bytes(), UrlEncodeExtension::NonChannelPath)
url_encode_extended(user_id.as_bytes(), UrlEncodeExtension::NonChannelPath)
),
query_parameters: HashMap::new(),
method: TransportMethod::Get,
Expand Down

0 comments on commit 11dacc0

Please sign in to comment.