Skip to content

Commit 5dc37ab

Browse files
More test fixes
1 parent 51a8479 commit 5dc37ab

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

examples/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function presence($pubnub, $presence)
261261
// snippet.end
262262

263263
// snippet.get_filter_expression
264-
$pubnub->getFilterConfiguration();
264+
$pubnub->getConfiguration()->getFilterExpression();
265265
// snippet.end
266266

267267
// snippet.disable_immutable_check

examples/MessageActions.php

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -493,37 +493,44 @@ function tagForAnalytics($pubnub, $channel, $messageTimetoken, $tag, $value)
493493
echo "\n=== MESSAGE ACTIONS DEMO COMPLETE ===\n";
494494

495495
// snippet.fetch_messages_with_paging
496-
function getMessageActionsWithPaging($pubnub, $channel, $start, $callback)
496+
function getMessageActionsWithPaging($pubnub, $channel, $start = null)
497497
{
498-
$pubnub->getMessageActions([
499-
'channel' => $channel,
500-
'page' => [
501-
'limit' => 5,
502-
'start' => $start
503-
]
504-
])->then(function ($result) use ($pubnub, $channel, $callback) {
505-
if (!empty($result->actions)) {
506-
getMessageActionsWithPaging(
507-
$pubnub,
508-
$channel,
509-
$result->actions[0]->actionTimetoken,
510-
$callback
511-
);
498+
$allActions = [];
499+
$currentStart = $start;
500+
501+
do {
502+
$builder = $pubnub->getMessageActions()
503+
->channel($channel)
504+
->limit(5);
505+
506+
if ($currentStart !== null) {
507+
$builder->start($currentStart);
508+
}
509+
510+
$result = $builder->sync();
511+
$actions = $result->getActions();
512+
513+
if (!empty($actions)) {
514+
$allActions = array_merge($allActions, $actions);
515+
// Get the timetoken of the last action for pagination
516+
$lastAction = end($actions);
517+
$currentStart = $lastAction->getActionTimetoken();
512518
} else {
513-
$callback([]);
519+
break;
514520
}
515-
}, function ($exception) {
516-
// Handle error
517-
});
521+
} while (!empty($actions) && count($allActions) < 20); // Limit to 20 for demo
522+
523+
return $allActions;
518524
}
519525

520-
getMessageActionsWithPaging($pubnub, 'my_channel', microtime(true) * 10000, function ($actions) {
521-
foreach ($actions as $action) {
522-
echo $action->type . "\n";
523-
echo $action->value . "\n";
524-
echo $action->uuid . "\n";
525-
echo $action->messageTimetoken . "\n";
526-
echo $action->actionTimetoken . "\n";
527-
}
528-
});
526+
// Usage example
527+
$actions = getMessageActionsWithPaging($pubnub, 'my_channel');
528+
foreach ($actions as $action) {
529+
echo "Type: " . $action->getType() . "\n";
530+
echo "Value: " . $action->getValue() . "\n";
531+
echo "UUID: " . $action->getUuid() . "\n";
532+
echo "Message Timetoken: " . $action->getMessageTimetoken() . "\n";
533+
echo "Action Timetoken: " . $action->getActionTimetoken() . "\n";
534+
echo "---\n";
535+
}
529536
// snippet.end

examples/Snippets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
$config = new PNConfiguration();
1010
$config->setSubscribeKey(getenv('SUBSCRIBE_KEY') ?: 'demo');
1111
$config->setPublishKey(getenv('PUBLISH_KEY') ?: 'demo');
12+
$config->setSecretKey(getenv('SECRET_KEY') ?: 'demo');
1213
$config->setUserId('snippets-demo');
1314
$pubnub = new PubNub($config);
1415

0 commit comments

Comments
 (0)