1
votes

I am trying to get the Presence of users in my chat roster using asmack. From what i understand, Presece.getType() should return one of these presence types:

Every presence packet has a type, which is one of the following values:

available -- (Default) indicates the user is available to receive messages.
unavailable -- the user is unavailable to receive messages.
subscribe -- request subscription to recipient's presence.
subscribed -- grant subscription to sender's presence.
unsubscribe -- request removal of subscription to sender's presence.
unsubscribed -- grant removal of subscription to sender's presence.
error -- the presence packet contains an error message.

Using Presence.getType() on my presence object for an online user gives me this:

Log.e("Presence?",myRoster.getPresence(entry.getUser()).getType().toString());

Unavailable

However, using Presence.isAvailable() on the same user gives me:

Log.e("Presence?",Boolean.toString(myRoster.getPresence(entry.getUser()).isAvailable()));

True

Shouldn't getType() and isAvailable() return me the same results according to the following definitions?

public Presence.Type getType()

Returns the type of this presence packet.

public boolean isAvailable()

Returns true if the presence type is available (online) and false if the user is unavailable (offline), or if this is a presence packet involved in a subscription operation. This is a convenience method equivalent to getType() == Presence.Type.available.

What am I missing? What's the difference between the two?

1

1 Answers

0
votes

If you look at the source you will find that

public boolean isAvailable() {
    return type == Type.available;    
}

also the javadoc of isAvailable() states that

This is a convenience method equivalent to getType() == Presence.Type.available.