Update account deletion API

This commit is contained in:
Ilya Laktyushin 2022-06-30 16:44:17 +03:00
parent 7868651acb
commit 4a9c3dacc8
6 changed files with 48 additions and 17 deletions

View File

@ -1147,7 +1147,7 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta
let _ = combineLatest( let _ = combineLatest(
queue: Queue.mainQueue(), queue: Queue.mainQueue(),
adminedPublicChannels.get() |> filter { $0 != nil } |> take(1), adminedPublicChannels.get() |> filter { $0 != nil } |> take(1),
context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.Peer(id: context.account.peerId)), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: context.account.peerId)),
context.engine.data.get( context.engine.data.get(
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: false), TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: false),
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: true) TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: true)

View File

@ -387,7 +387,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
proceedImpl = { [weak controller] in proceedImpl = { [weak controller] in
let presentationData = context.sharedContext.currentPresentationData.with { $0 } let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let action: ([EnginePeer]) -> Void = { preloadedPeers in let action: ([EnginePeer], String?) -> Void = { preloadedPeers, password in
let nextMode: DeleteAccountDataMode? let nextMode: DeleteAccountDataMode?
switch mode { switch mode {
case .peers: case .peers:
@ -423,7 +423,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
let accountId = context.account.id let accountId = context.account.id
let accountManager = context.sharedContext.accountManager let accountManager = context.sharedContext.accountManager
let _ = (context.engine.auth.deleteAccount(reason: "Manual") let _ = (context.engine.auth.deleteAccount(reason: "Manual", password: password)
|> deliverOnMainQueue).start(error: { _ in |> deliverOnMainQueue).start(error: { _ in
updateState { current in updateState { current in
var updated = current var updated = current
@ -447,7 +447,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
let _ = (preloadedGroupPeers.get() let _ = (preloadedGroupPeers.get()
|> take(1) |> take(1)
|> deliverOnMainQueue).start(next: { peers in |> deliverOnMainQueue).start(next: { peers in
action(peers) action(peers, nil)
}) })
case .phone: case .phone:
var phoneNumber: String? var phoneNumber: String?
@ -469,7 +469,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.DeleteAccount_InvalidPhoneNumberError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})])) presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.DeleteAccount_InvalidPhoneNumberError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]))
return return
} }
action([]) action([], nil)
} }
}) })
} }
@ -507,13 +507,13 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
return updated return updated
} }
action([]) action([], state.password)
}) })
return return
} }
default: default:
action([]) action([], nil)
} }
} }

View File

@ -156,11 +156,13 @@ public extension Api.functions.account {
} }
} }
public extension Api.functions.account { public extension Api.functions.account {
static func deleteAccount(reason: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) { static func deleteAccount(flags: Int32, reason: String, password: Api.InputCheckPasswordSRP?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(1099779595) buffer.appendInt32(-1564422284)
serializeInt32(flags, buffer: buffer, boxed: false)
serializeString(reason, buffer: buffer, boxed: false) serializeString(reason, buffer: buffer, boxed: false)
return (FunctionDescription(name: "account.deleteAccount", parameters: [("reason", String(describing: reason))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in if Int(flags) & Int(1 << 0) != 0 {password!.serialize(buffer, true)}
return (FunctionDescription(name: "account.deleteAccount", parameters: [("flags", String(describing: flags)), ("reason", String(describing: reason)), ("password", String(describing: password))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer) let reader = BufferReader(buffer)
var result: Api.Bool? var result: Api.Bool?
if let signature = reader.readInt32() { if let signature = reader.readInt32() {

View File

@ -494,7 +494,7 @@ public enum AccountResetError {
} }
public func performAccountReset(account: UnauthorizedAccount) -> Signal<Void, AccountResetError> { public func performAccountReset(account: UnauthorizedAccount) -> Signal<Void, AccountResetError> {
return account.network.request(Api.functions.account.deleteAccount(reason: "")) return account.network.request(Api.functions.account.deleteAccount(flags: 0, reason: "", password: nil))
|> map { _ -> Int32? in return nil } |> map { _ -> Int32? in return nil }
|> `catch` { error -> Signal<Int32?, AccountResetError> in |> `catch` { error -> Signal<Int32?, AccountResetError> in
if error.errorDescription.hasPrefix("2FA_CONFIRM_WAIT_") { if error.errorDescription.hasPrefix("2FA_CONFIRM_WAIT_") {

View File

@ -90,12 +90,41 @@ public extension TelegramEngine {
return _internal_updateTwoStepVerificationPassword(network: self.account.network, currentPassword: currentPassword, updatedPassword: updatedPassword) return _internal_updateTwoStepVerificationPassword(network: self.account.network, currentPassword: currentPassword, updatedPassword: updatedPassword)
} }
public func deleteAccount(reason: String) -> Signal<Never, DeleteAccountError> { public func deleteAccount(reason: String, password: String?) -> Signal<Never, DeleteAccountError> {
return self.account.network.request(Api.functions.account.deleteAccount(reason: reason)) let network = self.account.network
|> mapError { _ -> DeleteAccountError in
return .generic let passwordSignal: Signal<Api.InputCheckPasswordSRP?, DeleteAccountError>
if let password = password {
passwordSignal = _internal_twoStepAuthData(network)
|> mapError { _ -> DeleteAccountError in
return .generic
}
|> mapToSignal { authData -> Signal<Api.InputCheckPasswordSRP?, DeleteAccountError> in
if let currentPasswordDerivation = authData.currentPasswordDerivation, let srpSessionData = authData.srpSessionData {
guard let kdfResult = passwordKDF(encryptionProvider: network.encryptionProvider, password: password, derivation: currentPasswordDerivation, srpSessionData: srpSessionData) else {
return .fail(.generic)
}
return .single(.inputCheckPasswordSRP(srpId: kdfResult.id, A: Buffer(data: kdfResult.A), M1: Buffer(data: kdfResult.M1)))
} else {
return .single(nil)
}
}
} else {
passwordSignal = .single(nil)
}
return passwordSignal
|> mapToSignal { password -> Signal<Never, DeleteAccountError> in
var flags: Int32 = 0
if let _ = password {
flags |= (1 << 0)
}
return self.account.network.request(Api.functions.account.deleteAccount(flags: flags, reason: reason, password: password))
|> mapError { _ -> DeleteAccountError in
return .generic
}
|> ignoreValues
} }
|> ignoreValues
} }
public func updateTwoStepVerificationEmail(currentPassword: String, updatedEmail: String) -> Signal<UpdateTwoStepVerificationPasswordResult, UpdateTwoStepVerificationPasswordError> { public func updateTwoStepVerificationEmail(currentPassword: String, updatedEmail: String) -> Signal<UpdateTwoStepVerificationPasswordResult, UpdateTwoStepVerificationPasswordError> {

View File

@ -486,7 +486,7 @@ final class AuthorizedApplicationContext {
} }
let accountId = strongSelf.context.account.id let accountId = strongSelf.context.account.id
let accountManager = strongSelf.context.sharedContext.accountManager let accountManager = strongSelf.context.sharedContext.accountManager
let _ = (strongSelf.context.engine.auth.deleteAccount(reason: "GDPR") let _ = (strongSelf.context.engine.auth.deleteAccount(reason: "GDPR", password: nil)
|> deliverOnMainQueue).start(error: { _ in |> deliverOnMainQueue).start(error: { _ in
guard let strongSelf = self else { guard let strongSelf = self else {
return return