private void CreateSecretChatAction(TLUserBase user)
        {
            if (user == null)
            {
                return;
            }

            if (_dhConfig == null)
            {
                IsWorking = true;
                NotifyOfPropertyChange(() => IsNotWorking);
                NotifyOfPropertyChange(() => ProgressVisibility);
                _contact = user;

                //try to get dhConfig once again
                if (!_isGettingConfig)
                {
                    GetDHConfig();
                }

                return;
            }

            IsWorking = false;
            NotifyOfPropertyChange(() => IsNotWorking);
            NotifyOfPropertyChange(() => ProgressVisibility);

            AddSecretChatParticipantViewModel.CreateSecretChatCommon(user, _dhConfig, MTProtoService, CacheService, NavigationService, StateService, EventAggregator);
        }
Пример #2
0
        public void CancelSecretChat()
        {
            _contact = null;

            IsWorking = false;
            NotifyOfPropertyChange(() => IsNotWorking);
            NotifyOfPropertyChange(() => ProgressVisibility);
        }
Пример #3
0
        public void OpenInlineBot(TLUserBase bot)
        {
            var view = GetView() as IDialogDetailsView;

            if (view != null)
            {
                view.SetInlineBot(bot);
            }
        }
Пример #4
0
        public static bool SkipDialog(TLUserBase bot, TLDialogBase dialog)
        {
            if (bot != null && (!(dialog is TLDialog) || !(dialog.With is TLChat)))
            {
                return(true);
            }

            return(false);
        }
Пример #5
0
        public CallViewModel(TLUserBase user, IVoIPService voipService)
        {
            _callTimer          = new DispatcherTimer();
            _callTimer.Interval = TimeSpan.FromSeconds(0.33);
            _callTimer.Tick    += CallTimer_Tick;
            _voipService        = voipService;

            User = user;
        }
Пример #6
0
        private static string GetUserFullName(TLUserBase user, bool useActiveLinks)
        {
            if (user == null)
            {
                return(AppResources.User);
            }

            return(GetUserFullNameString(user.FullName, user.Index, useActiveLinks));
        }
Пример #7
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            PhoneNumber = GetObject <TLString>(bytes, ref position);
            User        = GetObject <TLUserBase>(bytes, ref position);

            return(this);
        }
        public static string GetFirstName(TLMessage25 message)
        {
            var message48 = message as TLMessage48;

            if (message48 != null)
            {
                if (message48.FwdHeader != null)
                {
                    var cacheService = InMemoryCacheService.Instance;
                    var channelId    = message48.FwdHeader.ChannelId;
                    if (channelId != null)
                    {
                        var channel = cacheService.GetChat(message48.FwdHeader.ChannelId) as TLChannel;
                        if (channel != null)
                        {
                            return(channel.Title.ToString());
                        }
                    }
                    else
                    {
                        var userId = message48.FwdHeader.FromId;
                        if (userId != null)
                        {
                            var fromUser = cacheService.GetUser(message48.FwdHeader.FromId);
                            if (fromUser != null)
                            {
                                return(TLUserBase.GetFirstName(fromUser.FirstName, fromUser.LastName, fromUser.Phone));
                            }
                        }
                    }
                }
            }

            if (message != null)
            {
                var fromUser = message.FwdFrom as TLUserBase;
                if (fromUser != null)
                {
                    return(TLUserBase.GetFirstName(fromUser.FirstName, fromUser.LastName, fromUser.Phone));
                }

                var fromChat = message.FwdFrom as TLChannel;
                if (fromChat != null)
                {
                    return(fromChat.Title.ToString());
                }

                var fromChatForbidden = message.FwdFrom as TLChannelForbidden;
                if (fromChatForbidden != null)
                {
                    return(fromChatForbidden.Title.ToString());
                }
            }

            return(null);
        }
 public void Handle(TLUserBase user)
 {
     if (With != null &&
         With.Index == user.Index)
     {
         Subtitle = GetSubtitle(user);
         NotifyOfPropertyChange(() => Subtitle);
         NotifyOfPropertyChange(() => With);
     }
 }
 public void Handle(TLUserBase user)
 {
     if (With is TLUserBase &&
         ((TLUserBase)With).Index == user.Index)
     {
         Subtitle = GetSubtitle();
         With     = user;
         NotifyOfPropertyChange(() => With);
     }
 }
        public void AddMention(TLUserBase userBase)
        {
            if (CurrentItem == null)
            {
                return;
            }

            CurrentItem.Mentions = CurrentItem.Mentions ?? new List <TLUserBase>();
            CurrentItem.Mentions.Add(userBase);
        }
