On top of the answer above, there is also a <show>
element that should be used in conjunction with the <status>
element. By using both elements, you can customize user's presence for each availability states.
Default: Available / Offline
By using <show>
: Available / Busy / Away / Extended Away / Offline
By using <show>
with <status>
: "Free to chat" / "Hard at work" / "In a meeting" / "Out for lunch".
If you use Openfire with this method: In User Sessions > Presence column, you will see:
Different colored icons for each user (e.g. green for available, red for busy, etc.)
A descriptive text beside the icons (e.g. "In a meeting")
Presence child elements
There are 3 elements that can change types of presence in XMPP.
<show/>
<status/>
<priority/>
(we'll exclude this for discussion)
Show
<show>
specifies an availability status of a user.
Values of the element must be specified according to the list below.
"chat" -- user is actively interested in chatting.
"dnd" -- user is busy (dnd a.k.a 'Do Not Disturb').
"away" -- user is temporarily away.
"xa" -- user is away for an extended period (xa a.k.a. 'eXtended Away').
If this element is not provided, user is assumed to only be either online and available.
Status
<status>
describes the availability status of a user. It is usually used in conjunction with the <show>
element to provide a detailed description of an availability state.
Values of the element can be of any descriptive text. For instance:
"Available to chat" -- can be used for "chat"
"Busy at work" -- can be used for "dnd"
"In a meeting" -- can be used for "away"
"On a vacation" -- can be used for "xa"
Usage in Objective-C
Here's how you should apply the above concept in code.
// Initialize variables
XMPPPresence *presence = [XMPPPresence presence];
NSXMLElement *show = [NSXMLElement elementWithName:@"show"];
NSXMLElement *status = [NSXMLElement elementWithName:@"status"];
// If user is available
[show setStringValue:@"chat"];
[status setStringValue:@"Available to chat"];
// If user is busy
[show setStringValue:@"dnd"];
[status setStringValue:@"Busy at work"];
// If user is away
[show setStringValue:@"away"];
[status setStringValue:@"In a meeting"];
// If user is away for a long period of time
[show setStringValue:@"xa"];
[status setStringValue:@"On a vacation"];
// Add the XML child elements to XMPPPresence
[presence addChild:show];
[presence addChild:status];
// Update new presence to server
[[[self appDelegate] xmppStream] sendElement:presence];
There you go, your customized user's presence will now be accurately reflected in your server.
See also: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence