public static string Convert(TLDecryptedMessageBase value, bool showContent)
        {
            var serviceMessage = value as TLDecryptedMessageService;

            if (serviceMessage != null)
            {
                if (serviceMessage.Action is TLDecryptedMessageActionEmpty)
                {
                    return(AppResources.SecretChatCreated);
                }

                return(DecryptedServiceMessageToTextConverter.Convert(serviceMessage));
            }

            var message = value as TLDecryptedMessage;

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

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

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

                if (message.Media != null)
                {
                    var messageMediaWebPage = message.Media as TLDecryptedMessageMediaWebPage;
                    if (messageMediaWebPage != null)
                    {
                        return(canSendString + messageMediaWebPage.Url);
                    }

                    if (message.Media is TLDecryptedMessageMediaDocument)
                    {
                        if (message.IsVoice())
                        {
                            return(canSendString + AppResources.VoiceMessage);
                        }

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

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

                        return(canSendString + AppResources.Document);
                    }

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

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

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

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

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

                    if (message.Media is TLDecryptedMessageMediaExternalDocument)
                    {
                        if (message.IsSticker())
                        {
                            return(canSendString + AppResources.Sticker);
                        }

                        return(canSendString + AppResources.Document);
                    }
                }

                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);
        }
示例#2
0
        public static string Convert(TLDecryptedMessageBase value, bool showContent)
        {
            var serviceMessage = value as TLDecryptedMessageService;

            if (serviceMessage != null)
            {
                if (serviceMessage.Action is TLDecryptedMessageActionEmpty)
                {
                    return(AppResources.SecretChatCreated);
                }

                return(DecryptedServiceMessageToTextConverter.Convert(serviceMessage));
            }

            var message = value as TLDecryptedMessage;

            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 TLDecryptedMessageMediaDocument)
                    {
                        return(canSendString + AppResources.Document);
                    }

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

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

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

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

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

                    if (message.Media is TLDecryptedMessageMediaExternalDocument)
                    {
                        if (message.IsSticker())
                        {
                            return(canSendString + AppResources.Sticker);
                        }

                        return(canSendString + AppResources.Document);
                    }
                }

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

                    return(canSendString + AppResources.Message);
                }
            }

            return(null);
        }