@@ -56,15 +56,15 @@ pub struct HeartbeatRequest<T, D> {
5656 /// Channel(s) for announcement.
5757 #[ builder(
5858 field( vis = "pub(in crate::dx::presence)" ) ,
59- setter( strip_option , into ) ,
59+ setter( custom , strip_option ) ,
6060 default = "vec![]"
6161 ) ]
6262 pub ( in crate :: dx:: presence) channels : Vec < String > ,
6363
6464 /// Channel group(s) for announcement.
6565 #[ builder(
6666 field( vis = "pub(in crate::dx::presence)" ) ,
67- setter( into , strip_option) ,
67+ setter( custom , strip_option) ,
6868 default = "vec![]"
6969 ) ]
7070 pub ( in crate :: dx:: presence) channel_groups : Vec < String > ,
@@ -120,6 +120,69 @@ pub struct HeartbeatRequest<T, D> {
120120}
121121
122122impl < T , D > HeartbeatRequestBuilder < T , D > {
123+ /// Channel(s) for announcement.
124+ pub fn channels < L > ( mut self , channels : L ) -> Self
125+ where
126+ L : Into < Vec < String > > ,
127+ {
128+ let mut unique = channels. into ( ) ;
129+ unique. sort_unstable ( ) ;
130+ unique. dedup ( ) ;
131+
132+ self . channels = Some ( unique) ;
133+ self
134+ }
135+
136+ /// Channel group(s) for announcement.
137+ pub fn channel_groups < L > ( mut self , channel_groups : L ) -> Self
138+ where
139+ L : Into < Vec < String > > ,
140+ {
141+ let mut unique = channel_groups. into ( ) ;
142+ unique. sort_unstable ( ) ;
143+ unique. dedup ( ) ;
144+
145+ self . channel_groups = Some ( unique) ;
146+ self
147+ }
148+
149+ /// A state that should be associated with the `user_id`.
150+ ///
151+ /// `state` object should be a `HashMap` with channel names as keys and
152+ /// nested `HashMap` with values. State with heartbeat can be set **only**
153+ /// for channels.
154+ ///
155+ /// # Example:
156+ /// ```rust,no_run
157+ /// # use std::collections::HashMap;
158+ /// # use pubnub::core::Serialize;
159+ /// # fn main() -> Result<(), pubnub::core::PubNubError> {
160+ /// let state: HashMap<String, HashMap<String, bool>> = HashMap::from([(
161+ /// "announce".to_string(),
162+ /// HashMap::<String, bool>::from([
163+ /// ("is_owner".to_string(), false),
164+ /// ("is_admin".to_string(), true)
165+ /// ])
166+ /// )]);
167+ /// # Ok(())
168+ /// # }
169+ /// ```
170+ pub fn state ( mut self , state : HashMap < String , Vec < u8 > > ) -> Self {
171+ let mut serialized_state = vec ! [ b'{' ] ;
172+ for ( key, mut value) in state {
173+ serialized_state. append ( & mut format ! ( "\" {}\" :" , key) . as_bytes ( ) . to_vec ( ) ) ;
174+ serialized_state. append ( & mut value) ;
175+ serialized_state. push ( b',' ) ;
176+ }
177+ if serialized_state. last ( ) == Some ( & b',' ) {
178+ serialized_state. pop ( ) ;
179+ }
180+ serialized_state. push ( b'}' ) ;
181+
182+ self . state = Some ( Some ( serialized_state) ) ;
183+ self
184+ }
185+
123186 /// Validate user-provided data for request builder.
124187 ///
125188 /// Validator ensure that provided information is enough to build valid
@@ -184,45 +247,6 @@ impl<T, D> HeartbeatRequest<T, D> {
184247 }
185248}
186249
187- impl < T , D > HeartbeatRequestBuilder < T , D > {
188- /// A state that should be associated with the `user_id`.
189- ///
190- /// `state` object should be a `HashMap` with channel names as keys and
191- /// nested `HashMap` with values. State with heartbeat can be set **only**
192- /// for channels.
193- ///
194- /// # Example:
195- /// ```rust,no_run
196- /// # use std::collections::HashMap;
197- /// # use pubnub::core::Serialize;
198- /// # fn main() -> Result<(), pubnub::core::PubNubError> {
199- /// let state: HashMap<String, HashMap<String, bool>> = HashMap::from([(
200- /// "announce".to_string(),
201- /// HashMap::<String, bool>::from([
202- /// ("is_owner".to_string(), false),
203- /// ("is_admin".to_string(), true)
204- /// ])
205- /// )]);
206- /// # Ok(())
207- /// # }
208- /// ```
209- pub fn state ( mut self , state : HashMap < String , Vec < u8 > > ) -> Self {
210- let mut serialized_state = vec ! [ b'{' ] ;
211- for ( key, mut value) in state {
212- serialized_state. append ( & mut format ! ( "\" {}\" :" , key) . as_bytes ( ) . to_vec ( ) ) ;
213- serialized_state. append ( & mut value) ;
214- serialized_state. push ( b',' ) ;
215- }
216- if serialized_state. last ( ) == Some ( & b',' ) {
217- serialized_state. pop ( ) ;
218- }
219- serialized_state. push ( b'}' ) ;
220-
221- self . state = Some ( Some ( serialized_state) ) ;
222- self
223- }
224- }
225-
226250impl < T , D > HeartbeatRequestBuilder < T , D >
227251where
228252 T : Transport + ' static ,
0 commit comments