示例#1
0
文件: ChatRooms.cs 项目: varlo/Unona9
 public static void LeaveUser(int chatRoomId, ChatSession chatSession)
 {
     List<ChatSession> lSessions = dChatRoomUsers[chatRoomId];
     ChatSession sessInstance = lSessions.Find(
         delegate(ChatSession sess) { return sess.ChatUserInstance.Id == chatSession.ChatUserInstance.Id; });
     if (sessInstance != null)
     {
         lSessions.Remove(sessInstance);
         if (sessInstance.JoinedChatRooms.IndexOf(chatRoomId) >= 0)
         {
             sessInstance.JoinedChatRooms.Remove(chatRoomId);
         }
     }
 }
示例#2
0
文件: ChatRooms.cs 项目: varlo/Unona9
        public static ChatRoomEvents FetchEvents(int chatRoomId, int? fromId, ChatSession chatSession)
        {
            if (!dChatRooms.ContainsKey(chatRoomId)) return null;
            List<ChatMessage> lMessages = dChatRooms[chatRoomId];

            ChatRoomEvents chatRoomEvents = new ChatRoomEvents();

            lock (lMessages)
            {
                chatRoomEvents.Messages.AddRange(
                    lMessages.FindAll(delegate(ChatMessage msg)
                                          {
                                              return (!fromId.HasValue
                                                       || (fromId.HasValue && msg.Id > fromId.Value))
                                                  && (!msg.TargetUserId.HasValue
                                                    || chatSession.ChatUserInstance.Id == msg.TargetUserId.Value);
                                          }));
                if (!fromId.HasValue && chatRoomEvents.Messages.Count > 10)
                    chatRoomEvents.Messages.RemoveRange(0, chatRoomEvents.Messages.Count - 10);
            }

            // Update last activity time
            ChatSession foundSession = dChatRoomUsers[chatRoomId].Find(
                delegate(ChatSession sess)
                    {
                        try
                        {
                            return sess.ChatUserInstance.Username == chatSession.ChatUserInstance.Username;
                        }
                        catch
                        {
                            return false;
                        }
                    });
            if (foundSession != null) foundSession.LastActivity = DateTime.Now;

            return chatRoomEvents;
        }
示例#3
0
文件: ChatRooms.cs 项目: varlo/Unona9
        public static void JoinUser(int chatRoomId, ChatSession chatSession)
        {
            if (!dChatRoomUsers.ContainsKey(chatRoomId))
                dChatRoomUsers.Add(chatRoomId, new List<ChatSession>());
            List<ChatSession> lSessions = dChatRoomUsers[chatRoomId];
            if (lSessions.Find(
                delegate(ChatSession sess)
                {
                    return sess.ChatUserInstance.Id == chatSession.ChatUserInstance.Id;
                }) == null)
            {
                lSessions.Add(chatSession);
            }

            chatSession.LastActivity = DateTime.Now;
        }