Пример #1
0
        protected Visibility ConvertShare(TLMessage message)
        {
            if (message.IsSticker())
            {
                return(Visibility.Collapsed);
            }
            else if (message.HasFwdFrom && message.FwdFrom.HasChannelId && !message.IsOut)
            {
                return(Visibility.Visible);
            }
            else if (message.HasFromId && !message.IsPost)
            {
                if (message.Media is TLMessageMediaEmpty || message.Media == null || message.Media is TLMessageMediaWebPage webpageMedia && !(webpageMedia.WebPage is TLWebPage))
                {
                    return(Visibility.Collapsed);
                }

                var user = message.From;
                if (user != null && user.IsBot)
                {
                    return(Visibility.Visible);
                }

                if (!message.IsOut)
                {
                    if (message.Media is TLMessageMediaGame || message.Media is TLMessageMediaInvoice)
                    {
                        return(Visibility.Visible);
                    }

                    var parent = message.Parent as TLChannel;
                    if (parent != null && parent.IsMegaGroup)
                    {
                        //TLRPC.Chat chat = MessagesController.getInstance().getChat(messageObject.messageOwner.to_id.channel_id);
                        //return chat != null && chat.username != null && chat.username.length() > 0 && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo);

                        return(parent.HasUsername && !(message.Media is TLMessageMediaContact) && !(message.Media is TLMessageMediaGeo) ? Visibility.Visible : Visibility.Collapsed);
                    }
                }
            }
            //else if (messageObject.messageOwner.from_id < 0 || messageObject.messageOwner.post)
            else if (message.IsPost)
            {
                //if (messageObject.messageOwner.to_id.channel_id != 0 && (messageObject.messageOwner.via_bot_id == 0 && messageObject.messageOwner.reply_to_msg_id == 0 || messageObject.type != 13))
                //{
                //    return Visibility.Visible;
                //}

                if (message.ToId is TLPeerChannel && (!message.HasViaBotId && !message.HasReplyToMsgId))
                {
                    return(Visibility.Visible);
                }
            }

            return(Visibility.Collapsed);
        }
Пример #2
0
 public void Download()
 {
     if (PHASE_FULL > Phase && _source is TLPhoto photo)
     {
         SetSource(photo, photo.Full, PHASE_FULL);
     }
     else if (PHASE_FULL > Phase && _source is TLDocument document && TLMessage.IsSticker(document))
     {
         SetWebPSource(document, document, document.Size, PHASE_FULL);
     }
 }
Пример #3
0
        public TLBitmapSource(TLDocument document, bool thumbnail)
        {
            _source = document;

            if (TLMessage.IsSticker(document))
            {
                if (thumbnail)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                if (TrySetWebPSource(document, PHASE_FULL))
                {
                    return;
                }

                SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                SetWebPSource(document, document, document.Size, PHASE_FULL);
            }
            else if (TLMessage.IsGif(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.GIF))
                {
                    SetDownloadSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsVideo(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.Video))
                {
                    SetDownloadSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsRoundVideo(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.Round))
                {
                    SetDownloadSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);
            }
        }
Пример #4
0
        public TLBitmapSource(TLDocument document, bool thumbnail)
        {
            _source = document;

            if (TLMessage.IsSticker(document))
            {
                if (thumbnail)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                if (TrySetWebPSource(document, PHASE_FULL) == false)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    SetWebPSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsGif(document))
            {
                if (thumbnail)
                {
                    SetSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                _renderer = _animatedFactory.CreateRenderer(320, 320);
                Image     = _renderer.ImageSource;

                if (TrySetAnimatedSource(document, PHASE_FULL) == false && ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.GIF))
                {
                    SetAnimatedSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsVideo(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.Video))
                {
                    //SetSource(photo, photo.Full, PHASE_FULL);
                }
            }
            else
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);
            }
        }
