Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ void UPubnubJsonUtilities::ListUsersFromChannelJsonToData(FString ResponseJson,
Result.ErrorMessage = "Failed to parse Response";
return;
}

Result = GetOperationResultFromJson(JsonObject);
FPubnubOperationResult ResultFromJson = GetOperationResultFromJson(JsonObject);
Result.ErrorMessage = ResultFromJson.ErrorMessage;
//Override status only if it was 0. Status could be set before in case of server error.
Result.Status = Result.Status == 0 ? ResultFromJson.Status : Result.Status;
Result.Error = Result.Status != 200;

JsonObject->TryGetNumberField(ANSI_TO_TCHAR("occupancy"), Data.Occupancy);
Expand Down
22 changes: 19 additions & 3 deletions Source/PubnubLibrary/Private/PubnubInternalMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
* - Log an error message to the output log
* - Invoke the provided delegate with a failure result and optional additional arguments
* - Immediately return from the calling function
*
*/
#define PUBNUB_ENSURE_USER_ID_IS_SET(Delegate, ...) \
do { \
Expand All @@ -75,13 +74,30 @@
} \
} while (false)

/**
* Verifies that provided condition is met.
*
* If the condition is not met, this macro will:
* - Log an error message to the output log
* - Invoke the provided delegate with a failure result and optional additional arguments
* - Immediately return from the calling function
*/
#define PUBNUB_ENSURE_CONDITION(Condition, ErrorMessage, Delegate, ...) \
do { \
if (!(Condition)) \
{ \
PubnubError(FString::Printf(TEXT("[%s]: %s Aborting operation."), *UPubnubUtilities::GetNameFromFunctionMacro(ANSI_TO_TCHAR(__FUNCTION__)), ErrorMessage)); \
UPubnubUtilities::CallPubnubDelegateWithInvalidArgumentResult(Delegate, ErrorMessage, ##__VA_ARGS__); \
return; \
} \
} while (false)

/**
* Verifies that a valid Pubnub user ID has been set before continuing.
*
* If the user ID is not set, this macro will:
* - Log an error message to the output log
* - Immediately return from the calling function
*
*/
#define PUBNUB_RETURN_IF_USER_ID_NOT_SET(...) \
do { \
Expand Down Expand Up @@ -135,4 +151,4 @@
PubnubError(FString::Printf(TEXT("[%s]: %s field can't be empty. Aborting operation."), *UPubnubUtilities::GetNameFromFunctionMacro(ANSI_TO_TCHAR(__FUNCTION__)), TEXT(#Field)), EPubnubErrorType::PET_Warning); \
return __VA_ARGS__; \
} \
} while (false)
} while (false)
15 changes: 14 additions & 1 deletion Source/PubnubLibrary/Private/PubnubSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,8 @@ void UPubnubSubsystem::ListUsersFromChannel_priv(FString Channel, FOnListUsersFr
{
PUBNUB_ENSURE_USER_ID_IS_SET(ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
PUBNUB_ENSURE_FIELD_NOT_EMPTY(Channel, ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
PUBNUB_ENSURE_CONDITION(ListUsersFromChannelSettings.Limit >= 0, TEXT("Limit can't be below 0."), ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());
PUBNUB_ENSURE_CONDITION(ListUsersFromChannelSettings.Offset >= 0, TEXT("Offset can't be below 0."), ListUsersFromChannelResponse, FPubnubListUsersFromChannelWrapper());

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

FString JsonResponse = GetLastResponse(ctx_pub);

//Execute provided delegate with results
FPubnubOperationResult Result;

//If response is empty, there was server error.
if(JsonResponse.IsEmpty())
{
JsonResponse = UPubnubUtilities::PubnubGetLastServerHttpResponse(ctx_pub);
//Presence api doesn't provide status code in the response, so we need to get it manually
Result.Status = pubnub_last_http_code(ctx_pub);
}

//Execute provided delegate with results
FPubnubListUsersFromChannelWrapper Data;
UPubnubJsonUtilities::ListUsersFromChannelJsonToData(JsonResponse, Result, Data);
UPubnubUtilities::CallPubnubDelegate(ListUsersFromChannelResponse, Result, Data);
Expand Down Expand Up @@ -2867,6 +2878,8 @@ void UPubnubSubsystem::HereNowUESettingsToPubnubHereNowOptions(FPubnubListUsersF
PubnubHereNowOptions.disable_uuids = HereNowSettings.DisableUserID;
PubnubHereNowOptions.state = HereNowSettings.State;
HereNowSettings.ChannelGroup.IsEmpty() ? PubnubHereNowOptions.channel_group = NULL : nullptr;
PubnubHereNowOptions.limit = HereNowSettings.Limit;
PubnubHereNowOptions.offset = HereNowSettings.Offset;
}

void UPubnubSubsystem::SetStateUESettingsToPubnubSetStateOptions(FPubnubSetStateSettings& SetStateSettings, pubnub_set_state_options& PubnubSetStateOptions)
Expand Down
2 changes: 2 additions & 0 deletions Source/PubnubLibrary/Public/PubnubStructLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ struct FPubnubListUsersFromChannelSettings
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") bool DisableUserID = true;
//If true (and if DisableUserID is false), will give associated state alongside user info.
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") bool State = false;
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") int Limit = 1000;
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Pubnub") int Offset = 0;
};

USTRUCT(BlueprintType)
Expand Down
Loading