@@ -493,37 +493,44 @@ function tagForAnalytics($pubnub, $channel, $messageTimetoken, $tag, $value)
493493echo "\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
0 commit comments