Forum Discussion

lorseau's avatar
13 years ago

REST : users/online

Hello,

 

I wanted to see the XML with "users/online" and I'm really surprised as in the XML file it's possible to have more a user more than once (yesterday there are even 5 times the same <user>...</user> node...).

Is it normal?

 

For instance, a response to "users/online" with 2x the same <user type="user" href="/users/id/19"> node

 

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<response status="success">
  <users>
    <user type="user" href="/users/id/19">
      <id type="int">19</id>
      <registered type="boolean">true</registered>
      <deleted type="boolean">false</deleted>
      <login type="string">lorseau</login>
      <anonymous type="boolean">false</anonymous>
      <last_visit_time type="date_time">2012-03-23T08:11:51+00:00</last_visit_time>
      <email type="string">lorseau@mega.com</email>
      <registration_time type="date_time">2012-01-30T13:15:53+00:00</registration_time>
      <average_message_rating type="float">0.0</average_message_rating>
      <average_rating type="float">0.0</average_rating>
      <banned type="boolean">false</banned>
    </user>
    <user type="user" href="/users/id/19">
      <id type="int">19</id>
      <registered type="boolean">true</registered>
      <deleted type="boolean">false</deleted>
      <login type="string">lorseau</login>
      <anonymous type="boolean">false</anonymous>
      <last_visit_time type="date_time">2012-03-23T08:11:51+00:00</last_visit_time>
      <email type="string">lorseau@mega.com</email>
      <registration_time type="date_time">2012-01-30T13:15:53+00:00</registration_time>
      <average_message_rating type="float">0.0</average_message_rating>
      <average_rating type="float">0.0</average_rating>
      <banned type="boolean">false</banned>
    </user>
  </users>
</response>

 

Thanks,

