Example #1
0
        private void RemoveUserFromChannel(int userId, int channelId)
        {
            UserActivtyEntry entry            = null;
            DateTime         joined           = DateTime.MinValue;
            bool             fireNotification = false;

            // Try to find the user in our map.
            if (m_userMap.TryGetValue(userId, out entry))
            {
                // The users exists, remove this activity.
                lock (entry.ActiveChannels)
                {
                    // Try to remove the value, if it exists it will succeeded.
                    UserTime time;
                    if (entry.ActiveChannels.Remove(channelId, out time))
                    {
                        // The user was here, clear them out now.
                        fireNotification = true;
                        joined           = time.Joined;
                    }

                    // If the maps is now empty, remove the user from the user map
                    if (entry.ActiveChannels.Count == 0)
                    {
                        m_userMap.TryRemove(userId, out entry);
                    }
                }
            }

            if (fireNotification)
            {
                FireUserActivity(userId, channelId, false, joined);
            }
        }
Example #2
0
        private void AddOrUpdateUserToChannel(int userId, int channelId)
        {
            // Make sure the user has an entry.
            UserActivtyEntry entry = null;

            while (!m_userMap.TryGetValue(userId, out entry))
            {
                // Create a new entry for this user.
                entry = new UserActivtyEntry()
                {
                    ActiveChannels = new Dictionary <int, UserTime>()
                };

                // Try to add the user to the map.
                m_userMap.TryAdd(userId, entry);
            }

            // Check if the user is already known to be watching or not.
            bool     fireNotification = false;
            DateTime joined           = DateTime.MinValue;

            lock (entry.ActiveChannels)
            {
                UserTime time;
                if (entry.ActiveChannels.TryGetValue(channelId, out time))
                {
                    // Update the last time we saw this
                    entry.ActiveChannels[channelId].LastSeen = DateTime.Now;
                }
                else
                {
                    // Create a new entry.
                    joined           = DateTime.Now;
                    fireNotification = true;

                    time = new UserTime()
                    {
                        Joined   = joined,
                        LastSeen = DateTime.Now
                    };

                    // Add it to the user's list
                    entry.ActiveChannels.Add(channelId, time);
                }
            }

            // If we should fire a notification and we found a new user fire the event.
            if (fireNotification)
            {
                FireUserActivity(userId, channelId, true, joined);
            }
        }
Example #3
0
        //public async void OnCommand(string command, ChatMessage msg)
        //{
        //    if (command.Equals("userstats"))
        //    {
        //        await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"I'm currently chatting with {m_currentViewerCount.ToString("n0", Carl.Culture)} viewers on {m_channelTracker.Count.ToString("n0", Carl.Culture)} mixer channels.", msg.IsWhisper);
        //    }
        //}

        private List <int> InternalGetActiveChannels(int userId)
        {
            List <int>       activeChannels = new List <int>();
            UserActivtyEntry entry          = null;
            DateTime         now            = DateTime.Now;

            if (m_userMap.TryGetValue(userId, out entry))
            {
                // The user exists, update the active list.
                lock (entry.ActiveChannels)
                {
                    foreach (var pair in entry.ActiveChannels)
                    {
                        activeChannels.Add(pair.Key);
                    }
                }
                return(activeChannels.Count == 0 ? null : activeChannels);
            }
            return(null);
        }