Skip to content

Commit fc85ad7

Browse files
Add Limit and Offset inputs to ListUsersFromChannel function. (#55)
feat(hereNow): Add Limit and Offset inputs to ListUsersFromChannel function. The ListUsersFromChannel method now returns a maximum of 1,000 occupants per channel. Previously, it would return all occupants regardless of count. If you have channels with more than 1,000 occupants, you must use pagination (new Limit and Offset parameters) to retrieve the complete list. BREAKING CHANGE
1 parent 76760b9 commit fc85ad7

File tree

22 files changed

+729
-19
lines changed

22 files changed

+729
-19
lines changed

.pubnub.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: unreal-engine
22
schema: 1
3-
version: v1.0.0
3+
version: 1.2.0
44
scm: github.com/pubnub/unreal-engine
55
changelog:
6+
- date: 2025-11-12
7+
version: 1.2.0
8+
changes:
9+
- type: feature
10+
text: "The `ListUsersFromChannel` method now returns a maximum of 1,000 occupants per channel. Previously, it would return all occupants regardless of count. If you have channels with more than 1,000 occupants, you must use pagination (new `Limit` and `Offset` parameters) to retrieve the complete list. **BREAKING CHANGE**."
611
- date: 2025-09-11
712
version: 1.1.0
813
changes:

PubnubLibrary.uplugin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
3-
"Version": 12,
4-
"VersionName": "1.1.0",
3+
"Version": 13,
4+
"VersionName": "1.2.0",
55
"FriendlyName": "Pubnub Unreal SDK",
66
"Description": "Quickly add interactive features to your game that scale without building your backend infrastructure.",
77
"Category": "Code",

Source/PubnubLibrary/Private/FunctionLibraries/PubnubJsonUtilities.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ void UPubnubJsonUtilities::ListUsersFromChannelJsonToData(FString ResponseJson,
250250
Result.ErrorMessage = "Failed to parse Response";
251251
return;
252252
}
253-
254-
Result = GetOperationResultFromJson(JsonObject);
253+
FPubnubOperationResult ResultFromJson = GetOperationResultFromJson(JsonObject);
254+
Result.ErrorMessage = ResultFromJson.ErrorMessage;
255+
//Override status only if it was 0. Status could be set before in case of server error.
256+
Result.Status = Result.Status == 0 ? ResultFromJson.Status : Result.Status;
255257
Result.Error = Result.Status != 200;
256258

257259
JsonObject->TryGetNumberField(ANSI_TO_TCHAR("occupancy"), Data.Occupancy);

Source/PubnubLibrary/Private/PubnubInternalMacros.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
* - Log an error message to the output log
6464
* - Invoke the provided delegate with a failure result and optional additional arguments
6565
* - Immediately return from the calling function
66-
*
6766
*/
6867
#define PUBNUB_ENSURE_USER_ID_IS_SET(Delegate, ...) \
6968
do { \
@@ -75,13 +74,30 @@
7574
} \
7675
} while (false)
7776

