Exemple #1
0
        private bool Filtered(ChatMessage message)
        {
            if (!App.Settings.ChatEnabled)
            {
                message.Dispose();
                return(true);
            }

            if (Game.BlockList.Contains(message.Author) && !(message is LfgMessage))
            {
                message.Dispose();
                return(true);
            }

            var pausedCount = _pauseQueue.Count;

            for (var i = 0; i < App.Settings.SpamThreshold; i++)
            {
                if (i >= pausedCount + ChatMessages.Count)
                {
                    continue;
                }
                if (Pass(message, i <= pausedCount - 1
                    ? _pauseQueue.ElementAt(i)
                    : ChatMessages[i - pausedCount]))
                {
                    continue;
                }
                message.Dispose();
                return(true);
            }

            //if (ChatMessages.Count < App.Settings.SpamThreshold)
            //{
            //    for (var i = 0; i < ChatMessages.Count - 1; i++)
            //    {
            //        var m = ChatMessages[i];
            //        if (Pass(message, m)) continue;
            //        message.Dispose();
            //        return false;
            //    }
            //}
            //else
            //{
            //    for (var i = 0; i < App.Settings.SpamThreshold; i++)
            //    {
            //        if (i > ChatMessages.Count - 1) continue;
            //        var m = ChatMessages[i];
            //        if (Pass(message, m)) continue;
            //        message.Dispose();
            //        return false;
            //    }
            //}
            return(false);
        }
        void ReleaseDesignerOutlets()
        {
            if (ChatMessage != null)
            {
                ChatMessage.Dispose();
                ChatMessage = null;
            }

            if (MessageBackgroundView != null)
            {
                MessageBackgroundView.Dispose();
                MessageBackgroundView = null;
            }

            if (ReceivedMessageDate != null)
            {
                ReceivedMessageDate.Dispose();
                ReceivedMessageDate = null;
            }

            if (SentMessageDate != null)
            {
                SentMessageDate.Dispose();
                SentMessageDate = null;
            }
        }
        //public void NotifyOpacityChange()
        //{
        //    ChatWindows.ToList().ForEach(x =>
        //    {
        //        //TODO: make this different per window
        //        x.VM.NotifyOpacityChange();
        //    });
        //}

        public void AddChatMessage(ChatMessage chatMessage)
        {
            //return;
            if (!SettingsHolder.ChatEnabled)
            {
                chatMessage.Dispose();
                return;
            }

            if (BlockedUsers.Contains(chatMessage.Author))
            {
                chatMessage.Dispose();
                return;
            }
            if (ChatMessages.Count < SettingsHolder.SpamThreshold)
            {
                for (var i = 0; i < ChatMessages.Count - 1; i++)
                {
                    var m = ChatMessages[i];
                    if (!Pass(chatMessage, m))
                    {
                        chatMessage.Dispose();
                        return;
                    }
                }
            }
            else
            {
                for (var i = 0; i < SettingsHolder.SpamThreshold; i++)
                {
                    if (i > ChatMessages.Count - 1)
                    {
                        continue;
                    }

                    var m = ChatMessages[i];
                    if (!Pass(chatMessage, m))
                    {
                        chatMessage.Dispose();

                        return;
                    }
                }
            }

            chatMessage.SplitSimplePieces();

            if (ChatWindows.All(x => !x.IsPaused))
            {
                ChatMessages.Insert(0, chatMessage);
                //_cache.Add(chatMessage);
            }
            else
            {
                _queue.Enqueue(chatMessage);
            }

            NewMessage?.Invoke(chatMessage);
            if (ChatMessages.Count > SettingsHolder.MaxMessages)
            {
                var toRemove = ChatMessages[ChatMessages.Count - 1];
                toRemove.Dispose();
                ChatMessages.RemoveAt(ChatMessages.Count - 1);
            }
            N(nameof(MessageCount));
        }