示例#1
0
        private string UpdateGlyph(TLDocument document)
        {
            Visibility = Visibility.Visible;

            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document) || TLMessage.IsMusic(document))
                {
                    return("\uE102");
                }

                return("\uE160");
            }
            else if (document.IsTransferring)
            {
                return("\uE10A");
            }
            else if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }
            else if (document.UploadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }

            return("\uE118");
        }
示例#2
0
        private void MessageCopyLinkExecute(TLMessage message)
        {
            if (message == null)
            {
                return;
            }

            if (With is TLChannel channel)
            {
                var link = $"{channel.Username}/{message.Id}";

                if (message.IsRoundVideo())
                {
                    link = $"https://telesco.pe/{link}";
                }
                else
                {
                    var config = CacheService.GetConfig();
                    if (config != null)
                    {
                        link = $"{config.MeUrlPrefix}{link}";
                    }
                    else
                    {
                        link = $"https://t.me/{link}";
                    }
                }

                var dataPackage = new DataPackage();
                dataPackage.SetText(link);
                Clipboard.SetContent(dataPackage);
            }
        }
示例#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 IAsyncOperation <ContentDialogBaseResult> ShowAsync(TLMessage message, bool withMyScore = false)
        {
            ViewModel.Comment       = null;
            ViewModel.ShareLink     = null;
            ViewModel.ShareTitle    = null;
            ViewModel.Messages      = new[] { message };
            ViewModel.InputMedia    = null;
            ViewModel.IsWithMyScore = withMyScore;

            var channel = message.Parent as TLChannel;

            if (channel != null && channel.IsBroadcast && channel.HasUsername)
            {
                var link = $"{channel.Username}/{message.Id}";

                if (message.IsRoundVideo())
                {
                    link = $"https://telesco.pe/{link}";
                }
                else
                {
                    link = MeUrlPrefixConverter.Convert(link);
                }

                string title = null;

                var media = message.Media as ITLMessageMediaCaption;
                if (media != null && !string.IsNullOrWhiteSpace(media.Caption))
                {
                    title = media.Caption;
                }
                else if (!string.IsNullOrWhiteSpace(message.Message))
                {
                    title = message.Message;
                }

                ViewModel.ShareLink  = new Uri(link);
                ViewModel.ShareTitle = title ?? channel.DisplayName;
            }
            else if (message.Media is TLMessageMediaGame gameMedia)
            {
                if (message.ViaBot != null && message.ViaBot.Username != null)
                {
                    ViewModel.ShareLink  = new Uri(MeUrlPrefixConverter.Convert($"{message.From.Username}?game={gameMedia.Game.ShortName}"));
                    ViewModel.ShareTitle = gameMedia.Game.Title;
                }
            }

            return(ShowAsync());
        }
示例#5
0
        private string UpdateGlyph(TLDocument document)
        {
            Visibility = Visibility.Visible;

            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                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))
                {
                    return("\uE102");
                }
                else if (TLMessage.IsGif(document))
                {
                    Visibility = Visibility.Collapsed;
                    return("\uE102");
                }

                return("\uE160");
            }
            else if (document.IsTransferring)
            {
                return("\uE10A");
            }
            else if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }
            else if (document.UploadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }

            return("\uE118");
        }
示例#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);
        }
示例#7
0
        public static async void Download_Click(FrameworkElement sender, TransferCompletedEventArgs e)
        {
            var element = sender as FrameworkElement;

            var bubble = element.Ancestors <MessageBubbleBase>().FirstOrDefault() as MessageBubbleBase;

            if (bubble == null)
            {
                return;
            }

            if (element.DataContext is TLMessageService serviceMessage && serviceMessage.Action is TLMessageActionChatEditPhoto editPhotoAction)
            {
                var media = element.Parent as FrameworkElement;
                if (media == null)
                {
                    media = element;
                }

                var chat = serviceMessage.Parent as TLChatBase;
                if (chat == null)
                {
                    return;
                }

                var chatFull = InMemoryCacheService.Current.GetFullChat(chat.Id);
                if (chatFull != null && chatFull.ChatPhoto is TLPhoto && chat != null)
                {
                    var viewModel = new ChatPhotosViewModel(bubble.ContextBase.ProtoService, bubble.ContextBase.CacheService, chatFull, chat, serviceMessage);
                    await GalleryView.Current.ShowAsync(viewModel, () => media);
                }

                return;
            }

            var message = element.DataContext as TLMessage;

            if (message == null)
            {
                return;
            }

            var document = message.GetDocument();

            if (TLMessage.IsGif(document) && !ApplicationSettings.Current.IsAutoPlayEnabled)
            {
                var page = bubble.Ancestors <IGifPlayback>().FirstOrDefault() as IGifPlayback;
                if (page == null)
                {
                    return;
                }

                if (bubble.ViewModel is TLMessage inner)
                {
                    page.Play(inner);
                }
            }
            else if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document) || message.IsPhoto())
            {
                var media = element.Ancestors().FirstOrDefault(x => x is FrameworkElement && ((FrameworkElement)x).Name.Equals("Media")) as FrameworkElement;
                if (media == null)
                {
                    media = element;
                }

                //ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("FullScreenPicture", media);

                GalleryViewModelBase viewModel;
                if (message.Parent == null || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document))
                {
                    viewModel = new SingleGalleryViewModel(new GalleryMessageItem(message));
                }
                else
                {
                    viewModel = new DialogGalleryViewModel(bubble.ContextBase.ProtoService, bubble.ContextBase.CacheService, message.Parent.ToInputPeer(), message);
                }

                await GalleryView.Current.ShowAsync(viewModel, () => media);
            }
            else if (e != null)
            {
                var file = await StorageFile.GetFileFromApplicationUriAsync(FileUtils.GetTempFileUri(e.FileName));

                await Launcher.LaunchFileAsync(file);
            }
        }
