WinterGram/submodules/PassportUI/Sources/SecureIdAuthControllerState.swift
isaac 86d1456552 Postbox -> TelegramEngine waves 107-137 (squashed)
31 waves of consumer-side migration from `import Postbox` to TelegramEngine
typealiases. Net: 173 import drops + 39 BUILD-dep drops + 1 new typealias
(`EngineStoryId = StoryId`, wave 113).

Wave shapes used:
- Orphan-import sweeps (107, 108, 128): drop `import Postbox` from files
  whose only Postbox-symbol reference was the import line itself, then
  resolve build failures. Methodology requires token-level (`grep -oE`)
  filtering, not line-level, to avoid masking real Postbox usage on lines
  that also contain `Namespaces.X` references.
- Identifier-swap mini-waves (109-127, 129-134, 136-137): rename
  Postbox-typealiased identifiers to engine equivalents
  (PeerId -> EnginePeer.Id, MessageId -> EngineMessage.Id,
  MediaId -> EngineMedia.Id, MessageIndex -> EngineMessage.Index,
  StoryId -> EngineStoryId, ItemCollectionId -> EngineItemCollectionId,
  PreferencesEntry -> EnginePreferencesEntry,
  FetchResourceSourceType/Error -> EngineFetchResourceSourceType/Error,
  MemoryBuffer -> EngineMemoryBuffer, MessageTags -> EngineMessage.Tags,
  MessageAttribute -> EngineMessage.Attribute,
  TempBox -> EngineTempBox).
- Asset-string FP-only orphans (124).
- Typealias addition + drain (113): added `EngineStoryId` typealias to
  TelegramCore, then drained 3+11 consumer sites.

