pubnub / pubnub-angular

Official PubNub AngularJS SDK
Other
84 stars 43 forks source link

How to implement callback in ngHistory in Pubnub? #5

Open rinirinku opened 10 years ago

rinirinku commented 10 years ago

When trying to retrieve the history message in the on event , the loading time is too long. The spinner show and hides too fast. But the message is not yet loaded.

How can we calculate or get the exact time to make the history load? $scope.limit = 100 PubNub.ngHistory( { channel : $scope.channel, limit : $scope.limit });

$rootScope.$on(PubNub.ngMsgEv($scope.channel), function(ngEvent, payload) {

            **ActivityIndicator.showSpinner();**

                $scope.$apply(function(){
                $scope.messages.push(payload.message);
            });

            $(".messages-wrap").scrollTop($(".messages-wrap")[0].scrollHeight);
            **ActivityIndicator.hideSpinner();**

        }); 
PatrickJS commented 9 years ago

couldn't you just use the callback?

PubNub.ngHistory( {
  channel : $scope.channel,
  limit : $scope.limit,
  callback: $scope.callback
});
sunnygleason commented 9 years ago

@rinirinku @gdi2290 the callback isn't exposed via angular - I've taken on a TODO item though to expose it in an upcoming version -- stay tuned!

In the meantime, you could call history via PubNub.jsapi.history(), although this bypasses the angular scope broadcast since it's going against the PUBNUB object directly under the hood.