77+
/**
78+
* Verifies that provided condition is met.
79+
*
80+
* If the condition is not met, this macro will:
81+
* - Log an error message to the output log
82+
* - Invoke the provided delegate with a failure result and optional additional arguments
83+
* - Immediately return from the calling function
84+
*/
85+
#define PUBNUB_ENSURE_CONDITION(Condition, ErrorMessage, Delegate, ...) \
86+
do { \
87+
if (!(Condition)) \
88+
{ \
89+
PubnubError(FString::Printf(TEXT("[%s]: %s Aborting operation."), *UPubnubUtilities::GetNameFromFunctionMacro(ANSI_TO_TCHAR(__FUNCTION__)), ErrorMessage)); \
90+
UPubnubUtilities::CallPubnubDelegateWithInvalidArgumentResult(Delegate, ErrorMessage, ##__VA_ARGS__); \
91+
return; \
92+
} \
93+
} while (false)
94+
7895
/**
7996
* Verifies that a valid Pubnub user ID has been set before continuing.
8097
*
8198
* If the user ID is not set, this macro will:
8299
* - Log an error message to the output log
83100
* - Immediately return from the calling function
84-
*
85101
*/
86102
#define PUBNUB_RETURN_IF_USER_ID_NOT_SET(...) \
87103
do { \
@@ -135,4 +151,4 @@
135151
PubnubError(FString::Printf(TEXT("[%s]: %s field can't be empty. Aborting operation."), *UPubnubUtilities::GetNameFromFunctionMacro(ANSI_TO_TCHAR(__FUNCTION__)), TEXT(#Field)), EPubnubErrorType::PET_Warning); \
136152
return __VA_ARGS__; \
137153
} \
138-
} while (false)
154+
} while (false)

Source/PubnubLibrary/Private/PubnubSubsystem.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,8 @@ void UPubnubSubsystem::ListUsersFromChannel_priv(FString Channel, FOnListUsersFr
18801880
{
18811881
PUBNUB_ENSURE_USER_ID_IS_SET(ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
18821882
PUBNUB_ENSURE_FIELD_NOT_EMPTY(Channel, ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
1883+
PUBNUB_ENSURE_CONDITION(ListUsersFromChannelSettings.Limit >= 0, TEXT("Limit can't be below 0."), ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
1884+
PUBNUB_ENSURE_CONDITION(ListUsersFromChannelSettings.Offset >= 0, TEXT("Offset can't be below 0."), ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
18831885

18841886
//Set all options from ListUsersFromChannelSettings
18851887
FUTF8StringHolder ChannelHolder(Channel);
@@ -1895,8 +1897,17 @@ void UPubnubSubsystem::ListUsersFromChannel_priv(FString Channel, FOnListUsersFr
18951897

18961898
FString JsonResponse = GetLastResponse(ctx_pub);
18971899

1898-
//Execute provided delegate with results
18991900
FPubnubOperationResult Result;
1901+
1902+
//If response is empty, there was server error.
1903+
if(JsonResponse.IsEmpty())
1904+
{
1905+
JsonResponse = UPubnubUtilities::PubnubGetLastServerHttpResponse(ctx_pub);
1906+
//Presence api doesn't provide status code in the response, so we need to get it manually
1907+
Result.Status = pubnub_last_http_code(ctx_pub);
1908+
}
1909+
1910+
//Execute provided delegate with results
19001911
FPubnubListUsersFromChannelWrapper Data;
19011912
UPubnubJsonUtilities::ListUsersFromChannelJsonToData(JsonResponse, Result, Data);
19021913
UPubnubUtilities::CallPubnubDelegate(ListUsersFromChannelResponse, Result, Data);
@@ -2867,6 +2878,8 @@ void UPubnubSubsystem::HereNowUESettingsToPubnubHereNowOptions(FPubnubListUsersF
28672878
PubnubHereNowOptions.disable_uuids = HereNowSettings.DisableUserID;
28682879
PubnubHereNowOptions.state = HereNowSettings.State;
28692880
HereNowSettings.ChannelGroup.IsEmpty() ? PubnubHereNowOptions.channel_group = NULL : nullptr;
2881+
PubnubHereNowOptions.limit = HereNowSettings.Limit;
2882+
PubnubHereNowOptions.offset = HereNowSettings.Offset;
28702883
}
28712884

28722885
void UPubnubSubsystem::SetStateUESettingsToPubnubSetStateOptions(FPubnubSetStateSettings& SetStateSettings, pubnub_set_state_options& PubnubSetStateOptions)

Source/PubnubLibrary/Public/PubnubStructLibrary.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct FPubnubListUsersFromChannelSettings
8383
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") bool DisableUserID = true;
8484
//If true (and if DisableUserID is false), will give associated state alongside user info.
8585
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") bool State = false;
86+
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") int Limit = 1000;
87+
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") int Offset = 0;
8688
};
8789

8890
USTRUCT(BlueprintType)

0 commit comments

Comments
 (0)