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>.....
  • xorrkaz's avatar
    13 years ago

    :-) 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.