How to implement “last seen at” functionality (like whatsapp) in XMPP?

你离开我真会死。 提交于 2020-01-24 06:26:08

问题


I am working on a chat application and want to add "last seen at" functionality. I am trying to implement it by using presence stanzas but getting one issue, please check at below link

Not getting unavailable presence of User A when User B is also unavailable

Is there any other way to implement last seen at functionality

please suggest


回答1:


The first Google result for "xmpp last seen" is XEP-0012: Last Activity, which is a protocol extension that can be used to find out when a user was online last time.

You send a request like this:

<iq from='romeo@montague.net/orchard' 
    id='last1'
    to='juliet@capulet.com'
    type='get'>
  <query xmlns='jabber:iq:last'/>
</iq>

And get a response like this:

<iq from='juliet@capulet.com' 
    id='last1'
    to='romeo@montague.net/orchard'
    type='result'>
  <query xmlns='jabber:iq:last' seconds='903'/>
</iq>

Which means that the contact was last online 903 seconds ago. Subtract this from the current time to get the "last seen" timestamp.




回答2:


Last seen and Last Activity are two different scenarios.

Last Activity is when user gone offline last time, but last seen is when user goes in background from the application in that case user will be available if application is not killed.You have to create new plugin on server side for last seen.




回答3:


The @legoscia solution will return the last activity time, which is your last logout time(not the last time when user was online), plz check this https://github.com/processone/ejabberd/issues/2265

If the user has at least one connected or available resource when the server receives the request, the response MUST (subject to local security policies) contain an empty element whose 'seconds' attribute is set to a value of '0'.

One solution is to kill the session every time the app goes in background and reconnect when the app is in foreground



来源:https://stackoverflow.com/questions/24449966/how-to-implement-last-seen-at-functionality-like-whatsapp-in-xmpp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!