Forum Discussion

jaread83's avatar
jaread83
Champion
9 years ago

User offline status when set to not display online status

I have built a custom online user panel using REST v2 and one of my testers found that their avatar is showing up in the list when they have gone to their settings and set it so they are shown as offline to everyone.

 

Is there a way I can check this users settings in my loop and not display them? I can't see anything in the Liql query results that would indicate their setting to display as offline.

 

This also leads on to something of a similar vein.. what do I do about it when a user has changed their setting to only display their online status for 'friends'? Here is a basic skeleton of my code which has the api call and loop...

 

<#assign query = "SELECT login, view_href, avatar, online_status, registration_data, rank FROM users limit 1000" />
<#assign res = restadmin("2.0", "/search?q=${query?url}").data.items />
<#assign users_id = [] />
<#list res as user>
<#if user.online_status = 'online' & user.registration_data.status = 'fully-registered'>
<a class="${rankClass}" href="${user.view_href}"><img src="${user.avatar.message}" title="${user.login}" alt="${user.login}" /></a>
</#if>
</#list>

If anyone has any ideas how I can not include a user who has set their preferences to not show up as online and even restrict their online status to their friends I would greatly appreciate it!

  • jaread83 - Use rest() instead of restadmin() in line 2 of your code, as using the restadmin overrides all the permissions and fetches all the data, even private. So while developing custom components, please keep in mind that you have to use the rest call unless absolutely necessary to use restadmin. Otherwise you could end up showing sensitive data to logged out users too.

     

    I hope this helps.

    • jaread83's avatar
      jaread83
      Champion

      Thanks for the tip VarunGrazitti but using rest affects my component for regular users and they see 'widget cannot be displayed' for them except for their own avatar. I am all for keeping things as secure as possible but I need the component to work for everyone. Any ideas why that would happen?

      • VarunGrazitti's avatar
        VarunGrazitti
        Boss

        jaread83 - I looked into this and following is the issue.

         

        When you are making call as rest in logged out state, there are few nodes missing in registration_data

         

        "registration_data":{  
                       "type":"registration_data",
                       "registration_time":"2014-09-18T13:48:50.554-07:00"
                    }

        For a logged in user, the API returns all the nodes as:

         

         "registration_data":{  
                       "type":"registration_data",
                       "registration_time":"2014-09-18T13:48:50.554-07:00",
                       "status":"fully-registered",
                       "registration_access_level":"all",
                       "confirm_email_status":true
                    }

        and you are using registration_data.status in your code which is not available when the user is logged out, hence the error:

         

        <#if user.online_status = 'online' & user.registration_data.status = 'fully-registered'>

         

        You could modify the code using if user is logged in or not. You should also use attempt recover blocks.

         

        I hope this helps.