Пример #12
0
        public ProfilePhotoViewerViewModel(IStateService stateService, IMTProtoService mtProtoService)
        {
            StateService   = stateService;
            MTProtoService = mtProtoService;

            _currentContact = StateService.CurrentContact;
            _currentChat    = StateService.CurrentChat;

            GroupedItems = new BindableCollection <TLPhotoBase>();
        }
Пример #13
0
        public void OpenMediaContact(TLUserBase user, TLString phone)
        {
            if (user == null)
            {
                return;
            }

            StateService.CurrentContact      = user;
            StateService.CurrentContactPhone = phone;
            NavigationService.UriFor <ContactViewModel>().Navigate();
        }
Пример #14
0
        private static bool IsUserValid(TLUserBase contact, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            return(contact.FirstName.ToString().StartsWith(text, StringComparison.OrdinalIgnoreCase) ||
                   contact.LastName.ToString().StartsWith(text, StringComparison.OrdinalIgnoreCase) ||
                   contact.FullName.StartsWith(text, StringComparison.OrdinalIgnoreCase));
        }
        private void OpenContactInternal(TLUserBase user, TLString phoneNumber)
        {
            if (user == null)
            {
                return;
            }

            StateService.CurrentContact      = user;
            StateService.CurrentContactPhone = phoneNumber;
            NavigationService.UriFor <ContactViewModel>().Navigate();
        }
        public SearchShellViewModel(ICacheService cacheService, IStateService stateService, INavigationService navigationService, SearchDialogsViewModel searchDialogs, SearchMessagesViewModel searchMessages)
        {
            _cacheService = cacheService;

            Recent = new ObservableCollection <TLObject>();

            var forwardMessages = stateService.ForwardMessages;
            var sharedContact   = stateService.SharedContact;
            var logFileName     = stateService.LogFileName;
            var accessToken     = stateService.AccessToken;
            var bot             = stateService.Bot;
            var webLink         = stateService.WebLink;
            var url             = stateService.Url;
            var urlText         = stateService.UrlText;
            var loadedDialogs   = stateService.LoadedDialogs;

            stateService.ForwardMessages = null;
            stateService.LogFileName     = null;
            stateService.SharedContact   = null;
            stateService.AccessToken     = null;
            stateService.Bot             = null;
            stateService.WebLink         = null;
            stateService.Url             = null;
            stateService.UrlText         = null;
            stateService.LoadedDialogs   = null;

            _forwardMessages = forwardMessages;
            _sharedContact   = sharedContact;
            _logFileName     = logFileName;
            _accessToken     = accessToken;
            _bot             = bot;
            _webLink         = webLink;
            _url             = url;
            _urlText         = urlText;

            SearchDialogs                         = searchDialogs;
            SearchDialogs.ChatsOnly               = bot != null;
            SearchDialogs.LoadedDilaogs           = loadedDialogs;
            SearchDialogs.OpenDialogDetailsAction = OpenDialogDetails;

            SearchMessages = searchMessages;
            SearchMessages.ForwardMessages = forwardMessages;

            _stateService      = stateService;
            _navigationService = navigationService;

            if (_stateService.Hashtag != null)
            {
                _hashtag = _stateService.Hashtag;
                _stateService.Hashtag = null;
            }

            SearchHint = GetSearchHint();
        }
Пример #17
0
        private bool SearchInlineBotResults(string text, out string searchText)
        {
            var searchInlineBotResults = false;

            searchText = string.Empty;
            if (CurrentInlineBot != null)
            {
                var user = CurrentInlineBot as IUserName;
                if (user != null)
                {
                    var username = user.UserName.ToString();
                    if (text != null &&
                        text.TrimStart().StartsWith("@" + username, StringComparison.OrdinalIgnoreCase))
                    {
                        searchText = ReplaceFirst(text.TrimStart(), "@" + username, string.Empty);
                        if (searchText.StartsWith(" "))
                        {
                            searchText             = ReplaceFirst(searchText, " ", string.Empty);
                            searchInlineBotResults = true;
                        }

                        if (!searchInlineBotResults)
                        {
                            if (string.Equals(text.TrimStart(), "@" + username, StringComparison.OrdinalIgnoreCase))
                            {
                                CurrentInlineBot = null;
                            }
                            else
                            {
                                SetBotInlinePlaceholder();
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(searchText))
                            {
                                SetBotInlinePlaceholder();
                            }
                            else
                            {
                                BotInlinePlaceholder = string.Empty;
                            }
                        }
                    }
                    else
                    {
                        CurrentInlineBot = null;
                    }
                }
            }

            return(searchInlineBotResults);
        }
        public EncryptionKeyViewModel(IStateService stateService)
        {
            _key = stateService.CurrentKey;
            stateService.CurrentKey = null;

            _contact = stateService.CurrentContact;
            stateService.CurrentContact = null;

            var timer = Stopwatch.StartNew();

            Bitmap            = CreateKeyBitmap();
            VisualizationTime = timer.Elapsed.ToString();
        }
