protected static bool IsInlineMedia(TLMessageMediaBase media) { if (media == null) { return(false); } if (media.TypeId == TLType.MessageMediaContact) { return(true); } else if (media.TypeId == TLType.MessageMediaGeoLive) { return(true); } else if (media.TypeId == TLType.MessageMediaVenue) { return(true); } else if (media.TypeId == TLType.MessageMediaPhoto) { var photoMedia = media as TLMessageMediaPhoto; if (string.IsNullOrWhiteSpace(photoMedia.Caption)) { return(false); } return(true); } else if (media.TypeId == TLType.MessageMediaDocument) { var documentMedia = media as TLMessageMediaDocument; if (TLMessage.IsMusic(documentMedia.Document)) { return(true); } else if (TLMessage.IsVoice(documentMedia.Document)) { return(true); } else if (TLMessage.IsVideo(documentMedia.Document)) { if (string.IsNullOrWhiteSpace(documentMedia.Caption)) { return(false); } } else if (TLMessage.IsGif(documentMedia.Document)) { if (string.IsNullOrWhiteSpace(documentMedia.Caption)) { return(false); } } return(true); } return(false); }
public void Enqueue(TLMessage message) { if (message == null) { return; } if (_mediaPlayer.Source == _playlist && _mediaPlayer.Source != null && _playlist != null && _inverse.TryGetValue(message, out MediaPlaybackItem item) && _playlist.Items.Contains(item)) { var index = _playlist.Items.IndexOf(item); if (index >= 0) { _playlist.MoveTo((uint)index); return; } } Dispose(); var peer = message.Parent?.ToInputPeer(); var voice = message.IsVoice(); _mediaPlayer.CommandManager.IsEnabled = !voice; //_mediaPlayer.AudioDeviceType = voice ? MediaPlayerAudioDeviceType.Communications : MediaPlayerAudioDeviceType.Multimedia; //_mediaPlayer.AudioCategory = voice ? MediaPlayerAudioCategory.Communications : MediaPlayerAudioCategory.Media; if (peer != null) { var filter = voice ? new Func <TLMessageBase, bool>(x => x.Id > message.Id && x is TLMessage xm && xm.IsVoice()) : new Func <TLMessageBase, bool>(x => x.Id < message.Id && x is TLMessage xm && xm.IsMusic()); //var response = await _protoService.SearchAsync(peer, null, null, filter, message.Date + 1, int.MaxValue, 0, 0, 50); //if (response.IsSucceeded) //{ // _queue = new Queue<TLMessage>(response.Result.Messages.OfType<TLMessage>().Reverse()); //} _cacheService.GetHistoryAsync(message.Parent.ToPeer(), result => { var items = result.OfType <TLMessage>(); if (voice) { items = items.Reverse(); } _queue = new Queue <TLMessage>(result.OfType <TLMessage>().Reverse()); _items = new List <TLMessage>(new[] { message }.Union(items)); Enqueue(message, true); }, predicate: filter); } //if (voice) //{ // await AttachAsync(); //} }
public object Convert(object value, Type targetType, object parameter, string language) { var documentMedia = value as TLMessageMediaDocument; if (documentMedia != null) { var document = documentMedia.Document as TLDocument; if (document != null) { var fileName = document.GetFileName(); if (File.Exists(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, fileName))) { if (TLMessage.IsVideo(document)) { return(Symbol.Play); } if (TLMessage.IsVoice(document)) { return(Symbol.Play); } return(Symbol.Page2); } } } //var videoMedia = value as TLMessageMediaVideo; //if (videoMedia != null) //{ // var video = videoMedia.Video as TLVideo; // if (video != null) // { // var fileName = video.GetFileName(); // if (File.Exists(Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName)) || Task.Run(() => File.Exists(videoMedia.IsoFileName)).Result) // { // return Symbol.Play; // } // } //} //var audioMedia = value as TLMessageMediaAudio; //if (audioMedia != null) //{ // var audio = audioMedia.Audio as TLAudio; // if (audio != null) // { // var fileName = audio.GetFileName(); // if (File.Exists(Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName))) // { // return Symbol.Play; // } // } //} return(Symbol.Download); }
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); }
private string UpdateGlyph(TLDocument document) { ContentVisibility = Visibility.Visible; Visibility = Visibility.Visible; if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1) { ContentVisibility = Visibility.Visible; return("\uE10A"); } else if (document.UploadingProgress > 0 && document.UploadingProgress < 1) { ContentVisibility = Visibility.Collapsed; return("\uE10A"); } else if (File.Exists(FileUtils.GetTempFileName(document.GetFileName()))) { ContentVisibility = Visibility.Collapsed; var message = DataContext as TLMessage; if (message != null && message.Media is TLMessageMediaDocument documentMedia && documentMedia.HasTTLSeconds) { return("\uE60D"); } if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsMusic(document) || TLMessage.IsVoice(document)) { return("\uE102"); } else if (TLMessage.IsGif(document)) { //Visibility = Visibility.Collapsed; return("\uE906"); } return("\uE160"); } return("\uE118"); }