Hard blockers identified during these waves (must restore `import Postbox`
when present): MediaResource[A-Za-z]* (any suffix -- the literal
`MediaResource` matches don't catch MediaResourceData/MediaResourceId/etc.),
Postbox/MediaBox/MediaResource raw types, PostboxCoding/PostboxEncoder/
PostboxDecoder, TempBoxFile, ValueBoxKey, PostboxView, combinedView,
HashFunctions, postboxLog, openPostbox, declareEncodable, PeerView,
MessageHistoryView, MessageHistoryThreadData, CachedPeerData, RenderedPeer,
SelectivePrivacyPeer, SimpleDictionary, ItemCollectionInfosView,
ItemCollectionItem, ItemCollectionItemIndex, ItemCollectionViewEntryIndex,
ChatListIndex, ChatListEntrySummaryComponents, CodableEntry,
MessageHistoryThread, MessageHistoryAnchorIndex,
MessageHistoryEntryLocation, PeerStoryStats, PeerNameIndex,
PeerSummaryCounterTags, ChatListTotalUnreadStateCategory/Stats,
arePeersEqual. Protocol-shape blockers: bare `Peer`/`Message`/`Media`
in function signatures, generic args, enum-case payloads, or dict value
types (e.g., `[PeerId: Peer]`, `case messages([Message])`,
`Signal<(Peer?, ...), NoError>`).

`replace_all PeerId -> EnginePeer.Id` is dangerous: mangles compound
names like `failedPeerId`, `ContactListPeerId`, `nextRemoteMediaId`,
`replyToMessageId`. Pre-flight grep `\b[a-z][a-zA-Z]*PeerId\b` and only
replace_all if 0 matches.

Also removes unneeded design/plan docs from a separate (link-highlighting)
feature branch:
- docs/superpowers/plans/2026-05-02-link-highlighting-modern-path-fixes.md
- docs/superpowers/specs/2026-05-02-link-highlighting-modern-path-fixes-design.md

Squashed commits: 6d82c2980d..e6de5d53a3 (59 commits, including
per-wave content commits and per-wave CLAUDE.md bumps).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 10:28:50 +02:00

154 lines
4.9 KiB
Swift

import Foundation
import UIKit
import TelegramCore
struct SecureIdEncryptedFormData {
let form: EncryptedSecureIdForm
let primaryLanguageByCountry: [String: String]
let accountPeer: EnginePeer
let servicePeer: EnginePeer
}
enum SecureIdAuthPasswordChallengeState {
case none
case checking
case invalid
}
enum SecureIdAuthControllerVerificationNoChallengeState: Equatable {
case notSet
case awaitingConfirmation(password: String?, emailPattern: String, codeLength: Int32?)
}
enum SecureIdAuthControllerVerificationState: Equatable {
case noChallenge(SecureIdAuthControllerVerificationNoChallengeState)
case passwordChallenge(hint: String, state: SecureIdAuthPasswordChallengeState, hasRecoveryEmail: Bool)
case verified(SecureIdAccessContext)
}
struct SecureIdAuthControllerFormState: Equatable {
var twoStepEmail: String?
var encryptedFormData: SecureIdEncryptedFormData?
var formData: SecureIdForm?
var verificationState: SecureIdAuthControllerVerificationState?
var removingValues: Bool = false
static func ==(lhs: SecureIdAuthControllerFormState, rhs: SecureIdAuthControllerFormState) -> Bool {
if let lhsTwoStepEmail = lhs.twoStepEmail, let rhsTwoStepEmail = rhs.twoStepEmail, lhsTwoStepEmail != rhsTwoStepEmail {
return false
} else if (lhs.twoStepEmail != nil) != (rhs.twoStepEmail != nil) {
return false
}
if (lhs.encryptedFormData != nil) != (rhs.encryptedFormData != nil) {
return false
}
if (lhs.formData != nil) != (rhs.formData != nil) {
return false
}
if let lhsFormData = lhs.formData, let rhsFormData = rhs.formData {
if lhsFormData != rhsFormData {
return false
}
} else if (lhs.formData != nil) != (rhs.formData != nil) {
return false
}
if lhs.verificationState != rhs.verificationState {
return false
}
if lhs.removingValues != rhs.removingValues {
return false
}
return true
}
}
struct SecureIdAuthControllerListState: Equatable {
var accountPeer: EnginePeer?
var twoStepEmail: String?
var verificationState: SecureIdAuthControllerVerificationState?
var encryptedValues: EncryptedAllSecureIdValues?
var primaryLanguageByCountry: [String: String]?
var values: [SecureIdValueWithContext]?
var removingValues: Bool = false
static func ==(lhs: SecureIdAuthControllerListState, rhs: SecureIdAuthControllerListState) -> Bool {
if lhs.accountPeer != rhs.accountPeer {
return false
}
if let lhsTwoStepEmail = lhs.twoStepEmail, let rhsTwoStepEmail = rhs.twoStepEmail, lhsTwoStepEmail != rhsTwoStepEmail {
return false
} else if (lhs.twoStepEmail != nil) != (rhs.twoStepEmail != nil) {
return false
}
if lhs.verificationState != rhs.verificationState {
return false
}
if (lhs.encryptedValues != nil) != (rhs.encryptedValues != nil) {
return false
}
if lhs.primaryLanguageByCountry != rhs.primaryLanguageByCountry {
return false
}
if lhs.values != rhs.values {
return false
}
if lhs.removingValues != rhs.removingValues {
return false
}
return true
}
}
enum SecureIdAuthControllerState: Equatable {
case form(SecureIdAuthControllerFormState)
case list(SecureIdAuthControllerListState)
var twoStepEmail: String? {
get {
switch self {
case let .form(form):
return form.twoStepEmail
case let .list(list):
return list.twoStepEmail
}
} set(value) {
switch self {
case var .form(form):
form.twoStepEmail = value
self = .form(form)
case var .list(list):
list.twoStepEmail = value
self = .list(list)
}
}
}
var verificationState: SecureIdAuthControllerVerificationState? {
get {
switch self {
case let .form(form):
return form.verificationState
case let .list(list):
return list.verificationState
}
} set(value) {
switch self {
case var .form(form):
form.verificationState = value
self = .form(form)
case var .list(list):
list.verificationState = value
self = .list(list)
}
}
}
var removingValues: Bool {
switch self {
case let .form(form):
return form.removingValues
case let .list(list):
return list.removingValues
}
}
}