query any user's online status
Use Case
Query any user online status "online" or "offline". eg. There are 5 users on the category experts panel. I want to use ajax to query their online status.
I am trying to setup an endpoint to achieve this.
<#assign username = "pleasechangeme" >
<#assign login_time = restadmin("users/login/" + username + "/sessions/online/latest").user_session.login_time?datetime("yyyy-MM-dd'T'HH:mm:ss+00:00") />
<#assign login_time_milliseconds = datesupport.setDate(login_time).millisecondsAsString?number />
<#assign now_milliseconds = datesupport.now.millisecondsAsString?number />
${login_time_milliseconds} ${now_milliseconds}
But it seems datesupport.now is using +08:00 timezone and login_time is using +00:00 timezone. And my testing result is always like now_milliseconds > login_time_milliseconds, which is wrong.
What I tried to do is to compare these 2 datetime, and if now - login_time > 30 minutes, I consider this user is not online.
Any ideas how to solve this problem?
And this method is not the best, because if this user logout immediately, he will still be considered online based on the 30 minutes logic.
Lithium built-in module can detect user's online status accurately.
http://lithosphere.lithium.com/t5/user/viewprofilepage/user-id/4654
http://lithosphere.lithium.com/t5/user/viewprofilepage/user-id/10728
You can see there is a online status on those viewprofilepage.
I was wondering is there a way to do this correctly.
BTW, I do know there is a rest call "/users/online". But I dont want to use it. What if it returns me 10,000 users in the xml.
- If I understand you correct, you need to get the status for a user (online or offline). For this you can just run following
http://community.lithium.com/community-name/restapi/vc/users/id/43/sessions/online/latest
If you get a value in the response means user is online. But if the response is null then the user is offline.
Hope this helps.
Regards,
Chhama