Hi,
Does type attribute in Presence class is an optional field?
In the source code, it does not write to xml when type is available. (in red color)
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder buf = new XmlStringBuilder();
buf.halfOpenElement(ELEMENT);
addCommonAttributes(buf);
if (type != Type.available) {
buf.attribute(“type”, type);
}
buf.rightAngleBracket();
I am new to smack, any help is really appreciated.
Thanks!
Flow
2
The type attribute is implicit and must be omitted if its value is ‘available’.
CSH
3
Available presence is not specified as extra “type” value. A presence is implicitly “available”, if there’s no type attribute.
RFC 6121:
In XMPP, an entity’s availability is signaled when its client generates a stanza with no ‘type’ attribute
<xs:attribute name=‘type’ use=‘optional’>
xs:simpleType
<xs:restriction base=‘xs:NMTOKEN’>
<xs:enumeration value=‘error’/>
<xs:enumeration value=‘probe’/>
<xs:enumeration value=‘subscribe’/>
<xs:enumeration value=‘subscribed’/>
<xs:enumeration value=‘unavailable’/>
<xs:enumeration value=‘unsubscribe’/>
<xs:enumeration value=‘unsubscribed’/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
But in the RosterListener,
How do I check if a user is available in the RosterListener. presenceChanged(presence) ?
Currently, I call presence.getType() and it always returns unavailable although i set the Presence of the other user to available.
Roster roster = Roster.getInstanceFor(con); roster.addRosterListener(new RosterListener() { // Ignored events public void entriesAdded(Collection<String> addresses) {} public void entriesDeleted(Collection<String> addresses) {} public void entriesUpdated(Collection<String> addresses) {} public void presenceChanged(Presence presence) { System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
if (presence.getType() == Presence.Type.available) {
//update UI
** }** } });
And from Presence.isAvailable()
/**
- Returns true if the {@link Type 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. Note that even
- when the user is available, their presence mode may be {@link Mode#away away},
- {@link Mode#xa extended away} or {@link Mode#dnd do not disturb}. Use
- {@link #isAway()} to determine if the user is away.
-
-
@return true if the presence type is available.
*/
public boolean isAvailable() {
return type == Type.available;
}
And Thank you for your fast reply!
As it turn out, my Presence subscribe had a problem.
To get the presenceChanged callback correctly, user need to send Presence(subscribe) to the other user.
Thank you