mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Refactor constructor use sites for types 220-229 to struct pattern
Constructors refactored: - passkey, passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow - pageRelatedArticle, pageTableCell, pageTableRow - paymentCharge - paidReactionPrivacyPeer - paymentFormMethod, paymentRequestedInfo, paymentSavedCredentialsCard Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3e5775b48e
commit
a3d66c99f0
7 changed files with 144 additions and 24 deletions
|
|
@ -139,7 +139,27 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PageRelatedArticle: TypeConstructorDescription {
|
||||
case pageRelatedArticle(flags: Int32, url: String, webpageId: Int64, title: String?, description: String?, photoId: Int64?, author: String?, publishedDate: Int32?)
|
||||
public class Cons_pageRelatedArticle {
|
||||
public var flags: Int32
|
||||
public var url: String
|
||||
public var webpageId: Int64
|
||||
public var title: String?
|
||||
public var description: String?
|
||||
public var photoId: Int64?
|
||||
public var author: String?
|
||||
public var publishedDate: Int32?
|
||||
public init(flags: Int32, url: String, webpageId: Int64, title: String?, description: String?, photoId: Int64?, author: String?, publishedDate: Int32?) {
|
||||
self.flags = flags
|
||||
self.url = url
|
||||
self.webpageId = webpageId
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.photoId = photoId
|
||||
self.author = author
|
||||
self.publishedDate = publishedDate
|
||||
}
|
||||
}
|
||||
case pageRelatedArticle(Cons_pageRelatedArticle)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -168,7 +188,19 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
indirect enum PageTableCell: TypeConstructorDescription {
|
||||
case pageTableCell(flags: Int32, text: Api.RichText?, colspan: Int32?, rowspan: Int32?)
|
||||
public class Cons_pageTableCell {
|
||||
public var flags: Int32
|
||||
public var text: Api.RichText?
|
||||
public var colspan: Int32?
|
||||
public var rowspan: Int32?
|
||||
public init(flags: Int32, text: Api.RichText?, colspan: Int32?, rowspan: Int32?) {
|
||||
self.flags = flags
|
||||
self.text = text
|
||||
self.colspan = colspan
|
||||
self.rowspan = rowspan
|
||||
}
|
||||
}
|
||||
case pageTableCell(Cons_pageTableCell)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -197,7 +229,13 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PageTableRow: TypeConstructorDescription {
|
||||
case pageTableRow(cells: [Api.PageTableCell])
|
||||
public class Cons_pageTableRow {
|
||||
public var cells: [Api.PageTableCell]
|
||||
public init(cells: [Api.PageTableCell]) {
|
||||
self.cells = cells
|
||||
}
|
||||
}
|
||||
case pageTableRow(Cons_pageTableRow)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -226,9 +264,15 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
indirect enum PaidReactionPrivacy: TypeConstructorDescription {
|
||||
public class Cons_paidReactionPrivacyPeer {
|
||||
public var peer: Api.InputPeer
|
||||
public init(peer: Api.InputPeer) {
|
||||
self.peer = peer
|
||||
}
|
||||
}
|
||||
case paidReactionPrivacyAnonymous
|
||||
case paidReactionPrivacyDefault
|
||||
case paidReactionPrivacyPeer(peer: Api.InputPeer)
|
||||
case paidReactionPrivacyPeer(Cons_paidReactionPrivacyPeer)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -271,7 +315,23 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum Passkey: TypeConstructorDescription {
|
||||
case passkey(flags: Int32, id: String, name: String, date: Int32, softwareEmojiId: Int64?, lastUsageDate: Int32?)
|
||||
public class Cons_passkey {
|
||||
public var flags: Int32
|
||||
public var id: String
|
||||
public var name: String
|
||||
public var date: Int32
|
||||
public var softwareEmojiId: Int64?
|
||||
public var lastUsageDate: Int32?
|
||||
public init(flags: Int32, id: String, name: String, date: Int32, softwareEmojiId: Int64?, lastUsageDate: Int32?) {
|
||||
self.flags = flags
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.date = date
|
||||
self.softwareEmojiId = softwareEmojiId
|
||||
self.lastUsageDate = lastUsageDate
|
||||
}
|
||||
}
|
||||
case passkey(Cons_passkey)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -300,7 +360,19 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PasswordKdfAlgo: TypeConstructorDescription {
|
||||
case passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow(salt1: Buffer, salt2: Buffer, g: Int32, p: Buffer)
|
||||
public class Cons_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow {
|
||||
public var salt1: Buffer
|
||||
public var salt2: Buffer
|
||||
public var g: Int32
|
||||
public var p: Buffer
|
||||
public init(salt1: Buffer, salt2: Buffer, g: Int32, p: Buffer) {
|
||||
self.salt1 = salt1
|
||||
self.salt2 = salt2
|
||||
self.g = g
|
||||
self.p = p
|
||||
}
|
||||
}
|
||||
case passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow(Cons_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)
|
||||
case passwordKdfAlgoUnknown
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
|
|
@ -337,7 +409,15 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PaymentCharge: TypeConstructorDescription {
|
||||
case paymentCharge(id: String, providerChargeId: String)
|
||||
public class Cons_paymentCharge {
|
||||
public var id: String
|
||||
public var providerChargeId: String
|
||||
public init(id: String, providerChargeId: String) {
|
||||
self.id = id
|
||||
self.providerChargeId = providerChargeId
|
||||
}
|
||||
}
|
||||
case paymentCharge(Cons_paymentCharge)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -366,7 +446,15 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PaymentFormMethod: TypeConstructorDescription {
|
||||
case paymentFormMethod(url: String, title: String)
|
||||
public class Cons_paymentFormMethod {
|
||||
public var url: String
|
||||
public var title: String
|
||||
public init(url: String, title: String) {
|
||||
self.url = url
|
||||
self.title = title
|
||||
}
|
||||
}
|
||||
case paymentFormMethod(Cons_paymentFormMethod)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -395,7 +483,21 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PaymentRequestedInfo: TypeConstructorDescription {
|
||||
case paymentRequestedInfo(flags: Int32, name: String?, phone: String?, email: String?, shippingAddress: Api.PostAddress?)
|
||||
public class Cons_paymentRequestedInfo {
|
||||
public var flags: Int32
|
||||
public var name: String?
|
||||
public var phone: String?
|
||||
public var email: String?
|
||||
public var shippingAddress: Api.PostAddress?
|
||||
public init(flags: Int32, name: String?, phone: String?, email: String?, shippingAddress: Api.PostAddress?) {
|
||||
self.flags = flags
|
||||
self.name = name
|
||||
self.phone = phone
|
||||
self.email = email
|
||||
self.shippingAddress = shippingAddress
|
||||
}
|
||||
}
|
||||
case paymentRequestedInfo(Cons_paymentRequestedInfo)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
@ -424,7 +526,15 @@ public extension Api {
|
|||
}
|
||||
public extension Api {
|
||||
enum PaymentSavedCredentials: TypeConstructorDescription {
|
||||
case paymentSavedCredentialsCard(id: String, title: String)
|
||||
public class Cons_paymentSavedCredentialsCard {
|
||||
public var id: String
|
||||
public var title: String
|
||||
public init(id: String, title: String) {
|
||||
self.id = id
|
||||
self.title = title
|
||||
}
|
||||
}
|
||||
case paymentSavedCredentialsCard(Cons_paymentSavedCredentialsCard)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
#if DEBUG
|
||||
|
|
|
|||
|
|
@ -364,7 +364,8 @@ public enum TwoStepPasswordDerivation {
|
|||
switch apiAlgo {
|
||||
case .passwordKdfAlgoUnknown:
|
||||
self = .unknown
|
||||
case let .passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow(salt1, salt2, g, p):
|
||||
case let .passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow(passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPowData):
|
||||
let (salt1, salt2, g, p) = (passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPowData.salt1, passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPowData.salt2, passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPowData.g, passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPowData.p)
|
||||
self = .sha256_sha256_PBKDF2_HMAC_sha512_sha256_srp(salt1: salt1.makeData(), salt2: salt2.makeData(), iterations: 100000, g: g, p: p.makeData())
|
||||
}
|
||||
}
|
||||
|
|
@ -375,7 +376,7 @@ public enum TwoStepPasswordDerivation {
|
|||
return .passwordKdfAlgoUnknown
|
||||
case let .sha256_sha256_PBKDF2_HMAC_sha512_sha256_srp(salt1, salt2, iterations, g, p):
|
||||
precondition(iterations == 100000)
|
||||
return .passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow(salt1: Buffer(data: salt1), salt2: Buffer(data: salt2), g: g, p: Buffer(data: p))
|
||||
return .passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow(.init(salt1: Buffer(data: salt1), salt2: Buffer(data: salt2), g: g, p: Buffer(data: p)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -497,7 +498,8 @@ public final class TelegramPasskey: Equatable {
|
|||
extension TelegramPasskey {
|
||||
convenience init(apiPasskey: Api.Passkey) {
|
||||
switch apiPasskey {
|
||||
case let .passkey(_, id, name, date, softwareEmojiId, lastUsageDate):
|
||||
case let .passkey(passkeyData):
|
||||
let (id, name, date, softwareEmojiId, lastUsageDate) = (passkeyData.id, passkeyData.name, passkeyData.date, passkeyData.softwareEmojiId, passkeyData.lastUsageDate)
|
||||
self.init(id: id, name: name, date: date, emojiId: softwareEmojiId, lastUsageDate: lastUsageDate)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ extension InstantPageListItem {
|
|||
extension InstantPageTableCell {
|
||||
convenience init(apiTableCell: Api.PageTableCell) {
|
||||
switch apiTableCell {
|
||||
case let .pageTableCell(flags, text, colspan, rowspan):
|
||||
case let .pageTableCell(pageTableCellData):
|
||||
let (flags, text, colspan, rowspan) = (pageTableCellData.flags, pageTableCellData.text, pageTableCellData.colspan, pageTableCellData.rowspan)
|
||||
var alignment = TableHorizontalAlignment.left
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
alignment = .center
|
||||
|
|
@ -74,7 +75,8 @@ extension InstantPageTableCell {
|
|||
extension InstantPageTableRow {
|
||||
convenience init(apiTableRow: Api.PageTableRow) {
|
||||
switch apiTableRow {
|
||||
case let .pageTableRow(cells):
|
||||
case let .pageTableRow(pageTableRowData):
|
||||
let cells = pageTableRowData.cells
|
||||
self.init(cells: cells.map({ InstantPageTableCell(apiTableCell: $0) }))
|
||||
}
|
||||
}
|
||||
|
|
@ -83,7 +85,8 @@ extension InstantPageTableRow {
|
|||
extension InstantPageRelatedArticle {
|
||||
convenience init(apiRelatedArticle: Api.PageRelatedArticle) {
|
||||
switch apiRelatedArticle {
|
||||
case let .pageRelatedArticle(_, url, webpageId, title, description, photoId, author, publishedDate):
|
||||
case let .pageRelatedArticle(pageRelatedArticleData):
|
||||
let (url, webpageId, title, description, photoId, author, publishedDate) = (pageRelatedArticleData.url, pageRelatedArticleData.webpageId, pageRelatedArticleData.title, pageRelatedArticleData.description, pageRelatedArticleData.photoId, pageRelatedArticleData.author, pageRelatedArticleData.publishedDate)
|
||||
var posterPhotoId: MediaId?
|
||||
if let photoId = photoId {
|
||||
posterPhotoId = MediaId(namespace: Namespaces.Media.CloudImage, id: photoId)
|
||||
|
|
|
|||
|
|
@ -217,7 +217,8 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
|
|||
let (peer, currency, totalAmount, payload, charge) = (messageActionPaymentRefundedData.peer, messageActionPaymentRefundedData.currency, messageActionPaymentRefundedData.totalAmount, messageActionPaymentRefundedData.payload, messageActionPaymentRefundedData.charge)
|
||||
let transactionId: String
|
||||
switch charge {
|
||||
case let .paymentCharge(id, _):
|
||||
case let .paymentCharge(paymentChargeData):
|
||||
let id = paymentChargeData.id
|
||||
transactionId = id
|
||||
}
|
||||
return TelegramMediaAction(action: .paymentRefunded(peerId: peer.peerId, currency: currency, totalAmount: totalAmount, payload: payload?.makeData(), transactionId: transactionId))
|
||||
|
|
|
|||
|
|
@ -1902,7 +1902,8 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
|
|||
mappedPrivacy = .default
|
||||
case .paidReactionPrivacyAnonymous:
|
||||
mappedPrivacy = .anonymous
|
||||
case let .paidReactionPrivacyPeer(peer):
|
||||
case let .paidReactionPrivacyPeer(paidReactionPrivacyPeerData):
|
||||
let peer = paidReactionPrivacyPeerData.peer
|
||||
let peerId: PeerId
|
||||
switch peer {
|
||||
case let .inputPeerChannel(inputPeerChannelData):
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ func _internal_updateStarsReactionPrivacy(account: Account, messageId: MessageId
|
|||
guard let inputPrivacyPeer else {
|
||||
return .complete()
|
||||
}
|
||||
mappedPrivacy = .paidReactionPrivacyPeer(peer: inputPrivacyPeer)
|
||||
mappedPrivacy = .paidReactionPrivacyPeer(.init(peer: inputPrivacyPeer))
|
||||
}
|
||||
|
||||
return account.network.request(Api.functions.messages.togglePaidReactionPrivacy(peer: inputPeer, msgId: messageId.id, private: mappedPrivacy))
|
||||
|
|
@ -431,7 +431,7 @@ private func requestSendStarsReaction(postbox: Postbox, network: Network, stateM
|
|||
guard let inputPrivacyPeer = transaction.getPeer(peerId).flatMap(apiInputPeer) else {
|
||||
return nil
|
||||
}
|
||||
mappedPrivacy = .paidReactionPrivacyPeer(peer: inputPrivacyPeer)
|
||||
mappedPrivacy = .paidReactionPrivacyPeer(.init(peer: inputPrivacyPeer))
|
||||
}
|
||||
privacy = mappedPrivacy
|
||||
break
|
||||
|
|
|
|||
|
|
@ -171,7 +171,8 @@ public struct BotPaymentMethod: Equatable {
|
|||
extension BotPaymentMethod {
|
||||
init(apiPaymentFormMethod: Api.PaymentFormMethod) {
|
||||
switch apiPaymentFormMethod {
|
||||
case let .paymentFormMethod(url, title):
|
||||
case let .paymentFormMethod(paymentFormMethodData):
|
||||
let (url, title) = (paymentFormMethodData.url, paymentFormMethodData.title)
|
||||
self.init(url: url, title: title)
|
||||
}
|
||||
}
|
||||
|
|
@ -236,7 +237,8 @@ extension BotPaymentInvoice {
|
|||
extension BotPaymentRequestedInfo {
|
||||
init(apiInfo: Api.PaymentRequestedInfo) {
|
||||
switch apiInfo {
|
||||
case let .paymentRequestedInfo(_, name, phone, email, shippingAddress):
|
||||
case let .paymentRequestedInfo(paymentRequestedInfoData):
|
||||
let (name, phone, email, shippingAddress) = (paymentRequestedInfoData.name, paymentRequestedInfoData.phone, paymentRequestedInfoData.email, paymentRequestedInfoData.shippingAddress)
|
||||
var parsedShippingAddress: BotPaymentShippingAddress?
|
||||
if let shippingAddress = shippingAddress {
|
||||
switch shippingAddress {
|
||||
|
|
@ -560,7 +562,8 @@ func _internal_fetchBotPaymentForm(accountPeerId: PeerId, postbox: Postbox, netw
|
|||
let parsedSavedInfo = savedInfo.flatMap(BotPaymentRequestedInfo.init)
|
||||
let parsedSavedCredentials = savedCredentials?.map({ savedCredentials -> BotPaymentSavedCredentials in
|
||||
switch savedCredentials {
|
||||
case let .paymentSavedCredentialsCard(id, title):
|
||||
case let .paymentSavedCredentialsCard(paymentSavedCredentialsCardData):
|
||||
let (id, title) = (paymentSavedCredentialsCardData.id, paymentSavedCredentialsCardData.title)
|
||||
return .card(id: id, title: title)
|
||||
}
|
||||
}) ?? []
|
||||
|
|
@ -655,7 +658,7 @@ func _internal_validateBotPaymentForm(account: Account, saveInfo: Bool, source:
|
|||
infoFlags |= (1 << 3)
|
||||
apiShippingAddress = .postAddress(streetLine1: address.streetLine1, streetLine2: address.streetLine2, city: address.city, state: address.state, countryIso2: address.countryIso2, postCode: address.postCode)
|
||||
}
|
||||
return account.network.request(Api.functions.payments.validateRequestedInfo(flags: flags, invoice: invoice, info: .paymentRequestedInfo(flags: infoFlags, name: formInfo.name, phone: formInfo.phone, email: formInfo.email, shippingAddress: apiShippingAddress)))
|
||||
return account.network.request(Api.functions.payments.validateRequestedInfo(flags: flags, invoice: invoice, info: .paymentRequestedInfo(.init(flags: infoFlags, name: formInfo.name, phone: formInfo.phone, email: formInfo.email, shippingAddress: apiShippingAddress))))
|
||||
|> mapError { error -> ValidateBotPaymentFormError in
|
||||
if error.errorDescription == "SHIPPING_NOT_AVAILABLE" {
|
||||
return .shippingNotAvailable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue