Exemplo n.º 1
0
Arquivo: Chat.cs Projeto: fredyfx/Aiva
        /// <summary>
        /// Add viewer to list
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        private async void AddViewerToList(string name, string id)
        {
            if (Viewer.Any(v => String.Compare(v.TwitchID, id) == 0)) // check if user is already in List
            {
                return;
            }

            TwitchLib.Api.Models.v5.Subscriptions.Subscription isUserSubscriber = null;
            if (AivaClient.Instance.IsPartnered)
            {
                isUserSubscriber = await AivaClient.Instance.TwitchApi.Channels.v5.CheckChannelSubscriptionByUserAsync(AivaClient.Instance.ChannelId, name);
            }

            var rnd    = new Random();
            var viewer = new Aiva.Models.Chat.Viewer {
                Name     = name,
                TwitchID = id,
                IsSub    = isUserSubscriber != null,
                Type     = isUserSubscriber != null?nameof(Aiva.Models.Enums.SortDirectionListView.Subscriber)
                               : nameof(Aiva.Models.Enums.SortDirectionListView.Viewer),
                               ChatNameColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256))
                                               //IsMod = will be filled from the event "ModeratoersReceived"
            };

            Application.Current.Dispatcher.Invoke(() => Viewer.Add(viewer));

            // Get Channel Moderators to fire "ModeratorsReceived"
            AivaClient.Instance.TwitchClient.GetChannelModerators(AivaClient.Instance.Channel);
        }