Ejemplo n.º 1
0
        public void UpdateMessage(IPlaybackService playbackService, MessageWithOwner message)
        {
            _playbackService = playbackService;
            _message         = message;

            _playbackService.PropertyChanged -= OnCurrentItemChanged;
            _playbackService.PropertyChanged += OnCurrentItemChanged;

            var audio = GetContent(message.Content);

            if (audio == null)
            {
                return;
            }

            Title.Text = audio.GetTitle();

            if (audio.AlbumCoverThumbnail != null)
            {
                UpdateThumbnail(message, audio.AlbumCoverThumbnail, audio.AlbumCoverThumbnail.File);
            }
            else
            {
                Texture.Background = null;
                Button.Style       = BootStrapper.Current.Resources["InlineFileButtonStyle"] as Style;
            }

            UpdateManager.Subscribe(this, message, audio.AudioValue, ref _fileToken, UpdateFile);
            UpdateFile(message, audio.AudioValue);
        }
Ejemplo n.º 2
0
        private void UpdatePlayback(MessageWithOwner message, Audio audio, File file)
        {
            if (message.IsEqualTo(_playbackService.CurrentItem))
            {
                if (_playbackService.PlaybackState == MediaPlaybackState.Paused)
                {
                    Button.SetGlyph(file.Id, MessageContentState.Play);
                }
                else
                {
                    Button.SetGlyph(file.Id, MessageContentState.Pause);
                }

                UpdatePosition();

                _playbackService.PlaybackStateChanged += OnPlaybackStateChanged;
                _playbackService.PositionChanged      += OnPositionChanged;
            }
            else
            {
                Button.SetGlyph(file.Id, MessageContentState.Play);
                Button.Progress = 1;

                if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting() && !file.Local.IsDownloadingActive && !file.Remote.IsUploadingActive)
                {
                    Subtitle.Text = audio.GetDuration() + " - " + FileSizeConverter.Convert(Math.Max(file.Size, file.ExpectedSize));
                }
                else
                {
                    Subtitle.Text = audio.GetDuration();
                }
            }

            Button.Progress = 1;
        }
Ejemplo n.º 3
0
        private void UpdateThumbnail(MessageWithOwner message, Thumbnail thumbnail, File file)
        {
            if (file.Local.IsFileExisting())
            {
                double ratioX = (double)48 / thumbnail.Width;
                double ratioY = (double)48 / thumbnail.Height;
                double ratio  = Math.Max(ratioX, ratioY);

                var width  = (int)(thumbnail.Width * ratio);
                var height = (int)(thumbnail.Height * ratio);

                Texture.Background = new ImageBrush {
                    ImageSource = new BitmapImage(UriEx.ToLocal(file.Local.Path))
                    {
                        DecodePixelWidth = width, DecodePixelHeight = height
                    }, Stretch = Stretch.UniformToFill, AlignmentX = AlignmentX.Center, AlignmentY = AlignmentY.Center
                };
                Button.Style = BootStrapper.Current.Resources["ImmersiveFileButtonStyle"] as Style;
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                message.ProtoService.DownloadFile(file.Id, 1);

                Texture.Background = null;
                Button.Style       = BootStrapper.Current.Resources["InlineFileButtonStyle"] as Style;
            }
        }
Ejemplo n.º 4
0
        public void UpdateMessage(IPlaybackService playbackService, MessageWithOwner message)
        {
            _playbackService = playbackService;
            _message         = message;

            _playbackService.PropertyChanged -= OnCurrentItemChanged;
            _playbackService.PropertyChanged += OnCurrentItemChanged;

            var voiceNote = GetContent(message.Content);

            if (voiceNote == null)
            {
                return;
            }

            if (message.ProtoService.TryGetUser(message.SenderId, out User user))
            {
                Title.Text = user.GetFullName();
            }
            else if (message.ProtoService.TryGetChat(message.SenderId, out Chat chat))
            {
                Title.Text = chat.Title;
            }
            else
            {
                Title.Text = string.Empty;
            }

            UpdateManager.Subscribe(this, message, voiceNote.Voice, ref _fileToken, UpdateFile);
            UpdateFile(message, voiceNote.Voice);
        }
Ejemplo n.º 5
0
        private void UpdateFile(MessageWithOwner message, File file)
        {
            var data = message.GetFileAndThumbnailAndName();

            if (data.File == null)
            {
                return;
            }

            if (data.Thumbnail != null && data.Thumbnail.File.Id == file.Id)
            {
                UpdateThumbnail(message, data.Thumbnail, file);
                return;
            }
            else if (data.File.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                //Button.Glyph = Icons.Cancel;
                Button.SetGlyph(file.Id, MessageContentState.Downloading);
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive)
            {
                //Button.Glyph = Icons.Cancel;
                Button.SetGlyph(file.Id, MessageContentState.Uploading);
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting())
            {
                //Button.Glyph = Icons.Download;
                Button.SetGlyph(file.Id, MessageContentState.Download);
                Button.Progress = 0;

                Subtitle.Text = FileSizeConverter.Convert(size) + " — " + UpdateTimeLabel(message);
            }
            else
            {
                //Button.Glyph = Icons.Document;
                Button.SetGlyph(file.Id, MessageContentState.Document);
                Button.Progress = 1;

                Subtitle.Text = FileSizeConverter.Convert(size) + " — " + UpdateTimeLabel(message);
            }
        }
Ejemplo n.º 6
0
        public void UpdateMessage(IMessageDelegate delegato, MessageWithOwner message)
        {
            _delegate = delegato;
            _message  = message;

            var data = message.GetFileAndThumbnailAndName();

            if (data.File == null)
            {
                return;
            }

            Ellipse.Background = UpdateEllipseBrush(data.FileName);

            if (string.IsNullOrEmpty(data.FileName))
            {
                if (message.ProtoService.TryGetUser(message.SenderId, out User user))
                {
                    Title.Text = user.GetFullName();
                }
                else if (message.ProtoService.TryGetChat(message.SenderId, out Chat chat))
                {
                    Title.Text = chat.Title;
                }
                else
                {
                    Title.Text = string.Empty;
                }
            }
            else
            {
                Title.Text = data.FileName;
            }

            if (data.Thumbnail != null)
            {
                UpdateThumbnail(message, data.Thumbnail, data.Thumbnail.File);
            }
            else
            {
                Texture.Background = null;
                Button.Style       = BootStrapper.Current.Resources["InlineFileButtonStyle"] as Style;
            }

            UpdateManager.Subscribe(this, message, data.File, ref _fileToken, UpdateFile);
            UpdateFile(message, data.File);
        }
Ejemplo n.º 7
0
        public void UpdateMessage(INavigationService navigationService, MessageWithOwner message)
        {
            _navigationService = navigationService;
            _message           = message;

            var caption = message.GetCaption();

            if (caption == null)
            {
                return;
            }

            var text = message.Content as MessageText;

            var links    = new List <string>();
            var hasThumb = false;

            string title         = null;
            string description   = null;
            string description2  = null;
            string webPageLink   = null;
            bool   webPageCached = false;

            var webPage = text?.WebPage;

            if (webPage != null)
            {
                title = webPage.Title;
                if (string.IsNullOrEmpty(title))
                {
                    title = webPage.SiteName;
                }

                description   = string.IsNullOrEmpty(webPage.Description?.Text) ? null : webPage.Description?.Text;
                webPageLink   = webPage.Url;
                webPageCached = webPage.InstantViewVersion != 0;

                //hasThumb = webPage.HasPhoto && webPage.Photo is TLPhoto photo && photo.Thumb != null;
            }

            if (caption.Entities.Count > 0)
            {
                for (int a = 0; a < caption.Entities.Count; a++)
                {
                    var entity = caption.Entities[a];
                    if (entity.Length <= 0 || entity.Offset < 0 || entity.Offset >= caption.Text.Length)
                    {
                        continue;
                    }
                    else if (entity.Offset + entity.Length > caption.Text.Length)
                    {
                        entity.Length = caption.Text.Length - entity.Offset;
                    }

                    if (a == 0 && webPageLink != null && !(entity.Offset == 0 && entity.Length == caption.Text.Length))
                    {
                        if (caption.Entities.Count == 1)
                        {
                            if (description == null)
                            {
                                description2 = caption.Text;
                            }
                        }
                        else
                        {
                            description2 = caption.Text;
                        }
                    }

                    try
                    {
                        string link = null;
                        if (entity.Type is TextEntityTypeTextUrl or TextEntityTypeUrl)
                        {
                            if (entity.Type is TextEntityTypeUrl)
                            {
                                link = caption.Text.Substring(entity.Offset, entity.Length);
                            }
                            else if (entity.Type is TextEntityTypeTextUrl textUrl)
                            {
                                link = textUrl.Url;
                            }
                            if (title == null || title.Length == 0)
                            {
                                title = link;
                                var url = link;
                                if (url.StartsWith("http") == false)
                                {
                                    url = "http://" + url;
                                }

                                var uri = new Uri(url);
                                title = uri.Host;
                                if (title == null)
                                {
                                    title = link;
                                }
                                int index;
                                if (title != null && (index = title.LastIndexOf('.')) >= 0)
                                {
                                    title = title.Substr(0, index);
                                    if ((index = title.LastIndexOf('.')) >= 0)
                                    {
                                        title = title.Substring(index + 1);
                                    }
                                    title = title.Substring(0, 1).ToUpper() + title.Substring(1);
                                }
                                if (entity.Offset != 0 || entity.Length != caption.Text.Length)
                                {
                                    description = caption.Text;
                                }
                            }
                        }
                        else if (entity.Type is TextEntityTypeEmailAddress)
                        {
                            if (title == null || title.Length == 0)
                            {
                                link  = "mailto:" + caption.Text.Substring(entity.Offset, entity.Length);
                                title = caption.Text.Substring(entity.Offset, entity.Length);
                                if (entity.Offset != 0 || entity.Length != caption.Text.Length)
                                {
                                    description = caption.Text;
                                }
                            }
                        }
                        if (link != null)
                        {
                            if (link.ToLower().IndexOf("http") != 0 && link.ToLower().IndexOf("mailto") != 0)
                            {
                                links.Add("http://" + link);
                            }
                            else
                            {
                                links.Add(link);
                            }
                        }
                    }
Ejemplo n.º 8
0
 public static string GetSummary(MessageWithOwner message, bool details = false)
 {
     return(GetSummary(message.ProtoService, message.Get(), details));
 }
Ejemplo n.º 9
0
        private void UpdateFile(MessageWithOwner message, File file)
        {
            _playbackService.PlaybackStateChanged -= OnPlaybackStateChanged;
            _playbackService.PositionChanged      -= OnPositionChanged;

            var audio = GetContent(message.Content);

            if (audio == null)
            {
                return;
            }

            if (audio.AlbumCoverThumbnail != null && audio.AlbumCoverThumbnail.File.Id == file.Id)
            {
                UpdateThumbnail(message, audio.AlbumCoverThumbnail, file);
                return;
            }
            else if (audio.AudioValue.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                FileButton target;
                if (SettingsService.Current.IsStreamingEnabled)
                {
                    target = Download;
                    DownloadPanel.Visibility = Visibility.Visible;
                }
                else
                {
                    target = Button;
                    DownloadPanel.Visibility = Visibility.Collapsed;
                }

                target.SetGlyph(file.Id, MessageContentState.Downloading);
                target.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed)
            {
                DownloadPanel.Visibility = Visibility.Collapsed;

                Button.SetGlyph(file.Id, MessageContentState.Uploading);
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting())
            {
                FileButton target;
                if (SettingsService.Current.IsStreamingEnabled)
                {
                    target = Download;
                    DownloadPanel.Visibility = Visibility.Visible;
                }
                else
                {
                    target = Button;
                    DownloadPanel.Visibility = Visibility.Collapsed;
                }

                target.SetGlyph(file.Id, MessageContentState.Download);
                target.Progress = 0;

                Subtitle.Text = audio.GetDuration() + " - " + FileSizeConverter.Convert(size);

                //if (message.Delegate.CanBeDownloaded(message))
                //{
                //    _message.ProtoService.DownloadFile(file.Id, 32);
                //}
            }
            else
            {
                DownloadPanel.Visibility = Visibility.Collapsed;

                if (!SettingsService.Current.IsStreamingEnabled)
                {
                    UpdatePlayback(message, audio, file);
                }
            }

            if (SettingsService.Current.IsStreamingEnabled)
            {
                UpdatePlayback(message, audio, file);
            }
        }
Ejemplo n.º 10
0
 private string UpdateTimeLabel(MessageWithOwner message)
 {
     return(Converter.BannedUntil(message.Date));
 }
Ejemplo n.º 11
0
 private bool MessageSelect_Loaded(MessageWithOwner message)
 {
     return(true);
 }
Ejemplo n.º 12
0
 private bool MessageForward_Loaded(MessageWithOwner message)
 {
     return(message.CanBeForwarded);
 }
Ejemplo n.º 13
0
 private bool MessageDelete_Loaded(MessageWithOwner message)
 {
     return(message.CanBeDeletedOnlyForSelf || message.CanBeDeletedForAllUsers);
 }
Ejemplo n.º 14
0
 private bool MessageView_Loaded(MessageWithOwner message)
 {
     return(true);
 }
Ejemplo n.º 15
0
        private void UpdateFile(MessageWithOwner message, File file)
        {
            _playbackService.PlaybackStateChanged -= OnPlaybackStateChanged;
            _playbackService.PositionChanged      -= OnPositionChanged;

            var voiceNote = GetContent(message.Content);

            if (voiceNote == null)
            {
                return;
            }

            if (voiceNote.Voice.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                //Button.Glyph = Icons.Cancel;
                Button.SetGlyph(file.Id, MessageContentState.Downloading);
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed)
            {
                //Button.Glyph = Icons.Cancel;
                Button.SetGlyph(file.Id, MessageContentState.Uploading);
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting())
            {
                //Button.Glyph = Icons.Download;
                Button.SetGlyph(file.Id, MessageContentState.Download);
                Button.Progress = 0;

                Subtitle.Text = voiceNote.GetDuration() + ", " + FileSizeConverter.Convert(size);

                //if (message.Delegate.CanBeDownloaded(message))
                //{
                //    _message.ProtoService.DownloadFile(file.Id, 32);
                //}
            }
            else
            {
                if (message.IsEqualTo(_playbackService.CurrentItem))
                {
                    if (_playbackService.PlaybackState == MediaPlaybackState.Paused)
                    {
                        //Button.Glyph = Icons.Play;
                        Button.SetGlyph(file.Id, MessageContentState.Play);
                    }
                    else
                    {
                        //Button.Glyph = Icons.Pause;
                        Button.SetGlyph(file.Id, MessageContentState.Pause);
                    }

                    UpdatePosition();

                    _playbackService.PlaybackStateChanged += OnPlaybackStateChanged;
                    _playbackService.PositionChanged      += OnPositionChanged;
                }
                else
                {
                    //Button.Glyph = Icons.Play;
                    Button.SetGlyph(file.Id, MessageContentState.Play);
                    Button.Progress = 1;

                    Subtitle.Text = voiceNote.GetDuration();
                }

                Button.Progress = 1;
            }
        }
Ejemplo n.º 16
0
 public static void Subscribe(object sender, MessageWithOwner message, File file, ref string token, UpdateHandler <File> handler, bool completionOnly = false, bool keepTargetAlive = false)
 {
     Subscribe(sender, message.ProtoService.SessionId, file, ref token, handler, completionOnly, keepTargetAlive);
 }