Re: Total # of Chatters in all Rooms

  •  01-07-2008, 8:35 AM

    Re: Total # of Chatters in all Rooms

    Hi:
     
    Here is a example about how to list the online users:
     
    you can just count it :
     
    int count=0;
    ChatPortal portal=ChatSystem.Instance.GetCurrentPortal();
    lock(portal)
    {
       foreach(ChatChannel channel in portal.GetStartedChannels())
       {
          count+=channel.GetAllUsers().Length;
       }
    }
     
     
    full example:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="CuteChat" %>
    <script runat=server>
    static string Encode(string val)
    {
     if(val==null)return "";
     return val.Replace("\\","\\\\").Replace("\"","\\\\");
    }
    </script>

    var onlineusers=[];

    <%
    ChatPortal portal=ChatSystem.Instance.GetCurrentPortal();
    lock(portal)
    {

    foreach(ChatChannel channel in portal.GetStartedChannels())
    {
    foreach(ChatPlaceUser user in channel.GetAllUsers())
    {
     if(user.AppearOffline)continue;

    %>

    onlineusers.push({
    UserId:"<%=user.Identity.UniqueId%>"
    ,
    Name:"<%=Encode(user.DisplayName)%>"
    ,
    IsGuest:<%=user.Identity.IsAnonymous?"true":"false"%>
    });


    <%}%>

    <%}%>

    <%}%>


    for(var i=0;i<onlineusers.length;i++)
    {
     var user=onlineusersIdea;
     document.write("<span class='onlineuser'>");
     document.write(user.Name);
     document.write("</span>");
    }

     
    Regards , Terry.
View Complete Thread