vitalyster/SharpXMPP

Presence catch

LumiProj opened this issue · 3 comments

Hi,

Using presence event handler I am able to get the realtime present of my friends those who attached to my roaster.
Now I can see the presence xml but little bit confuse how can I can easily fetch the Presence modes.
There is different xml for different modes likewise "Available , offline , away".
Following are all three types of presence xml. Just needed help is there any best approach is there to retrieve the presence from xml quickly or I need to parse/process the xml.

Available
<presence xml:lang="en" to="3458313789@abc.com/13095181656749857862393730" from="3458313788@ abc.com/gajim.233RA8V4" id="9b8943d3-aa0d-474c-9554-396ca73e3874" xmlns="jabber:client"> <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://gajim.org" ver="em/Gre+83xcNyMTMuavGSvT8wxA=" /> <x xmlns="vcard-temp:x:update" /> <delay from="3458313788@abc.com/gajim.233RA8V4" stamp="2020-09-23T16:59:29.126617Z" xmlns="urn:xmpp:delay" /> </presence>
offline
<presence xml:lang="en" to="3458313789@abc.com.com/13095181656749857862393730" from="3458313788@abc.com/gajim.233RA8V4" type="unavailable" id="e163f46e-e67c-4b60-ada6-e279ecadab8c" xmlns="jabber:client" />

Away
<presence xml:lang="en" to="3458313789@abc.com/13095181656749857862393730" from="3458313788@abc.com.com/gajim.233RA8V4" id="cc97741a-cb81-455b-9217-4cab9cb5842c" xmlns="jabber:client"> <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://gajim.org" ver="em/Gre+83xcNyMTMuavGSvT8wxA=" /> <x xmlns="vcard-temp:x:update" /> <show>away</show> </presence>

  1. Presence syntax is described in RFC6121, most important is the "type" attribute. If it missing - then it is "online" presence. Away presence is an online presence with an additional "show" element.
  2. You no need to "parse" anything, you already have the XMPPPresence variable which is System.Xml.Linq.XElement and you can use XML to LINQ to query its properties (like presence.Attribute("type").Value to check its type)

Hi,
Guys I am achieving the online and offline status using following code. It is no elegant but it does the job for me. I can easily process the User online/offline status.
The only issue is away is technically online with extra away element , What I am looking to identify the show element value so that would help the exact status.
My code is below . Can you guys help me out to get the away status as well.

var HasType = presence.Attribute("type");
if (HasType == null)
Online = true;
else
Online = false;

presence.Element("show")