private static List <SharedContact>?CreateSharedContacts(DataMessage content)
        {
            if (content.Contact.Count <= 0)
            {
                return(null);
            }

            var results = new List <SharedContact>();

            foreach (var contact in content.Contact)
            {
                Name name = new Name(contact.Name.DisplayName,
                                     contact.Name.GivenName,
                                     contact.Name.FamilyName,
                                     contact.Name.Prefix,
                                     contact.Name.Suffix,
                                     contact.Name.MiddleName);

                List <PostalAddress> postalAddresses = new List <PostalAddress>();
                if (contact.Address.Count > 0)
                {
                    foreach (var address in contact.Address)
                    {
                        PostalAddress.PostalAddressType postalAddressType = PostalAddress.PostalAddressType.HOME;

                        switch (address.Type)
                        {
                        case DataMessage.Types.Contact.Types.PostalAddress.Types.Type.Work: postalAddressType = PostalAddress.PostalAddressType.WORK; break;

                        case DataMessage.Types.Contact.Types.PostalAddress.Types.Type.Home: postalAddressType = PostalAddress.PostalAddressType.HOME; break;

                        case DataMessage.Types.Contact.Types.PostalAddress.Types.Type.Custom: postalAddressType = PostalAddress.PostalAddressType.CUSTOM; break;
                        }

                        postalAddresses.Add(new PostalAddress(postalAddressType,
                                                              address.Label,
                                                              address.Street,
                                                              address.Pobox,
                                                              address.Neighborhood,
                                                              address.City,
                                                              address.Region,
                                                              address.Postcode,
                                                              address.Country));
                    }
                }

                List <Phone> phones = new List <Phone>();
                if (contact.Number.Count > 0)
                {
                    foreach (var phone in contact.Number)
                    {
                        Phone.PhoneType phoneType = Phone.PhoneType.HOME;

                        switch (phone.Type)
                        {
                        case DataMessage.Types.Contact.Types.Phone.Types.Type.Home: phoneType = Phone.PhoneType.HOME; break;

                        case DataMessage.Types.Contact.Types.Phone.Types.Type.Work: phoneType = Phone.PhoneType.WORK; break;

                        case DataMessage.Types.Contact.Types.Phone.Types.Type.Mobile: phoneType = Phone.PhoneType.MOBILE; break;

                        case DataMessage.Types.Contact.Types.Phone.Types.Type.Custom: phoneType = Phone.PhoneType.CUSTOM; break;
                        }

                        phones.Add(new Phone(phone.Value, phoneType, phone.Label));
                    }
                }

                List <Email> emails = new List <Email>();
                if (contact.Email.Count > 0)
                {
                    foreach (var email in contact.Email)
                    {
                        Email.EmailType emailType = Email.EmailType.HOME;

                        switch (email.Type)
                        {
                        case DataMessage.Types.Contact.Types.Email.Types.Type.Home: emailType = Email.EmailType.HOME; break;

                        case DataMessage.Types.Contact.Types.Email.Types.Type.Work: emailType = Email.EmailType.WORK; break;

                        case DataMessage.Types.Contact.Types.Email.Types.Type.Mobile: emailType = Email.EmailType.MOBILE; break;

                        case DataMessage.Types.Contact.Types.Email.Types.Type.Custom: emailType = Email.EmailType.CUSTOM; break;
                        }

                        emails.Add(new Email(email.Value, emailType, email.Label));
                    }
                }

                Avatar?avatar = null;
                if (contact.Avatar != null)
                {
                    avatar = new Avatar(CreateAttachmentPointer(contact.Avatar.Avatar_), contact.Avatar.IsProfile);
                }

                string?organization = null;
                if (contact.HasOrganization)
                {
                    organization = contact.Organization;
                }

                SharedContact sharedContact = new SharedContact(name, avatar,
                                                                phones.Count > 0 ? phones : null,
                                                                emails.Count > 0 ? emails : null,
                                                                postalAddresses.Count > 0 ? postalAddresses : null,
                                                                organization);
                results.Add(sharedContact);
            }

            return(results);
        }
        public bool ChooseDialog(TLObject with, bool animateTitle)
        {
            if (with == null)
            {
                return(false);
            }

            if (ForwardedMessages != null)
            {
                var channel = with as TLChannel;
                if (channel != null && channel.IsBroadcast && !channel.Creator && !channel.IsEditor)
                {
                    MessageBox.Show(AppResources.PostToChannelError, AppResources.Error, MessageBoxButton.OK);

                    return(false);
                }
            }

            var result = MessageBoxResult.OK;

            if (LogFileName != null)
            {
                result = MessageBox.Show(AppResources.ForwardMessagesToThisChat, AppResources.Confirm, MessageBoxButton.OKCancel);
            }

            if (_webLink != null || _storageItems != null || _gameString != null)
            {
                var fullName = string.Empty;
                var chat     = with as TLChatBase;
                var user     = with as TLUserBase;
                if (chat != null)
                {
                    fullName = chat.FullName2;
                }
                if (user != null)
                {
                    fullName = user.FullName2;
                }

                if (_gameString != null)
                {
                    result = MessageBox.Show(string.Format(AppResources.ShareGameWith, fullName), AppResources.Confirm, MessageBoxButton.OKCancel);
                }
                else
                {
                    result = MessageBox.Show(string.Format(AppResources.ShareWith, fullName), AppResources.Confirm, MessageBoxButton.OKCancel);
                }
            }

            if (_bot != null)
            {
                var chat    = with as TLChat;
                var channel = with as TLChannel;
                if (chat == null && (channel == null || !channel.IsMegaGroup))
                {
                    return(false);
                }

                var chatName = chat != null ? chat.FullName : channel.FullName;
                result = MessageBox.Show(string.Format(AppResources.AddBotToTheGroup, chatName), AppResources.Confirm, MessageBoxButton.OKCancel);
            }

            if (result != MessageBoxResult.OK)
            {
                return(false);
            }

            if (_gameString != null)
            {
                var inputPeer = with as IInputPeer;
                if (inputPeer == null)
                {
                    return(false);
                }

                var mediaGame = new TLMessageMediaGame
                {
                    Game = new TLGame
                    {
                        Flags       = new TLInt(0),
                        Id          = new TLLong(0),
                        AccessHash  = new TLLong(0),
                        ShortName   = new TLString(_gameString),
                        Title       = new TLString(_gameString),
                        Description = TLString.Empty,
                        Photo       = new TLPhotoEmpty {
                            Id = new TLLong(0)
                        }
                    }
                };
                var message = GetMessage(with, inputPeer.ToInputPeer(), TLString.Empty, mediaGame);
                mediaGame.SourceMessage = message;
                IoC.Get <ICacheService>().SyncSendingMessage(message, null, m =>
                {
                    //IsWorking = true;
                    IoC.Get <IMTProtoService>().SendMediaAsync(inputPeer.ToInputPeer(), new TLInputMediaGame {
                        Id = new TLInputGameShortName {
                            ShortName = new TLString(_gameString), BotId = SharedContact.ToInputUser()
                        }
                    }, message,
                                                               updatesBase => Execute.BeginOnUIThread(() =>
                    {
                        var updates = updatesBase as TLUpdates;
                        if (updates != null)
                        {
                            var newChannelMessageUpdate = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage;
                            if (newChannelMessageUpdate != null)
                            {
                                var messageCommon = newChannelMessageUpdate.Message as TLMessageCommon;
                                if (messageCommon != null)
                                {
                                    var dialog = IoC.Get <ICacheService>().GetDialog(messageCommon);
                                    if (dialog != null)
                                    {
                                        IoC.Get <ITelegramEventAggregator>().Publish(new TopMessageUpdatedEventArgs(dialog, messageCommon));
                                    }
                                }
                            }

                            var newMessageUpdate = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                            if (newMessageUpdate != null)
                            {
                                var messageCommon = newMessageUpdate.Message as TLMessageCommon;
                                if (messageCommon != null)
                                {
                                    var dialog = IoC.Get <ICacheService>().GetDialog(messageCommon);
                                    if (dialog != null)
                                    {
                                        IoC.Get <ITelegramEventAggregator>().Publish(new TopMessageUpdatedEventArgs(dialog, messageCommon));
                                    }
                                }
                            }
                        }

                        //IsWorking = false;
                        IoC.Get <INavigationService>().RemoveBackEntry();
                        IoC.Get <INavigationService>().GoBack();
                    }),
                                                               error => Execute.BeginOnUIThread(() =>
                    {
                        //IsWorking = false;
                        Telegram.Api.Helpers.Execute.ShowDebugMessage("messages.sendMedia error=" + error);
                    }));
                });

                return(false);
            }

            StateService.With              = with;
            StateService.ForwardMessages   = ForwardedMessages;
            StateService.RemoveBackEntries = true;
            StateService.LogFileName       = LogFileName;
            StateService.SharedContact     = SharedContact;
            StateService.AccessToken       = _accessToken;
            StateService.Bot                = _bot;
            StateService.WebLink            = _webLink;
            StateService.StorageItems       = _storageItems;
            StateService.Url                = _url;
            StateService.UrlText            = _text;
            StateService.SwitchInlineButton = _switchInlineButton;
            StateService.AnimateTitle       = animateTitle;
            NavigationService.UriFor <DialogDetailsViewModel>().Navigate();

            return(true);
        }