Skip to content

Commit fd85720

Browse files
author
Max Presman
committed
Merge branch 'associated_channel_on_subscribe' into develop
2 parents 53e6287 + 5f2334a commit fd85720

6 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎.pubnub.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ changelog:
7777
features:
7878
access:
7979
- GRANT
80-
- AUDIT
8180
channel-groups:
8281
- ADD-CHANNELS
8382
- REMOVE-CHANNELS

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,13 @@ public static String signSHA256(final String key, final String data) throws PubN
132132
return new String(Base64.encode(hmacData, 0), Charset.forName("UTF-8")).replace('+', '-').replace('/', '_');
133133
}
134134

135+
public static String replaceLast(String string, String toReplace, String replacement) {
136+
int pos = string.lastIndexOf(toReplace);
137+
if (pos > -1) {
138+
return string.substring(0, pos).concat(replacement).concat(string.substring(pos + toReplace.length(), string.length()));
139+
} else {
140+
return string;
141+
}
142+
}
143+
135144
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ public class PNMessageResult {
1010

1111
private JsonNode message;
1212

13+
@Deprecated
1314
private String subscribedChannel;
15+
@Deprecated
1416
private String actualChannel;
17+
18+
private String channel;
19+
private String channelGroup;
20+
1521
private Long timetoken;
1622
private Object userMetadata;
1723

1824
}
25+

‎src/main/java/com/pubnub/api/models/consumer/pubsub/PNPresenceEventResult.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ public class PNPresenceEventResult {
1515
private Integer occupancy;
1616
private JsonNode state;
1717

18+
@Deprecated
1819
private String subscribedChannel;
20+
@Deprecated
1921
private String actualChannel;
22+
23+
private String channel;
24+
private String channelGroup;
25+
2026
private Long timetoken;
2127
private Object userMetadata;
2228

‎src/main/java/com/pubnub/api/models/server/SubscribeMessage.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SubscribeMessage {
1313
private String shard;
1414

1515
@JsonProperty("b")
16-
private String subscriptionMatch; // will contain channel group; or channel if user subscribed to channel
16+
private String subscriptionMatch;
1717

1818
@JsonProperty("c")
1919
private String channel;

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.node.ObjectNode;
66
import com.pubnub.api.PubNub;
77
import com.pubnub.api.PubNubException;
8+
import com.pubnub.api.PubNubUtil;
89
import com.pubnub.api.enums.PNOperationType;
910
import com.pubnub.api.enums.PNStatusCategory;
1011
import com.pubnub.api.managers.ListenerManager;
@@ -120,13 +121,27 @@ private void processIncomingPayload(final SubscribeMessage message) {
120121
subscriptionMatch = null;
121122
}
122123

123-
if (message.getChannel().contains("-pnpres")) {
124+
if (message.getChannel().endsWith("-pnpres")) {
124125
PresenceEnvelope presencePayload = mapper.convertValue(message.getPayload(), PresenceEnvelope.class);
125126

127+
String associatedChannel = message.getChannel();
128+
String associatedChannelGroup = message.getSubscriptionMatch();
129+
130+
if (associatedChannel != null) {
131+
associatedChannel = PubNubUtil.replaceLast(associatedChannel, "-pnpres", "");
132+
}
133+
if (associatedChannelGroup != null) {
134+
associatedChannelGroup = PubNubUtil.replaceLast(associatedChannelGroup, "-pnpres", "");
135+
}
136+
126137
PNPresenceEventResult pnPresenceEventResult = PNPresenceEventResult.builder()
127138
.event(presencePayload.getAction())
139+
// deprecated
128140
.actualChannel((subscriptionMatch != null) ? channel : null)
129141
.subscribedChannel(subscriptionMatch != null ? subscriptionMatch : channel)
142+
// deprecated
143+
.channel(associatedChannel)
144+
.channelGroup(associatedChannelGroup)
130145
.state(presencePayload.getData())
131146
.timetoken(publishMetaData.getPublishTimetoken())
132147
.occupancy(presencePayload.getOccupancy())
@@ -144,8 +159,12 @@ private void processIncomingPayload(final SubscribeMessage message) {
144159

145160
PNMessageResult pnMessageResult = PNMessageResult.builder()
146161
.message(extractedMessage)
162+
// deprecated
147163
.actualChannel((subscriptionMatch != null) ? channel : null)
148164
.subscribedChannel(subscriptionMatch != null ? subscriptionMatch : channel)
165+
// deprecated
166+
.channel(channel)
167+
.channelGroup(subscriptionMatch)
149168
.timetoken(publishMetaData.getPublishTimetoken())
150169
.build();
151170

0 commit comments

Comments
 (0)