上記の回答に加えて、要素<show>
と組み合わせて使用する必要がある要素もあり<status>
ます。両方の要素を使用することで、可用性の状態ごとにユーザーのプレゼンスをカスタマイズできます。
デフォルト: 利用可能 / オフライン
使用方法<show>
: 利用可能 / 話中 / 退席中 / 長時間退席中 / オフライン
で使用<show>
する<status>
: 「自由にチャット」/「仕事で忙しい」/「会議中」/「ランチに出かける」。
この方法で Openfire を使用する場合: [ユーザー セッション] > [プレゼンス] 列に、次のように表示されます。
ユーザーごとに異なる色のアイコン (例: 使用可能な場合は緑、使用中の場合は赤など)
アイコンの横の説明テキスト (例: 「会議中」)
子要素の存在
XMPP でプレゼンスの種類を変更できる要素は 3 つあります。
<show/>
<status/>
<priority/>
(これについては議論から除外します)
見せる
<show>
ユーザーの可用性ステータスを指定します。
要素の値は、以下のリストに従って指定する必要があります。
"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').
この要素が指定されていない場合、ユーザーはオンラインで利用可能であると見なされます。
状態
<status>
ユーザーの可用性ステータスを記述します。これは通常、要素と組み合わせて使用<show>
可能状態の詳細な説明を提供するために使用されます。
要素の値は、任意の説明テキストにすることができます。例えば:
"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"
Objective-C での使用法
上記の概念をコードに適用する方法を次に示します。
// 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];
これで、カスタマイズしたユーザーの存在がサーバーに正確に反映されます。
関連項目: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence