Forum Discussion

Claudius's avatar
11 years ago

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:

    http://lithosphere.lithium.com/t5/rest-api/bd-p/developers-rest-api?leaf-id=Settings.name.name#Settings.name.name

     

    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.

     

  • AdamN's avatar
    AdamN
    Khoros Oracle

    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:

    http://lithosphere.lithium.com/t5/rest-api/bd-p/developers-rest-api?leaf-id=Settings.name.name#Settings.name.name

     

    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.

     

    • nathan's avatar
      nathan
      Executive

      Is the fact that the 'last logged in' property might not exist in the user object documented anywhere?

       

      Reading this makes me wonder how many other properties that we rely upon might not exist in certain circumstances. It makes it quite difficult to develop and test without knowing which properties are optional. Attempt/recover works fine for dealing with unexpected errors (at the component level), but it isn't feasible to put them around every object property reference.