public bool CanBeDownloaded(MessageViewModel message)
        {
            var content = message.Content as object;

            if (content is MessageAnimation animationMessage)
            {
                content = animationMessage.Animation;
            }
            else if (content is MessageAudio audioMessage)
            {
                content = audioMessage.Audio;
            }
            else if (content is MessageDocument documentMessage)
            {
                content = documentMessage.Document;
            }
            else if (content is MessageGame gameMessage)
            {
                if (gameMessage.Game.Animation != null)
                {
                    content = gameMessage.Game.Animation;
                }
                else if (gameMessage.Game.Photo != null)
                {
                    content = gameMessage.Game.Photo;
                }
            }
            else if (content is MessageInvoice invoiceMessage)
            {
                content = invoiceMessage.Photo;
            }
            else if (content is MessageLocation locationMessage)
            {
                content = locationMessage.Location;
            }
            else if (content is MessagePhoto photoMessage)
            {
                content = photoMessage.Photo;
            }
            else if (content is MessageSticker stickerMessage)
            {
                content = stickerMessage.Sticker;
            }
            else if (content is MessageText textMessage)
            {
                if (textMessage?.WebPage?.Animation != null)
                {
                    content = textMessage?.WebPage?.Animation;
                }
                else if (textMessage?.WebPage?.Document != null)
                {
                    content = textMessage?.WebPage?.Document;
                }
                else if (textMessage?.WebPage?.Sticker != null)
                {
                    content = textMessage?.WebPage?.Sticker;
                }
                else if (textMessage?.WebPage?.Video != null)
                {
                    content = textMessage?.WebPage?.Video;
                }
                else if (textMessage?.WebPage?.VideoNote != null)
                {
                    content = textMessage?.WebPage?.VideoNote;
                }
                // PHOTO SHOULD ALWAYS BE AT THE END!
                else if (textMessage?.WebPage?.Photo != null)
                {
                    content = textMessage?.WebPage?.Photo;
                }
            }
            else if (content is MessageVideo videoMessage)
            {
                content = videoMessage.Video;
            }
            else if (content is MessageVideoNote videoNoteMessage)
            {
                content = videoNoteMessage.VideoNote;
            }
            else if (content is MessageVoiceNote voiceNoteMessage)
            {
                content = voiceNoteMessage.VoiceNote;
            }

            var file = message.GetFile();

            if (file != null && ProtoService.IsDownloadFileCanceled(file.Id))
            {
                return(false);
            }

            var chat = _chat;

            if (chat == null)
            {
                return(false);
            }

            if (content is Animation animation)
            {
                return(Settings.AutoDownload.ShouldDownloadVideo(GetChatType(chat), animation.AnimationValue.Size));
            }
            else if (content is Audio audio)
            {
                return(Settings.AutoDownload.ShouldDownloadDocument(GetChatType(chat), audio.AudioValue.Size));
            }
            else if (content is Document document)
            {
                return(Settings.AutoDownload.ShouldDownloadDocument(GetChatType(chat), document.DocumentValue.Size));
            }
            else if (content is Photo photo)
            {
                var big = photo.GetBig();
                if (big != null && ProtoService.IsDownloadFileCanceled(big.Photo.Id))
                {
                    return(false);
                }

                return(Settings.AutoDownload.ShouldDownloadPhoto(GetChatType(chat)));
            }
            else if (content is Sticker sticker)
            {
                // Stickers aren't part of the deal
                return(true);
            }
            else if (content is Video video)
            {
                return(Settings.AutoDownload.ShouldDownloadVideo(GetChatType(chat), video.VideoValue.Size));
            }
            else if (content is VideoNote videoNote)
            {
                return(Settings.AutoDownload.ShouldDownloadDocument(GetChatType(chat), videoNote.Video.Size));
            }
            else if (content is VoiceNote voiceNote)
            {
                // Voice notes aren't part of the deal
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool CanBeDownloaded(MessageViewModel message)
        {
            var content = message.Content as object;

            if (content is MessageAnimation animationMessage)
            {
                content = animationMessage.Animation;
            }
            else if (content is MessageAudio audioMessage)
            {
                content = audioMessage.Audio;
            }
            else if (content is MessageDocument documentMessage)
            {
                content = documentMessage.Document;
            }
            else if (content is MessageGame gameMessage)
            {
                if (gameMessage.Game.Animation != null)
                {
                    content = gameMessage.Game.Animation;
                }
                else if (gameMessage.Game.Photo != null)
                {
                    content = gameMessage.Game.Photo;
                }
            }
            else if (content is MessageInvoice invoiceMessage)
            {
                content = invoiceMessage.Photo;
            }
            else if (content is MessageLocation locationMessage)
            {
                content = locationMessage.Location;
            }
            else if (content is MessagePhoto photoMessage)
            {
                content = photoMessage.Photo;
            }
            else if (content is MessageSticker stickerMessage)
            {
                content = stickerMessage.Sticker;
            }
            else if (content is MessageText textMessage)
            {
                if (textMessage?.WebPage?.Animation != null)
                {
                    content = textMessage?.WebPage?.Animation;
                }
                else if (textMessage?.WebPage?.Document != null)
                {
                    content = textMessage?.WebPage?.Document;
                }
                else if (textMessage?.WebPage?.Sticker != null)
                {
                    content = textMessage?.WebPage?.Sticker;
                }
                else if (textMessage?.WebPage?.Video != null)
                {
                    content = textMessage?.WebPage?.Video;
                }
                else if (textMessage?.WebPage?.VideoNote != null)
                {
                    content = textMessage?.WebPage?.VideoNote;
                }
                // PHOTO SHOULD ALWAYS BE AT THE END!
                else if (textMessage?.WebPage?.Photo != null)
                {
                    content = textMessage?.WebPage?.Photo;
                }
            }
            else if (content is MessageVideo videoMessage)
            {
                content = videoMessage.Video;
            }
            else if (content is MessageVideoNote videoNoteMessage)
            {
                content = videoNoteMessage.VideoNote;
            }
            else if (content is MessageVoiceNote voiceNoteMessage)
            {
                content = voiceNoteMessage.VoiceNote;
            }

            var chat = _chat;

            if (chat == null)
            {
                return(false);
            }

            if (content is Animation animation)
            {
                return(ProtoService.Preferences.ShouldDownloadAnimation(GetChatType(chat), new NetworkTypeWiFi()));
            }
            else if (content is Audio audio)
            {
            }
            else if (content is Document document)
            {
                return(ProtoService.Preferences.ShouldDownloadDocument(GetChatType(chat), new NetworkTypeWiFi(), document.DocumentData.Size));
            }
            else if (content is Photo photo)
            {
                return(ProtoService.Preferences.ShouldDownloadPhoto(GetChatType(chat), new NetworkTypeWiFi()));
            }
            else if (content is Sticker sticker)
            {
            }
            else if (content is Video video)
            {
                return(ProtoService.Preferences.ShouldDownloadVideo(GetChatType(chat), new NetworkTypeWiFi(), video.VideoData.Size));
            }
            else if (content is VideoNote videoNote)
            {
                return(ProtoService.Preferences.ShouldDownloadVideoNote(GetChatType(chat), new NetworkTypeWiFi()));
            }
            else if (content is VoiceNote voiceNote)
            {
                return(ProtoService.Preferences.ShouldDownloadVoiceNote(GetChatType(chat), new NetworkTypeWiFi()));
            }

            return(false);
        }
        public static async Task <InstantGalleryViewModel> CreateAsync(IProtoService protoService, IEventAggregator aggregator, MessageViewModel message, WebPage webPage)
        {
            var items = new List <GalleryContent>();

            var response = await protoService.SendAsync(new GetWebPageInstantView(webPage.Url, false));

            if (response is WebPageInstantView instantView && instantView.IsFull)
            {
                foreach (var block in instantView.PageBlocks)
                {
                    if (block is PageBlockSlideshow slideshow)
                    {
                        foreach (var item in slideshow.PageBlocks)
                        {
                            items.Add(CountBlock(protoService, instantView, item));
                        }
                    }
                    else if (block is PageBlockCollage collage)
                    {
                        foreach (var item in collage.PageBlocks)
                        {
                            items.Add(CountBlock(protoService, instantView, item));
                        }
                    }
                }
            }

            var result = new InstantGalleryViewModel(protoService, aggregator);

            result.Items.ReplaceWith(items);
            result.FirstItem    = items.FirstOrDefault();
            result.SelectedItem = items.FirstOrDefault();
            result.TotalItems   = items.Count;

            return(result);
        }