Exemplo n.º 1
0
        public void StartEditMessage(string text, TLMessage message)
        {
            if (text == null)
            {
                return;
            }
            if (message == null)
            {
                return;
            }

            _editedMessage = message;

            var config    = CacheService.GetConfig();
            var editUntil = (config != null) ? (message.Date + config.EditTimeLimit + 300) : 0;

            if (message.FromId != null && message.ToId is TLPeerUser && message.FromId.Value == message.ToId.Id)
            {
                editUntil = 0;
            }

            Reply = new TLMessagesContainter
            {
                EditMessage = _editedMessage,
                EditUntil   = editUntil,
                // TODO: setup original content
                PreviousMessage = new TLMessage
                {
                    ToId   = message.ToId,
                    FromId = message.FromId,
                    IsOut  = message.IsOut
                }
            };

            SetText(text, message.Entities, true);

            //if (this._editMessageTimer == null)
            //{
            //    this._editMessageTimer = new DispatcherTimer();
            //    this._editMessageTimer.add_Tick(new EventHandler(this.OnEditMessageTimerTick));
            //    this._editMessageTimer.set_Interval(System.TimeSpan.FromSeconds(1.0));
            //}
            //this._editMessageTimer.Start();
            //this.IsEditingEnabled = true;
            //this.Text = text.ToString();

            CurrentInlineBot = null;

            //this.ClearStickerHints();
            //this.ClearInlineBotResults();
            //this.ClearUsernameHints();
            //this.ClearHashtagHints();
            //this.ClearCommandHints();
        }
        public void StartEditMessage(TLString text, TLMessage message)
        {
            if (text == null)
            {
                return;
            }
            if (message == null)
            {
                return;
            }

            _editedMessage = message;
            var config    = CacheService.GetConfig() as TLConfig48;
            var editUntil = config != null ? message.DateIndex + config.EditTimeLimit.Value + 5 * 60 : 0;

            if (message.FromId != null &&
                message.ToId is TLPeerUser &&
                message.FromId.Value == message.ToId.Id.Value)
            {
                editUntil = 0;
            }

            Reply = new TLMessagesContainter {
                EditMessage = _editedMessage as TLMessage25, EditUntil = editUntil
            };

            if (_editMessageTimer == null)
            {
                _editMessageTimer          = new DispatcherTimer();
                _editMessageTimer.Tick    += OnEditMessageTimerTick;
                _editMessageTimer.Interval = TimeSpan.FromSeconds(1.0);
            }

            _editMessageTimer.Start();

            IsEditingEnabled = true;
            Text             = text.ToString();

            CurrentInlineBot = null;
            ClearStickerHints();
            ClearInlineBotResults();
            ClearUsernameHints();
            ClearHashtagHints();
            ClearCommandHints();
        }
        public void Handle(TLUpdateWebPage updateWebPage)
        {
            Execute.BeginOnUIThread(() =>
            {
                var webPageBase = updateWebPage.WebPage;

                foreach (var webPageKeyValue in _webPagesCache)
                {
                    var mediaBase           = webPageKeyValue.Value;
                    var webPageMessageMedia = mediaBase as TLMessageMediaWebPage;
                    if (webPageMessageMedia != null)
                    {
                        var webPage = webPageMessageMedia.WebPage;
                        if (webPage != null)
                        {
                            if (webPage.Id.Value == webPageBase.Id.Value)
                            {
                                webPageMessageMedia.WebPage = webPageBase;

                                if (string.Equals(Text, webPageKeyValue.Key))
                                {
                                    if (webPageBase is TLWebPage || webPageBase is TLWebPagePending)
                                    {
                                        SaveReply();

                                        Reply = new TLMessagesContainter {
                                            WebPageMedia = webPageMessageMedia
                                        };
                                    }
                                    else
                                    {
                                        RestoreReply();
                                    }
                                }

                                break;
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 4
0
        private string GetMessagesContainerTemplate(TLMessagesContainter container, object parameter)
        {
            if (container.WebPageMedia != null)
            {
                var webpageMedia = container.WebPageMedia as TLMessageMediaWebPage;
                if (webpageMedia != null)
                {
                    return(GlobeGlyph);
                }
            }

            if (container.FwdMessages != null)
            {
                return(ForwardGlyph);
            }

            if (container.EditMessage != null)
            {
                return(EditGlyph);
            }

            return(ReplyGlyph);
        }
Exemplo n.º 5
0
        private bool GetMessagesContainerTemplate(TLMessagesContainter container)
        {
            //if (container.WebPageMedia != null)
            //{
            //    var webpageMedia = container.WebPageMedia as TLMessageMediaWebPage;
            //    if (webpageMedia != null)
            //    {
            //        var pendingWebpage = webpageMedia.Webpage as TLWebPagePending;
            //        if (pendingWebpage != null)
            //        {
            //            return WebPagePendingTemplate;
            //        }

            //        var webpage = webpageMedia.Webpage as TLWebPage;
            //        if (webpage != null)
            //        {
            //            return WebPageTemplate;
            //        }

            //        var emptyWebpage = webpageMedia.Webpage as TLWebPageEmpty;
            //        if (emptyWebpage != null)
            //        {
            //            return WebPageEmptyTemplate;
            //        }
            //    }
            //}

            if (container.FwdMessages != null)
            {
                if (container.FwdMessages.Count == 1)
                {
                    var forwardMessage = container.FwdMessages[0];
                    if (forwardMessage != null)
                    {
                        if (!string.IsNullOrEmpty(forwardMessage.Message) && (forwardMessage.Media == null || forwardMessage.Media is TLMessageMediaEmpty || forwardMessage.Media is TLMessageMediaWebPage))
                        {
                            return(SetTextTemplate(forwardMessage, "forward"));
                        }

                        var media = container.FwdMessages[0].Media;
                        if (media != null)
                        {
                            switch (media.TypeId)
                            {
                            case TLType.MessageMediaPhoto:
                                return(SetPhotoTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaGeo:
                                return(SetGeoPointTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaVenue:
                                return(SetVenueTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaContact:
                                return(SetContactTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaGame:
                                return(SetGameTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaEmpty:
                                return(SetUnsupportedTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaDocument:
                                if (forwardMessage.IsSticker())
                                {
                                    return(SetStickerTemplate(forwardMessage, "forward"));
                                }
                                else if (forwardMessage.IsGif())
                                {
                                    return(SetGifTemplate(forwardMessage, "forward"));
                                }
                                else if (forwardMessage.IsVoice())
                                {
                                    return(SetVoiceMessageTemplate(forwardMessage, "forward"));
                                }
                                else if (forwardMessage.IsVideo())
                                {
                                    return(SetVideoTemplate(forwardMessage, "forward"));
                                }
                                else if (forwardMessage.IsRoundVideo())
                                {
                                    return(SetRoundVideoTemplate(forwardMessage, "forward"));
                                }
                                else if (forwardMessage.IsAudio())
                                {
                                    return(SetAudioTemplate(forwardMessage, "forward"));
                                }

                                return(SetDocumentTemplate(forwardMessage, "forward"));

                            case TLType.MessageMediaUnsupported:
                                return(SetUnsupportedMediaTemplate(forwardMessage, "forward"));
                            }
                        }
                    }
                }

                return(SetForwardedMessagesTemplate(container.FwdMessages));
            }

            if (container.EditMessage != null)
            {
                var editMessage = container.EditMessage;
                if (editMessage != null)
                {
                    if (!string.IsNullOrEmpty(editMessage.Message) && (editMessage.Media == null || editMessage.Media is TLMessageMediaEmpty || editMessage.Media is TLMessageMediaWebPage))
                    {
                        return(SetTextTemplate(editMessage, "Edit message"));
                    }

                    var media = editMessage.Media;
                    if (media != null)
                    {
                        switch (media.TypeId)
                        {
                        case TLType.MessageMediaPhoto:
                            return(SetPhotoTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaGeo:
                            return(SetGeoPointTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaVenue:
                            return(SetVenueTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaContact:
                            return(SetContactTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaGame:
                            return(SetGameTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaEmpty:
                            return(SetUnsupportedTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaDocument:
                            if (editMessage.IsSticker())
                            {
                                return(SetStickerTemplate(editMessage, "Edit message"));
                            }
                            else if (editMessage.IsGif())
                            {
                                return(SetGifTemplate(editMessage, "Edit message"));
                            }
                            else if (editMessage.IsVoice())
                            {
                                return(SetVoiceMessageTemplate(editMessage, "Edit message"));
                            }
                            else if (editMessage.IsVideo())
                            {
                                return(SetVideoTemplate(editMessage, "Edit message"));
                            }
                            else if (editMessage.IsRoundVideo())
                            {
                                return(SetRoundVideoTemplate(editMessage, "Edit message"));
                            }
                            else if (editMessage.IsAudio())
                            {
                                return(SetAudioTemplate(editMessage, "Edit message"));
                            }

                            return(SetDocumentTemplate(editMessage, "Edit message"));

                        case TLType.MessageMediaUnsupported:
                            return(SetUnsupportedMediaTemplate(editMessage, "Edit message"));
                        }
                    }
                }

                return(SetUnsupportedTemplate(editMessage, "Edit message"));
            }

            return(SetUnsupportedTemplate(null, "Edit message"));
        }
Exemplo n.º 6
0
        private DataTemplate GetMessagesContainerTemplate(TLMessagesContainter container)
        {
            if (container.WebPageMedia != null)
            {
                var webPageMedia = container.WebPageMedia as TLMessageMediaWebPage;
                if (webPageMedia != null)
                {
                    var webPagePending = webPageMedia.WebPage as TLWebPagePending;
                    if (webPagePending != null)
                    {
                        return(WebPagePendingTemplate);
                    }

                    var webPage = webPageMedia.WebPage as TLWebPage;
                    if (webPage != null)
                    {
                        return(WebPageTemplate);
                    }

                    var webPageEmpty = webPageMedia.WebPage as TLWebPageEmpty;
                    if (webPageEmpty != null)
                    {
                        return(WebPageEmptyTemplate);
                    }
                }
            }

            if (container.FwdMessages != null)
            {
                if (container.FwdMessages.Count == 1)
                {
                    var message = container.FwdMessages[0];
                    if (message != null)
                    {
                        var text = container.FwdMessages[0].Message;

                        if (!string.IsNullOrEmpty(text.ToString()))
                        {
                            return(ForwardTextTemplate);
                        }

                        var media = container.FwdMessages[0].Media;
                        if (media != null)
                        {
                            var mediaPhoto = media as TLMessageMediaPhoto;
                            if (mediaPhoto != null)
                            {
                                return(ForwardPhotoTemplate);
                            }

                            var mediaAudio = media as TLMessageMediaAudio;
                            if (mediaAudio != null)
                            {
                                return(ForwardAudioTemplate);
                            }

                            var mediaDocument = media as TLMessageMediaDocument;
                            if (mediaDocument != null)
                            {
                                if (message.IsSticker())
                                {
                                    return(ForwardStickerTemplate);
                                }

                                return(ForwardDocumentTemplate);
                            }

                            var mediaVideo = media as TLMessageMediaVideo;
                            if (mediaVideo != null)
                            {
                                return(ForwardVideoTemplate);
                            }

                            var mediaGeo = media as TLMessageMediaGeo;
                            if (mediaGeo != null)
                            {
                                return(ForwardGeoPointTemplate);
                            }

                            var mediaContact = media as TLMessageMediaContact;
                            if (mediaContact != null)
                            {
                                return(ForwardContactTemplate);
                            }

                            var mediaEmpty = media as TLMessageMediaEmpty;
                            if (mediaEmpty != null)
                            {
                                return(ForwardEmptyTemplate);
                            }
                        }
                    }
                }

                return(ForwardedMessagesTemplate);
            }

            return(ReplyUnsupportedTemplate);
        }