コード例 #1
0
        public async Task AddAlert(AlertChatMessageViewModel alert)
        {
            if (!string.IsNullOrEmpty(alert.Color))
            {
                this.alertsLookup[alert.ID] = alert;

                if (ChannelSession.Settings.LatestChatAtTop)
                {
                    this.Alerts.Insert(0, alert);
                }
                else
                {
                    this.Alerts.Add(alert);
                }

                if (this.Alerts.Count > ChannelSession.Settings.MaxMessagesInChat)
                {
                    AlertChatMessageViewModel removedAlert = (ChannelSession.Settings.LatestChatAtTop) ? this.Alerts.Last() : this.Alerts.First();
                    this.alertsLookup.Remove(removedAlert.ID);
                    this.Alerts.Remove(removedAlert);
                }

                await ChannelSession.Services.Chat.WriteToChatEventLog(alert);

                if (!ChannelSession.Settings.OnlyShowAlertsInDashboard)
                {
                    await ChannelSession.Services.Chat.AddMessage(alert);
                }
            }
        }
コード例 #2
0
        public async Task AddAlert(AlertChatMessageViewModel alert)
        {
            if (!string.IsNullOrEmpty(alert.Color))
            {
                await DispatcherHelper.InvokeDispatcher(() =>
                {
                    this.alertsLookup[alert.ID] = alert;
                    this.Alerts.Insert(0, alert);

                    if (this.Alerts.Count > ChannelSession.Settings.MaxMessagesInChat)
                    {
                        AlertChatMessageViewModel removedAlert = this.Alerts.Last();
                        this.alertsLookup.Remove(removedAlert.ID);
                        this.Alerts.Remove(removedAlert);
                    }

                    return(Task.FromResult(0));
                });

                await ChannelSession.Services.Chat.WriteToChatEventLog(alert);

                if (!ChannelSession.Settings.OnlyShowAlertsInDashboard)
                {
                    await ChannelSession.Services.Chat.AddMessage(alert);
                }
            }
        }
コード例 #3
0
        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));
                            }
                        }
                    }
                }
            }
        }