public static string Convert(TLMessageBase value, bool showContent)
        {
            var emptyMessage = value as TLMessageEmpty;

            if (emptyMessage != null)
            {
                return(AppResources.EmptyMessage);
            }

            //var forwardedMessage = value as TLMessageForwarded;
            //if (forwardedMessage != null)
            //{
            //    return AppResources.ForwardedMessage;
            //}

            var serviceMessage = value as TLMessageService;

            if (serviceMessage != null)
            {
                return(ServiceMessageToTextConverter.Convert(serviceMessage));

                //return AppResources.ServiceMessage;
            }

            var message = value as TLMessage;

            if (message != null)
            {
                var canSendString = string.Empty;

                if (message.Status == MessageStatus.Failed)
                {
                    canSendString = string.Format("{0}: ", AppResources.SendingFailed);
                }

                var message73 = message as TLMessage73;
                if (message73 != null && message73.GroupedId != null)
                {
                    return(canSendString + AppResources.Album);
                }

                if (message.Media != null)
                {
                    var mediaInvoice = message.Media as TLMessageMediaInvoice;
                    if (mediaInvoice != null)
                    {
                        var description = mediaInvoice.Description;
                        if (!TLString.IsNullOrEmpty(description))
                        {
                            return(canSendString + description);
                        }

                        return(canSendString + AppResources.Invoice);
                    }

                    var mediaGame = message.Media as TLMessageMediaGame;
                    if (mediaGame != null)
                    {
                        return(canSendString + "🎮 " + mediaGame.Game.Title);
                    }

                    if (message.Media is TLMessageMediaDocument)
                    {
                        var captionString = string.Empty;
                        var str           = message.Message != null?message.Message.ToString().Replace("\r\n", "\n").Replace('\n', ' ') : string.Empty;

                        if (!string.IsNullOrEmpty(str))
                        {
                            captionString = ", " + str.Substring(0, Math.Min(str.Length, 40));
                        }

                        if (message.IsVoice())
                        {
                            return(canSendString + AppResources.VoiceMessage + captionString);
                        }

                        if (message.IsRoundVideo())
                        {
                            return(canSendString + AppResources.VideoMessage + captionString);
                        }

                        if (message.IsVideo())
                        {
                            return(canSendString + AppResources.Video + captionString);
                        }

                        if (message.IsGif())
                        {
                            return(canSendString + AppResources.Gif + captionString);
                        }

                        if (message.IsSticker())
                        {
                            return(canSendString + AppResources.Sticker + captionString);
                        }

                        var mediaDocument = message.Media as TLMessageMediaDocument45;
                        if (mediaDocument != null)
                        {
                            var document = mediaDocument.Document as TLDocument22;
                            if (document != null && !string.IsNullOrEmpty(document.DocumentName))
                            {
                                return(canSendString + document.DocumentName + captionString);
                            }
                        }

                        return(canSendString + AppResources.Document + captionString);
                    }

                    if (message.Media is TLMessageMediaContact)
                    {
                        return(canSendString + AppResources.Contact);
                    }

                    if (message.Media is TLMessageMediaGeoLive)
                    {
                        return(canSendString + AppResources.LiveLocation);
                    }

                    if (message.Media is TLMessageMediaGeo)
                    {
                        return(canSendString + AppResources.GeoPoint);
                    }

                    if (message.Media is TLMessageMediaPhoto)
                    {
                        if (!TLString.IsNullOrEmpty(message.Message))
                        {
                            var str = message.Message.ToString().Replace("\r\n", "\n").Replace('\n', ' ');
                            if (!string.IsNullOrEmpty(str))
                            {
                                return(canSendString + AppResources.Photo + ", " + str.Substring(0, Math.Min(str.Length, 40)));
                            }
                        }

                        return(canSendString + AppResources.Photo);
                    }

                    if (message.Media is TLMessageMediaVideo)
                    {
                        return(canSendString + AppResources.Video);
                    }

                    if (message.Media is TLMessageMediaAudio)
                    {
                        return(canSendString + AppResources.Audio);
                    }

                    if (message.Media is TLMessageMediaUnsupportedBase)
                    {
                        return(canSendString + AppResources.UnsupportedMedia);
                    }
                }

                if (message.Message != null)
                {
                    if (showContent)
                    {
                        var str = message.Message != null?message.Message.ToString() : string.Empty;

                        return(canSendString + str.Substring(0, Math.Min(str.Length, 40)).Replace("\r\n", "\n").Replace('\n', ' '));
                    }

                    return(canSendString + AppResources.Message);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static string Convert(TLMessageBase value, bool showContent)
        {
            var emptyMessage = value as TLMessageEmpty;

            if (emptyMessage != null)
            {
                return(AppResources.EmptyMessage);
            }

            //var forwardedMessage = value as TLMessageForwarded;
            //if (forwardedMessage != null)
            //{
            //    return AppResources.ForwardedMessage;
            //}

            var serviceMessage = value as TLMessageService;

            if (serviceMessage != null)
            {
                return(ServiceMessageToTextConverter.Convert(serviceMessage));

                //return AppResources.ServiceMessage;
            }

            var message = value as TLMessage;

            if (message != null)
            {
                var canSendString = string.Empty;

                if (message.Status == MessageStatus.Failed)
                {
                    canSendString = string.Format("{0}: ", AppResources.SendingFailed);
                }

                if (message.Media != null)
                {
                    if (message.Media is TLMessageMediaDocument)
                    {
                        if (message.IsSticker())
                        {
                            return(canSendString + AppResources.Sticker);
                        }

                        return(canSendString + AppResources.Document);
                    }

                    if (message.Media is TLMessageMediaContact)
                    {
                        return(canSendString + AppResources.Contact);
                    }

                    if (message.Media is TLMessageMediaGeo)
                    {
                        return(canSendString + AppResources.GeoPoint);
                    }

                    if (message.Media is TLMessageMediaPhoto)
                    {
                        return(canSendString + AppResources.Photo);
                    }

                    if (message.Media is TLMessageMediaVideo)
                    {
                        return(canSendString + AppResources.Video);
                    }

                    if (message.Media is TLMessageMediaAudio)
                    {
                        return(canSendString + AppResources.Audio);
                    }

                    if (message.Media is TLMessageMediaUnsupported)
                    {
                        return(canSendString + AppResources.UnsupportedMedia);
                    }
                }

                if (message.Message != null)
                {
                    if (showContent)
                    {
                        return(canSendString + message.Message);
                    }

                    return(canSendString + AppResources.Message);
                }
            }

            return(null);
        }