How do you change your presence to show dnd/away and etc.?
XMPPPresence *presence = [XMPPPresence presenceWithType:status];
[[[self appDelegate] xmppStream] sendElement:presence];
status
is an NSString
that I set to online/unavailable/away/busy/invisible.
It only works when I go online and/or unavailable.
Here's how it looks like after sending presence in my xmppStream
:
<presence type="away"><x xmlns="vcard-temp:x:update"><photo/></x></presence>
To change the status of your client you will need to use this simple code:
This simply means that the key to change the status of your client is by adding a status element to your presence. Please note that the openfire server will only show the "available/Offline" status when you hover on the user icon in the admin panel. This should not confuse you though. You can simply check the presence message sent by your client and received by the others which will show on of the status you have set ("online/unavailable/away/busy/invisible").
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 / OfflineBy 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.
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:
Usage in Objective-C
Here's how you should apply the above concept in code.
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