Exemplo n.º 1
0
        public void Terminate(TLAccountAuthorization authorization)
        {
            if (authorization == null)
            {
                return;
            }

            if (authorization.IsCurrent)
            {
                var result = MessageBox.Show(AppResources.LogOutConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel);
                if (result != MessageBoxResult.OK)
                {
                    return;
                }


                var updatesService = IoC.Get <IUpdatesService>();
                var pushService    = IoC.Get <IPushService>();

                pushService.UnregisterDeviceAsync(() =>
                                                  MTProtoService.LogOutAsync(() =>
                {
                    ContactsHelper.DeleteContactsAsync(null);

                    Execute.BeginOnUIThread(() =>
                    {
                        foreach (var activeTile in ShellTile.ActiveTiles)
                        {
                            if (activeTile.NavigationUri.ToString().Contains("Action=SecondaryTile"))
                            {
                                activeTile.Delete();
                            }
                        }
                    });
                }));

                Telegram.Logs.Log.Write("StartupViewModel SessionsViewModel.Terminate");
                SettingsViewModel.LogOutCommon(EventAggregator, MTProtoService, updatesService, CacheService, StateService, pushService, NavigationService);
            }
            else
            {
                IsWorking = true;
                MTProtoService.ResetAuthorizationAsync(
                    authorization.Hash,
                    result => BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    Items.Remove(authorization);
                }),
                    error =>
                {
                    IsWorking = false;
                    Execute.ShowDebugMessage("auth.resetAuthotization error " + error);
                });
            }
        }
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (Property.NameEquals(e.PropertyName, () => PeopleHub))
            {
#if WP8
                if (PreviousToken != null)
                {
                    PreviousToken.IsCanceled = true;
                }

                if (PeopleHub)
                {
                    var contacts = CacheService.GetContacts().Where(x => x != null && x.IsContact).ToList();
                    var token    = new ContactsOperationToken();

                    PreviousToken = token;
                    ContactsHelper.ImportContactsAsync(DownloadManager, token, contacts,
                                                       tuple =>
                    {
                        var importedCount = tuple.Item1;
                        var totalCount    = tuple.Item2;

                        var isComplete = importedCount == totalCount;
                        if (isComplete)
                        {
                            PreviousToken = null;
                        }

                        var duration = isComplete ? 0.5 : 2.0;
                        MTProtoService.SetMessageOnTime(duration,
                                                        string.Format(AppResources.SyncContactsProgress, importedCount, totalCount));
                    },
                                                       () =>
                    {
                        MTProtoService.SetMessageOnTime(0.0, string.Empty);
                    });
                }
                else
                {
                    IsPeopleHubEnabled = false;
                    MTProtoService.SetMessageOnTime(25.0, AppResources.DeletingContacts);
                    ContactsHelper.DeleteContactsAsync(() =>
                    {
                        IsPeopleHubEnabled = true;
                        MTProtoService.SetMessageOnTime(0.0, string.Empty);
                    });
                }
#endif
            }
        }
Exemplo n.º 3
0
        public void LogOut()
        {
            var result = MessageBox.Show(AppResources.LogOutConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel);

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


            Telegram.Logs.Log.Write("SettingsViewModel.LogOut");
            PushService.UnregisterDeviceAsync(() =>
                                              MTProtoService.LogOutAsync(logOutResult =>
            {
                ContactsHelper.DeleteContactsAsync(null);

                Execute.BeginOnUIThread(() =>
                {
                    foreach (var activeTile in ShellTile.ActiveTiles)
                    {
                        if (activeTile.NavigationUri.ToString().Contains("Action=SecondaryTile"))
                        {
                            activeTile.Delete();
                        }
                    }
                });

                //MTProtoService.LogOutTransportsAsync(
                //    () =>
                //    {

                //    },
                //    errors =>
                //    {

                //    });
            },
                                                                         error =>
            {
                Execute.ShowDebugMessage("account.logOut error " + error);
            }));

            LogOutCommon(EventAggregator, MTProtoService, UpdateService, CacheService, StateService, PushService, NavigationService);
        }