Refactor Api types 13-22 to use struct-wrapped constructors

Types refactored:
- AvailableReaction, BankCardOpenUrl, Birthday, Boost
- BotApp, BotAppSettings, BotBusinessConnection, BotCommand

Updated pattern matching and construction sites in TelegramCore.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Isaac 2026-01-15 19:19:24 +08:00
parent 94cb9d3228
commit a526aee73e
10 changed files with 157 additions and 19 deletions

View file

@ -565,7 +565,31 @@ public extension Api {
}
public extension Api {
enum AvailableReaction: TypeConstructorDescription {
case availableReaction(flags: Int32, reaction: String, title: String, staticIcon: Api.Document, appearAnimation: Api.Document, selectAnimation: Api.Document, activateAnimation: Api.Document, effectAnimation: Api.Document, aroundAnimation: Api.Document?, centerIcon: Api.Document?)
public class Cons_availableReaction {
public var flags: Int32
public var reaction: String
public var title: String
public var staticIcon: Api.Document
public var appearAnimation: Api.Document
public var selectAnimation: Api.Document
public var activateAnimation: Api.Document
public var effectAnimation: Api.Document
public var aroundAnimation: Api.Document?
public var centerIcon: Api.Document?
public init(flags: Int32, reaction: String, title: String, staticIcon: Api.Document, appearAnimation: Api.Document, selectAnimation: Api.Document, activateAnimation: Api.Document, effectAnimation: Api.Document, aroundAnimation: Api.Document?, centerIcon: Api.Document?) {
self.flags = flags
self.reaction = reaction
self.title = title
self.staticIcon = staticIcon
self.appearAnimation = appearAnimation
self.selectAnimation = selectAnimation
self.activateAnimation = activateAnimation
self.effectAnimation = effectAnimation
self.aroundAnimation = aroundAnimation
self.centerIcon = centerIcon
}
}
case availableReaction(Cons_availableReaction)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -594,7 +618,15 @@ public extension Api {
}
public extension Api {
enum BankCardOpenUrl: TypeConstructorDescription {
case bankCardOpenUrl(url: String, name: String)
public class Cons_bankCardOpenUrl {
public var url: String
public var name: String
public init(url: String, name: String) {
self.url = url
self.name = name
}
}
case bankCardOpenUrl(Cons_bankCardOpenUrl)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -684,7 +716,19 @@ public extension Api {
}
public extension Api {
enum Birthday: TypeConstructorDescription {
case birthday(flags: Int32, day: Int32, month: Int32, year: Int32?)
public class Cons_birthday {
public var flags: Int32
public var day: Int32
public var month: Int32
public var year: Int32?
public init(flags: Int32, day: Int32, month: Int32, year: Int32?) {
self.flags = flags
self.day = day
self.month = month
self.year = year
}
}
case birthday(Cons_birthday)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -750,7 +794,29 @@ public extension Api {
}
public extension Api {
enum Boost: TypeConstructorDescription {
case boost(flags: Int32, id: String, userId: Int64?, giveawayMsgId: Int32?, date: Int32, expires: Int32, usedGiftSlug: String?, multiplier: Int32?, stars: Int64?)
public class Cons_boost {
public var flags: Int32
public var id: String
public var userId: Int64?
public var giveawayMsgId: Int32?
public var date: Int32
public var expires: Int32
public var usedGiftSlug: String?
public var multiplier: Int32?
public var stars: Int64?
public init(flags: Int32, id: String, userId: Int64?, giveawayMsgId: Int32?, date: Int32, expires: Int32, usedGiftSlug: String?, multiplier: Int32?, stars: Int64?) {
self.flags = flags
self.id = id
self.userId = userId
self.giveawayMsgId = giveawayMsgId
self.date = date
self.expires = expires
self.usedGiftSlug = usedGiftSlug
self.multiplier = multiplier
self.stars = stars
}
}
case boost(Cons_boost)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -779,7 +845,29 @@ public extension Api {
}
public extension Api {
enum BotApp: TypeConstructorDescription {
case botApp(flags: Int32, id: Int64, accessHash: Int64, shortName: String, title: String, description: String, photo: Api.Photo, document: Api.Document?, hash: Int64)
public class Cons_botApp {
public var flags: Int32
public var id: Int64
public var accessHash: Int64
public var shortName: String
public var title: String
public var description: String
public var photo: Api.Photo
public var document: Api.Document?
public var hash: Int64
public init(flags: Int32, id: Int64, accessHash: Int64, shortName: String, title: String, description: String, photo: Api.Photo, document: Api.Document?, hash: Int64) {
self.flags = flags
self.id = id
self.accessHash = accessHash
self.shortName = shortName
self.title = title
self.description = description
self.photo = photo
self.document = document
self.hash = hash
}
}
case botApp(Cons_botApp)
case botAppNotModified
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
@ -816,7 +904,23 @@ public extension Api {
}
public extension Api {
enum BotAppSettings: TypeConstructorDescription {
case botAppSettings(flags: Int32, placeholderPath: Buffer?, backgroundColor: Int32?, backgroundDarkColor: Int32?, headerColor: Int32?, headerDarkColor: Int32?)
public class Cons_botAppSettings {
public var flags: Int32
public var placeholderPath: Buffer?
public var backgroundColor: Int32?
public var backgroundDarkColor: Int32?
public var headerColor: Int32?
public var headerDarkColor: Int32?
public init(flags: Int32, placeholderPath: Buffer?, backgroundColor: Int32?, backgroundDarkColor: Int32?, headerColor: Int32?, headerDarkColor: Int32?) {
self.flags = flags
self.placeholderPath = placeholderPath
self.backgroundColor = backgroundColor
self.backgroundDarkColor = backgroundDarkColor
self.headerColor = headerColor
self.headerDarkColor = headerDarkColor
}
}
case botAppSettings(Cons_botAppSettings)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG

View file

@ -1,6 +1,22 @@
public extension Api {
enum BotBusinessConnection: TypeConstructorDescription {
case botBusinessConnection(flags: Int32, connectionId: String, userId: Int64, dcId: Int32, date: Int32, rights: Api.BusinessBotRights?)
public class Cons_botBusinessConnection {
public var flags: Int32
public var connectionId: String
public var userId: Int64
public var dcId: Int32
public var date: Int32
public var rights: Api.BusinessBotRights?
public init(flags: Int32, connectionId: String, userId: Int64, dcId: Int32, date: Int32, rights: Api.BusinessBotRights?) {
self.flags = flags
self.connectionId = connectionId
self.userId = userId
self.dcId = dcId
self.date = date
self.rights = rights
}
}
case botBusinessConnection(Cons_botBusinessConnection)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -29,7 +45,15 @@ public extension Api {
}
public extension Api {
enum BotCommand: TypeConstructorDescription {
case botCommand(command: String, description: String)
public class Cons_botCommand {
public var command: String
public var description: String
public init(command: String, description: String) {
self.command = command
self.description = description
}
}
case botCommand(Cons_botCommand)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG

View file

@ -16,7 +16,8 @@ extension BotMenuButton {
extension BotAppSettings {
init(apiBotAppSettings: Api.BotAppSettings) {
switch apiBotAppSettings {
case let .botAppSettings(_, placeholder, backgroundColor, backgroundDarkColor, headerColor, headerDarkColor):
case let .botAppSettings(botAppSettingsData):
let (_, placeholder, backgroundColor, backgroundDarkColor, headerColor, headerDarkColor) = (botAppSettingsData.flags, botAppSettingsData.placeholderPath, botAppSettingsData.backgroundColor, botAppSettingsData.backgroundDarkColor, botAppSettingsData.headerColor, botAppSettingsData.headerDarkColor)
self.init(
placeholderData: placeholder.flatMap { $0.makeData() },
backgroundColor: backgroundColor,
@ -52,7 +53,8 @@ extension BotInfo {
if let apiCommands = apiCommands {
commands = apiCommands.map { command in
switch command {
case let .botCommand(command, description):
case let .botCommand(botCommandData):
let (command, description) = (botCommandData.command, botCommandData.description)
return BotCommand(text: command, description: description)
}
}

View file

@ -56,7 +56,8 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
return TelegramMediaAction(action: .botDomainAccessGranted(domain: domain))
} else {
var appName: String?
if case let .botApp(_, _, _, _, appNameValue, _, _, _, _) = app {
if case let .botApp(botAppData) = app {
let appNameValue = botAppData.title
appName = appNameValue
}
var type: BotSendMessageAccessGrantedType?

View file

@ -1774,7 +1774,8 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
let botPeerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))
let commands: [BotCommand] = apiCommands.map { command in
switch command {
case let .botCommand(command, description):
case let .botCommand(botCommandData):
let (command, description) = (botCommandData.command, botCommandData.description)
return BotCommand(text: command, description: description)
}
}

View file

@ -314,7 +314,8 @@ public final class AvailableReactions: Equatable, Codable {
private extension AvailableReactions.Reaction {
convenience init?(apiReaction: Api.AvailableReaction) {
switch apiReaction {
case let .availableReaction(flags, reaction, title, staticIcon, appearAnimation, selectAnimation, activateAnimation, effectAnimation, aroundAnimation, centerIcon):
case let .availableReaction(availableReactionData):
let (flags, reaction, title, staticIcon, appearAnimation, selectAnimation, activateAnimation, effectAnimation, aroundAnimation, centerIcon) = (availableReactionData.flags, availableReactionData.reaction, availableReactionData.title, availableReactionData.staticIcon, availableReactionData.appearAnimation, availableReactionData.selectAnimation, availableReactionData.activateAnimation, availableReactionData.effectAnimation, availableReactionData.aroundAnimation, availableReactionData.centerIcon)
guard let staticIconFile = telegramMediaFileFromApiDocument(staticIcon, altDocuments: []) else {
return nil
}

View file

@ -279,7 +279,8 @@ private final class ChannelBoostersContextImpl {
var resultBoosts: [ChannelBoostersContext.State.Boost] = []
for boost in boosts {
switch boost {
case let .boost(flags, id, userId, giveawayMessageId, date, expires, usedGiftSlug, multiplier, stars):
case let .boost(boostData):
let (flags, id, userId, giveawayMessageId, date, expires, usedGiftSlug, multiplier, stars) = (boostData.flags, boostData.id, boostData.userId, boostData.giveawayMsgId, boostData.date, boostData.expires, boostData.usedGiftSlug, boostData.multiplier, boostData.stars)
var boostFlags: ChannelBoostersContext.State.Boost.Flags = []
var boostPeer: EnginePeer?
if let userId = userId {

View file

@ -749,7 +749,8 @@ func _internal_getBotApp(account: Account, reference: BotAppReference) -> Signal
switch result {
case let .botApp(botAppFlags, app):
switch app {
case let .botApp(flags, id, accessHash, shortName, title, description, photo, document, hash):
case let .botApp(botAppData):
let (flags, id, accessHash, shortName, title, description, photo, document, hash) = (botAppData.flags, botAppData.id, botAppData.accessHash, botAppData.shortName, botAppData.title, botAppData.description, botAppData.photo, botAppData.document, botAppData.hash)
let _ = flags
var appFlags = BotApp.Flags()
if (botAppFlags & (1 << 0)) != 0 {
@ -775,7 +776,8 @@ func _internal_getBotApp(account: Account, reference: BotAppReference) -> Signal
extension BotApp {
convenience init?(apiBotApp: Api.BotApp) {
switch apiBotApp {
case let .botApp(_, id, accessHash, shortName, title, description, photo, document, hash):
case let .botApp(botAppData):
let (id, accessHash, shortName, title, description, photo, document, hash) = (botAppData.id, botAppData.accessHash, botAppData.shortName, botAppData.title, botAppData.description, botAppData.photo, botAppData.document, botAppData.hash)
self.init(id: id, accessHash: accessHash, shortName: shortName, title: title, description: description, photo: telegramMediaImageFromApiPhoto(photo), document: document.flatMap { telegramMediaFileFromApiDocument($0, altDocuments: []) }, hash: hash, flags: [])
case .botAppNotModified:
return nil

View file

@ -40,7 +40,8 @@ public struct BankCardInfo {
extension BankCardUrl {
init(apiBankCardOpenUrl: Api.BankCardOpenUrl) {
switch apiBankCardOpenUrl {
case let .bankCardOpenUrl(url, name):
case let .bankCardOpenUrl(bankCardOpenUrlData):
let (url, name) = (bankCardOpenUrlData.url, bankCardOpenUrlData.name)
self.title = name
self.url = url
}

View file

@ -59,7 +59,8 @@ public final class TelegramBirthday: Codable, Equatable {
extension TelegramBirthday {
convenience init(apiBirthday: Api.Birthday) {
switch apiBirthday {
case let .birthday(_, day, month, year):
case let .birthday(birthdayData):
let (_, day, month, year) = (birthdayData.flags, birthdayData.day, birthdayData.month, birthdayData.year)
self.init(
day: day,
month: month,
@ -73,7 +74,7 @@ extension TelegramBirthday {
if let _ = self.year {
flags |= (1 << 0)
}
return .birthday(flags: flags, day: self.day, month: self.month, year: self.year)
return .birthday(Api.Birthday.Cons_birthday(flags: flags, day: self.day, month: self.month, year: self.year))
}
}