Exemplo n.º 1
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);
        }