@@ -37,6 +37,8 @@ public class SetState extends Endpoint<Envelope<Map<String, Object>>, PNSetState
3737 private List <String > channelGroups ;
3838 @ Setter
3939 private Object state ;
40+ @ Setter
41+ private String uuid ;
4042
4143 public SetState (PubNub pubnubInstance , SubscriptionManager subscriptionManagerInstance ) {
4244 super (pubnubInstance );
@@ -61,14 +63,18 @@ protected void validateParams() throws PubNubException {
6163 @ Override
6264 protected Call <Envelope <Map <String , Object >>> doWork (Map <String , String > params ) throws PubNubException {
6365 ObjectWriter ow = new ObjectMapper ().writer ();
66+ String selectedUUID = uuid != null ? uuid : this .getPubnub ().getConfiguration ().getUuid ();
6467 String stringifiedState ;
6568
66- StateOperation stateOperation = StateOperation .builder ()
67- .state (state )
68- .channels (channels )
69- .channelGroups (channelGroups )
70- .build ();
71- subscriptionManager .adaptStateBuilder (stateOperation );
69+ // only store the state change if we are modifying it for ourselves.
70+ if (selectedUUID .equals (this .getPubnub ().getConfiguration ().getUuid ())) {
71+ StateOperation stateOperation = StateOperation .builder ()
72+ .state (state )
73+ .channels (channels )
74+ .channelGroups (channelGroups )
75+ .build ();
76+ subscriptionManager .adaptStateBuilder (stateOperation );
77+ }
7278
7379 PresenceService service = this .createRetrofit ().create (PresenceService .class );
7480
@@ -87,7 +93,7 @@ protected Call<Envelope<Map<String, Object>>> doWork(Map<String, String> params)
8793
8894 String channelCSV = channels .size () > 0 ? PubNubUtil .joinString (channels , "," ) : "," ;
8995
90- return service .setState (this .getPubnub ().getConfiguration ().getSubscribeKey (), channelCSV , this . getPubnub (). getConfiguration (). getUuid () , params );
96+ return service .setState (this .getPubnub ().getConfiguration ().getSubscribeKey (), channelCSV , selectedUUID , params );
9197 }
9298
9399 @ Override
0 commit comments