예제 #1
0
        public ChatMessageViewUser GetChatMessageViewUser(GopUser user)
        {
            ChatMessageViewUser viewUser;

            if (user.UserId != null)
            {
                if (CacheViewUsers && userIdToViewUserCache.TryGetValue(user.UserId.Value, out viewUser))
                {
                    return(viewUser);
                }

                var loggedInUser = Users.AsNoTracking()
                                   .Where(u => u.Id == user.UserId)
                                   .Select(u => new { u.UserName, u.ChatColor })
                                   .Single();
                viewUser = new ChatMessageViewUser
                {
                    Username  = loggedInUser.UserName,
                    ChatColor = loggedInUser.ChatColor,
                    LoggedIn  = true
                };

                userIdToViewUserCache[user.UserId.Value] = viewUser;
            }
            else
            {
                if (CacheViewUsers)
                {
                    if (ipAddressToViewUserCache.TryGetValue(user.IpAddress, out viewUser))
                    {
                        return(viewUser);
                    }
                    return(new ChatMessageViewUser
                    {
                        Username = user.IpAddress,
                        ChatColor = DefaultChatColor,
                        LoggedIn = false
                    });
                }

                viewUser = new ChatMessageViewUser
                {
                    Username  = GetNameForIpAddress(user.IpAddress),
                    ChatColor = DefaultChatColor,
                    LoggedIn  = false
                };
                ipAddressToViewUserCache[user.IpAddress] = viewUser;
            }

            return(viewUser);
        }
예제 #2
0
 public string GetChatColor(GopUser user) => GetChatMessageViewUser(user).ChatColor;
예제 #3
0
 public string GetUsername(GopUser user) => GetChatMessageViewUser(user).Username;