Пример #1
0
        public void Calculate()
        {
            _posArray.Clear();
            Positions.Clear();
            int count = Messages.Count;

            if (count <= 1)
            {
                return;
            }

            int   totalWidth  = 0;
            float totalHeight = 0.0f;

            int           firstSpanAdditionalSize = 200;
            float         maxSizeHeight           = 814.0f;
            StringBuilder proportions             = new StringBuilder();
            float         averageAspectRatio      = 1.0f;
            bool          isOut     = false;
            int           maxX      = 0;
            bool          forceCalc = false;

            for (int a = 0; a < count; a++)
            {
                TLMessage messageObject = Messages[a];
                TLVector <TLPhotoSizeBase> photoThumbs = null;
                if (a == 0)
                {
                    //isOut = messageObject.isOutOwner();
                }
                if (messageObject.Media is TLMessageMediaPhoto photoMedia && photoMedia.Photo is TLPhoto photo)
                {
                    photoThumbs = photo.Sizes;
                }
Пример #2
0
        private string GetURLFromMessage(TLMessage message)
        {
            var reply = (TLReplyInlineMarkup)message.ReplyMarkup;
            var btn   = (TLKeyboardButtonUrl)reply.Rows[0].Buttons[0];

            return(btn.Url);
        }
Пример #3
0
        private bool SetPhotoTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            FindName(nameof(ThumbRoot));
            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Visible;
            }

            // 🖼

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "Photo";
            MessageLabel.Text = string.Empty;

            var photoMedia = message.Media as TLMessageMediaPhoto;

            if (photoMedia != null)
            {
                if (!string.IsNullOrWhiteSpace(photoMedia.Caption))
                {
                    ServiceLabel.Text += ", ";
                    MessageLabel.Text += photoMedia.Caption.Replace("\r\n", "\n").Replace('\n', ' ');
                }

                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(photoMedia, true);
            }

            return(true);
        }
Пример #4
0
        private bool SetAudioTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Collapsed;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = Strings.Android.AttachAudio;
            MessageLabel.Text = string.Empty;

            var documentMedia = message.Media as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                var document = documentMedia.Document as TLDocument;
                if (document != null)
                {
                    ServiceLabel.Text = document.Title;
                }

                if (!string.IsNullOrWhiteSpace(documentMedia.Caption))
                {
                    ServiceLabel.Text += ", ";
                    MessageLabel.Text += documentMedia.Caption.Replace('\n', ' ');
                }
            }

            return(true);
        }
Пример #5
0
        private bool SetStickerTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Collapsed;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "Sticker";
            MessageLabel.Text = string.Empty;

            var documentMedia = message.Media as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                var document = documentMedia.Document as TLDocument;
                if (document != null)
                {
                    var attribute = document.Attributes.OfType <TLDocumentAttributeSticker>().FirstOrDefault();
                    if (attribute != null)
                    {
                        if (!string.IsNullOrEmpty(attribute.Alt))
                        {
                            ServiceLabel.Text = $"{attribute.Alt} Sticker";
                        }
                    }
                }
            }

            return(true);
        }
Пример #6
0
        public string ConvertViews(TLMessage message, int?views)
        {
            var number = string.Empty;

            if (message.HasViews)
            {
                //ViewsGlyph.Text = "\uE607\u2009";
                ViewsGlyph.Text = "\uE607\u00A0\u00A0";

                number  = Convert.ShortNumber(Math.Max(views ?? 1, 1));
                number += "   ";

                if (message.IsPost && message.HasPostAuthor && message.PostAuthor != null)
                {
                    number += $"{message.PostAuthor}, ";
                }
                else if (message.HasFwdFrom && message.FwdFrom != null && message.FwdFrom.HasPostAuthor && message.FwdFrom.PostAuthor != null)
                {
                    number += $"{message.FwdFrom.PostAuthor}, ";
                }
            }
            else
            {
                ViewsGlyph.Text = string.Empty;
            }

            return(number);
        }
        public SettingsAppearanceViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
            : base(protoService, cacheService, aggregator)
        {
            Message1 = new TLMessage
            {
                Message         = "Ahh you kids today with techno music! Enjoy the classics, like Hasselhoff!",
                Date            = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now.AddSeconds(-25)),
                HasReplyToMsgId = true,
                ReplyToMsgId    = int.MaxValue,
                Reply           = new TLMessage
                {
                    Message = "Reinhardt, we need to find you some new tunes.",
                    From    = new TLUser
                    {
                        HasFirstName = true,
                        FirstName    = "Lucio"
                    }
                }
            };

            Message2 = new TLMessage
            {
                Message = "I can't take you seriously right now. Sorry..",
                Date    = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now),
                IsFirst = true,
                IsOut   = true,
                State   = TLMessageState.Read
            };
        }
Пример #8
0
        private bool SetWebPageTemplate(TLMessage message, string title)
        {
            var webPageMedia = message.Media as TLMessageMediaWebPage;

            if (webPageMedia != null)
            {
                var webPage = webPageMedia.WebPage as TLWebPage;
                if (webPage != null && webPage.Photo != null && webPage.Type != null)
                {
                    Visibility = Visibility.Visible;

                    FindName(nameof(ThumbRoot));
                    if (ThumbRoot != null)
                    {
                        ThumbRoot.Visibility = Visibility.Visible;
                    }

                    TitleLabel.Text   = GetFromLabel(message, title);
                    ServiceLabel.Text = string.Empty;
                    MessageLabel.Text = message.Message.Replace("\r\n", "\n").Replace('\n', ' ');

                    ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                    ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(webPage.Photo, true);
                }
                else
                {
                    return(SetTextTemplate(message, title));
                }
            }

            return(true);
        }
Пример #9
0
        private bool SetVoiceMessageTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Collapsed;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "Voice message";
            MessageLabel.Text = string.Empty;

            var documentMedia = message.Media as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                if (!string.IsNullOrWhiteSpace(documentMedia.Caption))
                {
                    ServiceLabel.Text += ", ";
                    MessageLabel.Text += documentMedia.Caption.Replace("\r\n", "\n").Replace('\n', ' ');
                }
            }

            return(true);
        }
Пример #10
0
        public MyMessage(Manager mngr, TLMessage message)
        {
            this.message = message;
            this.Text    = message.Message;
            Buttons      = new List <Button>();
            TLReplyInlineMarkup markup = null;

            try
            {
                markup = ((TLReplyInlineMarkup)message.ReplyMarkup);
            }
            catch { }
            if (markup != null)
            {
                for (int row = 0; row < markup.Rows.Count; row++)
                {
                    for (int but = 0; but < markup.Rows[row].Buttons.Count; but++)
                    {
                        Button button = Button.Create(mngr, message, markup.Rows[row].Buttons[but], new Button.BtnPosition {
                            Row = row, Btn = but
                        });
                        Buttons.Add(button);
                    }
                }
            }
        }
Пример #11
0
        private bool SetGameTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            FindName(nameof(ThumbRoot));
            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Visible;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "🎮 Game";
            MessageLabel.Text = string.Empty;

            var gameMedia = message.Media as TLMessageMediaGame;

            if (gameMedia != null && gameMedia.Game != null)
            {
                ServiceLabel.Text = $"🎮 {gameMedia.Game.Title}";

                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(gameMedia.Game.Photo, true);
            }

            return(true);
        }
Пример #12
0
        void PublishExpiredMessage(TLMessage message)
        {
            if (message.Media is TLMessageMediaPhoto photoMedia)
            {
                photoMedia.Photo      = null;
                photoMedia.Caption    = null;
                photoMedia.HasPhoto   = false;
                photoMedia.HasCaption = false;

                photoMedia.DestructDate = null;
                photoMedia.DestructIn   = null;
            }
            else if (message.Media is TLMessageMediaDocument documentMedia)
            {
                documentMedia.Document    = null;
                documentMedia.Caption     = null;
                documentMedia.HasDocument = false;
                documentMedia.HasCaption  = false;

                documentMedia.DestructDate = null;
                documentMedia.DestructIn   = null;
            }

            Aggregator.Publish(new MessageExpiredEventArgs(message));
        }
Пример #13
0
        private void OpenLocation(TLMessage message)
        {
            var liveLocationsService = IoC.Get <ILiveLocationService>();
            var messageGeoLive       = CurrentDialog != null?liveLocationsService.Get(CurrentDialog.Peer, MTProtoService.CurrentUserId) : null;

            if (messageGeoLive != null)
            {
                var cachedMessage = CacheService.GetMessage(messageGeoLive.Id, With is TLChannel ? ((TLChannel)With).Id : null) as TLMessage;
                if (cachedMessage != null)
                {
                    messageGeoLive = cachedMessage;
                }
            }

            if (LocationPicker == null)
            {
                LocationPicker = IoC.Get <MapViewModel>();
                LocationPicker.LiveLocations.Clear();
                LocationPicker.With                      = With;
                LocationPicker.MessageGeo                = message;
                LocationPicker.MessageGeoLive            = messageGeoLive;
                LocationPicker.ContinueAction            = ContinueSendLocation;
                LocationPicker.StopLiveLocationAction    = StopLiveLocation;
                LocationPicker.UpdateLiveLocationsAction = UpdateLiveLocations;
                NotifyOfPropertyChange(() => LocationPicker);
            }
            else
            {
                LocationPicker.LiveLocations.Clear();
                LocationPicker.With           = With;
                LocationPicker.MessageGeo     = message;
                LocationPicker.MessageGeoLive = messageGeoLive;
                BeginOnUIThread(() => LocationPicker.OpenEditor());
            }
        }
        private void SendVideoInternal(TLMessage message, CompressingVideoFile file)
        {
            if (file.IsCompressionEnabled)
            {
                message.Status = MessageStatus.Compressing;

                GetCompressedFile(file,
                                  (compressedFile, compressedSize) =>
                {
                    message.Media.IsoFileName = compressedFile.Path;
                    message.Media.File        = compressedFile;
                    message.Status            = MessageStatus.Sending;
                    var mediaVideo            = message.Media as TLMessageMediaVideo;
                    if (mediaVideo != null)
                    {
                        var video = mediaVideo.Video as TLVideo;
                        if (video != null)
                        {
                            video.Size = new TLInt((int)compressedSize);
                            SendCompressedVideoInternal(message, compressedFile);
                        }
                    }
                },
                                  error =>
                {
                    message.Status = MessageStatus.Failed;
                });
            }
            else
            {
                SendCompressedVideoInternal(message, file.Source);
            }
        }
Пример #15
0
        private string UpdateSizeLabel(TLMessage message)
        {
            var mediaDocument = message.Media as TLMessageMediaDocument;

            if (mediaDocument == null)
            {
                return("0 B");
            }

            var document = mediaDocument.Document as TLDocument;

            if (document == null)
            {
                return("0 B");
            }

            var bytesCount = document.Size;

            if (bytesCount < 1024)
            {
                return(string.Format("{0} B", bytesCount));
            }

            if (bytesCount < 1024 * 1024)
            {
                return(string.Format("{0} KB", ((double)bytesCount / 1024).ToString("0.0", CultureInfo.InvariantCulture)));
            }

            if (bytesCount < 1024 * 1024 * 1024)
            {
                return(string.Format("{0} MB", ((double)bytesCount / 1024 / 1024).ToString("0.0", CultureInfo.InvariantCulture)));
            }

            return(string.Format("{0} GB", ((double)bytesCount / 1024 / 1024 / 1024).ToString("0.0", CultureInfo.InvariantCulture)));
        }
Пример #16
0
        public static TLKeyboardButtonUrl GetButtonWithUrl(this TLMessage message, string searchText)
        {
            var markup = message.ReplyMarkup as TLReplyInlineMarkup;

            if (markup == null)
            {
                return(null);
            }

            var keyboardLinesButtons = markup.Rows.Select(row => row.Buttons); //берем все кнопки из строк

            //преобразовываем список списков в одномерный список
            var absButtons = new List <TLAbsKeyboardButton>();

            foreach (var buttons in keyboardLinesButtons)
            {
                absButtons.AddRange(buttons);
            }

            //ищем кнопку для перехода по ссылке
            var button = absButtons
                         .OfType <TLKeyboardButtonUrl>()
                         .FirstOrDefault(x => x.Text.ToLower().Contains(searchText.ToLower()));

            return(button);
        }
Пример #17
0
        //public virtual async Task<string> GetLastMessageFromUser(string sUserName)
        //{
        //    string sResult;
        //    var client = new TLSharp.Core.TelegramClient(apiId, apiHash);
        //    await client.ConnectAsync();
        //    var normalizedUser = (sUserName.StartsWith("@") ?
        //        sUserName.Substring(1, sUserName.Length - 1) :
        //        sUserName).ToLower();
        //    var dialogs = (TLDialogs)await client.GetUserDialogsAsync();
        //    var user = dialogs.Users
        //        .Where(x => x.GetType() == typeof(TLUser))
        //        .OfType<TLUser>()
        //        .FirstOrDefault(x => x.Username != null && x.Username.ToLower() == normalizedUser);

        //    TLAbsMessages tlAbsMessages = await client.GetHistoryAsync(new TLInputPeerUser() {
        //        UserId = user.Id,
        //        AccessHash = user.AccessHash.Value
        //    }, 0, -1, 100);
        //    TLMessages tlMessages = (TLMessages)tlAbsMessages;
        //    TLMessage lastmessage = (TLMessage)tlMessages.Messages[0];
        //    sResult = lastmessage.FromId.ToString() + ":" + lastmessage.Message;
        //    return sResult;
        //}
        public virtual async Task <TLMessage> GetLastMessageFromUser(string sUserName)
        {
            TLMessage lastmessage = null;
            var       client      = new TLSharp.Core.TelegramClient(apiId, apiHash);
            await client.ConnectAsync();

            var normalizedUser = (sUserName.StartsWith("@") ?
                                  sUserName.Substring(1, sUserName.Length - 1) :
                                  sUserName).ToLower();
            var dialogs = (TLDialogs)await client.GetUserDialogsAsync();

            var user = dialogs.Users
                       .Where(x => x.GetType() == typeof(TLUser))
                       .OfType <TLUser>()
                       .FirstOrDefault(x => x.Username != null && x.Username.ToLower() == normalizedUser);

            TLAbsMessages tlAbsMessages = await client.GetHistoryAsync(new TLInputPeerUser()
            {
                UserId     = user.Id,
                AccessHash = user.AccessHash.Value
            }, 0, -1, 100);

            if (tlAbsMessages.GetType() == typeof(TLMessagesSlice))
            {
                var castMessages = (TLMessagesSlice)tlAbsMessages;
                lastmessage = (TLMessage)castMessages.Messages[0];
            }
            else if (tlAbsMessages.GetType() == typeof(TLMessages))
            {
                TLMessages tlMessages = (TLMessages)tlAbsMessages;
                lastmessage = (TLMessage)tlMessages.Messages[0];
            }
            return(lastmessage);
        }
Пример #18
0
        private bool SetRoundVideoTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            FindName(nameof(ThumbRoot));
            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Visible;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "Video message";
            MessageLabel.Text = string.Empty;

            var documentMedia = message.Media as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                if (!string.IsNullOrWhiteSpace(documentMedia.Caption))
                {
                    ServiceLabel.Text += ", ";
                    MessageLabel.Text += documentMedia.Caption.Replace("\r\n", "\n").Replace('\n', ' ');
                }

                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = new CornerRadius(18);
                ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(documentMedia.Document, true);
            }

            return(true);
        }
Пример #19
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.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");
        }
        public async Task Execute()
        {
            try
            {
                while (!Params.TokenSource.Token.IsCancellationRequested)
                {
                    await CheckRunningTime();

                    _adMessage = await GetAdMessage();

                    _adMessageNotFoundCount = 0;
                    string link = GetAdLink();
                    await CheckDuplicatedAdLink(link);
                    await ExecuteWatchAdAndWaitForEndOfAdCommand();
                }
            }
            catch (AdMessageNotFoundException)
            {
                _adMessageNotFoundCount++;
                if (_adMessageNotFoundCount > 10)
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + "Заданий нет, ждем 10 минут");
                    await Task.Delay(TimeSpan.FromMinutes(10));

                    _adMessageNotFoundCount = 0;
                }
                await ExecuteVisitCommand();

                await Task.Delay((_adMessageNotFoundCount + 1) * 1000);
            }
            catch (BrowserTimeoutException)
            {
                await ExecuteSkipAdCommand();

                await Task.Delay(1000);
            }
            catch (CapchaException)
            {
                await ExecuteSkipAdCommand();

                await Task.Delay(1500);
            }
            catch (ClickBotNotStartedException)
            {
                await ExecuteStartCommand();

                await Task.Delay(1000);
            }
            catch (TLSharp.Core.Network.Exceptions.FloodException ex)
            {
                Console.WriteLine(ex.Message);
                await Task.Delay(ex.TimeToWait.Add(TimeSpan.FromMinutes(3)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType());
                Console.WriteLine("Непредвиденная ошибка: " + ex.Message);
            }
        }
Пример #21
0
        public TLDocument GetFileData(TLMessagesSlice messages)
        {
            TLMessage message = (TLMessage)messages.Messages.AsEnumerable().ElementAt(0);
            TLMessageMediaDocument mediadata = (TLMessageMediaDocument)message.Media;
            TLDocument             filedata  = (TLDocument)mediadata.Document;

            return(filedata);
        }
Пример #22
0
        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();
            //}
        }
Пример #23
0
        static public int GetMessageId(TLMessagesSlice dialogs)
        {
            var all_messages = dialogs.Messages.AsEnumerable().ToList();

            lastmessage = all_messages.Where(c => c.GetType() == typeof(TLMessage)).Cast <TLMessage>().ElementAt(0);
            int msg_id = lastmessage.Id;

            return(msg_id);
        }
Пример #24
0
        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);
        }
Пример #25
0
        private IUploadManager ChooseUploadManager(TLDocument document)
        {
            if (TLMessage.IsVideo(document))
            {
                return(UnigramContainer.Current.ResolveType <IUploadVideoManager>());
            }

            return(UnigramContainer.Current.ResolveType <IUploadDocumentManager>());
        }
Пример #26
0
        protected static bool IsInlineMedia(TLMessageMediaBase media)
        {
            if (media == null)
            {
                return(false);
            }

            if (media.TypeId == TLType.MessageMediaContact)
            {
                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);
        }
Пример #27
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);
        }
Пример #28
0
        void SelfDestructIn(TLMessage item, int delay)
        {
            _selfDestructItems.Add(item);

            if (!_selfDestructTimer.IsActive || _selfDestructTimer.RemainingTime.TotalSeconds > delay)
            {
                //_selfDestructTimer.CallOnce(delay);
                _selfDestructTimer.CallOnce(1);
            }
        }
 public MessageToDelete(TLMessage r3, long chatId, DateTime timeToDelete, long botId, ChatType?chatType,
                        long?accessHash)
 {
     messageId         = r3.Id;
     this.chatId       = chatId;
     this.timeToDelete = timeToDelete;
     this.botId        = botId;
     this.chatType     = chatType;
     this.accessHash   = accessHash;
 }
Пример #30
0
        public InstantGalleryViewModel(TLMessage message, TLWebPage webPage)
            : base(null, null, null)
        {
            _shouldGroup = true;

            Items        = new MvxObservableCollection <GalleryItem>(GetWebPagePhotos(message, webPage));
            FirstItem    = Items.FirstOrDefault();
            SelectedItem = Items.FirstOrDefault();
            TotalItems   = Items.Count;
        }