Before getting the historical logs (from angular code, needs adaptation):
PubNub.jsapi.history
channel: clearLogsChannel
count: 1
callback: (messages) ->
endTime = 0
if messages[0][0]?
endTime = messages[0][0]
# We fetch the last 200 logs and then broadcast a 'history-loaded'
# event so that interested listeners are notified. The implementation
# is a bit hacky, hence the explanation below:
#
# re ngHistoryQ: that's a new method in pubnub-angular@1.2.0-beta
# that fetches history and returns a promise. Lib authors found it
# a good idea to make this work differently than ngHistory and *not*
# broadcast events for incoming messages.
#
# re _ngFireMessages: this is private API that broadcasts events
# for incoming messages. Given that the authors haven't released a
# new version for more than a year (as of Jan 2016), and that the
# version in bower.json is pinned, we expect no future issues with this.
#
# We do use a beta release of pubnub-angular that's pinned to a
# specific version. Should you upgrade the version in bower.json,
# make sure you test this part. If it breaks, just implement a custom
# callback where you broadcast events for incoming messages manually.
PubNub.ngHistoryQ
channel: channel
count: 200
end: endTime
callback: PubNub._ngFireMessages channel
.then ->
$timeout ->
$rootScope.$broadcast("history-loaded-#{uuid}")
Before getting the historical logs (from angular code, needs adaptation):
And to clear the logs: