Example #1
0
        public ChatMessageControl(ChatMessageViewModel message)
        {
            this.Loaded += ChatMessageControl_Loaded;

            InitializeComponent();

            this.DataContext   = this.Message = message;
            this.messageHeader = new ChatMessageHeaderControl(this.Message);
        }
        private void ChatMessageControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.IsLoaded && this.DataContext != null && this.DataContext is ChatMessageViewModel && this.Message == null)
            {
                this.Message            = (ChatMessageViewModel)this.DataContext;
                this.Message.OnDeleted += Message_OnDeleted;
                bool italics     = false;
                bool highlighted = false;

                this.Separator.Visibility = (ChannelSession.Settings.AddSeparatorsBetweenMessages) ? Visibility.Visible : Visibility.Collapsed;

                if (this.DataContext is AlertChatMessageViewModel)
                {
                    AlertChatMessageViewModel alert      = (AlertChatMessageViewModel)this.DataContext;
                    SolidColorBrush           foreground = null;
                    if (!string.IsNullOrEmpty(alert.Color) && !alert.Color.Equals(ColorSchemes.DefaultColorScheme))
                    {
                        string color = alert.Color;
                        try
                        {
                            if (ColorSchemes.HTMLColorSchemeDictionary.ContainsKey(color))
                            {
                                color = ColorSchemes.HTMLColorSchemeDictionary[color];
                            }
                            foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom(color));
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LogLevel.Error, "Bad Alert Color: " + color);
                            Logger.Log(ex);
                        }
                    }
                    this.AddStringMessage(alert.PlainTextMessage, foreground: foreground);
                    this.MessageWrapPanel.HorizontalAlignment = HorizontalAlignment.Center;
                }
                else
                {
                    ChatMessageHeaderControl header = new ChatMessageHeaderControl();
                    header.DataContext = this.DataContext;
                    this.MessageWrapPanel.Children.Add(header);

                    bool showMessage = true;

                    if (this.DataContext is ChatMessageViewModel)
                    {
                        ChatMessageViewModel message = (ChatMessageViewModel)this.DataContext;
                        highlighted = highlighted || message.IsStreamerTagged;
                    }

                    if (this.DataContext is TwitchChatMessageViewModel)
                    {
                        TwitchChatMessageViewModel twitchMessage = (TwitchChatMessageViewModel)this.DataContext;
                        italics     = twitchMessage.IsSlashMe;
                        highlighted = highlighted || twitchMessage.IsHighlightedMessage;
                    }

                    if (showMessage)
                    {
                        foreach (object messagePart in this.Message.MessageParts)
                        {
                            if (messagePart is string)
                            {
                                string messagePartString = (string)messagePart;
                                this.AddStringMessage(messagePartString, isHighlighted: highlighted, isItalicized: italics);
                            }
                            else if (messagePart is TwitchV5API.EmoteModel)
                            {
                                this.MessageWrapPanel.Children.Add(new ChatImageControl((TwitchV5API.EmoteModel)messagePart));
                            }
                            else if (messagePart is BetterTTVEmoteModel)
                            {
                                this.MessageWrapPanel.Children.Add(new ChatImageControl((BetterTTVEmoteModel)messagePart));
                            }
                            else if (messagePart is FrankerFaceZEmoteModel)
                            {
                                this.MessageWrapPanel.Children.Add(new ChatImageControl((FrankerFaceZEmoteModel)messagePart));
                            }
                            else if (messagePart is TwitchBitsCheerViewModel)
                            {
                                this.MessageWrapPanel.Children.Add(new ChatImageControl((TwitchBitsCheerViewModel)messagePart));
                            }
                        }
                    }
                }
            }
        }