mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 21:41:45 +00:00
Update account deletion API
This commit is contained in:
parent
7868651acb
commit
4a9c3dacc8
@ -1147,7 +1147,7 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta
|
||||
let _ = combineLatest(
|
||||
queue: Queue.mainQueue(),
|
||||
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(
|
||||
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: false),
|
||||
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: true)
|
||||
|
||||
@ -387,7 +387,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
|
||||
proceedImpl = { [weak controller] in
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
let action: ([EnginePeer]) -> Void = { preloadedPeers in
|
||||
let action: ([EnginePeer], String?) -> Void = { preloadedPeers, password in
|
||||
let nextMode: DeleteAccountDataMode?
|
||||
switch mode {
|
||||
case .peers:
|
||||
@ -423,7 +423,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
|
||||
|
||||
let accountId = context.account.id
|
||||
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
|
||||
updateState { current in
|
||||
var updated = current
|
||||
@ -447,7 +447,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
|
||||
let _ = (preloadedGroupPeers.get()
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { peers in
|
||||
action(peers)
|
||||
action(peers, nil)
|
||||
})
|
||||
case .phone:
|
||||
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: {})]))
|
||||
return
|
||||
}
|
||||
action([])
|
||||
action([], nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -507,13 +507,13 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat
|
||||
return updated
|
||||
}
|
||||
|
||||
action([])
|
||||
action([], state.password)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
default:
|
||||
action([])
|
||||
action([], nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -156,11 +156,13 @@ 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()
|
||||
buffer.appendInt32(1099779595)
|
||||
buffer.appendInt32(-1564422284)
|
||||
serializeInt32(flags, 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)
|
||||
var result: Api.Bool?
|
||||
if let signature = reader.readInt32() {
|
||||
|
||||
@ -494,7 +494,7 @@ public enum 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 }
|
||||
|> `catch` { error -> Signal<Int32?, AccountResetError> in
|
||||
if error.errorDescription.hasPrefix("2FA_CONFIRM_WAIT_") {
|
||||
|
||||
@ -90,12 +90,41 @@ public extension TelegramEngine {
|
||||
return _internal_updateTwoStepVerificationPassword(network: self.account.network, currentPassword: currentPassword, updatedPassword: updatedPassword)
|
||||
}
|
||||
|
||||
public func deleteAccount(reason: String) -> Signal<Never, DeleteAccountError> {
|
||||
return self.account.network.request(Api.functions.account.deleteAccount(reason: reason))
|
||||
|> mapError { _ -> DeleteAccountError in
|
||||
return .generic
|
||||
public func deleteAccount(reason: String, password: String?) -> Signal<Never, DeleteAccountError> {
|
||||
let network = self.account.network
|
||||
|
||||
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> {
|
||||
|
||||
@ -486,7 +486,7 @@ final class AuthorizedApplicationContext {
|
||||
}
|
||||
let accountId = strongSelf.context.account.id
|
||||
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
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user