Refactor constructor use sites for types 250-259 to struct pattern

Migrates the following constructors to use struct-wrapped associated values:
- postInteractionCountersMessage, postInteractionCountersStory
- premiumGiftCodeOption, premiumSubscriptionOption
- prepaidGiveaway, prepaidStarsGiveaway
- privacyValueAllowChatParticipants, privacyValueAllowUsers
- privacyValueDisallowChatParticipants, privacyValueDisallowUsers
- publicForwardMessage, publicForwardStory
- quickReply
- reactionCustomEmoji, reactionEmoji

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Isaac 2026-01-18 14:24:53 +08:00
parent 90737abf6d
commit 07313cbb84
11 changed files with 203 additions and 37 deletions

View file

@ -617,8 +617,32 @@ public extension Api {
}
public extension Api {
enum PostInteractionCounters: TypeConstructorDescription {
case postInteractionCountersMessage(msgId: Int32, views: Int32, forwards: Int32, reactions: Int32)
case postInteractionCountersStory(storyId: Int32, views: Int32, forwards: Int32, reactions: Int32)
public class Cons_postInteractionCountersMessage {
public var msgId: Int32
public var views: Int32
public var forwards: Int32
public var reactions: Int32
public init(msgId: Int32, views: Int32, forwards: Int32, reactions: Int32) {
self.msgId = msgId
self.views = views
self.forwards = forwards
self.reactions = reactions
}
}
public class Cons_postInteractionCountersStory {
public var storyId: Int32
public var views: Int32
public var forwards: Int32
public var reactions: Int32
public init(storyId: Int32, views: Int32, forwards: Int32, reactions: Int32) {
self.storyId = storyId
self.views = views
self.forwards = forwards
self.reactions = reactions
}
}
case postInteractionCountersMessage(Cons_postInteractionCountersMessage)
case postInteractionCountersStory(Cons_postInteractionCountersStory)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -654,7 +678,25 @@ public extension Api {
}
public extension Api {
enum PremiumGiftCodeOption: TypeConstructorDescription {
case premiumGiftCodeOption(flags: Int32, users: Int32, months: Int32, storeProduct: String?, storeQuantity: Int32?, currency: String, amount: Int64)
public class Cons_premiumGiftCodeOption {
public var flags: Int32
public var users: Int32
public var months: Int32
public var storeProduct: String?
public var storeQuantity: Int32?
public var currency: String
public var amount: Int64
public init(flags: Int32, users: Int32, months: Int32, storeProduct: String?, storeQuantity: Int32?, currency: String, amount: Int64) {
self.flags = flags
self.users = users
self.months = months
self.storeProduct = storeProduct
self.storeQuantity = storeQuantity
self.currency = currency
self.amount = amount
}
}
case premiumGiftCodeOption(Cons_premiumGiftCodeOption)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -683,7 +725,25 @@ public extension Api {
}
public extension Api {
enum PremiumSubscriptionOption: TypeConstructorDescription {
case premiumSubscriptionOption(flags: Int32, transaction: String?, months: Int32, currency: String, amount: Int64, botUrl: String, storeProduct: String?)
public class Cons_premiumSubscriptionOption {
public var flags: Int32
public var transaction: String?
public var months: Int32
public var currency: String
public var amount: Int64
public var botUrl: String
public var storeProduct: String?
public init(flags: Int32, transaction: String?, months: Int32, currency: String, amount: Int64, botUrl: String, storeProduct: String?) {
self.flags = flags
self.transaction = transaction
self.months = months
self.currency = currency
self.amount = amount
self.botUrl = botUrl
self.storeProduct = storeProduct
}
}
case premiumSubscriptionOption(Cons_premiumSubscriptionOption)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -712,8 +772,34 @@ public extension Api {
}
public extension Api {
enum PrepaidGiveaway: TypeConstructorDescription {
case prepaidGiveaway(id: Int64, months: Int32, quantity: Int32, date: Int32)
case prepaidStarsGiveaway(id: Int64, stars: Int64, quantity: Int32, boosts: Int32, date: Int32)
public class Cons_prepaidGiveaway {
public var id: Int64
public var months: Int32
public var quantity: Int32
public var date: Int32
public init(id: Int64, months: Int32, quantity: Int32, date: Int32) {
self.id = id
self.months = months
self.quantity = quantity
self.date = date
}
}
public class Cons_prepaidStarsGiveaway {
public var id: Int64
public var stars: Int64
public var quantity: Int32
public var boosts: Int32
public var date: Int32
public init(id: Int64, stars: Int64, quantity: Int32, boosts: Int32, date: Int32) {
self.id = id
self.stars = stars
self.quantity = quantity
self.boosts = boosts
self.date = date
}
}
case prepaidGiveaway(Cons_prepaidGiveaway)
case prepaidStarsGiveaway(Cons_prepaidStarsGiveaway)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG

View file

@ -1,17 +1,41 @@
public extension Api {
enum PrivacyRule: TypeConstructorDescription {
public class Cons_privacyValueAllowChatParticipants {
public var chats: [Int64]
public init(chats: [Int64]) {
self.chats = chats
}
}
public class Cons_privacyValueAllowUsers {
public var users: [Int64]
public init(users: [Int64]) {
self.users = users
}
}
public class Cons_privacyValueDisallowChatParticipants {
public var chats: [Int64]
public init(chats: [Int64]) {
self.chats = chats
}
}
public class Cons_privacyValueDisallowUsers {
public var users: [Int64]
public init(users: [Int64]) {
self.users = users
}
}
case privacyValueAllowAll
case privacyValueAllowBots
case privacyValueAllowChatParticipants(chats: [Int64])
case privacyValueAllowChatParticipants(Cons_privacyValueAllowChatParticipants)
case privacyValueAllowCloseFriends
case privacyValueAllowContacts
case privacyValueAllowPremium
case privacyValueAllowUsers(users: [Int64])
case privacyValueAllowUsers(Cons_privacyValueAllowUsers)
case privacyValueDisallowAll
case privacyValueDisallowBots
case privacyValueDisallowChatParticipants(chats: [Int64])
case privacyValueDisallowChatParticipants(Cons_privacyValueDisallowChatParticipants)
case privacyValueDisallowContacts
case privacyValueDisallowUsers(users: [Int64])
case privacyValueDisallowUsers(Cons_privacyValueDisallowUsers)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -202,8 +226,22 @@ public extension Api {
}
public extension Api {
indirect enum PublicForward: TypeConstructorDescription {
case publicForwardMessage(message: Api.Message)
case publicForwardStory(peer: Api.Peer, story: Api.StoryItem)
public class Cons_publicForwardMessage {
public var message: Api.Message
public init(message: Api.Message) {
self.message = message
}
}
public class Cons_publicForwardStory {
public var peer: Api.Peer
public var story: Api.StoryItem
public init(peer: Api.Peer, story: Api.StoryItem) {
self.peer = peer
self.story = story
}
}
case publicForwardMessage(Cons_publicForwardMessage)
case publicForwardStory(Cons_publicForwardStory)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -239,7 +277,19 @@ public extension Api {
}
public extension Api {
enum QuickReply: TypeConstructorDescription {
case quickReply(shortcutId: Int32, shortcut: String, topMessage: Int32, count: Int32)
public class Cons_quickReply {
public var shortcutId: Int32
public var shortcut: String
public var topMessage: Int32
public var count: Int32
public init(shortcutId: Int32, shortcut: String, topMessage: Int32, count: Int32) {
self.shortcutId = shortcutId
self.shortcut = shortcut
self.topMessage = topMessage
self.count = count
}
}
case quickReply(Cons_quickReply)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -268,8 +318,20 @@ public extension Api {
}
public extension Api {
enum Reaction: TypeConstructorDescription {
case reactionCustomEmoji(documentId: Int64)
case reactionEmoji(emoticon: String)
public class Cons_reactionCustomEmoji {
public var documentId: Int64
public init(documentId: Int64) {
self.documentId = documentId
}
}
public class Cons_reactionEmoji {
public var emoticon: String
public init(emoticon: String) {
self.emoticon = emoticon
}
}
case reactionCustomEmoji(Cons_reactionCustomEmoji)
case reactionEmoji(Cons_reactionEmoji)
case reactionEmpty
case reactionPaid

View file

@ -230,7 +230,8 @@ extension SelectivePrivacySettings {
current = .enableEveryone(disableFor: [:])
case .privacyValueAllowContacts:
current = .enableContacts(enableFor: [:], disableFor: [:], enableForPremium: false, enableForBots: false)
case let .privacyValueAllowUsers(users):
case let .privacyValueAllowUsers(privacyValueAllowUsersData):
let users = privacyValueAllowUsersData.users
for id in users {
if let peer = peers[PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id))] {
enableFor[peer.peer.id] = peer
@ -240,13 +241,15 @@ extension SelectivePrivacySettings {
break
case .privacyValueDisallowContacts:
break
case let .privacyValueDisallowUsers(users):
case let .privacyValueDisallowUsers(privacyValueDisallowUsersData):
let users = privacyValueDisallowUsersData.users
for id in users {
if let peer = peers[PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id))] {
disableFor[peer.peer.id] = peer
}
}
case let .privacyValueAllowChatParticipants(chats):
case let .privacyValueAllowChatParticipants(privacyValueAllowChatParticipantsData):
let chats = privacyValueAllowChatParticipantsData.chats
for id in chats {
for possibleId in [PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(id))] {
if let peer = peers[possibleId] {
@ -254,7 +257,8 @@ extension SelectivePrivacySettings {
}
}
}
case let .privacyValueDisallowChatParticipants(chats):
case let .privacyValueDisallowChatParticipants(privacyValueDisallowChatParticipantsData):
let chats = privacyValueDisallowChatParticipantsData.chats
for id in chats {
for possibleId in [PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(id))] {
if let peer = peers[possibleId] {

View file

@ -73,7 +73,8 @@ private extension PremiumPromoConfiguration {
var productOptions: [PremiumProductOption] = []
for option in options {
if case let .premiumSubscriptionOption(flags, transaction, months, currency, amount, botUrl, storeProduct) = option {
if case let .premiumSubscriptionOption(premiumSubscriptionOptionData) = option {
let (flags, transaction, months, currency, amount, botUrl, storeProduct) = (premiumSubscriptionOptionData.flags, premiumSubscriptionOptionData.transaction, premiumSubscriptionOptionData.months, premiumSubscriptionOptionData.currency, premiumSubscriptionOptionData.amount, premiumSubscriptionOptionData.botUrl, premiumSubscriptionOptionData.storeProduct)
productOptions.append(PremiumProductOption(isCurrent: (flags & (1 << 1)) != 0, months: months, currency: currency, amount: amount, botUrl: botUrl, transactionId: transaction, availableForUpgrade: (flags & (1 << 2)) != 0, storeProductId: storeProduct))
}
}

View file

@ -1184,9 +1184,11 @@ extension StatsPercentValue {
extension ChannelStatsPostInteractions {
init(apiPostInteractionCounters: Api.PostInteractionCounters, peerId: PeerId) {
switch apiPostInteractionCounters {
case let .postInteractionCountersMessage(msgId, views, forwards, reactions):
case let .postInteractionCountersMessage(postInteractionCountersMessageData):
let (msgId, views, forwards, reactions) = (postInteractionCountersMessageData.msgId, postInteractionCountersMessageData.views, postInteractionCountersMessageData.forwards, postInteractionCountersMessageData.reactions)
self = ChannelStatsPostInteractions(postId: .message(id: EngineMessage.Id(peerId: peerId, namespace: Namespaces.Message.Cloud, id: msgId)), views: views, forwards: forwards, reactions: reactions)
case let .postInteractionCountersStory(storyId, views, forwards, reactions):
case let .postInteractionCountersStory(postInteractionCountersStoryData):
let (storyId, views, forwards, reactions) = (postInteractionCountersStoryData.storyId, postInteractionCountersStoryData.views, postInteractionCountersStoryData.forwards, postInteractionCountersStoryData.reactions)
self = ChannelStatsPostInteractions(postId: .story(peerId: peerId, id: storyId), views: views, forwards: forwards, reactions: reactions)
}
}

View file

@ -310,11 +310,13 @@ private final class StoryStatsPublicForwardsContextImpl {
var resultForwards: [StoryStatsPublicForwardsContext.State.Forward] = []
for forward in forwards {
switch forward {
case let .publicForwardMessage(apiMessage):
case let .publicForwardMessage(publicForwardMessageData):
let apiMessage = publicForwardMessageData.message
if let message = StoreMessage(apiMessage: apiMessage, accountPeerId: accountPeerId, peerIsForum: false), let renderedMessage = locallyRenderedMessage(message: message, peers: peers) {
resultForwards.append(.message(EngineMessage(renderedMessage)))
}
case let .publicForwardStory(apiPeer, apiStory):
case let .publicForwardStory(publicForwardStoryData):
let (apiPeer, apiStory) = (publicForwardStoryData.peer, publicForwardStoryData.story)
if let storedItem = Stories.StoredItem(apiStoryItem: apiStory, peerId: apiPeer.peerId, transaction: transaction), case let .item(item) = storedItem, let media = item.media, let peer = peers[apiPeer.peerId] {
let mappedItem = EngineStoryItem(
id: item.id,

View file

@ -183,9 +183,11 @@ extension MessageReaction.Reaction {
switch apiReaction {
case .reactionEmpty:
return nil
case let .reactionEmoji(emoticon):
case let .reactionEmoji(reactionEmojiData):
let emoticon = reactionEmojiData.emoticon
self = .builtin(emoticon)
case let .reactionCustomEmoji(documentId):
case let .reactionCustomEmoji(reactionCustomEmojiData):
let documentId = reactionCustomEmojiData.documentId
self = .custom(documentId)
case .reactionPaid:
self = .stars
@ -195,9 +197,9 @@ extension MessageReaction.Reaction {
var apiReaction: Api.Reaction {
switch self {
case let .builtin(value):
return .reactionEmoji(emoticon: value)
return .reactionEmoji(.init(emoticon: value))
case let .custom(fileId):
return .reactionCustomEmoji(documentId: fileId)
return .reactionCustomEmoji(.init(documentId: fileId))
case .stars:
return .reactionPaid
}

View file

@ -171,7 +171,8 @@ func _internal_keepShortcutMessagesUpdated(account: Account) -> Signal<Never, No
for quickReply in quickReplies {
switch quickReply {
case let .quickReply(shortcutId, shortcut, topMessage, _):
case let .quickReply(quickReplyData):
let (shortcutId, shortcut, topMessage, _) = (quickReplyData.shortcutId, quickReplyData.shortcut, quickReplyData.topMessage, quickReplyData.count)
state.shortcuts.append(QuickReplyMessageShortcut(
id: shortcutId,
shortcut: shortcut

View file

@ -2234,15 +2234,18 @@ extension Stories.StoredItem {
base = .everyone
case .privacyValueDisallowAll:
base = .nobody
case let .privacyValueAllowUsers(users):
case let .privacyValueAllowUsers(privacyValueAllowUsersData):
let users = privacyValueAllowUsersData.users
for id in users {
additionalPeerIds.append(EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value(id)))
}
case let .privacyValueDisallowUsers(users):
case let .privacyValueDisallowUsers(privacyValueDisallowUsersData):
let users = privacyValueDisallowUsersData.users
for id in users {
additionalPeerIds.append(EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value(id)))
}
case let .privacyValueAllowChatParticipants(chats):
case let .privacyValueAllowChatParticipants(privacyValueAllowChatParticipantsData):
let chats = privacyValueAllowChatParticipantsData.chats
for id in chats {
if let peer = transaction.getPeer(EnginePeer.Id(namespace: Namespaces.Peer.CloudGroup, id: EnginePeer.Id.Id._internalFromInt64Value(id))) {
additionalPeerIds.append(peer.id)

View file

@ -299,7 +299,7 @@ func _internal_parseInputInvoice(transaction: Transaction, source: BotPaymentInv
flags |= (1 << 1)
}
let option: Api.PremiumGiftCodeOption = .premiumGiftCodeOption(flags: flags, users: option.users, months: option.months, storeProduct: option.storeProductId, storeQuantity: option.storeQuantity, currency: option.currency, amount: option.amount)
let option: Api.PremiumGiftCodeOption = .premiumGiftCodeOption(.init(flags: flags, users: option.users, months: option.months, storeProduct: option.storeProductId, storeQuantity: option.storeQuantity, currency: option.currency, amount: option.amount))
return .inputInvoicePremiumGiftCode(.init(purpose: inputPurpose, option: option))
case let .giftCode(users, currency, amount, option, text, entities):
@ -329,7 +329,7 @@ func _internal_parseInputInvoice(transaction: Transaction, source: BotPaymentInv
flags |= (1 << 1)
}
let option: Api.PremiumGiftCodeOption = .premiumGiftCodeOption(flags: flags, users: option.users, months: option.months, storeProduct: option.storeProductId, storeQuantity: option.storeQuantity, currency: option.currency, amount: option.amount)
let option: Api.PremiumGiftCodeOption = .premiumGiftCodeOption(.init(flags: flags, users: option.users, months: option.months, storeProduct: option.storeProductId, storeQuantity: option.storeQuantity, currency: option.currency, amount: option.amount))
return .inputInvoicePremiumGiftCode(.init(purpose: inputPurpose, option: option))
case let .stars(option, peerId):

View file

@ -370,7 +370,8 @@ func _internal_launchPrepaidGiveaway(account: Account, peerId: EnginePeer.Id, pu
extension PremiumGiftCodeOption {
init(apiGiftCodeOption: Api.PremiumGiftCodeOption) {
switch apiGiftCodeOption {
case let .premiumGiftCodeOption(_, users, months, storeProduct, storeQuantity, curreny, amount):
case let .premiumGiftCodeOption(premiumGiftCodeOptionData):
let (_, users, months, storeProduct, storeQuantity, curreny, amount) = (premiumGiftCodeOptionData.flags, premiumGiftCodeOptionData.users, premiumGiftCodeOptionData.months, premiumGiftCodeOptionData.storeProduct, premiumGiftCodeOptionData.storeQuantity, premiumGiftCodeOptionData.currency, premiumGiftCodeOptionData.amount)
self.init(users: users, months: months, storeProductId: storeProduct, storeQuantity: storeQuantity ?? 1, currency: curreny, amount: amount)
}
}
@ -405,12 +406,14 @@ public extension PremiumGiftCodeInfo {
extension PrepaidGiveaway {
init(apiPrepaidGiveaway: Api.PrepaidGiveaway) {
switch apiPrepaidGiveaway {
case let .prepaidGiveaway(id, months, quantity, date):
case let .prepaidGiveaway(prepaidGiveawayData):
let (id, months, quantity, date) = (prepaidGiveawayData.id, prepaidGiveawayData.months, prepaidGiveawayData.quantity, prepaidGiveawayData.date)
self.id = id
self.prize = .premium(months: months)
self.quantity = quantity
self.date = date
case let .prepaidStarsGiveaway(id, stars, quantity, boosts, date):
case let .prepaidStarsGiveaway(prepaidStarsGiveawayData):
let (id, stars, quantity, boosts, date) = (prepaidStarsGiveawayData.id, prepaidStarsGiveawayData.stars, prepaidStarsGiveawayData.quantity, prepaidStarsGiveawayData.boosts, prepaidStarsGiveawayData.date)
self.id = id
self.prize = .stars(stars: stars, boosts: boosts)
self.quantity = quantity