Project

General

Profile

Send last seen info in presence

Gureen Ryuu
Added over 4 years ago

I want to implement a last seen presence on the server.

I noticed the presence plugin already adds a last seen to contacts that are in the user's roster, however that information is not being returned to the client when it asks the server to return the presence of a certain user's roster contact.

Is such a feature already available in Tigase? And if so, how can we enable it?


Replies (9)

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

Are you talking about any particular XEP?

Added by Gureen Ryuu over 4 years ago

Not in particular, no, at least I couldn't find any in my searches. I found one, but I doubt it's what I'm looking for, since it relates to the last login/log out rather than last presence change http://www.xmpp.org/extensions/xep-0012.html

<contact activity="1.0" jid="testing@example.com" preped="simple" subs="both" last-seen="1400677778188" weight="1.0" name="Testing"/>

The behavior I want is similar to that of whatsapp, as in, when the user puts the app in the background, I want to send the server the last seen info to update, and send it as a broadcast the roster contacts.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

What you say is actually quite easy, assuming I understand you correctly.

When your app is put in the background it should send a presence to the server with a custom message. This can be either unavailable presence or available with away state and a custom, human readable text. Then the server would automatically distribute the presence to all contacts in the roster. Of course the custom text can contain time of going to standby mode.

Added by Gureen Ryuu over 4 years ago

You're right, it is quite easy, but from the client side. We already have it implemented by sending an extension including the timestamp.

But the problem is that the timestamp will be coming from the phone, and if the user has a wrong date on his phone, then that will cause a problem.. It's why we want to use the last seen made by the server.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

But the problem is that the timestamp will be coming from the phone, and if the user has a wrong date on his phone, then that will cause a problem..

Is this a real problem? Most (if not all) phones capable of running XMPP client adjust their date and time automatically using some time server. Do you really think it happens often enough to cause problems that some phones have incorrect date and time? The only real problem I can see is different time zones. But if your client sets the time in UTC format, then it should be good enough.

It's why we want to use the last seen made by the server.

In such a case I think there is quite simple solution which would be a combination of the above and minor server side custom logic.

I would go for the presence based broadcast as it is normally done in XMPP world. The client sends the presence update (or the server on behalf of the client if client disconnected without sending presence). The presence sent by a client can contain a timestamp or not but the server can add it's own timestamp to all user's presences. So the presence broadcast would always contain server's timestamp. I think a small modification in the Presence plugin would be enough.

Added by Gureen Ryuu over 4 years ago

Ok, we've tried as you advised. It works for the case when two users are online.

But when two users are offline, and when one of them gets online, we are just getting presence unavailable when we request the presence of the other user, and no request is being done to the server, so we are not getting the proper timestamp and presence. (We are using aSmack for the client side)

xmppConnection.getRoster().getPresence("testinguser@example.com");

Also I wonder, if this is solved, won't the server append the timestamp of when it sent the presence to the user requesting it, as opposed to when the other user set it? (Right now I'm appending the timestamp at the beginning of the

@ process(final Packet packet, final XMPPResourceConnection session, final NonAuthUserRepository repo, final Queue results, final Map settings)@

method.

Thank you for your patience and help with this!

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

Well, right now Tigase does not persists information about users' activity and in particular Tigase does not persists information about last user's presence. This is because we usually deal with very large installations with a traffic getting up to 500k packets per second. There is no way this can volume of information can be persisted in DB.

  1. Let's say UserA is offline.

  2. In the meantime UserB comes online and then he goes offline.

  3. Then UserA logs on. He has no track of what happened to UserB, even if UserA has some information in his roster about UserB last activity it would be outdated.

In theory, userB could keep his last activity in RAM while he is online and store it into DB when he disconnects. This would not create an insane DB load. However, when userA comes back online and he has like 250 contacts in his roster, then he would need to execute 250 DB queries to check last activity of all his buddies. This would be kind of a slow.

So, in other words. We could implement the last activity, but to be honest, I do not have a good idea how to do it efficiently without a significant impact on performance.

Added by Gureen Ryuu over 4 years ago

After much discussion we've decided to drop this for the time being and, as you said, trust in the phone's timestamp that is being sent.

I just have one more question, if possible.

Looking over the Presence plugin, I noticed it has a switch case on the pres_type. Which value of pres_type is sent only when the user first logs in and sends his first presence? in_initial or out_initial?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

in_initial and out_initial are different phases of presence stanza processing. Please have a look at this article to learn how packets are processed by Tigase: http://www.tigase.org/content/how-packets-are-processed-sm-and-plugins

    (1-9/9)