Skip to content

Commit 9021c27

Browse files
authored
Merge pull request #6 from pubnub/pt137514037
Fixed user state issue for other UUID
2 parents 6fa3915 + f53fb3a commit 9021c27

File tree

10 files changed

+211
-40
lines changed

10 files changed

+211
-40
lines changed

.pubnub.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
22
changelog:
3+
-
4+
changes:
5+
-
6+
text: "Fixed user state issue for other UUID"
7+
type: bug
8+
date: Jan 12, 17
9+
version: v3.7.6.2
310
-
411
changes:
512
-
@@ -15,7 +22,7 @@ changelog:
1522
-
1623
text: "Find out which UUID sent the message (only avialable when debug symbol `PUBNUB_PS_V2_RESPONSE` is used)."
1724
type: feature
18-
date: ~
25+
date: Dec 9, 16
1926
version: v3.7.6
2027
-
2128
changes:
@@ -35,7 +42,7 @@ changelog:
3542
-
3643
text: "Added a debug symbol `PUBNUB_PS_V2_RESPONSE` to enable v4 subscribe"
3744
type: feature
38-
date: ~
45+
date: Sep 24, 16
3946
version: v3.7.4
4047
-
4148
changes:
@@ -61,7 +68,7 @@ changelog:
6168
-
6269
text: "Code optimizations"
6370
type: improvement
64-
date: ~
71+
date: Aug 2, 16
6572
version: v3.7.2
6673
-
6774
changes:
@@ -71,7 +78,7 @@ changelog:
7178
-
7279
text: "For iOS if the value of NonSubscribeTimeout and SubscribeTimeout is greater than 59 secs, the SDK will force the value to be 59 secs."
7380
type: improvement
74-
date: ~
81+
date: Jun 21, 16
7582
version: v3.6.9.1
7683
-
7784
changes:
@@ -193,4 +200,4 @@ features:
193200
name: unity
194201
schema: 1
195202
scm: github.com/pubnub/unity
196-
version: “3.7.6.1
203+
version: “3.7.6.2