Пример #19
0
        public static void DeleteDialogCommon(TLUserBase userBase, IMTProtoService mtProtoService, System.Action callback, Action <TLRPCError> faultCallback = null)
        {
            if (userBase == null)
            {
                return;
            }

            var inputPeer = userBase.ToInputPeer();

            DeleteHistoryAsync(mtProtoService, false, inputPeer, new TLInt(0),
                               result => callback.SafeInvoke(),
                               faultCallback.SafeInvoke);
        }
        public static string GetUserStatus(TLUserBase user)
        {
            if (user.Index == Constants.TelegramNotificationsId)
            {
                return(AppResources.ServiceNotifications.ToLowerInvariant());
            }

            if (user.BotInfo is TLBotInfo)
            {
                return(AppResources.Bot.ToLowerInvariant());
            }

            return(UserStatusToStringConverter.Convert(user.Status));
        }
 public void OpenMediaContact(TLInt userId, TLUserBase user, TLString phoneNumber)
 {
     if (user == null)
     {
         MTProtoService.GetFullUserAsync(new TLInputUserContact {
             UserId = userId
         },
                                         userFull => OpenContactInternal(userFull.User, phoneNumber));
     }
     else
     {
         OpenContactInternal(user, phoneNumber);
     }
 }
Пример #22
0
        public static string Convert(TLMessageService serviceMessage, bool useActiveLinks = false)
        {
            TLInt      fromId           = new TLInt(0); //serviceMessage.FromId;
            TLUserBase fromUser         = null;         //IoC.Get<ICacheService>().GetUser(fromId);
            string     fromUserFullName = null;         //fromUser != null ? fromUser.FullName : AppResources.User;

            var action = serviceMessage.Action;

            if (action != null && _actionsCache.ContainsKey(action.GetType()))
            {
                return(_actionsCache[action.GetType()](action, fromId.Value, fromUserFullName, useActiveLinks));
            }

            return(null);
        }
        public void Open(TLUserBase user, TLChatBase chat, Action <AddChatParticipantBoxResult> callback)
        {
            var userName = user.FirstName;

            if (TLString.IsNullOrEmpty(userName))
            {
                userName = user.LastName;
            }

            AddUserToTheGroupString = string.Format(AppResources.AddUserToTheGroup, userName, chat.FullName);
            NotifyOfPropertyChange(() => AddUserToTheGroupString);

            IsOpen    = true;
            _callback = callback;
        }
        private void OpenContactInternal(TLUserBase user, TLString phoneNumber)
        {
            if (user == null)
            {
                return;
            }

            if (View != null)
            {
                View.CreateBitmapCache(() => BeginOnUIThread(() =>
                {
                    StateService.CurrentContact      = user;
                    StateService.CurrentContactPhone = phoneNumber;
                    NavigationService.UriFor <ContactViewModel>().Navigate();
                }));
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var user = value as TLUserBase;

            if (user != null)
            {
                return(TLUserBase.GetFirstName(user.FirstName, user.LastName, user.Phone));
            }

            var chat = value as TLChatBase;

            if (chat != null)
            {
                return(chat.FullName);
            }

            return(value);
        }
Пример #26
0
        public static void NavigateToUser(TLUserBase userBase, string accessToken, PageKind pageKind = PageKind.Dialog)
        {
            if (userBase == null)
            {
                return;
            }

            Execute.BeginOnUIThread(() =>
            {
                var navigationService = IoC.Get <INavigationService>();
                if (pageKind == PageKind.Profile)
                {
                    IoC.Get <IStateService>().CurrentContact = userBase;
                    //IoC.Get<IStateService>().RemoveBackEntries = true;
                    navigationService.Navigate(new Uri("/Views/Contacts/ContactView.xaml", UriKind.Relative));
                }
                else if (pageKind == PageKind.Search)
                {
                    var user = userBase as TLUser;
                    if (user != null && user.IsBotGroupsBlocked)
                    {
                        MessageBox.Show(AppResources.AddBotToGroupsError, AppResources.Error, MessageBoxButton.OK);
                        return;
                    }

                    IoC.Get <IStateService>().With = userBase;
                    IoC.Get <IStateService>().RemoveBackEntries = true;
                    IoC.Get <IStateService>().AccessToken       = accessToken;
                    IoC.Get <IStateService>().Bot = userBase;
                    navigationService.Navigate(new Uri("/Views/Dialogs/ChooseDialogView.xaml?rndParam=" + TLInt.Random(), UriKind.Relative));
                }
                else
                {
                    IoC.Get <IStateService>().With = userBase;
                    IoC.Get <IStateService>().RemoveBackEntries = true;
                    IoC.Get <IStateService>().AccessToken       = accessToken;
                    IoC.Get <IStateService>().Bot = userBase;
                    navigationService.Navigate(new Uri("/Views/Dialogs/DialogDetailsView.xaml?rndParam=" + TLInt.Random(), UriKind.Relative));
                }
                // fix DialogDetailsView -> DialogDetailsView
                //IoC.Get<INavigationService>().UriFor<DialogDetailsViewModel>().Navigate();
            });
        }
        public void SetContact(TLUserBase userBase)
        {
            CurrentItem = userBase;
            NotifyOfPropertyChange(() => CurrentItem);

            Items.Clear();
            var userNotRegistered = userBase as TLUserNotRegistered;

            if (userNotRegistered != null)
            {
                if (userNotRegistered.Phones != null)
                {
                    foreach (var phone in userNotRegistered.Phones)
                    {
                        Items.Add(phone);
                    }
                }
            }

            if (Items.Count == 0)
            {
                Items.Add(new TLUserPhone
                {
                    Kind        = new TLInt(1),
                    Number      = userBase.Phone,
                    Description = TLString.Empty
                });
            }


            for (var index = 0; index < Items.Count; index++)
            {
                var userPhone = Items[index] as TLUserPhone;
                if (userPhone != null)
                {
                    userPhone.IsSelected    = index == 0;
                    userPhone.IsIconVisible = index == 0;
                }
            }
        }
Пример #28
0
        public void OpenContactDetails(TLUserBase contact, ShareContactDetailsMode mode)
        {
            Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
            {
                MorePanel.Visibility      = Visibility.Collapsed;
                AppBarPanel.Visibility    = Visibility.Collapsed;
                SearchPlaceholder.Content = null;

                if (_contactDetailsView == null)
                {
                    var contactDetailsViewModel = new ShareContactDetailsViewModel(contact)
                    {
                        Mode     = mode,
                        Callback = ViewModel.UserActionContinue
                    };

                    _contactDetailsView = new ShareContactDetailsView();
                    _contactDetailsView.ClosePivotAction = visibility =>
                    {
                        Items.IsHitTestVisible = visibility == Visibility.Visible;
                        AppBarPanel.Visibility = visibility;
                    };
                    ViewModelBinder.Bind(contactDetailsViewModel, _contactDetailsView, null);

                    ContactDetailsContentControl.Visibility = Visibility.Visible;
                    ContactDetailsContentControl.Content    = _contactDetailsView;
                }
                else
                {
                    var contactDetailsViewModel = _contactDetailsView.DataContext as ShareContactDetailsViewModel;
                    if (contactDetailsViewModel != null)
                    {
                        contactDetailsViewModel.SetContact(contact);
                    }
                    ContactDetailsContentControl.Visibility = Visibility.Visible;
                    _contactDetailsView.BeginOpenStoryboard();
                }
            });
        }
Пример #29
0
        public static void ImportContactAsync(TLUserBase contact, TLString phone, IMTProtoService mtProtoService, Action <TLImportedContacts> callback, Action <TLRPCError> faultCallback)
        {
            var importedContacts = new TLVector <TLInputContactBase>
            {
                new TLInputContact
                {
                    Phone     = phone,
                    FirstName = contact.FirstName,
                    LastName  = contact.LastName,
                    ClientId  = new TLLong(contact.Id.Value)
                }
            };

            mtProtoService.ImportContactsAsync(
                importedContacts,
                callback.SafeInvoke,
                error =>
            {
                faultCallback.SafeInvoke(error);
                Execute.ShowDebugMessage("contacts.importContacts error: " + error);
            });
        }
Пример #30
0
        private void SendContact(TLUserBase contact)
        {
            if (TLString.IsNullOrEmpty(contact.Phone))
            {
                var username = contact as IUserName;
                if (username != null && !TLString.IsNullOrEmpty(username.UserName))
                {
                    string accessToken = null;
                    var    bot         = contact as TLUser;
                    if (bot != null && bot.IsBot && !string.IsNullOrEmpty(bot.AccessToken))
                    {
                        accessToken     = bot.AccessToken;
                        bot.AccessToken = null;
                    }

                    _text = string.Format(Constants.UsernameLinkPlaceholder, username.UserName);
                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        _text += "?start=" + accessToken;
                    }
                    Send();

                    return;
                }

                return;
            }

            var media = new TLMessageMediaContact82
            {
                UserId      = contact.Id,
                FirstName   = contact.FirstName,
                LastName    = contact.LastName,
                PhoneNumber = contact.Phone,
                VCard       = TLString.Empty
            };

            ContinueSendContact(media);
        }