powered by Jive Software

Subscribed to and from

Hi, would you consider adding the following methods to RosterEntry?

Optionally they can be made non-static, but the nullity check, which is useful in this case, cannot be performed; unless they’'re moved to class Roster and be changed to receive a username (just like getPresence(String) et al).

public static boolean subscribedTo(RosterEntry entry) {

if (null == entry) return false;

ItemType entryType = entry.getType();

if (null == entryType) return false;

return entryType.equals(RosterPacket.ItemType.TO) || entryType.equals(RosterPacket.ItemType.BOTH);

}

public static boolean subscribedFrom(RosterEntry entry) {

if (null == entry) return false;

ItemType entryType = entry.getType();

if (null == entryType) return false;

return entryType.equals(RosterPacket.ItemType.FROM) || entryType.equals(RosterPacket.ItemType.BOTH);

}

Alternatively the ItemType constants could be made bitmasks and BOTH = FROM | TO, thus making the tests simpler. I use them to determine whether a user is offline or I’'m not suscribed to its presence changes and to decide whether to remove an user from the roster or just unsubscribe from its presence depending on whether the other user is subscribed to my presence.

Here’'s a snippet that illustrates my first case:

Presence presence = getRoster().getPresence(user);

String status = “Unknown”; // Shouldn’'t happen, but it might be changed later.

if (null != presence) {

Presence.Type type = presence.getType();

if (Presence.Type.UNAVAILABLE == type)

status = “Offline”;

else if (Presence.Type.AVAILABLE == type)

status = presence.getMode().toString();

} else {

RosterEntry entry = getRoster().getEntry(user);

if (subscribedTo(entry))

status = “Offline”;

else

status = “Not subscribed”;

}

I think they could be useful for other uses, too.

Message was edited by:

Javier Kohen

Consider the case where entryType is null.

Maybe this will be useful, too:

public static boolean subscriptionPending(RosterEntry entry) {

if (null == entry) return false;

ItemType entryType = entry.getType();

if (null == entryType) return false;

return entryType.equals(RosterPacket.ItemType.NONE);

}

And the example must be modified accordingly:

if (subscribedTo(entry))

status = “Offline”;

else if (subscriptionPending(entry))

status = “Subscription pending”;

else

status = “Not subscribed”;

Message was edited by:

Javier Kohen

Consider the case where entryType is null.