zorn-v/xmpp

getMessages return array size 0

LtotheWT opened this issue · 7 comments

Hi @zorn-v thanks for this repo.
I have successfully send message through ur library, but i cant get back the messages through the getMessages() function.

Try to use blocked mode getMessages(true) it blocks script execution until some messages received. Otherwise you should call getMesages in some loop.

thx for the quick response @zorn-v, i tried getMessages(true) but no luck.
Does the getMessages() retrieve offline message ?

Don't test it but it should I think.

keep getting empty array from getMessages(true), is there anything i need to do other than below code ?

$address = "xxx.com:5222";
$username = "user";
$password = "aaaaaaaa";

$options = new Options($address);
$options->setUsername($username)
->setPassword($password);
$client = new Client($options);
$client->connect();

$message = $client->getMessages(true);
print_r($message);

Maybe you receive anyting other than messages. Try something like this

//...
$client->connect();
while (true) {
    $messages = $client->getMessages(true);
    if (count($messages) >0) {
        print_r($messages);
    }
}

hey @zorn-v, thx for ur support. Unfortunately i still cant manage to make it work. Thanks for the help.

Heya @LtotheWT @zorn-v

$client->connect();
$i = true;
    while($i){
        $getmessages = $client->getMessages(true);
        
        if (count($getmessages) > 0) {
            print_r($getmessages);
        }
        else {
            $i = false;
        }
    }

This fetches all the offline messages as expected - while this solves the issue, I still couldn't understand why the array returns only one message at a time instead of getting all the messages in a single array.

Appreciate any pointers or explanation for the same.

Thanks!