Пример #5
0
        public TLBitmapSource(TLDocument document, bool thumbnail)
        {
            _source = document;

            if (TLMessage.IsSticker(document))
            {
                if (thumbnail)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                if (TrySetWebPSource(document, PHASE_FULL) == false)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    SetWebPSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else
            {
                SetSource(null, document.Thumb, PHASE_FULL);
            }
        }
Пример #6
0
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            var boh = DataTemplate.GetExtensionInstance(container as FrameworkElement);

            var presenter = container as ContentControl;

            if (presenter != null && item is TLDocument doc)
            {
                presenter.Content = new TLMessage {
                    Media = new TLMessageMediaDocument {
                        Document = doc
                    }
                };
            }

            if (item is TLMessage message)
            {
                item = message.Media;
            }

            if (item is TLMessageMediaEmpty)
            {
                return(EmptyTemplate);
            }
            else if (item is TLMessageMediaContact)
            {
                return(ContactTemplate);
            }
            else if (item is TLMessageMediaPhoto)
            {
                return(PhotoTemplate);
            }
            else if (item is TLMessageMediaGame)
            {
                return(GameTemplate);
            }
            else if (item is TLMessageMediaVenue)
            {
                return(VenueTemplate);
            }
            else if (item is TLMessageMediaGeo)
            {
                return(GeoPointTemplate);
            }
            else if (item is TLMessageMediaInvoice invoiceMedia)
            {
                if (invoiceMedia.HasPhoto && invoiceMedia.Photo != null)
                {
                    return(InvoicePhotoTemplate);
                }

                return(InvoiceTemplate);
            }
            else if (item is TLMessageMediaDocument || item is TLDocument)
            {
                if (item is TLMessageMediaDocument documentMedia)
                {
                    item = documentMedia.Document;
                }

                if (item is TLDocument document)
                {
                    if (TLMessage.IsVoice(document))
                    {
                        return(AudioTemplate);
                    }
                    else if (TLMessage.IsVideo(document))
                    {
                        return(VideoTemplate);
                    }
                    else if (TLMessage.IsRoundVideo(document))
                    {
                        return(RoundVideoTemplate);
                    }
                    else if (TLMessage.IsGif(document))
                    {
                        return(GifTemplate);
                    }
                    else if (TLMessage.IsSticker(document))
                    {
                        return(StickerTemplate);
                    }
                    else if (TLMessage.IsMusic(document))
                    {
                        return(MusicTemplate);
                    }

                    // TODO: ???
                    //var externalDocument = documentMedia.Document as TLDocumentExternal;
                    //if (externalDocument != null && TLMessage.IsGif(externalDocument))
                    //{
                    //    return GifTemplate;
                    //}

                    if (document.Thumb != null && !(document.Thumb is TLPhotoSizeEmpty))
                    {
                        return(DocumentThumbTemplate);
                    }
                }

                return(DocumentTemplate);
            }
            else if (item is TLMessageMediaWebPage webpageMedia)
            {
                if (webpageMedia.WebPage is TLWebPageEmpty)
                {
                    return(EmptyTemplate);
                }
                else if (webpageMedia.WebPage is TLWebPagePending)
                {
                    return(EmptyTemplate);
                }
                else if (webpageMedia.WebPage is TLWebPage webpage)
                {
                    /*if (TLMessage.IsGif(webpage.Document))
                     * {
                     *  return WebPageGifTemplate;
                     * }
                     * else
                     * if (webpage.Document != null && webpage.Type.Equals("document", StringComparison.OrdinalIgnoreCase))
                     * {
                     *  return WebPageDocumentTemplate;
                     * }*/

                    if (webpage.Document != null)
                    {
                        return(WebPageDocumentTemplate);
                    }

                    if (webpage.Photo != null && webpage.Type != null)
                    {
                        if (IsWebPagePhotoTemplate(webpage))
                        {
                            return(WebPagePhotoTemplate);
                        }

                        return(WebPageSmallPhotoTemplate);
                    }
                }
                return(WebPageTemplate);
            }
            else if (item is TLMessageMediaUnsupported)
            {
                return(UnsupportedTemplate);
            }

            return(null);
        }