How to check if a user is sharing their online status?
I have a custom component that displays some profile information for users including their last visit. I'm using the following REST call for that
<#assign dateLastVisited = rest("/users/login/${page.context.user.login}/last_visit_time").value />
If that user has set their online status to be shown to "friends only" or even "no one" (See http://lithosphere.lithium.com/t5/default-user-profiles/Set-default-privacy-settings/ta-p/108831 ) this will fail though and show some nasty widget errors. Is there any way to check if the viewing user has the permission to view another users login information? Or shall I just wrap it into some try-catch block?
Hi Claudius,
This preference is stored as a user setting called "profile.show_online_status". You can obtain the value like any other user setting via the REST API:
So your call would look like:
/users/id/77/settings/name/profile.show_online_status
Currently, the possible values are:
- all
- none
- friends_only
These correspond to the options presented in the UI. The "friends_only" one may give you a little trouble, since you'd have to look up whether or not the person viewing is a friend of the person whose online status they're trying to view. You could also take a conservative approach and lump "friends_only" in with "none".
Alternately, you could try using an attempt/recover block in FreeMarker like you mentioned. If it reaches the "recover" block, you could assume that the user doesn't have permission and not show the status.