Skip to content

Commit fc231eb

Browse files
marceloinacioMax Presman
authored andcommitted
Message_TTL and Publisher
1 parent c0bfa8d commit fc231eb

File tree

7 files changed

+45
-3
lines changed

7 files changed

+45
-3
lines changed

.pubnub.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ features:
149149
- PUBLISH-ASYNC
150150
- PUBLISH-FIRE
151151
- PUBLISH-REPLICATION-FLAG
152+
- PUBLISH-MESSAGE-TTL
152153
storage:
153154
- STORAGE-REVERSE
154155
- STORAGE-INCLUDE-TIMETOKEN
@@ -164,3 +165,4 @@ features:
164165
- SUBSCRIBE-WITH-TIMETOKEN
165166
- SUBSCRIBE-WILDCARD
166167
- SUBSCRIBE-FILTER-EXPRESSION
168+
- SUBSCRIBE-PUBLISHER-UUID

src/main/java/com/pubnub/api/endpoints/pubsub/Publish.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public class Publish extends Endpoint<List<Object>, PNPublishResult> {
3535
private Object meta;
3636
@Setter
3737
private Boolean replicate;
38+
@Setter
39+
private Boolean storeInHistory;
40+
@Setter
41+
private Integer ttl;
3842

3943
private PublishSequenceManager publishSequenceManager;
4044

@@ -43,6 +47,7 @@ public Publish(PubNub pubnub, PublishSequenceManager providedPublishSequenceMana
4347

4448
this.publishSequenceManager = providedPublishSequenceManager;
4549
this.replicate = true;
50+
this.storeInHistory = true;
4651
}
4752

4853
@Override
@@ -59,6 +64,9 @@ protected final void validateParams() throws PubNubException {
5964
if (this.getPubnub().getConfiguration().getPublishKey() == null || this.getPubnub().getConfiguration().getPublishKey().isEmpty()) {
6065
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PUBLISH_KEY_MISSING).build();
6166
}
67+
// if (storeInHistory && ttl == null) {
68+
//
69+
// }
6270
}
6371

6472
@Override
@@ -97,6 +105,10 @@ protected final Call<List<Object>> doWork(Map<String, String> params) throws Pub
97105
params.put("norep", "true");
98106
}
99107

108+
if (storeInHistory && ttl != null) {
109+
params.put("ttl", String.valueOf(ttl));
110+
}
111+
100112
if (this.getPubnub().getConfiguration().getCipherKey() != null) {
101113
Crypto crypto = new Crypto(this.getPubnub().getConfiguration().getCipherKey());
102114
stringifiedMessage = crypto.encrypt(stringifiedMessage).replace("\n", "");

src/main/java/com/pubnub/api/models/consumer/pubsub/PNMessageResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ public class PNMessageResult {
2121
private Long timetoken;
2222
private Object userMetadata;
2323

24+
private String publisher;
2425
}
2526

src/main/java/com/pubnub/api/workers/SubscribeMessageWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private void processIncomingPayload(final SubscribeMessage message) {
166166
.channel(channel)
167167
.subscription(subscriptionMatch)
168168
.timetoken(publishMetaData.getPublishTimetoken())
169+
.publisher(message.getIssuingClientId())
169170
.build();
170171

171172

src/test/java/com/pubnub/api/endpoints/pubsub/PublishTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,31 @@ public void testInvalidMeta() throws PubNubException, InterruptedException {
390390
assertEquals("myUUID", requests.get(0).queryParameter("uuid").firstValue());
391391
assertNull(requests.get(0).queryParameter("norep"));
392392
}
393+
394+
@Test
395+
public void testTTLStoreInHistoryDefaultSuccessSync() throws PubNubException, InterruptedException {
396+
397+
stubFor(get(urlPathEqualTo("/publish/myPublishKey/mySubscribeKey/0/coolChannel/0/%22hi%22"))
398+
.willReturn(aResponse().withBody("[1,\"Sent\",\"14598111595318003\"]")));
399+
400+
instance.channel("coolChannel").message("hi").ttl(10).sync();
401+
402+
List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/.*")));
403+
assertEquals(1, requests.size());
404+
assertEquals("10", requests.get(0).queryParameter("ttl").firstValue());
405+
}
406+
407+
@Test
408+
public void testTTLStoreInHistoryFalseSuccessSync() throws PubNubException, InterruptedException {
409+
410+
stubFor(get(urlPathEqualTo("/publish/myPublishKey/mySubscribeKey/0/coolChannel/0/%22hi%22"))
411+
.willReturn(aResponse().withBody("[1,\"Sent\",\"14598111595318003\"]")));
412+
413+
instance.channel("coolChannel").message("hi").storeInHistory(false).sync();
414+
415+
List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/.*")));
416+
assertEquals(1, requests.size());
417+
assertEquals(null, requests.get(0).queryParameter("ttl"));
418+
}
419+
393420
}

src/test/java/com/pubnub/api/endpoints/pubsub/SubscribeEndpointTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,4 @@ public void stopAndReconnect() throws PubNubException {
214214
assertEquals(2, requests.size());
215215
}
216216

217-
218-
219217
}

src/test/java/com/pubnub/api/managers/SubscriptionManagerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void testSubscribeBuilder() {
105105
final AtomicInteger gotStatus = new AtomicInteger();
106106
final AtomicBoolean gotMessage = new AtomicBoolean();
107107
stubFor(get(urlPathEqualTo("/v2/subscribe/mySubscribeKey/ch2,ch1/0"))
108-
.willReturn(aResponse().withBody("{\"t\":{\"t\":\"14607577960932487\",\"r\":1},\"m\":[{\"a\":\"4\",\"f\":0,\"i\":\"Client-g5d4g\",\"p\":{\"t\":\"14607577960925503\",\"r\":1},\"o\":{\"t\":\"14737141991877032\",\"r\":2},\"k\":\"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\",\"c\":\"coolChannel\",\"d\":{\"text\":\"Message\"},\"b\":\"coolChannel\"}]}")));
108+
.willReturn(aResponse().withBody("{\"t\":{\"t\":\"14607577960932487\",\"r\":1},\"m\":[{\"a\":\"4\",\"f\":0,\"i\":\"Publisher-A\",\"p\":{\"t\":\"14607577960925503\",\"r\":1},\"o\":{\"t\":\"14737141991877032\",\"r\":2},\"k\":\"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\",\"c\":\"coolChannel\",\"d\":{\"text\":\"Message\"},\"b\":\"coolChannel\"}]}")));
109109

110110
pubnub.addListener(new SubscribeCallback() {
111111
@Override
@@ -124,6 +124,7 @@ public void message(PubNub pubnub, PNMessageResult message) {
124124
assertEquals("Message", message.getMessage().get("text").asText());
125125
assertEquals("coolChannel", message.getChannel());
126126
assertEquals(null, message.getSubscription());
127+
assertEquals("Publisher-A", message.getPublisher());
127128
gotMessage.set(true);
128129
}
129130

0 commit comments

Comments
 (0)