Skip to content

Commit b5d43a6

Browse files
author
Max Presman
committed
4.0.4 / setting state for other uuid's
1 parent 826a126 commit b5d43a6

6 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
4.0.4
3+
- setting State for other UUID's is now supported (again)
4+
25
4.0.3
36
- fire() method and no-replicaton options.
47

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.3
1+
4.0.4

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
id 'findbugs'
1010
}
1111
group = 'com.pubnub'
12-
version = '4.0.3'
12+
version = '4.0.4'
1313

1414
description = """"""
1515

‎src/main/java/com/pubnub/api/PubNub.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class PubNub {
5050
private static final int TIMESTAMP_DIVIDER = 1000;
5151
private static final int MAX_SEQUENCE = 65535;
5252

53-
private static final String SDK_VERSION = "4.0.3";
53+
private static final String SDK_VERSION = "4.0.4";
5454

5555
public PubNub(final PNConfiguration initialConfig) {
5656
this.configuration = initialConfig;

‎src/main/java/com/pubnub/api/endpoints/presence/SetState.java‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎src/test/java/com/pubnub/api/endpoints/presence/SetStateEndpointTest.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ public void applyStateForChannelSync() throws PubNubException, InterruptedExcept
5555
assertEquals(1, requests.size());
5656
}
5757

58+
@Test
59+
public void applyStateForSomebodyElseChannelSync() throws PubNubException, InterruptedException {
60+
61+
stubFor(get(urlPathEqualTo("/v2/presence/sub-key/mySubscribeKey/channel/testChannel/uuid/someoneElseUUID/data"))
62+
.withQueryParam("uuid", matching("myUUID"))
63+
.withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava"))
64+
.withQueryParam("state", matching("%7B%22age%22%3A20%7D"))
65+
.willReturn(aResponse().withBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}")));
66+
67+
Map<String, Object> myState = new HashMap<>();
68+
myState.put("age", 20);
69+
70+
PNSetStateResult result = partialSetState.channels(Arrays.asList("testChannel")).state(myState).uuid("someoneElseUUID").sync();
71+
assertEquals(result.getState().get("age"), 20);
72+
assertEquals(result.getState().get("status"), "online");
73+
74+
List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/.*")));
75+
assertEquals(1, requests.size());
76+
}
77+
5878
@Test
5979
public void applyStateForChannelsSync() throws PubNubException, InterruptedException {
6080

0 commit comments

Comments
 (0)