示例#8
0
        public IAsyncOperation <ContentDialogBaseResult> ShowAsync(TLMessage message, bool withMyScore = false)
        {
            ViewModel.ShareLink     = null;
            ViewModel.ShareTitle    = null;
            ViewModel.Message       = message;
            ViewModel.InputMedia    = null;
            ViewModel.IsWithMyScore = withMyScore;

            var channel = message.Parent as TLChannel;

            if (channel != null && channel.IsBroadcast && channel.HasUsername)
            {
                var link = $"{channel.Username}/{message.Id}";

                if (message.IsRoundVideo())
                {
                    link = $"https://telesco.pe/{link}";
                }
                else
                {
                    var config = ViewModel.CacheService.GetConfig();
                    if (config != null)
                    {
                        var linkPrefix = config.MeUrlPrefix;
                        if (linkPrefix.EndsWith("/"))
                        {
                            linkPrefix = linkPrefix.Substring(0, linkPrefix.Length - 1);
                        }
                        if (linkPrefix.StartsWith("https://"))
                        {
                            linkPrefix = linkPrefix.Substring(8);
                        }
                        else if (linkPrefix.StartsWith("http://"))
                        {
                            linkPrefix = linkPrefix.Substring(7);
                        }

                        link = $"https://{linkPrefix}/{link}";
                    }
                    else
                    {
                        link = $"https://t.me/{link}";
                    }
                }

                string title = null;

                var media = message.Media as ITLMessageMediaCaption;
                if (media != null && !string.IsNullOrWhiteSpace(media.Caption))
                {
                    title = media.Caption;
                }
                else if (!string.IsNullOrWhiteSpace(message.Message))
                {
                    title = message.Message;
                }

                ViewModel.ShareLink  = new Uri(link);
                ViewModel.ShareTitle = title ?? channel.DisplayName;
            }
            else if (message.Media is TLMessageMediaGame gameMedia)
            {
                var config = ViewModel.CacheService.GetConfig();
                if (config != null && message.ViaBot != null && message.ViaBot.Username != null)
                {
                    var linkPrefix = config.MeUrlPrefix;
                    if (linkPrefix.EndsWith("/"))
                    {
                        linkPrefix = linkPrefix.Substring(0, linkPrefix.Length - 1);
                    }
                    if (linkPrefix.StartsWith("https://"))
                    {
                        linkPrefix = linkPrefix.Substring(8);
                    }
                    else if (linkPrefix.StartsWith("http://"))
                    {
                        linkPrefix = linkPrefix.Substring(7);
                    }

                    ViewModel.ShareLink  = new Uri($"https://{linkPrefix}/{message.From.Username}?game={gameMedia.Game.ShortName}");
                    ViewModel.ShareTitle = gameMedia.Game.Title;
                }
            }

            return(ShowAsync());
        }
示例#9
0
 public DialogGalleryViewModel(TLInputPeerBase peer, TLMessage selected, IMTProtoService protoService)
     : base(protoService, null, null)
 {
     if (selected.Media is TLMessageMediaPhoto photoMedia || selected.IsVideo() || selected.IsRoundVideo() || selected.IsGif())
     {
         Items = new MvxObservableCollection <GalleryItem> {
             new GalleryMessageItem(selected)
         };
         SelectedItem = Items[0];
         FirstItem    = Items[0];
     }