private async Task <RoomViewModel> GetRoomInfoCore(ChatRoom room) { var recentMessages = _recentMessageCache.GetRecentMessages(room.Name); // If we haven't cached enough messages just populate it now if (recentMessages.Count == 0) { var messages = await(from m in _repository.GetMessagesByRoom(room) orderby m.When descending select m).Take(50).ToListAsync(); // Reverse them since we want to get them in chronological order messages.Reverse(); recentMessages = messages.Select(m => new MessageViewModel(m)).ToList(); _recentMessageCache.Add(room.Name, recentMessages); } // Get online users through the repository List <ChatUser> onlineUsers = await _repository.GetOnlineUsers(room).ToListAsync(); return(new RoomViewModel { Name = room.Name, Users = from u in onlineUsers select new UserViewModel(u), Owners = from u in room.Owners.Online() select u.Name, RecentMessages = recentMessages, Topic = room.Topic ?? String.Empty, Welcome = room.Welcome ?? String.Empty, Closed = room.Closed }); }
private RoomViewModel GetRoomInfoCore(ChatRoom room) { var recentMessages = _recentMessageCache.GetRecentMessages(room.Name); // If we haven't cached enough messages just populate it now if (recentMessages.Count == 0) { var messages = _repository.GetMessagesByRoom(room) .Take(50) .OrderBy(o => o.When) .ToList(); recentMessages = messages.Select(m => new MessageViewModel(m)).ToList(); _recentMessageCache.Add(room.Name, recentMessages); } List <ChatUser> onlineUsers = _repository.GetOnlineUsers(room).ToList(); return(new RoomViewModel { Name = room.Name, Users = from u in onlineUsers select new UserViewModel(u), Owners = _repository.GetRoomOwners(room).Online().Select(n => n.Name), RecentMessages = recentMessages, Topic = room.Topic ?? string.Empty, Welcome = room.Welcome ?? String.Empty, Closed = room.Closed }); }
public ChatMessage AddMessage(ChatUser user, ChatRoom room, string id, string content) { var chatMessage = new ChatMessage { Id = id, User = user, Content = content, When = DateTimeOffset.UtcNow, Room = room, HtmlEncoded = false }; _recentMessageCache.Add(chatMessage); _repository.Add(chatMessage); return chatMessage; }