From df3b1cddcf56a7bbcb67fa33f777e70b33f4e607 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Fri, 16 Jan 2026 01:29:09 +0800 Subject: [PATCH] Refactor Api types 60-64 to use struct-wrapped constructors Co-Authored-By: Claude Opus 4.5 --- submodules/TelegramApi/Sources/Api5.swift | 86 +++++++++++++++++-- .../Sources/ApiUtils/ApiGroupOrChannel.swift | 3 +- .../ApiUtils/CachedGroupParticipants.swift | 3 +- .../TelegramCore/Sources/Authorization.swift | 2 +- .../State/AccountStateManagementUtils.swift | 6 +- .../Sources/State/MessageReactions.swift | 4 +- .../Sources/State/UpdatesApiUtils.swift | 6 +- .../SyncCore/SyncCore_CachedGroupData.swift | 3 +- .../ChangeAccountPhoneNumber.swift | 2 +- .../Auth/CancelAccountReset.swift | 2 +- .../Peers/UpdateCachedPeerData.swift | 6 +- .../SecureId/VerifySecureIdValue.swift | 2 +- .../TelegramEngine/Themes/ChatThemes.swift | 6 +- 13 files changed, 106 insertions(+), 25 deletions(-) diff --git a/submodules/TelegramApi/Sources/Api5.swift b/submodules/TelegramApi/Sources/Api5.swift index f450c5b81a..c23a838fe4 100644 --- a/submodules/TelegramApi/Sources/Api5.swift +++ b/submodules/TelegramApi/Sources/Api5.swift @@ -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 diff --git a/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift b/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift index 031c176753..debd5658da 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift @@ -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 diff --git a/submodules/TelegramCore/Sources/ApiUtils/CachedGroupParticipants.swift b/submodules/TelegramCore/Sources/ApiUtils/CachedGroupParticipants.swift index 82afdc8967..8d9098a8e1 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/CachedGroupParticipants.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/CachedGroupParticipants.swift @@ -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 diff --git a/submodules/TelegramCore/Sources/Authorization.swift b/submodules/TelegramCore/Sources/Authorization.swift index db7ce4dd78..8a756b639f 100644 --- a/submodules/TelegramCore/Sources/Authorization.swift +++ b/submodules/TelegramCore/Sources/Authorization.swift @@ -185,7 +185,7 @@ public func sendAuthorizationCode(accountManager: AccountManager mapError { error -> RequestChangeAccountPhoneNumberVerificationError in if error.errorDescription.hasPrefix("FLOOD_WAIT") { return .limitExceeded diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift b/submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift index b1dc5b9705..e94124a5d4 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift @@ -18,7 +18,7 @@ public enum RequestCancelAccountResetDataError { } func _internal_requestCancelAccountResetData(network: Network, hash: String) -> Signal { - 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 diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift index 23d2749168..8288eb0fc3 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift @@ -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 diff --git a/submodules/TelegramCore/Sources/TelegramEngine/SecureId/VerifySecureIdValue.swift b/submodules/TelegramCore/Sources/TelegramEngine/SecureId/VerifySecureIdValue.swift index 400feb5289..4d5850f5a9 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/SecureId/VerifySecureIdValue.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/SecureId/VerifySecureIdValue.swift @@ -19,7 +19,7 @@ public struct SecureIdPreparePhoneVerificationPayload { } public func secureIdPreparePhoneVerification(network: Network, value: SecureIdPhoneValue) -> Signal { - 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 diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift index cd920db4a2..bcc501a474 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift @@ -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 }