Assets/Scripts/Editor/HelpersUnitTestsNew.cs

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -297,54 +297,102 @@ public void TestGetNamesFromChannelEntitiesCommon2<T>(bool channelGroup, bool ch
297297
[Test]
298298
public void TestUpdateOrAddUserStateOfEntityErrorCallbackObj(){
299299
TestUpdateOrAddUserStateOfEntityCommon<object>(true, false, true, false,
300-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
300+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
301301
}
302302

303303
[Test]
304304
public void TestUpdateOrAddUserStateOfEntityObj(){
305305
TestUpdateOrAddUserStateOfEntityCommon<object>(false, false, false, false,
306-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
306+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
307307
}
308308

309309
[Test]
310310
public void TestUpdateOrAddUserStateOfEntityErrorCallbackEditObj(){
311311
TestUpdateOrAddUserStateOfEntityCommon<object>(true, true, false, false,
312-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
312+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
313313
}
314314

315315
[Test]
316316
public void TestUpdateOrAddUserStateOfEntityEditObj(){
317317
TestUpdateOrAddUserStateOfEntityCommon<object>(false, true, false, false,
318-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
318+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
319319
}
320320

321321
[Test]
322322
public void TestUpdateOrAddUserStateOfEntityErrorCallback(){
323323
TestUpdateOrAddUserStateOfEntityCommon<string>(true, false, true, false,
324-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
324+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
325325
}
326326

327327
[Test]
328328
public void TestUpdateOrAddUserStateOfEntity(){
329329
TestUpdateOrAddUserStateOfEntityCommon<string>(false, false, false, false,
330-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
330+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
331331
}
332332

333333
[Test]
334334
public void TestUpdateOrAddUserStateOfEntityErrorCallbackEdit(){
335335
TestUpdateOrAddUserStateOfEntityCommon<string>(true, true, false, false,
336-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
336+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
337337
}
338338

339339
[Test]
340340
public void TestUpdateOrAddUserStateOfEntityEdit(){
341341
TestUpdateOrAddUserStateOfEntityCommon<string>(false, true, false, false,
342-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
342+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, false);
343+
}
344+
345+
[Test]
346+
public void TestUpdateOrAddUserStateOfEntityErrorCallbackObjOther(){
347+
TestUpdateOrAddUserStateOfEntityCommon<object>(true, false, true, false,
348+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
349+
}
350+
351+
[Test]
352+
public void TestUpdateOrAddUserStateOfEntityObjOther(){
353+
TestUpdateOrAddUserStateOfEntityCommon<object>(false, false, false, false,
354+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
355+
}
356+
357+
[Test]
358+
public void TestUpdateOrAddUserStateOfEntityErrorCallbackEditObjOther(){
359+
TestUpdateOrAddUserStateOfEntityCommon<object>(true, true, false, false,
360+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
361+
}
362+
363+
[Test]
364+
public void TestUpdateOrAddUserStateOfEntityEditObjOther(){
365+
TestUpdateOrAddUserStateOfEntityCommon<object>(false, true, false, false,
366+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
367+
}
368+
369+
[Test]
370+
public void TestUpdateOrAddUserStateOfEntityErrorCallbackOther(){
371+
TestUpdateOrAddUserStateOfEntityCommon<string>(true, false, true, false,
372+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
373+
}
374+
375+
[Test]
376+
public void TestUpdateOrAddUserStateOfEntityOther(){
377+
TestUpdateOrAddUserStateOfEntityCommon<string>(false, false, false, false,
378+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
379+
}
380+
381+
[Test]
382+
public void TestUpdateOrAddUserStateOfEntityErrorCallbackEditOther(){
383+
TestUpdateOrAddUserStateOfEntityCommon<string>(true, true, false, false,
384+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
385+
}
386+
387+
[Test]
388+
public void TestUpdateOrAddUserStateOfEntityEditOther(){
389+
TestUpdateOrAddUserStateOfEntityCommon<string>(false, true, false, false,
390+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, true);
343391
}
344392

345393
public void TestUpdateOrAddUserStateOfEntityCommon<T>(bool isChannelGroup, bool edit,
346394
bool checkErrorCallback, bool ssl, Action<T> userCallback, Action<T> connectCallback,
347-
Action<T> wildcardPresenceCallback, Action<T> disconnectCallback){
395+
Action<T> wildcardPresenceCallback, Action<T> disconnectCallback, bool isForOtherUUID){
348396

349397
var dictSM = new Dictionary<string, object>();
350398
dictSM.Add("k","v");
@@ -376,16 +424,16 @@ public void TestUpdateOrAddUserStateOfEntityCommon<T>(bool isChannelGroup, bool
376424
lstCe2.Add(ce1);
377425

378426
Helpers.UpdateOrAddUserStateOfEntity<T>(channelName, isChannelGroup, dictSM2, edit,
379-
userCallback, ErrorCallbackUserState, PubnubErrorFilter.Level.Info
380-
, ref lstCe2);
427+
userCallback, ErrorCallbackUserState, PubnubErrorFilter.Level.Info,
428+
isForOtherUUID, ref lstCe2);
381429
string ustate = pubnub.JsonPluggableLibrary.SerializeToJsonString(lstCe2[0].ChannelParams.UserState);
382430
string state2 = pubnub.JsonPluggableLibrary.SerializeToJsonString(dictSM2);
383431
UnityEngine.Debug.Log(string.Format("{0}\n{1}", state2, ustate));
384432
}
385433

386434
if(Helpers.UpdateOrAddUserStateOfEntity<T>(channelName, isChannelGroup, dictSM, edit,
387-
userCallback, ErrorCallbackUserState, PubnubErrorFilter.Level.Info
388-
, ref lstCe)){
435+
userCallback, ErrorCallbackUserState, PubnubErrorFilter.Level.Info,
436+
isForOtherUUID, ref lstCe)){
389437
string ustate = pubnub.JsonPluggableLibrary.SerializeToJsonString(lstCe[0].ChannelParams.UserState);
390438
UnityEngine.Debug.Log(string.Format("{0}\n{1}", state, ustate));
391439
Assert.AreEqual(ustate, state,
@@ -408,17 +456,37 @@ void ErrorCallbackUserState (PubnubClientError result)
408456
[Test]
409457
public void TestCheckAndAddExistingUserStateEdit(){
410458
TestCheckAndAddExistingUserStateCommon<string>(false,
411-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
459+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, "", "");
412460
}
413461

414462
[Test]
415463
public void TestCheckAndAddExistingUserStateEditObj(){
416464
TestCheckAndAddExistingUserStateCommon<object>(false,
417-
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback);
465+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, "", "");
466+
}
467+
468+
[Test]
469+
public void TestCheckAndAddExistingUserStateEditOther(){
470+
TestCheckAndAddExistingUserStateCommon<string>(false,
471+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, "uuid1", "uuid2");
472+
}
473+
474+
[Test]
475+
public void TestCheckAndAddExistingUserStateEditObjOther(){
476+
TestCheckAndAddExistingUserStateCommon<object>(false,
477+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, "uuid1", "uuid2");
478+
}
479+
480+
[Test]
481+
public void TestCheckAndAddExistingUserStateEditObjBoth(){
482+
TestCheckAndAddExistingUserStateCommon<object>(false,
483+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, "", "");
484+
TestCheckAndAddExistingUserStateCommon<object>(false,
485+
Common.UserCallback, Common.ConnectCallback, Common.WildcardPresenceCallback, Common.DisconnectCallback, "uuid1", "uuid2");
418486
}
419487

420488
public void TestCheckAndAddExistingUserStateCommon<T>( bool edit, Action<T> userCallback, Action<T> connectCallback,
421-
Action<T> wildcardPresenceCallback, Action<T> disconnectCallback
489+
Action<T> wildcardPresenceCallback, Action<T> disconnectCallback, string uuid, string sessionUUID
422490
){
423491
var dictSM = new Dictionary<string, object>();
424492
dictSM.Add("k","v");
@@ -441,7 +509,7 @@ Action<T> wildcardPresenceCallback, Action<T> disconnectCallback
441509
bool stateChanged = Helpers.CheckAndAddExistingUserState<T>(string.Join(",",ch),
442510
string.Join(",",cg), dictSM, userCallback,
443511
ErrorCallbackUserState,PubnubErrorFilter.Level.Info
444-
, edit, out userstate, out lstCE);
512+
, edit, uuid, sessionUUID, out userstate, out lstCE);
445513

446514
bool ceFound = true;
447515
foreach(ChannelEntity ch2 in lstCE){

Assets/Scripts/Pubnub/Helpers.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,37 +268,48 @@ internal static string GetNamesFromChannelEntities (List<ChannelEntity> channelE
268268
internal static bool UpdateOrAddUserStateOfEntity<T>(string channel, bool isChannelGroup,
269269
Dictionary<string, object> userState, bool edit,
270270
Action<T> userCallback, Action<PubnubClientError> errorCallback,
271-
PubnubErrorFilter.Level errorLevel, ref List<ChannelEntity> channelEntities)
271+
PubnubErrorFilter.Level errorLevel, bool isForOtherUUID, ref List<ChannelEntity> channelEntities)
272272
{
273273
ChannelEntity ce = CreateChannelEntity<T> (channel, false, isChannelGroup,
274274
userState, userCallback, null, errorCallback, null, null);
275-
bool stateChanged = Subscription.Instance.UpdateOrAddUserStateOfEntity (ref ce, userState, edit);
276-
if (!stateChanged) {
277-
string message = "No change in User State";
275+
bool stateChanged = false;
278276

279-
PubnubCallbacks.CallErrorCallback<T> (ce, message,
280-
PubnubErrorCode.UserStateUnchanged, PubnubErrorSeverity.Info, errorLevel);
281-
} else {
277+
if (isForOtherUUID) {
278+
ce.ChannelParams.UserState = userState;
282279
channelEntities.Add (ce);
280+
stateChanged = true;
281+
} else {
282+
stateChanged = Subscription.Instance.UpdateOrAddUserStateOfEntity (ref ce, userState, edit);
283+
if (!stateChanged) {
284+
string message = "No change in User State";
285+
286+
PubnubCallbacks.CallErrorCallback<T> (ce, message,
287+
PubnubErrorCode.UserStateUnchanged, PubnubErrorSeverity.Info, errorLevel);
288+
} else {
289+
channelEntities.Add (ce);
290+
}
283291
}
284292
return stateChanged;
285293
}
286294

287295
internal static bool CheckAndAddExistingUserState<T>(string channel, string channelGroup, Dictionary<string, object> userState,
288296
Action<T> userCallback, Action<PubnubClientError> errorCallback,
289-
PubnubErrorFilter.Level errorLevel, bool edit,
297+
PubnubErrorFilter.Level errorLevel, bool edit, string uuid, string sessionUUID,
290298
out string returnUserState, out List<ChannelEntity> channelEntities
291299
)
292300
{
293301
string[] channels = channel.Trim().Split (',');
294302
string[] channelGroups = channelGroup.Trim().Split (',');
295303
bool stateChanged = false;
304+
bool isForOtherUUID = false;
296305
channelEntities = new List<ChannelEntity> ();
297-
306+
if (!string.IsNullOrEmpty (uuid) && !sessionUUID.Equals (uuid)) {
307+
isForOtherUUID = true;
308+
}
298309
foreach (string ch in channels) {
299310
if (!string.IsNullOrEmpty (ch)) {
300311
bool changeState = UpdateOrAddUserStateOfEntity<T> (ch, false, userState, edit,
301-
userCallback, errorCallback, errorLevel, ref channelEntities);
312+
userCallback, errorCallback, errorLevel, isForOtherUUID, ref channelEntities);
302313
if (changeState && !stateChanged) {
303314
stateChanged = true;
304315
}
@@ -308,7 +319,7 @@ internal static bool CheckAndAddExistingUserState<T>(string channel, string chan
308319
foreach (string ch in channelGroups) {
309320
if (!string.IsNullOrEmpty (ch)) {
310321
bool changeState = UpdateOrAddUserStateOfEntity<T> (ch, true, userState, edit,
311-
userCallback, errorCallback, errorLevel, ref channelEntities);
322+
userCallback, errorCallback, errorLevel, isForOtherUUID, ref channelEntities);
312323
if (changeState && !stateChanged) {
313324
stateChanged = true;
314325
}

Assets/Scripts/Pubnub/PubnubUnity.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//Build Date: Dec 21, 2016
2-
//ver3.7.6.1/Unity5
1+
//Build Date: Jan 12, 2017
2+
//ver3.7.6.2/Unity5
33
using System;
44
using UnityEngine;
55
using System.Collections;
@@ -51,8 +51,8 @@ public void RaisePropertyChanged (string propertyName)
5151
private bool ssl = true;
5252
private static long lastSubscribeTimetoken = 0;
5353
private static long lastSubscribeTimetokenForNewMultiplex = 0;
54-
private const string build = "3.7.6.1";
55-
private static string pnsdkVersion = "PubNub-CSharp-Unity5/3.7.6.1";
54+
private const string build = "3.7.6.2";
55+
private static string pnsdkVersion = "PubNub-CSharp-Unity5/3.7.6.2";
5656

5757
private int pubnubWebRequestCallbackIntervalInSeconds = 310;
5858
private int pubnubOperationTimeoutIntervalInSeconds = 15;
@@ -761,6 +761,7 @@ public void SetUserState<T> (string channel, string channelGroup, string uuid, s
761761
List<ChannelEntity> channelEntities;
762762
if (Helpers.CheckAndAddExistingUserState<T> (channel, channelGroup,
763763
deserializeUserState, userCallback, errorCallback, errorLevel, false,
764+
uuid, this.SessionUUID,
764765
out userState, out channelEntities
765766
)) {
766767
SharedSetUserState<T> (channel, channelGroup,
@@ -778,7 +779,8 @@ public void SetUserState<T> (string channel, string channelGroup, string uuid,
778779
List<ChannelEntity> channelEntities;
779780
if (Helpers.CheckAndAddExistingUserState<T> (channel, channelGroup,
780781
new Dictionary<string, object> { { keyValuePair.Key, keyValuePair.Value } }, userCallback,
781-
errorCallback, errorLevel, true, out userState, out channelEntities
782+
errorCallback, errorLevel, true, uuid, this.SessionUUID,
783+
out userState, out channelEntities
782784
)) {
783785

784786
SharedSetUserState<T> (channel, channelGroup, channelEntities, uuid, userState);

0 commit comments

Comments
 (0)