Laurent

  • :-) Yep, it is.  A user can be logged in multiple times.  We recently redid our Users Online widget and had to take this into account.  Here is the code we are currently using:

     

    <div
    	class="lia-panel lia-panel-standard UsersOnlineTaplet Chrome lia-component-forums-widget-users-online">
    	<div class="lia-decoration-border">
    		<div class="lia-decoration-border-top">
    			<div></div>
    		</div>
    		<div class="lia-decoration-border-content">
    			<div>
    				<div class="lia-panel-heading-bar-wrapper">
    					<div class="lia-panel-heading-bar">
    						<span class="lia-panel-heading-bar-title">Users Online</span>
    					</div>
    				</div>
    				<div class="lia-panel-content-wrapper">
    					<div class="lia-panel-content">
    						<div id="usersOnlineTaplet" class="UsersOnlineTaplet">
    							<div class="lia-users-online-current">
                                    <#assign member_count = rest('/users/online/registered/count').value?number />                                
                                    <#assign guest_count = rest('/users/online/anonymous/count').value?number />
    								<div class="lia-text">Currently online: ${member_count} <#if member_count <= 1>member<#else>members</#if> ${guest_count} <#if guest_count <= 1>guest<#else>guests</#if></div>
    							</div>
    
    							<div class="lia-users-online-recent">
    
    								<div class="lia-text">Recent logins:</div>
    
    
    								<ul id="list_0" class="lia-list-standard-inline">
    								  <#assign seen_users = {} />
                                    
                                      <#list rest('/users/online?page_size=5&restapi.response_style=view').users.user as online_user>
                                        <#if ! seen_users[online_user.@href]??>
                                          <#assign seen_users = seen_users + {online_user.@href:1} />
                                          <#assign online_user_ranking = rest(online_user.@href + '/ranking').ranking />
                                          <#assign avatar_info = restadmin(online_user.@href + "/profiles/avatar").image />
                                    
    									<li style="float:none!important;"><span class="UserName lia-user-name"> <img
    											class="lia-user-rank-icon-left" title="${online_user_ranking.name}"
    											alt="${online_user_ranking.name}"
    											src="${avatar_info.url}" style="width: auto; height: auto; max-width: 64px; max-height: 36px;" /> <a
    											class="lia-link-navigation lia-page-link lia-user-name-link"
    											style="<#if online_user_ranking.display.color != ''>color: #${online_user_ranking.display.color}</#if>" 
                                                target="_self"
    											href="${online_user.@view_href}"><span
    												class="<#if online_user_ranking.display.bold == 'true'>login-bold</#if>">${online_user.login}</span></a></span>
    									</li>
    									</#if>
                                        
                                      </#list>
    
    								</ul>
    							</div>                            
    
    							<div class="lia-view-all">
    								<a class="lia-link-navigation view-all-link" id="link_147"
    									href="/t5/forums/usersonlinepage">View All</a>
    							</div>
    						</div>
    					</div>
    				</div>
    			</div>
    		</div>
    		<div class="lia-decoration-border-bottom">
    			<div></div>
    		</div>
    	</div>
    </div>

     

    Note the seen_users hash to track those users we've already displayed.

  • :-) Yep, it is.  A user can be logged in multiple times.  We recently redid our Users Online widget and had to take this into account.  Here is the code we are currently using:

     

    <div
    	class="lia-panel lia-panel-standard UsersOnlineTaplet Chrome lia-component-forums-widget-users-online">
    	<div class="lia-decoration-border">
    		<div class="lia-decoration-border-top">
    			<div></div>
    		</div>
    		<div class="lia-decoration-border-content">
    			<div>
    				<div class="lia-panel-heading-bar-wrapper">
    					<div class="lia-panel-heading-bar">
    						<span class="lia-panel-heading-bar-title">Users Online</span>
    					</div>
    				</div>
    				<div class="lia-panel-content-wrapper">
    					<div class="lia-panel-content">
    						<div id="usersOnlineTaplet" class="UsersOnlineTaplet">
    							<div class="lia-users-online-current">
                                    <#assign member_count = rest('/users/online/registered/count').value?number />                                
                                    <#assign guest_count = rest('/users/online/anonymous/count').value?number />
    								<div class="lia-text">Currently online: ${member_count} <#if member_count <= 1>member<#else>members</#if> ${guest_count} <#if guest_count <= 1>guest<#else>guests</#if></div>
    							</div>
    
    							<div class="lia-users-online-recent">
    
    								<div class="lia-text">Recent logins:</div>
    
    
    								<ul id="list_0" class="lia-list-standard-inline">
    								  <#assign seen_users = {} />
                                    
                                      <#list rest('/users/online?page_size=5&restapi.response_style=view').users.user as online_user>
                                        <#if ! seen_users[online_user.@href]??>
                                          <#assign seen_users = seen_users + {online_user.@href:1} />
                                          <#assign online_user_ranking = rest(online_user.@href + '/ranking').ranking />
                                          <#assign avatar_info = restadmin(online_user.@href + "/profiles/avatar").image />
                                    
    									<li style="float:none!important;"><span class="UserName lia-user-name"> <img
    											class="lia-user-rank-icon-left" title="${online_user_ranking.name}"
    											alt="${online_user_ranking.name}"
    											src="${avatar_info.url}" style="width: auto; height: auto; max-width: 64px; max-height: 36px;" /> <a
    											class="lia-link-navigation lia-page-link lia-user-name-link"
    											style="<#if online_user_ranking.display.color != ''>color: #${online_user_ranking.display.color}</#if>" 
                                                target="_self"
    											href="${online_user.@view_href}"><span
    												class="<#if online_user_ranking.display.bold == 'true'>login-bold</#if>">${online_user.login}</span></a></span>
    									</li>
    									</#if>
                                        
                                      </#list>
    
    								</ul>
    							</div>                            
    
    							<div class="lia-view-all">
    								<a class="lia-link-navigation view-all-link" id="link_147"
    									href="/t5/forums/usersonlinepage">View All</a>
    							</div>
    						</div>
    					</div>
    				</div>
    			</div>
    		</div>
    		<div class="lia-decoration-border-bottom">
    			<div></div>
    		</div>
    	</div>
    </div>

     

    Note the seen_users hash to track those users we've already displayed.

  • Hi Laurent,
    yes. It's not only in the data via REST you can also see it in the "Online users" widget on your site. For example when you sign in with your userdata from different browsers or different machines you will have multiple concurrent user sessions.
    So actually this data reflects "Online user sessions" and is thus correct with those user duplicates.