Beispiel #1
0
        protected override async Task LoadInlineMedias()
        {
            if (Config?.Visual?.InlineMedia != true)
            {
                return;
            }

            var mediaEntities = Model?.Entities?.MediaEntities ?? Enumerable.Empty <MediaEntity>();
            var entities      = mediaEntities.Distinct(TwitterComparers.MediaEntityComparer);

            foreach (var vm in entities.Select(entity => new StatusMediaViewModel(entity, Context.UserId)))
            {
                vm.OpenRequested += Image_OpenRequested;
                _InlineMedias.Add(vm);
            }

            var urlEntities = Model?.Entities?.UrlEntities ?? Enumerable.Empty <UrlEntity>();
            var urls        = urlEntities.Distinct(TwitterComparers.UrlEntityComparer).Select(e => e.ExpandedUrl);

            foreach (var url in urls)
            {
                var extracted = await MediaExtractor.ExtractMedia(url);

                if (extracted != null)
                {
                    var vm = new StatusMediaViewModel(extracted);
                    vm.OpenRequested += Image_OpenRequested;
                    _InlineMedias.Add(vm);
                }
            }

            RaisePropertyChanged(nameof(InlineMedias));
        }
Beispiel #2
0
        protected override async Task LoadInlineMedias()
        {
            if (Config?.Visual?.InlineMedia != true)
            {
                return;
            }

            var videos = (Model?.ExtendedEntities?.MediaEntities?.Where(e => e.Type == "animated_gif" || e.Type == "video") ??
                          Enumerable.Empty <MediaEntity>()).ToArray();

            var mediaEntities    = Model?.Entities?.MediaEntities ?? Enumerable.Empty <MediaEntity>();
            var extendedEntities = Model?.ExtendedEntities?.MediaEntities ?? Enumerable.Empty <MediaEntity>();

            var entities = mediaEntities.Concat(extendedEntities)
                           .Distinct(TwitterComparers.MediaEntityComparer)
                           .Except(videos, TwitterComparers.MediaEntityComparer);

            entities = entities.Concat(videos);

            foreach (var vm in entities.Select(entity => new StatusMediaViewModel(entity)))
            {
                if (_InlineMedias.Contains(vm))
                {
                    continue;
                }

                vm.OpenRequested += Image_OpenRequested;
                _InlineMedias.Add(vm);
            }

            var urlEntities         = Model?.Entities?.UrlEntities ?? Enumerable.Empty <UrlEntity>();
            var extendedUrlEntities = Model?.ExtendedEntities?.UrlEntities ?? Enumerable.Empty <UrlEntity>();
            var urls = urlEntities.Concat(extendedUrlEntities).Distinct(TwitterComparers.UrlEntityComparer).Select(e => e.ExpandedUrl);

            foreach (var url in urls)
            {
                var extracted = await MediaExtractor.ExtractMedia(url);

                if (extracted != null)
                {
                    var vm = new StatusMediaViewModel(extracted, new Uri(url));
                    if (_InlineMedias.Contains(vm))
                    {
                        continue;
                    }

                    vm.OpenRequested += Image_OpenRequested;
                    _InlineMedias.Add(vm);
                }
            }

            RaisePropertyChanged(nameof(InlineMedias));
        }