get unread messages on particular channel pubnub p

2019-07-15 08:05发布

Goal:- to get unread messages on particular channel.

User login to the upitch website.

Once he will go to the Message page we are maintaining the message_page_visited_count = 1

when user routs from message page to any other page we are updating message_page_visited_count = 0 and updating time stamp.

now for updating timestamp we are using mysql function strtotime("now") something like this.

$this->Userlink->updateAll(
                    array('pubnub_time_stamp' => strtotime("now")), array('Userlink.id' => $loggedInUser)
            ); // updating timestamp for logged in user 1455687812

Which updates 1455687812 ten digits timestamp into our database for logged in user.

As discussed with the pubnub team, pubnub team said to add 7 zeros to the right end of my timestamp. Which turns to be 14556878120000000

i have integrated php-sdk pubnub

include_once './vendor/autoload.php';
use Pubnub\Pubnub;
$publish_key   = publish_key
$subscribe_key = subscribe_key
$pubnub = new Pubnub($publish_key, $subscribe_key);

I found the way to implement history something like this.

history(
string $channel, 
integer $count = 100, 
boolean $include_token = null,
integer $start = null, 
integer $end = null,
boolean $reverse = false)

By implementing that:-

$result= $pubnub->history(
"2242_2272_1116", //my channel
null,
true, 
null,
14556878120000000, //endtime token with 7 zeros
null);
echo "<pre>";
print_r($result);die;

By printing why i am getting all messages ?? instead of getting messages after given time-token ??

Reason can be adding 7 zeros is not accepted by pubnub if so kindly suggest me to convert my time-stamp(1455687812) to pubnub time token(17 Digits).

or please point out me what i am doing wrong here?

Your help will be appreciated thanks in advance.

EDIT

I fetch the messages and its time-token something like this.. // TIMETOKENS AND MESSAGES

14556879844588614  Really want some more levels
14556879769565496  The fact I can see
14556871094404310  Haunted
14556871091411782  Hello
14556870983775230  Hello

$result= $pubnub->history(
"2242_2272_1116", 
null,
true, 
null,
14556871094404310, null);
echo "<pre>";
print_r($result);die;

I am passing the 3rd message's time token that is 14556871094404310 and message is Haunted Now expected output would be

14556879844588614  Really want some more levels
14556879769565496  The fact I can see

Why its returning all the message instead of 2 message ?

Note:- This time i did not add any zero's and used originally generated timetoken by pubnub.

Even doing this also returning all the messages!

still no luck.

1条回答
Root(大扎)
2楼-- · 2019-07-15 08:45

We discussed this privately in your support ticket and it just came down to the timetokens you use and the parameters you use in the PubNub history API.

The given timetoken is not the exact publish timetoken of the message you seek so the results may not be what you might expect.

See the PubNub PHP Storage tutorial docs for full details and consult PubNub Support for further assistance.

查看更多
登录 后发表回答