Refactor Api types 60-64 to use struct-wrapped constructors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Isaac 2026-01-16 01:29:09 +08:00
parent dc3d2dc789
commit df3b1cddcf
13 changed files with 106 additions and 25 deletions

View file

@ -149,8 +149,28 @@ public extension Api {
}
public extension Api {
enum ChatParticipants: TypeConstructorDescription {
case chatParticipants(chatId: Int64, participants: [Api.ChatParticipant], version: Int32)
case chatParticipantsForbidden(flags: Int32, chatId: Int64, selfParticipant: Api.ChatParticipant?)
public class Cons_chatParticipants {
public var chatId: Int64
public var participants: [Api.ChatParticipant]
public var version: Int32
public init(chatId: Int64, participants: [Api.ChatParticipant], version: Int32) {
self.chatId = chatId
self.participants = participants
self.version = version
}
}
public class Cons_chatParticipantsForbidden {
public var flags: Int32
public var chatId: Int64
public var selfParticipant: Api.ChatParticipant?
public init(flags: Int32, chatId: Int64, selfParticipant: Api.ChatParticipant?) {
self.flags = flags
self.chatId = chatId
self.selfParticipant = selfParticipant
}
}
case chatParticipants(Cons_chatParticipants)
case chatParticipantsForbidden(Cons_chatParticipantsForbidden)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -186,7 +206,19 @@ public extension Api {
}
public extension Api {
enum ChatPhoto: TypeConstructorDescription {
case chatPhoto(flags: Int32, photoId: Int64, strippedThumb: Buffer?, dcId: Int32)
public class Cons_chatPhoto {
public var flags: Int32
public var photoId: Int64
public var strippedThumb: Buffer?
public var dcId: Int32
public init(flags: Int32, photoId: Int64, strippedThumb: Buffer?, dcId: Int32) {
self.flags = flags
self.photoId = photoId
self.strippedThumb = strippedThumb
self.dcId = dcId
}
}
case chatPhoto(Cons_chatPhoto)
case chatPhotoEmpty
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
@ -223,9 +255,21 @@ public extension Api {
}
public extension Api {
enum ChatReactions: TypeConstructorDescription {
case chatReactionsAll(flags: Int32)
public class Cons_chatReactionsAll {
public var flags: Int32
public init(flags: Int32) {
self.flags = flags
}
}
public class Cons_chatReactionsSome {
public var reactions: [Api.Reaction]
public init(reactions: [Api.Reaction]) {
self.reactions = reactions
}
}
case chatReactionsAll(Cons_chatReactionsAll)
case chatReactionsNone
case chatReactionsSome(reactions: [Api.Reaction])
case chatReactionsSome(Cons_chatReactionsSome)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -268,8 +312,22 @@ public extension Api {
}
public extension Api {
enum ChatTheme: TypeConstructorDescription {
case chatTheme(emoticon: String)
case chatThemeUniqueGift(gift: Api.StarGift, themeSettings: [Api.ThemeSettings])
public class Cons_chatTheme {
public var emoticon: String
public init(emoticon: String) {
self.emoticon = emoticon
}
}
public class Cons_chatThemeUniqueGift {
public var gift: Api.StarGift
public var themeSettings: [Api.ThemeSettings]
public init(gift: Api.StarGift, themeSettings: [Api.ThemeSettings]) {
self.gift = gift
self.themeSettings = themeSettings
}
}
case chatTheme(Cons_chatTheme)
case chatThemeUniqueGift(Cons_chatThemeUniqueGift)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -305,7 +363,19 @@ public extension Api {
}
public extension Api {
enum CodeSettings: TypeConstructorDescription {
case codeSettings(flags: Int32, logoutTokens: [Buffer]?, token: String?, appSandbox: Api.Bool?)
public class Cons_codeSettings {
public var flags: Int32
public var logoutTokens: [Buffer]?
public var token: String?
public var appSandbox: Api.Bool?
public init(flags: Int32, logoutTokens: [Buffer]?, token: String?, appSandbox: Api.Bool?) {
self.flags = flags
self.logoutTokens = logoutTokens
self.token = token
self.appSandbox = appSandbox
}
}
case codeSettings(Cons_codeSettings)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG

View file

@ -6,7 +6,8 @@ import TelegramApi
func imageRepresentationsForApiChatPhoto(_ photo: Api.ChatPhoto) -> [TelegramMediaImageRepresentation] {
var representations: [TelegramMediaImageRepresentation] = []
switch photo {
case let .chatPhoto(flags, photoId, strippedThumb, dcId):
case let .chatPhoto(chatPhotoData):
let (flags, photoId, strippedThumb, dcId) = (chatPhotoData.flags, chatPhotoData.photoId, chatPhotoData.strippedThumb, chatPhotoData.dcId)
let hasVideo = (flags & (1 << 0)) != 0
let smallResource: TelegramMediaResource
let fullSizeResource: TelegramMediaResource

View file

@ -22,7 +22,8 @@ extension GroupParticipant {
extension CachedGroupParticipants {
convenience init?(apiParticipants: Api.ChatParticipants) {
switch apiParticipants {
case let .chatParticipants(_, participants, version):
case let .chatParticipants(chatParticipantsData):
let (participants, version) = (chatParticipantsData.participants, chatParticipantsData.version)
self.init(participants: participants.map { GroupParticipant(apiParticipant: $0) }, version: version)
case .chatParticipantsForbidden:
return nil

View file

@ -185,7 +185,7 @@ public func sendAuthorizationCode(accountManager: AccountManager<TelegramAccount
appSandbox = pushNotificationConfiguration.isSandbox ? .boolTrue : .boolFalse
}
let sendCode = Api.functions.auth.sendCode(phoneNumber: phoneNumber, apiId: apiId, apiHash: apiHash, settings: .codeSettings(flags: flags, logoutTokens: authTokens.map { Buffer(data: $0) }, token: token, appSandbox: appSandbox))
let sendCode = Api.functions.auth.sendCode(phoneNumber: phoneNumber, apiId: apiId, apiHash: apiHash, settings: .codeSettings(.init(flags: flags, logoutTokens: authTokens.map { Buffer(data: $0) }, token: token, appSandbox: appSandbox)))
enum SendCodeResult {
case password(hint: String?)

View file

@ -1267,9 +1267,11 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
case let .updateChatParticipants(participants):
let groupPeerId: PeerId
switch participants {
case let .chatParticipants(chatId, _, _):
case let .chatParticipants(chatParticipantsData):
let chatId = chatParticipantsData.chatId
groupPeerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .chatParticipantsForbidden(_, chatId, _):
case let .chatParticipantsForbidden(chatParticipantsForbiddenData):
let chatId = chatParticipantsForbiddenData.chatId
groupPeerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
}
updatedState.updateCachedPeerData(groupPeerId, { current in

View file

@ -1022,9 +1022,9 @@ func _internal_updatePeerReactionSettings(account: Account, peerId: PeerId, reac
let mappedReactions: Api.ChatReactions
switch reactionSettings.allowedReactions {
case .all:
mappedReactions = .chatReactionsAll(flags: 0)
mappedReactions = .chatReactionsAll(.init(flags: 0))
case let .limited(array):
mappedReactions = .chatReactionsSome(reactions: array.map(\.apiReaction))
mappedReactions = .chatReactionsSome(.init(reactions: array.map(\.apiReaction)))
case .empty:
mappedReactions = .chatReactionsNone
}

View file

@ -303,9 +303,11 @@ extension Api.Update {
return [PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId)), PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))]
case let .updateChatParticipants(participants):
switch participants {
case let .chatParticipants(chatId, _, _):
case let .chatParticipants(chatParticipantsData):
let chatId = chatParticipantsData.chatId
return [PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))]
case let .chatParticipantsForbidden(_, chatId, _):
case let .chatParticipantsForbidden(chatParticipantsForbiddenData):
let chatId = chatParticipantsForbiddenData.chatId
return [PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))]
}
case let .updateDeleteChannelMessages(channelId, _, _, _):

View file

@ -89,7 +89,8 @@ extension PeerAllowedReactions {
switch apiReactions {
case .chatReactionsAll:
self = .all
case let .chatReactionsSome(reactions):
case let .chatReactionsSome(chatReactionsSomeData):
let reactions = chatReactionsSomeData.reactions
self = .limited(reactions.compactMap(MessageReaction.Reaction.init(apiReaction:)))
case .chatReactionsNone:
self = .empty

View file

@ -50,7 +50,7 @@ func _internal_requestChangeAccountPhoneNumberVerification(account: Account, api
appSandbox = pushNotificationConfiguration.isSandbox ? .boolTrue : .boolFalse
}
return account.network.request(Api.functions.account.sendChangePhoneCode(phoneNumber: phoneNumber, settings: .codeSettings(flags: flags, logoutTokens: nil, token: token, appSandbox: appSandbox)), automaticFloodWait: false)
return account.network.request(Api.functions.account.sendChangePhoneCode(phoneNumber: phoneNumber, settings: .codeSettings(.init(flags: flags, logoutTokens: nil, token: token, appSandbox: appSandbox))), automaticFloodWait: false)
|> mapError { error -> RequestChangeAccountPhoneNumberVerificationError in
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .limitExceeded

View file

@ -18,7 +18,7 @@ public enum RequestCancelAccountResetDataError {
}
func _internal_requestCancelAccountResetData(network: Network, hash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
return network.request(Api.functions.account.sendConfirmPhoneCode(hash: hash, settings: .codeSettings(flags: 0, logoutTokens: nil, token: nil, appSandbox: nil)), automaticFloodWait: false)
return network.request(Api.functions.account.sendConfirmPhoneCode(hash: hash, settings: .codeSettings(.init(flags: 0, logoutTokens: nil, token: nil, appSandbox: nil))), automaticFloodWait: false)
|> mapError { error -> RequestCancelAccountResetDataError in
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .limitExceeded

View file

@ -570,7 +570,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
switch allowedReactions {
case .chatReactionsAll:
mappedAllowedReactions = .all
case let .chatReactionsSome(reactions):
case let .chatReactionsSome(chatReactionsSomeData):
let reactions = chatReactionsSomeData.reactions
mappedAllowedReactions = .limited(reactions.compactMap(MessageReaction.Reaction.init(apiReaction:)))
case .chatReactionsNone:
mappedAllowedReactions = .empty
@ -838,7 +839,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
switch allowedReactions {
case .chatReactionsAll:
mappedAllowedReactions = .all
case let .chatReactionsSome(reactions):
case let .chatReactionsSome(chatReactionsSomeData):
let reactions = chatReactionsSomeData.reactions
mappedAllowedReactions = .limited(reactions.compactMap(MessageReaction.Reaction.init(apiReaction:)))
case .chatReactionsNone:
mappedAllowedReactions = .empty

View file

@ -19,7 +19,7 @@ public struct SecureIdPreparePhoneVerificationPayload {
}
public func secureIdPreparePhoneVerification(network: Network, value: SecureIdPhoneValue) -> Signal<SecureIdPreparePhoneVerificationPayload, SecureIdPreparePhoneVerificationError> {
return network.request(Api.functions.account.sendVerifyPhoneCode(phoneNumber: value.phone, settings: .codeSettings(flags: 0, logoutTokens: nil, token: nil, appSandbox: nil)), automaticFloodWait: false)
return network.request(Api.functions.account.sendVerifyPhoneCode(phoneNumber: value.phone, settings: .codeSettings(.init(flags: 0, logoutTokens: nil, token: nil, appSandbox: nil))), automaticFloodWait: false)
|> mapError { error -> SecureIdPreparePhoneVerificationError in
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .flood

View file

@ -167,9 +167,11 @@ public enum ChatTheme: PostboxCoding, Codable, Equatable {
extension ChatTheme {
init?(apiChatTheme: Api.ChatTheme) {
switch apiChatTheme {
case let .chatTheme(emoticon):
case let .chatTheme(chatThemeData):
let emoticon = chatThemeData.emoticon
self = .emoticon(emoticon)
case let .chatThemeUniqueGift(gift, themeSettings):
case let .chatThemeUniqueGift(chatThemeUniqueGiftData):
let (gift, themeSettings) = (chatThemeUniqueGiftData.gift, chatThemeUniqueGiftData.themeSettings)
guard let gift = StarGift(apiStarGift: gift) else {
return nil
}