public static bool TypeStarsWith(this TLRPCError error, TLErrorType type) { var strings = error.ErrorMessage.Split(':'); var typeString = strings[0]; return(typeString.StartsWith(type.ToString(), StringComparison.OrdinalIgnoreCase)); }
private void ConfirmChangePhoneNumber() { IsWorking = true; StateService.PhoneCode = new TLString(Code); MTProtoService.ChangePhoneAsync( StateService.PhoneNumber, StateService.PhoneCodeHash, StateService.PhoneCode, auth => BeginOnUIThread(() => { TLUtils.IsLogEnabled = false; TLUtils.LogItems.Clear(); TimeCounterString = string.Empty; HelpVisibility = Visibility.Collapsed; _callTimer.Stop(); _isProcessing = false; auth.NotifyOfPropertyChange(() => auth.Phone); NavigationService.RemoveBackEntry(); NavigationService.GoBack(); IsWorking = false; }), error => BeginOnUIThread(() => { _lastError = error; IsWorking = false; if (error.TypeEquals(ErrorType.PHONE_NUMBER_UNOCCUPIED)) { _callTimer.Stop(); StateService.SentCode = _sentCode; StateService.ClearNavigationStack = true; NavigationService.UriFor <SignUpViewModel>().Navigate(); } else if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID)) { MessageBox.Show(AppResources.PhoneCodeInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY)) { MessageBox.Show(AppResources.PhoneCodeEmpty, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EXPIRED)) { MessageBox.Show(AppResources.PhoneCodeExpiredString, AppResources.Error, MessageBoxButton.OK); OnBackKeyPress(); NavigationService.GoBack(); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { #if DEBUG MessageBox.Show(error.ToString()); #endif } })); }
public void Confirm() { if (_changePhoneNumber) { ConfirmChangePhoneNumber(); return; } IsWorking = true; StateService.PhoneCode = new TLString(Code); MTProtoService.ConfirmPhoneAsync( StateService.PhoneCodeHash, StateService.PhoneCode, auth => BeginOnUIThread(() => { var currentUser = CacheService.GetUser(new TLInt(StateService.CurrentUserId)); if (currentUser != null) { MessageBox.Show(string.Format(AppResources.CancelAccountResetSuccess, "+" + currentUser.Phone), AppResources.Success, MessageBoxButton.OK); } IsWorking = false; NavigationService.GoBack(); }), error => BeginOnUIThread(() => { _lastError = error; IsWorking = false; if (error.TypeEquals(ErrorType.PHONE_NUMBER_UNOCCUPIED)) { _callTimer.Stop(); StateService.ClearNavigationStack = true; StateService.SentCode = _sentCode; NavigationService.UriFor <SignUpViewModel>().Navigate(); } else if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID)) { MessageBox.Show(AppResources.PhoneCodeInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY)) { MessageBox.Show(AppResources.PhoneCodeEmpty, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EXPIRED)) { MessageBox.Show(AppResources.PhoneCodeExpiredString, AppResources.Error, MessageBoxButton.OK); OnBackKeyPress(); NavigationService.GoBack(); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { Telegram.Api.Helpers.Execute.ShowDebugMessage("account.signIn error " + error); } })); }
private TLUploadFileBase ReuploadFile(TLUploadFileCdnRedirect redirect, byte[] requestToken, TLFileLocation location, int offset, int limit, out TLRPCError er, out bool isCanceled) { var manualResetEvent = new ManualResetEvent(false); TLUploadFileBase result = null; TLRPCError outError = null; var outIsCanceled = false; var req = new TLUploadReuploadCdnFile(); req.FileToken = redirect.FileToken; req.RequestToken = requestToken; _mtProtoService.SendRequestAsync <bool>("upload.reuploadCdnFile", req, location.DCId, false, callback => { if (callback) { result = GetCdnFile(redirect, location, offset, limit, out outError, out outIsCanceled); while (result == null) { result = GetCdnFile(redirect, location, offset, limit, out outError, out outIsCanceled); if (outIsCanceled) { break; } } manualResetEvent.Set(); } }, error => { outError = error; if (error.CodeEquals(TLErrorCode.INTERNAL) || (error.CodeEquals(TLErrorCode.BAD_REQUEST) && (error.TypeEquals(TLErrorType.LOCATION_INVALID) || error.TypeEquals(TLErrorType.VOLUME_LOC_NOT_FOUND))) || (error.CodeEquals(TLErrorCode.NOT_FOUND) && error.ErrorMessage != null && error.ErrorMessage.ToString().StartsWith("Incorrect dhGen"))) { outIsCanceled = true; manualResetEvent.Set(); return; } int delay; lock (_randomRoot) { delay = _random.Next(1000, 3000); } Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set()); }); manualResetEvent.WaitOne(20 * 1000); er = outError; isCanceled = outIsCanceled; return(result); }
public static bool CodeEquals(this TLRPCError error, TLErrorCode code) { if (Enum.IsDefined(typeof(TLErrorCode), error.ErrorCode)) { return((TLErrorCode)error.ErrorCode == code); } return(false); }
private void ChangePhoneNumber() { IsWorking = true; NotifyOfPropertyChange(() => CanSignIn); var phoneNumber = PhoneCode + PhoneNumber; _startTime = DateTime.Now; _showHelpTimer.Start(); MTProtoService.SendChangePhoneCodeAsync(new TLString(phoneNumber), null, sentCode => BeginOnUIThread(() => { _showHelpTimer.Stop(); StateService.SentCode = sentCode; StateService.PhoneNumber = new TLString(phoneNumber); StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber)); StateService.PhoneCodeHash = sentCode.PhoneCodeHash; StateService.PhoneRegistered = new TLBool(false); StateService.SendCallTimeout = sentCode.SendCallTimeout; StateService.ChangePhoneNumber = true; var sentCode50 = sentCode as TLSentCode50; if (sentCode50 != null) { StateService.Type = sentCode50.Type; StateService.NextType = sentCode50.NextType; } NavigationService.UriFor <ConfirmViewModel>().Navigate(); IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); }), error => BeginOnUIThread(() => { _lastError = error; IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID)) { MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_NUMBER_OCCUPIED)) { MessageBox.Show(string.Format(AppResources.NewNumberTaken, "+" + phoneNumber), AppResources.Error, MessageBoxButton.OK); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { Execute.ShowDebugMessage("account.sendChangePhoneCode error " + error); } })); }
private void ProcessFault(HistoryItem item, TLRPCError error) { item.LastError = error; if (error != null && (error.CodeEquals(ErrorCode.BAD_REQUEST) || error.CodeEquals(ErrorCode.FLOOD) || error.CodeEquals(ErrorCode.UNAUTHORIZED))) { RemoveFromQueue(item); item.FaultQueueCallback.SafeInvoke(error); } }
protected TLVector <TLFileHash> ReuploadFile(TLFileCdnRedirect redirect, TLInt dcId, TLString requestToken, out TLRPCError er, out bool isCanceled, out bool isTokenInvalid) { var manualResetEvent = new ManualResetEvent(false); TLVector <TLFileHash> result = null; TLRPCError outError = null; var outIsCanceled = false; var outIsTokenInvalid = false; _mtProtoService.ReuploadCdnFileAsync(dcId, redirect.FileToken, requestToken, callback => { result = callback; manualResetEvent.Set(); }, error => { outError = error; if (error.CodeEquals(ErrorCode.INTERNAL) || (error.CodeEquals(ErrorCode.BAD_REQUEST) && (error.TypeEquals(ErrorType.LOCATION_INVALID) || error.TypeEquals(ErrorType.VOLUME_LOC_NOT_FOUND))) || (error.CodeEquals(ErrorCode.NOT_FOUND) && error.Message != null && error.Message.ToString().StartsWith("Incorrect dhGen"))) { outIsCanceled = true; manualResetEvent.Set(); return; } if (error.CodeEquals(ErrorCode.BAD_REQUEST) && (error.TypeEquals(ErrorType.FILE_TOKEN_INVALID) || error.TypeEquals(ErrorType.REQUEST_TOKEN_INVALID))) { outIsTokenInvalid = true; manualResetEvent.Set(); return; } int delay; lock (_randomRoot) { delay = _random.Next(1000, 3000); } Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set()); }); manualResetEvent.WaitOne(); er = outError; isCanceled = outIsCanceled; isTokenInvalid = outIsTokenInvalid; return(result); }
public CreateChannelStep2ViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { AdminedPublicChannels = new ObservableCollection <TLChatBase>(); InviteLink = AppResources.Loading; _newChannel = StateService.NewChannel; StateService.NewChannel = null; MTProtoService.CheckUsernameAsync(new TLInputChannelEmpty(), new TLString("username"), result => BeginOnUIThread(() => { TooMuchUsernames = false; }), error => BeginOnUIThread(() => { if (TLRPCError.TypeEquals(error, ErrorType.CHANNELS_ADMIN_PUBLIC_TOO_MUCH)) { HasError = true; Error = AppResources.ChannelsAdminPublicTooMuchShort; TooMuchUsernames = true; GetAdminedPublichChannelsAsync(); } })); PropertyChanged += (sender, args) => { if (Property.NameEquals(args.PropertyName, () => IsPublic)) { if (!IsPublic && Invite == null) { ExportInvite(); } } else if (Property.NameEquals(args.PropertyName, () => UserName)) { var userName = UserName; BeginOnUIThread(TimeSpan.FromSeconds(0.3), () => { if (string.Equals(userName, UserName)) { Check(); } }); } }; }
private TLUploadFileBase GetFile(TLFileLocation location, int offset, int limit, out TLRPCError er, out bool isCanceled) { var manualResetEvent = new ManualResetEvent(false); TLUploadFileBase result = null; TLRPCError outError = null; var outIsCanceled = false; _protoService.GetFileAsync(location.DCId, location.ToInputFileLocation(), offset, limit, callback => { result = callback; manualResetEvent.Set(); if (callback is TLUploadFile file) { _statsService.IncrementReceivedBytesCount(_protoService.NetworkType, _dataType, 4 + 4 + file.Bytes.Length + 4); } }, error => { outError = error; if (error.CodeEquals(TLErrorCode.INTERNAL) || (error.CodeEquals(TLErrorCode.BAD_REQUEST) && (error.TypeEquals(TLErrorType.LOCATION_INVALID) || error.TypeEquals(TLErrorType.VOLUME_LOC_NOT_FOUND))) || (error.CodeEquals(TLErrorCode.NOT_FOUND) && error.ErrorMessage != null && error.ErrorMessage.StartsWith("Incorrect dhGen"))) { outIsCanceled = true; manualResetEvent.Set(); return; } int delay; lock (_randomRoot) { delay = _random.Next(1000, 3000); } Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set()); }); manualResetEvent.WaitOne(20 * 1000); er = outError; isCanceled = outIsCanceled; return(result); }
private TLVector <TLCdnFileHash> GetCdnFileHashes(TLUploadFileCdnRedirect redirect, TLFileLocation location, int offset, out TLRPCError er, out bool isCanceled) { var manualResetEvent = new ManualResetEvent(false); TLVector <TLCdnFileHash> result = null; TLRPCError outError = null; var outIsCanceled = false; var req = new TLUploadGetCdnFileHashes(); req.FileToken = redirect.FileToken; req.Offset = offset; _protoService.SendRequestAsync <TLVector <TLCdnFileHash> >("upload.getCdnFileHashes", req, location.DCId, true, callback => { result = callback; manualResetEvent.Set(); }, error => { outError = error; if (error.CodeEquals(TLErrorCode.INTERNAL) || (error.CodeEquals(TLErrorCode.BAD_REQUEST) && (error.TypeEquals(TLErrorType.LOCATION_INVALID) || error.TypeEquals(TLErrorType.VOLUME_LOC_NOT_FOUND))) || (error.CodeEquals(TLErrorCode.NOT_FOUND) && error.ErrorMessage != null && error.ErrorMessage.ToString().StartsWith("Incorrect dhGen"))) { outIsCanceled = true; manualResetEvent.Set(); return; } int delay; lock (_randomRoot) { delay = _random.Next(1000, 3000); } Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set()); }); manualResetEvent.WaitOne(20 * 1000); er = outError; isCanceled = outIsCanceled; return(result); }
public static bool TypeEquals(this TLRPCError error, TLErrorType type) { if (error.ErrorMessage == null) { return(false); } var strings = error.ErrorMessage.Split(':'); var typeString = strings[0]; if (Enum.IsDefined(typeof(TLErrorType), typeString)) { var value = (TLErrorType)Enum.Parse(typeof(TLErrorType), typeString, true); return(value == type); } return(false); }
protected TLFileBase GetFile(TLInt dcId, TLInputFileLocationBase location, TLInt offset, TLInt limit, out TLRPCError er, out bool isCanceled) { var manualResetEvent = new ManualResetEvent(false); TLFileBase result = null; TLRPCError outError = null; var outIsCanceled = false; _mtProtoService.GetFileAsync(dcId, location, offset, limit, file => { result = file; manualResetEvent.Set(); }, error => { outError = error; if (error.CodeEquals(ErrorCode.INTERNAL) || (error.CodeEquals(ErrorCode.BAD_REQUEST) && (error.TypeEquals(ErrorType.LOCATION_INVALID) || error.TypeEquals(ErrorType.VOLUME_LOC_NOT_FOUND))) || (error.CodeEquals(ErrorCode.NOT_FOUND) && error.Message != null && error.Message.ToString().StartsWith("Incorrect dhGen"))) { outIsCanceled = true; manualResetEvent.Set(); return; } int delay; lock (_randomRoot) { delay = _random.Next(1000, 3000); } Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set()); }); manualResetEvent.WaitOne(); er = outError; isCanceled = outIsCanceled; return(result); }
private void ClearPassword() { var password = _password as TLPassword84; if (password == null) { return; } IsWorking = true; BeginOnThreadPool(() => { var newSettings = new TLPasswordInputSettings83 { Flags = new TLInt(0), NewAlgo = new TLPasswordKdfAlgoUnknown(), NewPasswordHash = TLString.Empty, Hint = TLString.Empty, Email = TLString.Empty }; MTProtoService.GetPasswordAsync( result1 => { var srpParams = result1 as IPasswordSRPParams; if (srpParams == null) { BeginOnUIThread(() => IsWorking = false); return; } var currentPasswordHash = password.CurrentPasswordHash ?? TLString.Empty; MTProtoService.UpdatePasswordSettingsAsync(SRP.GetCheck(currentPasswordHash, srpParams.SRPId, srpParams.SRPB, srpParams.CurrentAlgo), newSettings, result => BeginOnUIThread(() => { StopTimer(); IsWorking = false; var noPassword = new TLPassword84 { Flags = new TLInt(0), EmailUnconfirmedPattern = TLString.Empty, NewSecureSalt = TLString.Empty, SecretRandom = TLString.Empty }; var password81 = _password as TLPassword84; if (password81 != null) { noPassword.NewAlgo = password81.NewAlgo; noPassword.NewSecureSalt = password81.NewSecureSalt; noPassword.SecretRandom = password81.SecretRandom; } _password = noPassword; if (_password != null) { PasswordEnabled = _password.IsAvailable; RecoveryEmailUnconfirmedVisibility = !TLString.IsNullOrEmpty(_password.EmailUnconfirmedPattern) || (_password is TLPassword && ((TLPassword)_password).HasRecovery.Value) ? Visibility.Visible : Visibility.Collapsed; NotifyOfPropertyChange(() => RecoveryEmailLabel); NotifyOfPropertyChange(() => CompletePasswordLabel); NotifyOfPropertyChange(() => ChangePasswordVisibility); NotifyOfPropertyChange(() => CompletePasswordVisibility); } EventAggregator.Publish(_password); }), error => BeginOnUIThread(() => { IsWorking = false; var messageBuilder = new StringBuilder(); //messageBuilder.AppendLine(AppResources.ServerErrorMessage); //messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.updatePasswordSettings"); messageBuilder.AppendLine("Result: " + error); if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_HASH_INVALID)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.NEW_PASSWORD_BAD)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.NEW_SALT_INVALID)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_INVALID)) { Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_UNCONFIRMED)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } } else { Execute.ShowDebugMessage("account.updatePasswordSettings error " + error); } })); }, error1 => BeginOnUIThread(() => { IsWorking = false; })); }); }
private TLUploadFileBase GetCdnFile(TLUploadFileCdnRedirect redirect, TLFileLocation location, int offset, int limit, out TLRPCError er, out bool isCanceled) { var manualResetEvent = new ManualResetEvent(false); TLUploadFileBase result = null; TLRPCError outError = null; var outIsCanceled = false; var req = new TLUploadGetCdnFile(); req.FileToken = redirect.FileToken; req.Limit = limit; req.Offset = offset; _mtProtoService.SendRequestAsync <TLUploadCdnFileBase>("upload.getCdnFile", req, redirect.DCId, true, callback => { if (callback is TLUploadCdnFile file) { var iv = redirect.EncryptionIV; var counter = offset / 16; iv[15] = (byte)(counter & 0xFF); iv[14] = (byte)((counter >> 8) & 0xFF); iv[13] = (byte)((counter >> 16) & 0xFF); iv[12] = (byte)((counter >> 24) & 0xFF); var key = CryptographicBuffer.CreateFromByteArray(redirect.EncryptionKey); var ecount_buf = new byte[0]; var num = 0u; var bytes = Utils.AES_ctr128_encrypt(file.Bytes, key, ref iv, ref ecount_buf, ref num); result = new TLUploadFile { Bytes = bytes }; manualResetEvent.Set(); _statsService.IncrementReceivedBytesCount(_mtProtoService.NetworkType, _dataType, file.Bytes.Length + 4); } else if (callback is TLUploadCdnFileReuploadNeeded reupload) { result = ReuploadFile(redirect, reupload.RequestToken, location, offset, limit, out outError, out outIsCanceled); while (result == null) { result = ReuploadFile(redirect, reupload.RequestToken, location, offset, limit, out outError, out outIsCanceled); if (outIsCanceled) { break; } } manualResetEvent.Set(); } }, error => { outError = error; if (error.CodeEquals(TLErrorCode.INTERNAL) || (error.CodeEquals(TLErrorCode.BAD_REQUEST) && (error.TypeEquals(TLErrorType.LOCATION_INVALID) || error.TypeEquals(TLErrorType.VOLUME_LOC_NOT_FOUND))) || (error.CodeEquals(TLErrorCode.NOT_FOUND) && error.ErrorMessage != null && error.ErrorMessage.ToString().StartsWith("Incorrect dhGen"))) { outIsCanceled = true; manualResetEvent.Set(); return; } int delay; lock (_randomRoot) { delay = _random.Next(1000, 3000); } Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set()); }); manualResetEvent.WaitOne(20 * 1000); er = outError; isCanceled = outIsCanceled; return(result); }
public void RecoverPassword() { if (_passwordBase == null) { return; } if (IsWorking) { return; } HasError = false; Error = string.Empty; IsWorking = true; MTProtoService.RecoverPasswordAsync(new TLString(Code), auth => BeginOnUIThread(() => { IsWorking = false; if (!_passwordBase.IsAuthRecovery) { MTProtoService.GetPasswordAsync( passwordResult => BeginOnUIThread(() => { MessageBox.Show(AppResources.PasswordDeactivated, AppResources.AppName, MessageBoxButton.OK); StateService.RemoveBackEntry = true; StateService.Password = passwordResult; NavigationService.UriFor <PasswordViewModel>().Navigate(); }), error2 => { Execute.ShowDebugMessage("account.getPassword error " + error2); }); } else { _passwordBase.IsAuthRecovery = false; #if LOG_REGISTRATION TLUtils.WriteLog("auth.recoverPassword result " + auth); TLUtils.WriteLog("TLUtils.IsLogEnabled=false"); #endif TLUtils.IsLogEnabled = false; TLUtils.LogItems.Clear(); var result = MessageBox.Show( AppResources.ConfirmPushMessage, AppResources.ConfirmPushTitle, MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { Notifications.Disable(); } else { Notifications.Enable(); } ConfirmViewModel.UpdateNotificationsAsync(MTProtoService, StateService); MTProtoService.SetInitState(); StateService.CurrentUserId = auth.User.Index; StateService.FirstRun = true; SettingsHelper.SetValue(Constants.IsAuthorizedKey, true); ShellViewModel.Navigate(NavigationService); } }), error => BeginOnUIThread(() => { IsWorking = false; var messageBuilder = new StringBuilder(); //messageBuilder.AppendLine(AppResources.Error); //messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.recoveryPassword"); messageBuilder.AppendLine("Result: " + error); if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { HasError = true; Error = AppResources.FloodWaitString; Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { HasError = true; Error = AppResources.ServerError; Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.CODE_EMPTY)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.CODE_INVALID)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_EMPTY)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_RECOVERY_NA)) { HasError = true; Error = AppResources.EmailInvalid; Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_RECOVERY_EXPIRED)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK)); } else { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } } else { HasError = true; Error = string.Empty; Execute.ShowDebugMessage("account.recoveryPassword error " + error); } })); }
private void processRequestResult(RequestInfo requestInfo, TLRPCError error) { requestInfos.Remove(requestInfo); if (error == null) { try { if (downloadedBytes != requestInfo.offset) { if (state == stateDownloading) { delayedRequestInfos.Add(requestInfo); if (requestInfo.response != null) { //requestInfo.response.disableFree = true; } else { //requestInfo.responseWeb.disableFree = true; } } return; } byte[] bytes; if (requestInfo.response != null) { bytes = requestInfo.response.Bytes; } else if (requestInfo.responseWeb != null) { bytes = requestInfo.responseWeb.Bytes; } else if (requestInfo.responseCdn != null) { bytes = requestInfo.responseCdn.Bytes; } else { bytes = null; } if (bytes == null || bytes.Length == 0) { OnFinishLoadingFile(true); return; } //if (requestInfo.responseCdn != null) //{ // int offset = requestInfo.offset / 16; // this.cdnIv[15] = (byte)(offset & 0xFF); // this.cdnIv[14] = (byte)((offset >> 8) & 0xFF); // this.cdnIv[13] = (byte)((offset >> 16) & 0xFF); // this.cdnIv[12] = (byte)((offset >> 24) & 0xFF); // Utilities.aesCtrDecryption(bytes, this.cdnKey, this.cdnIv, 0, bytes.Length); //} int currentBytesSize = bytes.Length; downloadedBytes += currentBytesSize; bool finishedDownloading = currentBytesSize != currentDownloadChunkSize || (totalBytesCount == downloadedBytes || downloadedBytes % currentDownloadChunkSize != 0) && (totalBytesCount <= 0 || totalBytesCount <= downloadedBytes); //if (key != null) //{ // Utilities.aesIgeEncryption(bytes, key, iv, false, true, 0, bytes.Length); // if (finishedDownloading && bytesCountPadding != 0) // { // bytes.limit(bytes.limit() - bytesCountPadding); // } //} if (fileOutputStream != null) { //FileChannel channel = fileOutputStream.getChannel(); //channel.write(bytes.buffer); fileOutputStream.Write(bytes, 0, bytes.Length); } if (fiv != null) { fiv.Seek(0, SeekOrigin.Begin); fiv.Write(iv, 0, iv.Length); } if (totalBytesCount > 0 && state == stateDownloading) { DidChangedLoadProgress?.Invoke(this, Math.Min(1.0f, (float)downloadedBytes / (float)totalBytesCount)); } for (int a = 0; a < this.delayedRequestInfos.Count; a += stateDownloading) { RequestInfo delayedRequestInfo = (RequestInfo)this.delayedRequestInfos[a]; if (this.downloadedBytes == delayedRequestInfo.offset) { this.delayedRequestInfos.RemoveAt(a); processRequestResult(delayedRequestInfo, null); if (delayedRequestInfo.response != null) { //delayedRequestInfo.response.disableFree = false; //delayedRequestInfo.response.freeResources(); } else if (delayedRequestInfo.responseWeb != null) { //delayedRequestInfo.responseWeb.disableFree = false; //delayedRequestInfo.responseWeb.freeResources(); } else if (delayedRequestInfo.responseCdn != null) { //delayedRequestInfo.responseCdn.disableFree = false; //delayedRequestInfo.responseCdn.freeResources(); } break; } } if (finishedDownloading) { OnFinishLoadingFile(true); } else { startDownloadRequest(); } } catch (Exception e) { onFail(false, 0); //FileLog.e(e); } } else { if (error.ErrorMessage.Contains("FILE_MIGRATE_")) { String errorMsg = error.ErrorMessage.Replace("FILE_MIGRATE_", ""); int? val; try { val = int.Parse(errorMsg); } catch (Exception e) { val = null; } if (val == null) { onFail(false, 0); } else { datacenter_id = val.Value; nextDownloadOffset = 0; startDownloadRequest(); } } else if (error.ErrorMessage.Contains("OFFSET_INVALID")) { if (downloadedBytes % currentDownloadChunkSize == 0) { try { OnFinishLoadingFile(true); } catch (Exception e) { //FileLog.e(e); onFail(false, 0); } } else { onFail(false, 0); } } else if (error.ErrorMessage.Contains("RETRY_LIMIT")) { onFail(false, 2); } else if (error.ErrorMessage.Contains("is already authorizing")) { nextDownloadOffset = 0; startDownloadRequest(); } else { //if (location != null) //{ // FileLog.e("" + location + " id = " + location.id + " local_id = " + location.local_id + " access_hash = " + location.access_hash + " volume_id = " + location.volume_id + " secret = " + location.secret); //} //else if (webLocation != null) //{ // FileLog.e("" + webLocation + " id = " + webLocation.url + " access_hash = " + webLocation.access_hash); //} onFail(false, 0); } } }
public static string GetErrorTypeString(this TLRPCError error) { var strings = error.ErrorMessage.Split(':'); return(strings[0]); }
private void ProcessGlobalSearch(SearchDocumentsRequest nextDocumentsRequest) { if (nextDocumentsRequest.GlobalResults != null) { if (nextDocumentsRequest.GlobalResults.Count > 0) { BeginOnUIThread(() => { if (nextDocumentsRequest.IsCanceled) { return; } foreach (var result in nextDocumentsRequest.GlobalResults) { Items.Add((TLMessage)result); } NotifyOfPropertyChange(() => IsEmptyList); Status = Items.Count > 0 ? string.Empty : AppResources.NoResults; }); } } else { IsWorking = true; MTProtoService.SearchAsync( nextDocumentsRequest.InputPeer, new TLString(nextDocumentsRequest.Text), null, InputMessageFilter, new TLInt(0), new TLInt(0), new TLInt(0), new TLInt(0), new TLInt(100), new TLInt(0), result => { IsWorking = false; nextDocumentsRequest.GlobalResults = new List <TLMessageBase>(result.Messages.Count); foreach (var message in result.Messages) { if (nextDocumentsRequest.ResultsIndex == null || !nextDocumentsRequest.ResultsIndex.ContainsKey(message.Index)) { nextDocumentsRequest.GlobalResults.Add(message); } } BeginOnUIThread(() => { if (nextDocumentsRequest.IsCanceled) { return; } if (nextDocumentsRequest.GlobalResults.Count > 0) { foreach (var message in nextDocumentsRequest.GlobalResults) { Items.Add((TLMessage)message); } NotifyOfPropertyChange(() => IsEmptyList); } Status = Items.Count > 0 ? string.Empty : AppResources.NoResults; }); }, error => { IsWorking = false; if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST) && TLRPCError.TypeEquals(error, ErrorType.QUERY_TOO_SHORT)) { nextDocumentsRequest.GlobalResults = new List <TLMessageBase>(); } else if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { nextDocumentsRequest.GlobalResults = new List <TLMessageBase>(); BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK)); } Execute.ShowDebugMessage("messages.search error " + error); }); } }
public static void ProcessError(TLRPCError error, TLType request, params Object[] args) { if (error.ErrorCode == 406 || error.ErrorMessage == null) { return; } if (request == TLType.ChannelsJoinChannel || request == TLType.ChannelsEditAdmin || request == TLType.ChannelsInviteToChannel || request == TLType.MessagesAddChatUser || request == TLType.MessagesStartBot || request == TLType.ChannelsEditBanned) { //if (fragment != null) //{ ShowAddUserAlert(error.ErrorMessage, (Boolean)args[0]); //} //else //{ // if (error.ErrorMessage.Equals("PEER_FLOOD")) // { // ShowPeerFloodAlert(1); // } //} } else if (request == TLType.MessagesCreateChat) { if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowFloodWaitAlert(error.ErrorMessage); } else { ShowAddUserAlert(error.ErrorMessage, false); } } else if (request == TLType.ChannelsCreateChannel) { if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowFloodWaitAlert(error.ErrorMessage); } } else if (request == TLType.MessagesEditMessage) { if (!error.ErrorMessage.Equals("MESSAGE_NOT_MODIFIED")) { ShowSimpleAlert(Strings.Android.EditMessageError); } } else if (request == TLType.MessagesSendMessage || request == TLType.MessagesSendMedia || request == TLType.MessagesSendInlineBotResult || request == TLType.MessagesForwardMessages) { if (error.ErrorMessage.Equals("PEER_FLOOD")) { ShowPeerFloodAlert(0); } } else if (request == TLType.MessagesImportChatInvite) { if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else if (error.ErrorMessage.Equals("USERS_TOO_MUCH")) { ShowSimpleAlert(Strings.Android.JoinToGroupErrorFull); } else { ShowSimpleAlert(Strings.Android.JoinToGroupErrorNotExist); } } else if (request == TLType.MessagesGetAttachedStickers) { //Toast.makeText(fragment.getParentActivity(), Strings.Android.ErrorOccurred + "\n" + error.ErrorMessage, Toast.LENGTH_SHORT).show(); } else if (request == TLType.AccountConfirmPhone) { if (error.ErrorMessage.Contains("PHONE_CODE_EMPTY") || error.ErrorMessage.Contains("PHONE_CODE_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidCode); } else if (error.ErrorMessage.Contains("PHONE_CODE_EXPIRED")) { ShowSimpleAlert(Strings.Android.CodeExpired); } else if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else { ShowSimpleAlert(error.ErrorMessage); } } else if (request == TLType.AuthResendCode) { if (error.ErrorMessage.Contains("PHONE_NUMBER_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidPhoneNumber); } else if (error.ErrorMessage.Contains("PHONE_CODE_EMPTY") || error.ErrorMessage.Contains("PHONE_CODE_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidCode); } else if (error.ErrorMessage.Contains("PHONE_CODE_EXPIRED")) { ShowSimpleAlert(Strings.Android.CodeExpired); } else if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else if (error.ErrorCode != -1000) { ShowSimpleAlert(Strings.Android.ErrorOccurred + "\n" + error.ErrorMessage); } } else if (request == TLType.AccountSendConfirmPhoneCode) { if (error.ErrorCode == 400) { ShowSimpleAlert(Strings.Android.CancelLinkExpired); } else if (error.ErrorMessage != null) { if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else { ShowSimpleAlert(Strings.Android.ErrorOccurred); } } } else if (request == TLType.AccountChangePhone) { if (error.ErrorMessage.Contains("PHONE_NUMBER_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidPhoneNumber); } else if (error.ErrorMessage.Contains("PHONE_CODE_EMPTY") || error.ErrorMessage.Contains("PHONE_CODE_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidCode); } else if (error.ErrorMessage.Contains("PHONE_CODE_EXPIRED")) { ShowSimpleAlert(Strings.Android.CodeExpired); } else if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else { ShowSimpleAlert(error.ErrorMessage); } } else if (request == TLType.AccountSendChangePhoneCode) { if (error.ErrorMessage.Contains("PHONE_NUMBER_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidPhoneNumber); } else if (error.ErrorMessage.Contains("PHONE_CODE_EMPTY") || error.ErrorMessage.Contains("PHONE_CODE_INVALID")) { ShowSimpleAlert(Strings.Android.InvalidCode); } else if (error.ErrorMessage.Contains("PHONE_CODE_EXPIRED")) { ShowSimpleAlert(Strings.Android.CodeExpired); } else if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else if (error.ErrorMessage.StartsWith("PHONE_NUMBER_OCCUPIED")) { ShowSimpleAlert(string.Format(Strings.Android.ChangePhoneNumberOccupied, (String)args[0])); } else { ShowSimpleAlert(Strings.Android.ErrorOccurred); } } else if (request == TLType.AccountUpdateUsername) { switch (error.ErrorMessage) { case "USERNAME_INVALID": ShowSimpleAlert(Strings.Android.UsernameInvalid); break; case "USERNAME_OCCUPIED": ShowSimpleAlert(Strings.Android.UsernameInUse); break; //case "USERNAMES_UNAVAILABLE": // ShowSimpleAlert(Strings.Android.FeatureUnavailable); // break; default: ShowSimpleAlert(Strings.Android.ErrorOccurred); break; } } else if (request == TLType.ContactsImportContacts) { if (error == null || error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleAlert(Strings.Android.FloodWait); } else { ShowSimpleAlert(Strings.Android.ErrorOccurred + "\n" + error.ErrorMessage); } } else if (request == TLType.AccountGetPassword || request == TLType.AccountGetTmpPassword) { if (error.ErrorMessage.StartsWith("FLOOD_WAIT")) { ShowSimpleToast(GetFloodWaitString(error.ErrorMessage)); } else { ShowSimpleToast(error.ErrorMessage); } } else if (request == TLType.PaymentsSendPaymentForm) { switch (error.ErrorMessage) { case "BOT_PRECHECKOUT_FAILED": ShowSimpleToast(Strings.Android.PaymentPrecheckoutFailed); break; case "PAYMENT_FAILED": ShowSimpleToast(Strings.Android.PaymentFailed); break; default: ShowSimpleToast(error.ErrorMessage); break; } } else if (request == TLType.PaymentsValidateRequestedInfo) { switch (error.ErrorMessage) { case "SHIPPING_NOT_AVAILABLE": ShowSimpleToast(Strings.Android.PaymentNoShippingMethod); break; default: ShowSimpleToast(error.ErrorMessage); break; } } //// Added //else if (request == TLType.AuthSignUp) //{ // if (error.ErrorMessage.Contains("PHONE_NUMBER_INVALID")) // { // ShowSimpleAlert(Strings.Android.InvalidPhoneNumber); // } // else if (error.ErrorMessage.Contains("PHONE_CODE_EMPTY") || error.ErrorMessage.Contains("PHONE_CODE_INVALID")) // { // ShowSimpleAlert(Strings.Android.InvalidCode); // } // else if (error.ErrorMessage.Contains("PHONE_CODE_EXPIRED")) // { // ShowSimpleAlert(Strings.Android.CodeExpired); // } // else if (error.ErrorMessage.Contains("FIRSTNAME_INVALID")) // { // ShowSimpleAlert(Strings.Android.InvalidFirstName); // } // else if (error.ErrorMessage.Contains("LASTNAME_INVALID")) // { // ShowSimpleAlert(Strings.Android.InvalidLastName); // } // else // { // ShowSimpleAlert(error.ErrorMessage); // } //} return; }
public void Confirm() { if (_changePhoneNumber) { ConfirmChangePhoneNumber(); return; } IsWorking = true; StateService.PhoneCode = new TLString(Code); #if LOG_REGISTRATION TLUtils.WriteLog("auth.signIn"); #endif MTProtoService.SignInAsync( StateService.PhoneNumber, StateService.PhoneCodeHash, StateService.PhoneCode, auth => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.signIn result " + auth); TLUtils.WriteLog("TLUtils.IsLogEnabled=false"); #endif TLUtils.IsLogEnabled = false; TLUtils.LogItems.Clear(); TimeCounterString = string.Empty; HelpVisibility = Visibility.Collapsed; _callTimer.Stop(); var result = MessageBox.Show( AppResources.ConfirmPushMessage, AppResources.ConfirmPushTitle, MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { StateService.GetNotifySettingsAsync(settings => { var s = settings ?? new Settings(); s.ContactAlert = false; s.ContactMessagePreview = true; s.ContactSound = StateService.Sounds[0]; s.GroupAlert = false; s.GroupMessagePreview = true; s.GroupSound = StateService.Sounds[0]; s.InAppMessagePreview = true; s.InAppSound = true; s.InAppVibration = true; StateService.SaveNotifySettingsAsync(s); }); MTProtoService.UpdateNotifySettingsAsync( new TLInputNotifyUsers(), new TLInputPeerNotifySettings { EventsMask = new TLInt(1), MuteUntil = new TLInt(int.MaxValue), ShowPreviews = new TLBool(true), Sound = new TLString(StateService.Sounds[0]) }, r => { }); MTProtoService.UpdateNotifySettingsAsync( new TLInputNotifyChats(), new TLInputPeerNotifySettings { EventsMask = new TLInt(1), MuteUntil = new TLInt(int.MaxValue), ShowPreviews = new TLBool(true), Sound = new TLString(StateService.Sounds[0]) }, r => { }); } else { StateService.GetNotifySettingsAsync(settings => { var s = settings ?? new Settings(); s.ContactAlert = true; s.ContactMessagePreview = true; s.ContactSound = StateService.Sounds[0]; s.GroupAlert = true; s.GroupMessagePreview = true; s.GroupSound = StateService.Sounds[0]; s.InAppMessagePreview = true; s.InAppSound = true; s.InAppVibration = true; StateService.SaveNotifySettingsAsync(s); }); MTProtoService.UpdateNotifySettingsAsync( new TLInputNotifyUsers(), new TLInputPeerNotifySettings { EventsMask = new TLInt(1), MuteUntil = new TLInt(0), ShowPreviews = new TLBool(true), Sound = new TLString(StateService.Sounds[0]) }, r => { }); MTProtoService.UpdateNotifySettingsAsync( new TLInputNotifyChats(), new TLInputPeerNotifySettings { EventsMask = new TLInt(1), MuteUntil = new TLInt(0), ShowPreviews = new TLBool(true), Sound = new TLString(StateService.Sounds[0]) }, r => { }); } MTProtoService.SetInitState(); //_updatesService.SetCurrentUser(auth.User); _isProcessing = false; StateService.CurrentUserId = auth.User.Index; StateService.ClearNavigationStack = true; StateService.FirstRun = true; SettingsHelper.SetValue(Constants.IsAuthorizedKey, true); NavigationService.UriFor <ShellViewModel>().Navigate(); IsWorking = false; }), error => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.signIn error " + error); #endif _lastError = error; IsWorking = false; if (error.TypeEquals(ErrorType.PHONE_NUMBER_UNOCCUPIED)) { _callTimer.Stop(); StateService.ClearNavigationStack = true; NavigationService.UriFor <SignUpViewModel>().Navigate(); } else if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID)) { MessageBox.Show(AppResources.PhoneCodeInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY)) { MessageBox.Show(AppResources.PhoneCodeEmpty, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EXPIRED)) { MessageBox.Show(AppResources.PhoneCodeExpiredString, AppResources.Error, MessageBoxButton.OK); OnBackKeyPress(); NavigationService.GoBack(); } else if (error.TypeEquals(ErrorType.SESSION_PASSWORD_NEEDED)) { IsWorking = true; MTProtoService.GetPasswordAsync( password => BeginOnUIThread(() => { IsWorking = false; _callTimer.Stop(); StateService.Password = password; StateService.RemoveBackEntry = true; NavigationService.UriFor <ConfirmPasswordViewModel>().Navigate(); }), error2 => { IsWorking = false; Telegram.Api.Helpers.Execute.ShowDebugMessage("account.getPassword error " + error); }); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { Telegram.Api.Helpers.Execute.ShowDebugMessage("account.signIn error " + error); } })); }
public void SignIn() { if (_changePhoneNumber) { ChangePhoneNumber(); return; } #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode"); #endif IsWorking = true; NotifyOfPropertyChange(() => CanSignIn); var phoneNumber = PhoneCode + PhoneNumber; _startTime = DateTime.Now; _showHelpTimer.Start(); MTProtoService.SendCodeAsync(new TLString(phoneNumber), TLSmsType.Code, sentCode => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode result: " + sentCode); #endif _sentCode = sentCode; _showHelpTimer.Stop(); StateService.PhoneNumber = new TLString(phoneNumber); StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber)); StateService.PhoneCodeHash = sentCode.PhoneCodeHash; StateService.PhoneRegistered = sentCode.PhoneRegistered; StateService.SendCallTimeout = sentCode.SendCallTimeout; NavigationService.UriFor <ConfirmViewModel>().Navigate(); IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); }), attemptNumber => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode attempt failed " + attemptNumber); #endif Execute.ShowDebugMessage("auth.sendCode attempt failed " + attemptNumber); }), error => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode error " + error); #endif _lastError = error; IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID)) { MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { Execute.ShowDebugMessage("auth.sendCode error " + error); } })); }
public void Done() { if (IsWorking) { return; } var username = IsPublic ? UserName : string.Empty; if (username != null && username.StartsWith("@")) { username = username.Substring(1, username.Length - 1); } IsWorking = true; MTProtoService.UpdateUsernameAsync(_newChannel.ToInputChannel(), new TLString(username), user => Execute.BeginOnUIThread(() => { //CacheService.SyncUser(user, result => EventAggregator.Publish(new UserNameChangedEventArgs(result))); IsWorking = false; _newChannel.UserName = new TLString(UserName); StateService.NewChannel = _newChannel; StateService.RemoveBackEntry = true; NavigationService.UriFor <CreateChannelStep3ViewModel>().Navigate(); }), error => Execute.BeginOnUIThread(() => { IsWorking = false; if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { HasError = true; Error = AppResources.FloodWaitString; MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { var messageBuilder = new StringBuilder(); messageBuilder.AppendLine(AppResources.ServerErrorMessage); messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: channels.updateUsername"); messageBuilder.AppendLine("Result: " + error); HasError = true; Error = AppResources.ServerError; MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_INVALID)) { HasError = true; Error = AppResources.ChannelNameInvalid; MessageBox.Show(AppResources.ChannelNameInvalid, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_OCCUPIED)) { HasError = true; Error = AppResources.ChannelNameOccupied; MessageBox.Show(AppResources.ChannelNameOccupied, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.TypeEquals(error, ErrorType.CHANNELS_ADMIN_PUBLIC_TOO_MUCH)) { HasError = true; Error = AppResources.ChannelsAdminPublicTooMuchShort; MessageBox.Show(AppResources.ChannelsAdminPublicTooMuch, AppResources.Error, MessageBoxButton.OK); } else { HasError = true; Error = error.ToString(); } } else { HasError = true; Error = string.Empty; Execute.ShowDebugMessage("channels.updateUsername error " + error); } })); }
public void Validate() { if (PaymentInfo == null) { return; } if (PaymentInfo.Message == null) { return; } if (PaymentInfo.Form == null) { return; } var info = new TLPaymentRequestedInfo { Flags = new TLInt(0) }; if (PaymentInfo.Form.Invoice.NameRequested) { info.Name = new TLString(Name); } if (PaymentInfo.Form.Invoice.PhoneRequested) { info.Phone = new TLString(PhoneCode + PhoneNumber); } if (PaymentInfo.Form.Invoice.EmailRequested) { info.Email = new TLString(Email); } if (PaymentInfo.Form.Invoice.ShippingAddressRequested) { info.ShippingAddress = new TLPostAddress { StreetLine1 = new TLString(StreetLine1), StreetLine2 = new TLString(StreetLine2), City = new TLString(City), State = new TLString(State), CountryIso2 = new TLString(SelectedCountry != null ? SelectedCountry.Code : string.Empty), PostCode = new TLString(PostCode) }; } IsWorking = true; MTProtoService.ValidateRequestedInfoAsync( SaveShippingInformation, PaymentInfo.Message.Id, info, result => Execute.BeginOnUIThread(() => { IsWorking = false; PaymentInfo.ValidatedInfo = result; PaymentInfo.Form.SavedInfo = info; if (!SaveShippingInformation && PaymentInfo != null && PaymentInfo.Form != null && PaymentInfo.Form.SavedInfo != null) { IsWorking = true; MTProtoService.ClearSavedInfoAsync(false, true, result2 => Execute.BeginOnUIThread(() => { IsWorking = false; NavigateToNextStep(); }), error2 => Execute.BeginOnUIThread(() => { IsWorking = false; Telegram.Api.Helpers.Execute.ShowDebugMessage("payments.clearInfo error " + error2); })); } else { NavigateToNextStep(); } }), error => Execute.BeginOnUIThread(() => { IsWorking = false; Error = error; NotifyOfPropertyChange(() => Error); Telegram.Api.Helpers.Execute.ShowDebugMessage("payments.validateRequestedInfo error " + error); })); }
public MTProtoResponse(TLRPCError error) { _error = error; }
public void ForgotPassword() { if (_password == null) { return; } BeginOnUIThread(() => { if (_password.HasRecovery.Value) { IsWorking = true; MTProtoService.RequestPasswordRecoveryAsync( result => BeginOnUIThread(() => { IsWorking = false; _password.EmailUnconfirmedPattern = result.EmailPattern; _password.IsAuthRecovery = true; MessageBox.Show(string.Format(AppResources.SentRecoveryCodeMessage, result.EmailPattern), AppResources.AppName, MessageBoxButton.OK); StateService.Password = _password; StateService.RemoveBackEntry = true; NavigationService.UriFor <PasswordRecoveryViewModel>().Navigate(); ResetAccountVisibility = Visibility.Visible; }), error => BeginOnUIThread(() => { IsWorking = false; var messageBuilder = new StringBuilder(); messageBuilder.AppendLine(AppResources.Error); messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.requestPasswordRecovery"); messageBuilder.AppendLine("Result: " + error); if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_EMPTY)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_RECOVERY_NA)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } } else { Execute.ShowDebugMessage("account.requestPasswordRecovery error " + error); } ResetAccountVisibility = Visibility.Visible; })); } else { MessageBox.Show(AppResources.NoRecoveryEmailMessage, AppResources.Sorry, MessageBoxButton.OK); ResetAccountVisibility = Visibility.Visible; } }); }
public void Check() { var checkedUsername = UserName; var username = UserName; if (username != null && username.StartsWith("@")) { username = username.Substring(1, username.Length - 1); } if (string.IsNullOrEmpty(username)) { HasError = false; IsUsernameAvailable = false; //Error = string.Empty; return; } var isValidSymbols = username.All(IsValidSymbol); if (!isValidSymbols) { HasError = true; Error = AppResources.ChannelNameInvalid; return; } if (username[0] >= '0' && username[0] <= '9') { HasError = true; Error = AppResources.ChannelNameStartsWithNumber; return; } if (username.Length < Constants.UsernameMinLength) { HasError = true; Error = AppResources.ChannelNameShort; return; } HasError = false; IsUsernameAvailable = false; MTProtoService.CheckUsernameAsync(_newChannel.ToInputChannel(), new TLString(username), result => BeginOnUIThread(() => { HasError = !result.Value; if (HasError) { Error = AppResources.ChannelNameOccupied; } if (string.Equals(checkedUsername, UserName) && result.Value) { IsUsernameAvailable = true; UsernameAvailableString = string.Format(AppResources.NameIsAvailable, checkedUsername); } }), error => BeginOnUIThread(() => { HasError = true; if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { Error = AppResources.FloodWaitString; } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { var messageBuilder = new StringBuilder(); messageBuilder.AppendLine(AppResources.ServerErrorMessage); messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: channels.checkUsername"); messageBuilder.AppendLine("Result: " + error); Error = AppResources.ServerError; } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_INVALID)) { Error = AppResources.ChannelNameInvalid; } else if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_OCCUPIED)) { Error = AppResources.ChannelNameOccupied; } else if (TLRPCError.TypeEquals(error, ErrorType.CHANNELS_ADMIN_PUBLIC_TOO_MUCH)) { MessageBox.Show(AppResources.ChannelsAdminPublicTooMuch, AppResources.Error, MessageBoxButton.OK); Error = AppResources.ChannelsAdminPublicTooMuchShort; TooMuchUsernames = true; GetAdminedPublichChannelsAsync(); } else { Error = error.ToString(); } } else { Error = string.Empty; Execute.ShowDebugMessage("channels.checkUsername error " + error); } })); }
private void ProcessGlobalSearch(SearchUsersRequest nextUsersRequest) { if (nextUsersRequest.GlobalResults != null) { if (nextUsersRequest.GlobalResults.Count > 0) { BeginOnUIThread(() => { if (nextUsersRequest.IsCanceled) { return; } Items.Add(new TLServiceText { Text = AppResources.GlobalSearch }); foreach (var user in nextUsersRequest.GlobalResults) { Items.Add(user); } //Status = Items.Count == 0 ? AppResources.NoResults : string.Empty; }); } } else { //if (nextUsersRequest.Text.Length < 5) //{ // nextUsersRequest.GlobalResults = new List<TLObject>(); // return; //} MTProtoService.SearchAsync(new TLString(nextUsersRequest.Text), new TLInt(100), result => Execute.BeginOnUIThread(() => { nextUsersRequest.GlobalResults = new List <TLObject>(); foreach (var user in result.Users) { nextUsersRequest.GlobalResults.Add(user); } var contactsFound40 = result as TLContactsFound40; if (contactsFound40 != null) { foreach (var chat in contactsFound40.Chats) { nextUsersRequest.GlobalResults.Add(chat); } } if (nextUsersRequest.IsCanceled) { return; } var items = new List <TLUserBase>(); foreach (var user in result.Users) { if (!nextUsersRequest.ResultsIndex.ContainsKey(user.Index)) { items.Add(user); } } if (items.Count > 0) { Items.Add(new TLServiceText { Text = AppResources.GlobalSearch }); foreach (var user in items) { Items.Add(user); } } }), error => { if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST) && TLRPCError.TypeEquals(error, ErrorType.QUERY_TOO_SHORT)) { nextUsersRequest.GlobalResults = new List <TLObject>(); } else if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { nextUsersRequest.GlobalResults = new List <TLObject>(); BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK)); } Execute.ShowDebugMessage("contacts.search error " + error); }); } }
public MTProtoResponse(object value, TLRPCError error) { _result = value; _error = error; }
public void RevokeLink(TLChatBase chat) { var channel = chat as TLChannel; if (channel == null) { return; } var richTextBox = new RichTextBox { TextWrapping = TextWrapping.Wrap }; ConvertToSupergroupView.SetFormattedText(richTextBox, string.Format(AppResources.RevokeLinkConfirmation2, "t.me/" + channel.UserName, channel.FullName)); #if WP8 var isFullHD = Application.Current.Host.Content.ScaleFactor == 225; if (isFullHD) { richTextBox.FontSize = 17.667; } #endif ShellViewModel.ShowCustomMessageBox(null, AppResources.RevokeLink, AppResources.Cancel.ToLowerInvariant(), AppResources.Revoke.ToLowerInvariant(), dismissed => { if (dismissed == CustomMessageBoxResult.LeftButton) { IsWorking = true; MTProtoService.UpdateUsernameAsync(channel.ToInputChannel(), TLString.Empty, user => Execute.BeginOnUIThread(() => { IsWorking = false; channel.UserName = TLString.Empty; channel.NotifyOfPropertyChange(() => channel.UserName); TooMuchUsernames = false; HasError = false; Error = string.Empty; Check(); }), error => Execute.BeginOnUIThread(() => { IsWorking = false; if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { //HasError = true; //Error = AppResources.FloodWaitString; MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { var messageBuilder = new StringBuilder(); messageBuilder.AppendLine(AppResources.ServerErrorMessage); messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: channels.updateUsername"); messageBuilder.AppendLine("Result: " + error); //HasError = true; //Error = AppResources.ServerError; MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_NOT_MODIFIED)) { channel.UserName = TLString.Empty; channel.NotifyOfPropertyChange(() => channel.UserName); HasError = false; Error = string.Empty; Check(); return; } else if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_INVALID)) { //HasError = true; //Error = AppResources.ChannelNameInvalid; MessageBox.Show(AppResources.ChannelNameInvalid, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_OCCUPIED)) { //HasError = true; //Error = AppResources.ChannelNameInvalid; MessageBox.Show(AppResources.ChannelNameOccupied, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.TypeEquals(error, ErrorType.CHANNELS_ADMIN_PUBLIC_TOO_MUCH)) { //HasError = true; //Error = AppResources.ChannelsAdminPublicTooMuchShort; MessageBox.Show(AppResources.ChannelsAdminPublicTooMuch, AppResources.Error, MessageBoxButton.OK); } else { //HasError = true; //Error = error.ToString(); Execute.ShowDebugMessage("channels.updateUsername error " + error); } } else { //HasError = true; //Error = string.Empty; Execute.ShowDebugMessage("channels.updateUsername error " + error); } })); } }, richTextBox); }