Skip to content

Commit 3ef8453

Browse files
authored
Merge pull request #22 from pubnub/CE-3355-Message-Count-Changes
Message Count Changes
2 parents 153ec4e + d5a5619 commit 3ef8453

File tree

10 files changed

+72
-28
lines changed

10 files changed

+72
-28
lines changed

.pubnub.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
2-
changelog:
2+
changelog:
3+
-
4+
changes:
5+
-
6+
text: "Message Counts simplification (Breaking changes from the previous version)."
7+
type: improvement
8+
date: Mar 13, 19
9+
version: v4.2.0
310
-
411
changes:
512
-
@@ -365,4 +372,4 @@ supported-platforms:
365372
- "Ubuntu 12.04+, with Graphics card DX9 (shader model 3.0) or DX11 with feature level 9.3 capabilities; and CPU SSE2 instruction set support."
366373
- "Mac OS X 10.8+, with Graphics card DX9 (shader model 3.0) or DX11 with feature level 9.3 capabilities; and CPU SSE2 instruction set support."
367374
version: "PubNub Unity SDK"
368-
version: v4.1.1
375+
version: v4.2.0

PubNubUnity/Assets/PubNub/Builders/History/MessageCountsRequestBuilder.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public MessageCountsRequestBuilder(PubNubUnity pn):base(pn, PNOperationType.PNMe
1414

1515
private string TimetokenToUse {get; set;}
1616

17-
private List<string> ChannelTimetokensToUse {get; set;}
17+
private List<long> ChannelTimetokensToUse {get; set;}
1818

1919
public MessageCountsRequestBuilder Channels(List<string> channelNames){
2020
ChannelsToUse = channelNames;
2121
return this;
2222
}
2323

24-
public MessageCountsRequestBuilder ChannelsTimetoken(List<string> channelTimetoken){
24+
public MessageCountsRequestBuilder ChannelsTimetoken(List<long> channelTimetoken){
2525
ChannelTimetokensToUse = channelTimetoken;
2626
return this;
2727
}
@@ -37,12 +37,26 @@ public void Async(Action<PNMessageCountsResult, PNStatus> callback)
3737
{
3838
this.Callback = callback;
3939
if((this.ChannelsToUse == null) || ((this.ChannelsToUse != null) && (this.ChannelsToUse.Count <= 0))){
40-
PNStatus pnStatus = base.CreateErrorResponseFromMessage("HistoryChannel is null or empty", null, PNStatusCategory.PNBadRequestCategory);
40+
PNStatus pnStatus = base.CreateErrorResponseFromMessage("Channel is null or empty", null, PNStatusCategory.PNBadRequestCategory);
4141
Callback(null, pnStatus);
4242

4343
return;
4444
}
4545

46+
if(((this.ChannelTimetokensToUse == null) || ((this.ChannelTimetokensToUse != null) && (this.ChannelTimetokensToUse.Count <= 0))) && (string.IsNullOrEmpty(TimetokenToUse))){
47+
PNStatus pnStatus = base.CreateErrorResponseFromMessage("Channel Timetoken is null or empty", null, PNStatusCategory.PNBadRequestCategory);
48+
Callback(null, pnStatus);
49+
50+
return;
51+
}
52+
53+
if ((ChannelTimetokensToUse.Count > 1) && (ChannelTimetokensToUse.Count() != ChannelsToUse.Count())) {
54+
PNStatus pnStatus = base.CreateErrorResponseFromMessage("Length of Channels Timetoken and Channels do not match", null, PNStatusCategory.PNBadRequestCategory);
55+
Callback(null, pnStatus);
56+
57+
return;
58+
}
59+
4660
base.Async(this);
4761
}
4862
#endregion
@@ -51,14 +65,28 @@ protected override void RunWebRequest(QueueManager qm){
5165
RequestState requestState = new RequestState ();
5266
requestState.OperationType = base.OperationType;
5367

68+
string TimetokenToUseString = "";
69+
string ChannelsTimetokenToUseString = "";
70+
if ((ChannelTimetokensToUse != null) && (ChannelTimetokensToUse.Count == 1)) {
71+
TimetokenToUseString = ChannelTimetokensToUse[0].ToString();
72+
ChannelsTimetokenToUseString = "";
73+
} else if (ChannelTimetokensToUse != null){
74+
TimetokenToUseString = "";
75+
ChannelsTimetokenToUseString = String.Join(",", ChannelTimetokensToUse.Select(p=>p.ToString()).ToArray());
76+
} else {
77+
// TODO: Remove in next major version bump
78+
TimetokenToUseString = TimetokenToUse;
79+
ChannelsTimetokenToUseString = "";
80+
}
81+
5482
#if (ENABLE_PUBNUB_LOGGING)
55-
this.PubNubInstance.PNLog.WriteToLog(string.Format ("MessageCountsRequestBuilder: \nChannel {0} \nChannelTimetokens: {1} \nTimetokenToUse:{2}", string.Join(",", this.ChannelsToUse.ToArray()), (ChannelTimetokensToUse!=null)?string.Join(",", this.ChannelTimetokensToUse.ToArray()):"", this.TimetokenToUse), PNLoggingMethod.LevelInfo);
83+
this.PubNubInstance.PNLog.WriteToLog(string.Format ("MessageCountsRequestBuilder: \nChannel {0} \nChannelTimetokens: {1} \nTimetokenToUse:{2}", string.Join(",", this.ChannelsToUse.ToArray()), ChannelsTimetokenToUseString, ChannelsTimetokenToUseString), PNLoggingMethod.LevelInfo);
5684
#endif
57-
85+
5886
Uri request = BuildRequests.BuildMessageCountsRequest(
5987
ChannelsToUse.ToArray(),
60-
(ChannelTimetokensToUse!=null)?ChannelTimetokensToUse.ToArray():null,
61-
TimetokenToUse,
88+
ChannelsTimetokenToUseString,
89+
TimetokenToUseString,
6290
this.PubNubInstance,
6391
this.QueryParams
6492
);

PubNubUnity/Assets/PubNub/Editor/MessageCountsBuildRequestsTests.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NUnit.Framework;
44
using System.Text;
55
using System.Collections.Generic;
6+
using System.Linq;
67

78
namespace PubNubAPI.Tests
89
{
@@ -14,7 +15,7 @@ public class MessageCountsBuildRequestsTests
1415
public void TestBuildMessageCountsRequestMultiChannelAuthSSL ()
1516
{
1617
string[] channels = { "test", "test2" };
17-
string[] channelsTimetoken = { "15499825804610610", "15499925804610615" };
18+
long[] channelsTimetoken = { 15499825804610610, 15499925804610615 };
1819
string timetoken = "15499825804610609";
1920
TestMessageCountsBuildRequestCommon (channels, channelsTimetoken, timetoken, true, "authKey", false);
2021
}
@@ -23,7 +24,7 @@ public void TestBuildMessageCountsRequestMultiChannelAuthSSL ()
2324
public void TestBuildMessageCountsRequestMultiChannelTTAuthSSL ()
2425
{
2526
string[] channels = { "test", "test2" };
26-
string[] channelsTimetoken = { };
27+
long[] channelsTimetoken = { };
2728
string timetoken = "15499825804610609";
2829
TestMessageCountsBuildRequestCommon (channels, channelsTimetoken, timetoken, true, "authKey", false);
2930
}
@@ -32,7 +33,7 @@ public void TestBuildMessageCountsRequestMultiChannelTTAuthSSL ()
3233
public void TestBuildMessageCountsRequestMultiChannelCTAuthSSL ()
3334
{
3435
string[] channels = { "test", "test2" };
35-
string[] channelsTimetoken = { "15499825804610610", "15499925804610615" };
36+
long[] channelsTimetoken = { 15499825804610610, 15499925804610615 };
3637
string timetoken = "";
3738
TestMessageCountsBuildRequestCommon (channels, channelsTimetoken, timetoken, true, "authKey", false);
3839
}
@@ -41,7 +42,7 @@ public void TestBuildMessageCountsRequestMultiChannelCTAuthSSL ()
4142
public void TestBuildMessageCountsRequestMultiChannelAuthSSLQP ()
4243
{
4344
string[] channels = { "test", "test2" };
44-
string[] channelsTimetoken = { "15499825804610610", "15499925804610615" };
45+
long[] channelsTimetoken = { 15499825804610610, 15499925804610615 };
4546
string timetoken = "15499825804610609";
4647
TestMessageCountsBuildRequestCommon (channels, channelsTimetoken, timetoken, true, "authKey", true);
4748
}
@@ -50,7 +51,7 @@ public void TestBuildMessageCountsRequestMultiChannelAuthSSLQP ()
5051
public void TestBuildMessageCountsRequestMultiChannelTTAuthSSLQP ()
5152
{
5253
string[] channels = { "test", "test2" };
53-
string[] channelsTimetoken = { };
54+
long[] channelsTimetoken = { };
5455
string timetoken = "15499825804610609";
5556
TestMessageCountsBuildRequestCommon (channels, channelsTimetoken, timetoken, true, "authKey", true);
5657
}
@@ -59,12 +60,12 @@ public void TestBuildMessageCountsRequestMultiChannelTTAuthSSLQP ()
5960
public void TestBuildMessageCountsRequestMultiChannelCTAuthSSLQP ()
6061
{
6162
string[] channels = { "test", "test2" };
62-
string[] channelsTimetoken = { "15499825804610610", "15499925804610615" };
63+
long[] channelsTimetoken = { 15499825804610610, 15499925804610615 };
6364
string timetoken = "";
6465
TestMessageCountsBuildRequestCommon (channels, channelsTimetoken, timetoken, true, "authKey", true);
6566
}
6667

67-
public void TestMessageCountsBuildRequestCommon(string[] channels, string[] channelsTimetoken, string timetoken, bool ssl, string authKey, bool sendQueryParams)
68+
public void TestMessageCountsBuildRequestCommon(string[] channels, long[] channelsTimetoken, string timetoken, bool ssl, string authKey, bool sendQueryParams)
6869
{
6970
Dictionary<string,string> queryParams = new Dictionary<string, string>();
7071
string queryParamString = "";
@@ -100,10 +101,10 @@ public void TestMessageCountsBuildRequestCommon(string[] channels, string[] chan
100101
}
101102

102103
if(channelsTimetoken != null){
103-
channelsTimetokenStr = string.Join(",", channelsTimetoken);
104+
channelsTimetokenStr = String.Join(",", channelsTimetoken.Select(p=>p.ToString()).ToArray());
104105
}
105106

106-
Uri uri = BuildRequests.BuildMessageCountsRequest (channels, channelsTimetoken, timetoken, pnUnity, queryParams);
107+
Uri uri = BuildRequests.BuildMessageCountsRequest (channels, channelsTimetokenStr, timetoken, pnUnity, queryParams);
107108

108109
//https://ps.pndsn.com/v3/history/sub-key/demo/message-counts/test,test2?timetoken=15499825804610609&channelsTimetoken=15499825804610610,15499925804610615&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX%2F4.1.1
109110
string expected = string.Format ("http{0}://{1}/v3/history/sub-key/{2}/message-counts/{3}?timetoken={4}&channelsTimetoken={5}{6}&uuid={7}&pnsdk={8}{9}",

PubNubUnity/Assets/PubNub/EndPoints/HIstory/MessageCountsBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ public MessageCountsBuilder Channels(List<string> channelNames){
1414
return this;
1515
}
1616

17-
public MessageCountsBuilder ChannelsTimetoken(List<string> channelsTimetoken){
17+
public MessageCountsBuilder ChannelsTimetoken(List<long> channelsTimetoken){
1818
pubBuilder.ChannelsTimetoken(channelsTimetoken);
1919
return this;
2020
}
2121

22+
[Obsolete("Use ChannelsTimetoken instead, pass one value in ChannelsTimetoken to achieve the same results.")]
2223
public MessageCountsBuilder Timetoken(string timetoken){
2324
pubBuilder.Timetoken(timetoken);
2425
return this;

PubNubUnity/Assets/PubNub/Examples/Example.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void Init(){
417417

418418
void MessageCounts(List<string> listChannels, PubNub pubnub){
419419
//pubnub.MessageCounts().ChannelTimetokens(new List<string>{"15499825804610610","15499925804610615"}).Channels(listChannels).Timetoken("1549982652").Async((result, status) =>{
420-
pubnub.MessageCounts().Channels(listChannels).Timetoken("1549982652").Async((result, status) =>{
420+
pubnub.MessageCounts().Channels(listChannels).ChannelsTimetoken(new List<long>{1549982652}).Async((result, status) =>{
421421
if(status.Error){
422422
Debug.Log (string.Format("In Example, MessageCounts Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
423423
} else {
@@ -427,7 +427,7 @@ void MessageCounts(List<string> listChannels, PubNub pubnub){
427427
}
428428
}
429429
});
430-
pubnub.MessageCounts().Channels(listChannels).ChannelsTimetoken(new List<string>{"1551795013294","155179501329433"}).Async((result, status) =>{
430+
pubnub.MessageCounts().Channels(listChannels).ChannelsTimetoken(new List<long>{1551795013294,155179501329433}).Async((result, status) =>{
431431
if(status.Error){
432432
Debug.Log (string.Format("In Example, MessageCounts Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
433433
} else {

PubNubUnity/Assets/PubNub/Models/Server/BuildRequests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ public static Uri BuildDeleteMessagesRequest (string channel, long start, long e
181181
return BuildRestApiRequest<Uri> (url, PNOperationType.PNDeleteMessagesOperation, parameterBuilder.ToString(), pnInstance, queryParams);
182182
}
183183

184-
public static Uri BuildMessageCountsRequest (string[] channels, string[] channelsTimetoken, string timetoken, PubNubUnity pnInstance, Dictionary<string, string> queryParams)
184+
public static Uri BuildMessageCountsRequest (string[] channels, string channelsTimetoken, string timetoken, PubNubUnity pnInstance, Dictionary<string, string> queryParams)
185185
{
186186
StringBuilder parameterBuilder = new StringBuilder ();
187187

188188
parameterBuilder.AppendFormat ("?timetoken={0}", timetoken);
189-
parameterBuilder.AppendFormat ("&channelsTimetoken={0}", (channelsTimetoken!=null)?string.Join(",", channelsTimetoken):"");
189+
parameterBuilder.AppendFormat ("&channelsTimetoken={0}", channelsTimetoken);
190190

191191
List<string> url = new List<string> ();
192192

PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,14 @@ public IEnumerator TestMessageCounts() {
33653365
channelList2.Add(channel);
33663366
channelList2.Add(channel2);
33673367
bool tresult = false;
3368+
pubnub.MessageCounts().Channels(channelList2).ChannelsTimetoken(new List<long>{10, 11, 12}).Async((result, status) => {
3369+
tresult = true;
3370+
Assert.True(status.Error.Equals(true));
33683371

3372+
});
3373+
yield return new WaitForSeconds (1);
3374+
3375+
tresult = false;
33693376
long timetoken1 = 0;
33703377
pubnub.Time().Async((result, status) => {
33713378
timetoken1 = result.TimeToken;
@@ -3434,7 +3441,7 @@ public IEnumerator TestMessageCounts() {
34343441
Assert.True(!timetoken3.Equals(0));
34353442

34363443
tresult = false;
3437-
pubnub.MessageCounts().Channels(channelList2).ChannelsTimetoken(new List<string>{timetoken2.ToString(), timetoken3.ToString()}).Async((result, status) => {
3444+
pubnub.MessageCounts().Channels(channelList2).ChannelsTimetoken(new List<long>{timetoken2, timetoken3}).Async((result, status) => {
34383445
Assert.True(status.Error.Equals(false));
34393446
Debug.Log("status.Error.Equals(false)"+status.Error.Equals(false));
34403447
if(!status.Error){
@@ -3463,7 +3470,7 @@ public IEnumerator TestMessageCounts() {
34633470
Assert.True(tresult, "MessageCounts test didnt return 2");
34643471

34653472
tresult = false;
3466-
pubnub.MessageCounts().Channels(channelList2).Timetoken(timetoken2.ToString()).Async((result, status) => {
3473+
pubnub.MessageCounts().Channels(channelList2).ChannelsTimetoken(new List<long>{timetoken2}).Async((result, status) => {
34673474
Assert.True(status.Error.Equals(false));
34683475
Debug.Log("status.Error.Equals(false)"+status.Error.Equals(false));
34693476
if(!status.Error){

PubNubUnity/Assets/PubNub/PubNubUnity/PubNubUnityBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PubNubAPI
77
public class PubNubUnityBase
88
{
99
protected Counter publishMessageCounter;
10-
private const string build = "4.1.1";
10+
private const string build = "4.2.0";
1111
private string pnsdkVersion = string.Format ("PubNub-CSharp-Unity/{0}", build);
1212

1313
public string Version {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://api.travis-ci.org/pubnub/unity.svg?branch=master)](https://travis-ci.org/pubnub/unity) [![Build status](https://ci.appveyor.com/api/projects/status/1p3494pnt6rgqdsm/branch/master?svg=true)](https://ci.appveyor.com/project/PubNub/unity)
44

5-
## PubNub 4.1.1 Web Data Push Cloud-Hosted API for Unity 5+
5+
## PubNub 4.2.0 Web Data Push Cloud-Hosted API for Unity 5+
66
### Supports PC, Mac, Linux, iOS, Android, Windows Store Universal 10 and WebGL
77

88
## All new PubNub Unity SDK

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.1
1+
4.2.0

0 commit comments

Comments
 (0)