Refactor constructor use sites for types 240-249 to struct pattern

Types refactored: phoneCallProtocol, phoneConnection, phoneConnectionWebrtc,
photo, photoEmpty, photoCachedSize, photoPathSize, photoSize, photoSizeEmpty,
photoSizeProgressive, photoStrippedSize, poll, pollAnswer, pollAnswerVoters,
pollResults, popularContact, postAddress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Isaac 2026-01-18 02:25:52 +08:00
parent c6b0ef5da3
commit 90737abf6d
16 changed files with 318 additions and 71 deletions

View file

@ -67,7 +67,19 @@ public extension Api {
}
public extension Api {
enum PhoneCallProtocol: TypeConstructorDescription {
case phoneCallProtocol(flags: Int32, minLayer: Int32, maxLayer: Int32, libraryVersions: [String])
public class Cons_phoneCallProtocol {
public var flags: Int32
public var minLayer: Int32
public var maxLayer: Int32
public var libraryVersions: [String]
public init(flags: Int32, minLayer: Int32, maxLayer: Int32, libraryVersions: [String]) {
self.flags = flags
self.minLayer = minLayer
self.maxLayer = maxLayer
self.libraryVersions = libraryVersions
}
}
case phoneCallProtocol(Cons_phoneCallProtocol)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -96,8 +108,42 @@ public extension Api {
}
public extension Api {
enum PhoneConnection: TypeConstructorDescription {
case phoneConnection(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, peerTag: Buffer)
case phoneConnectionWebrtc(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, username: String, password: String)
public class Cons_phoneConnection {
public var flags: Int32
public var id: Int64
public var ip: String
public var ipv6: String
public var port: Int32
public var peerTag: Buffer
public init(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, peerTag: Buffer) {
self.flags = flags
self.id = id
self.ip = ip
self.ipv6 = ipv6
self.port = port
self.peerTag = peerTag
}
}
public class Cons_phoneConnectionWebrtc {
public var flags: Int32
public var id: Int64
public var ip: String
public var ipv6: String
public var port: Int32
public var username: String
public var password: String
public init(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, username: String, password: String) {
self.flags = flags
self.id = id
self.ip = ip
self.ipv6 = ipv6
self.port = port
self.username = username
self.password = password
}
}
case phoneConnection(Cons_phoneConnection)
case phoneConnectionWebrtc(Cons_phoneConnectionWebrtc)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -133,8 +179,34 @@ public extension Api {
}
public extension Api {
enum Photo: TypeConstructorDescription {
case photo(flags: Int32, id: Int64, accessHash: Int64, fileReference: Buffer, date: Int32, sizes: [Api.PhotoSize], videoSizes: [Api.VideoSize]?, dcId: Int32)
case photoEmpty(id: Int64)
public class Cons_photo {
public var flags: Int32
public var id: Int64
public var accessHash: Int64
public var fileReference: Buffer
public var date: Int32
public var sizes: [Api.PhotoSize]
public var videoSizes: [Api.VideoSize]?
public var dcId: Int32
public init(flags: Int32, id: Int64, accessHash: Int64, fileReference: Buffer, date: Int32, sizes: [Api.PhotoSize], videoSizes: [Api.VideoSize]?, dcId: Int32) {
self.flags = flags
self.id = id
self.accessHash = accessHash
self.fileReference = fileReference
self.date = date
self.sizes = sizes
self.videoSizes = videoSizes
self.dcId = dcId
}
}
public class Cons_photoEmpty {
public var id: Int64
public init(id: Int64) {
self.id = id
}
}
case photo(Cons_photo)
case photoEmpty(Cons_photoEmpty)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -170,12 +242,70 @@ public extension Api {
}
public extension Api {
enum PhotoSize: TypeConstructorDescription {
case photoCachedSize(type: String, w: Int32, h: Int32, bytes: Buffer)
case photoPathSize(type: String, bytes: Buffer)
case photoSize(type: String, w: Int32, h: Int32, size: Int32)
case photoSizeEmpty(type: String)
case photoSizeProgressive(type: String, w: Int32, h: Int32, sizes: [Int32])
case photoStrippedSize(type: String, bytes: Buffer)
public class Cons_photoCachedSize {
public var type: String
public var w: Int32
public var h: Int32
public var bytes: Buffer
public init(type: String, w: Int32, h: Int32, bytes: Buffer) {
self.type = type
self.w = w
self.h = h
self.bytes = bytes
}
}
public class Cons_photoPathSize {
public var type: String
public var bytes: Buffer
public init(type: String, bytes: Buffer) {
self.type = type
self.bytes = bytes
}
}
public class Cons_photoSize {
public var type: String
public var w: Int32
public var h: Int32
public var size: Int32
public init(type: String, w: Int32, h: Int32, size: Int32) {
self.type = type
self.w = w
self.h = h
self.size = size
}
}
public class Cons_photoSizeEmpty {
public var type: String
public init(type: String) {
self.type = type
}
}
public class Cons_photoSizeProgressive {
public var type: String
public var w: Int32
public var h: Int32
public var sizes: [Int32]
public init(type: String, w: Int32, h: Int32, sizes: [Int32]) {
self.type = type
self.w = w
self.h = h
self.sizes = sizes
}
}
public class Cons_photoStrippedSize {
public var type: String
public var bytes: Buffer
public init(type: String, bytes: Buffer) {
self.type = type
self.bytes = bytes
}
}
case photoCachedSize(Cons_photoCachedSize)
case photoPathSize(Cons_photoPathSize)
case photoSize(Cons_photoSize)
case photoSizeEmpty(Cons_photoSizeEmpty)
case photoSizeProgressive(Cons_photoSizeProgressive)
case photoStrippedSize(Cons_photoStrippedSize)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -239,7 +369,23 @@ public extension Api {
}
public extension Api {
enum Poll: TypeConstructorDescription {
case poll(id: Int64, flags: Int32, question: Api.TextWithEntities, answers: [Api.PollAnswer], closePeriod: Int32?, closeDate: Int32?)
public class Cons_poll {
public var id: Int64
public var flags: Int32
public var question: Api.TextWithEntities
public var answers: [Api.PollAnswer]
public var closePeriod: Int32?
public var closeDate: Int32?
public init(id: Int64, flags: Int32, question: Api.TextWithEntities, answers: [Api.PollAnswer], closePeriod: Int32?, closeDate: Int32?) {
self.id = id
self.flags = flags
self.question = question
self.answers = answers
self.closePeriod = closePeriod
self.closeDate = closeDate
}
}
case poll(Cons_poll)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -268,7 +414,15 @@ public extension Api {
}
public extension Api {
enum PollAnswer: TypeConstructorDescription {
case pollAnswer(text: Api.TextWithEntities, option: Buffer)
public class Cons_pollAnswer {
public var text: Api.TextWithEntities
public var option: Buffer
public init(text: Api.TextWithEntities, option: Buffer) {
self.text = text
self.option = option
}
}
case pollAnswer(Cons_pollAnswer)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -297,7 +451,17 @@ public extension Api {
}
public extension Api {
enum PollAnswerVoters: TypeConstructorDescription {
case pollAnswerVoters(flags: Int32, option: Buffer, voters: Int32)
public class Cons_pollAnswerVoters {
public var flags: Int32
public var option: Buffer
public var voters: Int32
public init(flags: Int32, option: Buffer, voters: Int32) {
self.flags = flags
self.option = option
self.voters = voters
}
}
case pollAnswerVoters(Cons_pollAnswerVoters)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -326,7 +490,23 @@ public extension Api {
}
public extension Api {
enum PollResults: TypeConstructorDescription {
case pollResults(flags: Int32, results: [Api.PollAnswerVoters]?, totalVoters: Int32?, recentVoters: [Api.Peer]?, solution: String?, solutionEntities: [Api.MessageEntity]?)
public class Cons_pollResults {
public var flags: Int32
public var results: [Api.PollAnswerVoters]?
public var totalVoters: Int32?
public var recentVoters: [Api.Peer]?
public var solution: String?
public var solutionEntities: [Api.MessageEntity]?
public init(flags: Int32, results: [Api.PollAnswerVoters]?, totalVoters: Int32?, recentVoters: [Api.Peer]?, solution: String?, solutionEntities: [Api.MessageEntity]?) {
self.flags = flags
self.results = results
self.totalVoters = totalVoters
self.recentVoters = recentVoters
self.solution = solution
self.solutionEntities = solutionEntities
}
}
case pollResults(Cons_pollResults)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -355,7 +535,15 @@ public extension Api {
}
public extension Api {
enum PopularContact: TypeConstructorDescription {
case popularContact(clientId: Int64, importers: Int32)
public class Cons_popularContact {
public var clientId: Int64
public var importers: Int32
public init(clientId: Int64, importers: Int32) {
self.clientId = clientId
self.importers = importers
}
}
case popularContact(Cons_popularContact)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG
@ -384,7 +572,23 @@ public extension Api {
}
public extension Api {
enum PostAddress: TypeConstructorDescription {
case postAddress(streetLine1: String, streetLine2: String, city: String, state: String, countryIso2: String, postCode: String)
public class Cons_postAddress {
public var streetLine1: String
public var streetLine2: String
public var city: String
public var state: String
public var countryIso2: String
public var postCode: String
public init(streetLine1: String, streetLine2: String, city: String, state: String, countryIso2: String, postCode: String) {
self.streetLine1 = streetLine1
self.streetLine2 = streetLine2
self.city = city
self.state = state
self.countryIso2 = countryIso2
self.postCode = postCode
}
}
case postAddress(Cons_postAddress)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
#if DEBUG

View file

@ -446,7 +446,8 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI
case let .messageMediaPoll(messageMediaPollData):
let (poll, results) = (messageMediaPollData.poll, messageMediaPollData.results)
switch poll {
case let .poll(id, flags, question, answers, closePeriod, _):
case let .poll(pollData):
let (id, flags, question, answers, closePeriod, _) = (pollData.id, pollData.flags, pollData.question, pollData.answers, pollData.closePeriod, pollData.closeDate)
let publicity: TelegramMediaPollPublicity
if (flags & (1 << 1)) != 0 {
publicity = .public

View file

@ -12,7 +12,8 @@ extension TelegramExtendedMedia {
dimensions = PixelDimensions(width: width, height: height)
}
var immediateThumbnailData: Data?
if let thumb = thumb, case let .photoStrippedSize(_, bytes) = thumb {
if let thumb = thumb, case let .photoStrippedSize(photoStrippedSizeData) = thumb {
let bytes = photoStrippedSizeData.bytes
immediateThumbnailData = bytes.makeData()
}
self = .preview(dimensions: dimensions, immediateThumbnailData: immediateThumbnailData, videoDuration: videoDuration)

View file

@ -167,18 +167,23 @@ func telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: Int32,
var representations: [TelegramMediaImageRepresentation] = []
for size in sizes {
switch size {
case let .photoCachedSize(type, w, h, _):
case let .photoCachedSize(photoCachedSizeData):
let (type, w, h, _) = (photoCachedSizeData.type, photoCachedSizeData.w, photoCachedSizeData.h, photoCachedSizeData.bytes)
let resource = CloudDocumentSizeMediaResource(datacenterId: datacenterId, documentId: documentId, accessHash: accessHash, sizeSpec: type, fileReference: fileReference)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSize(type, w, h, _):
case let .photoSize(photoSizeData):
let (type, w, h, _) = (photoSizeData.type, photoSizeData.w, photoSizeData.h, photoSizeData.size)
let resource = CloudDocumentSizeMediaResource(datacenterId: datacenterId, documentId: documentId, accessHash: accessHash, sizeSpec: type, fileReference: fileReference)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(type, w, h, sizes):
case let .photoSizeProgressive(photoSizeProgressiveData):
let (type, w, h, sizes) = (photoSizeProgressiveData.type, photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
let resource = CloudDocumentSizeMediaResource(datacenterId: datacenterId, documentId: documentId, accessHash: accessHash, sizeSpec: type, fileReference: fileReference)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: sizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoPathSize(_, data):
case let .photoPathSize(photoPathSizeData):
let (_, data) = (photoPathSizeData.type, photoPathSizeData.bytes)
immediateThumbnailData = data.makeData()
case let .photoStrippedSize(_, data):
case let .photoStrippedSize(photoStrippedSizeData):
let (_, data) = (photoStrippedSizeData.type, photoStrippedSizeData.bytes)
immediateThumbnailData = data.makeData()
case .photoSizeEmpty:
break

View file

@ -8,18 +8,22 @@ func telegramMediaImageRepresentationsFromApiSizes(datacenterId: Int32, photoId:
var representations: [TelegramMediaImageRepresentation] = []
for size in sizes {
switch size {
case let .photoCachedSize(type, w, h, _):
case let .photoCachedSize(photoCachedSizeData):
let (type, w, h) = (photoCachedSizeData.type, photoCachedSizeData.w, photoCachedSizeData.h)
let resource = CloudPhotoSizeMediaResource(datacenterId: datacenterId, photoId: photoId, accessHash: accessHash, sizeSpec: type, size: nil, fileReference: fileReference)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSize(type, w, h, size):
case let .photoSize(photoSizeData):
let (type, w, h, size) = (photoSizeData.type, photoSizeData.w, photoSizeData.h, photoSizeData.size)
let resource = CloudPhotoSizeMediaResource(datacenterId: datacenterId, photoId: photoId, accessHash: accessHash, sizeSpec: type, size: Int64(size), fileReference: fileReference)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(type, w, h, sizes):
case let .photoSizeProgressive(photoSizeProgressiveData):
let (type, w, h, sizes) = (photoSizeProgressiveData.type, photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
if !sizes.isEmpty {
let resource = CloudPhotoSizeMediaResource(datacenterId: datacenterId, photoId: photoId, accessHash: accessHash, sizeSpec: type, size: Int64(sizes[sizes.count - 1]), fileReference: fileReference)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: sizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
}
case let .photoStrippedSize(_, data):
case let .photoStrippedSize(photoStrippedSizeData):
let data = photoStrippedSizeData.bytes
immediateThumbnailData = data.makeData()
case .photoPathSize:
break
@ -32,7 +36,8 @@ func telegramMediaImageRepresentationsFromApiSizes(datacenterId: Int32, photoId:
func telegramMediaImageFromApiPhoto(_ photo: Api.Photo) -> TelegramMediaImage? {
switch photo {
case let .photo(flags, id, accessHash, fileReference, _, sizes, videoSizes, dcId):
case let .photo(photoData):
let (flags, id, accessHash, fileReference, sizes, videoSizes, dcId) = (photoData.flags, photoData.id, photoData.accessHash, photoData.fileReference, photoData.sizes, photoData.videoSizes, photoData.dcId)
let (immediateThumbnailData, representations) = telegramMediaImageRepresentationsFromApiSizes(datacenterId: dcId, photoId: id, accessHash: accessHash, fileReference: fileReference.makeData(), sizes: sizes)
var imageFlags: TelegramMediaImageFlags = []
let hasStickers = (flags & (1 << 0)) != 0

View file

@ -6,7 +6,8 @@ import TelegramApi
extension TelegramMediaPollOption {
init(apiOption: Api.PollAnswer) {
switch apiOption {
case let .pollAnswer(text, option):
case let .pollAnswer(pollAnswerData):
let (text, option) = (pollAnswerData.text, pollAnswerData.option)
let answerText: String
let answerEntities: [MessageTextEntity]
switch text {
@ -20,14 +21,15 @@ extension TelegramMediaPollOption {
}
var apiOption: Api.PollAnswer {
return .pollAnswer(text: .textWithEntities(text: self.text, entities: apiEntitiesFromMessageTextEntities(self.entities, associatedPeers: SimpleDictionary())), option: Buffer(data: self.opaqueIdentifier))
return .pollAnswer(.init(text: .textWithEntities(text: self.text, entities: apiEntitiesFromMessageTextEntities(self.entities, associatedPeers: SimpleDictionary())), option: Buffer(data: self.opaqueIdentifier)))
}
}
extension TelegramMediaPollOptionVoters {
init(apiVoters: Api.PollAnswerVoters) {
switch apiVoters {
case let .pollAnswerVoters(flags, option, voters):
case let .pollAnswerVoters(pollAnswerVotersData):
let (flags, option, voters) = (pollAnswerVotersData.flags, pollAnswerVotersData.option, pollAnswerVotersData.voters)
self.init(selected: (flags & (1 << 0)) != 0, opaqueIdentifier: option.makeData(), count: voters, isCorrect: (flags & (1 << 1)) != 0)
}
}
@ -36,7 +38,8 @@ extension TelegramMediaPollOptionVoters {
extension TelegramMediaPollResults {
init(apiResults: Api.PollResults) {
switch apiResults {
case let .pollResults(_, results, totalVoters, recentVoters, solution, solutionEntities):
case let .pollResults(pollResultsData):
let (results, totalVoters, recentVoters, solution, solutionEntities) = (pollResultsData.results, pollResultsData.totalVoters, pollResultsData.recentVoters, pollResultsData.solution, pollResultsData.solutionEntities)
var parsedSolution: TelegramMediaPollResults.Solution?
if let solution = solution, let solutionEntities = solutionEntities, !solution.isEmpty {
parsedSolution = TelegramMediaPollResults.Solution(text: solution, entities: messageTextEntitiesFromApiEntities(solutionEntities))

View file

@ -330,7 +330,7 @@ func mediaContentToUpload(accountPeerId: PeerId, network: Network, postbox: Post
mappedSolutionEntities = apiTextAttributeEntities(TextEntitiesMessageAttribute(entities: solution.entities), associatedPeers: SimpleDictionary())
pollMediaFlags |= 1 << 1
}
let inputPoll = Api.InputMedia.inputMediaPoll(.init(flags: pollMediaFlags, poll: Api.Poll.poll(id: 0, flags: pollFlags, question: .textWithEntities(text: poll.text, entities: apiEntitiesFromMessageTextEntities(poll.textEntities, associatedPeers: SimpleDictionary())), answers: poll.options.map({ $0.apiOption }), closePeriod: poll.deadlineTimeout, closeDate: nil), correctAnswers: correctAnswers, solution: mappedSolution, solutionEntities: mappedSolutionEntities))
let inputPoll = Api.InputMedia.inputMediaPoll(.init(flags: pollMediaFlags, poll: Api.Poll.poll(.init(id: 0, flags: pollFlags, question: .textWithEntities(text: poll.text, entities: apiEntitiesFromMessageTextEntities(poll.textEntities, associatedPeers: SimpleDictionary())), answers: poll.options.map({ $0.apiOption }), closePeriod: poll.deadlineTimeout, closeDate: nil)), correctAnswers: correctAnswers, solution: mappedSolution, solutionEntities: mappedSolutionEntities))
return .single(.content(PendingMessageUploadedContentAndReuploadInfo(content: .media(inputPoll, text), reuploadInfo: nil, cacheReferenceKey: nil)))
} else if let todo = media as? TelegramMediaTodo {
var flags: Int32 = 0
@ -856,7 +856,8 @@ private func uploadedVideoCover(network: Network, postbox: Postbox, resourceRefe
switch uploadResult {
case let .messageMediaPhoto(messageMediaPhotoData):
let photo = messageMediaPhotoData.photo
if case let .photo(_, id, accessHash, fileReference, _, _, _, _) = photo {
if case let .photo(photoData) = photo {
let (id, accessHash, fileReference) = (photoData.id, photoData.accessHash, photoData.fileReference)
return .inputPhoto(.init(id: id, accessHash: accessHash, fileReference: fileReference))
} else {
return .inputPhotoEmpty

View file

@ -4364,12 +4364,14 @@ func replayFinalState(
var updatedPoll = poll
let resultsMin: Bool
switch results {
case let .pollResults(flags, _, _, _, _, _):
case let .pollResults(pollResultsData):
let flags = pollResultsData.flags
resultsMin = (flags & (1 << 0)) != 0
}
if let apiPoll = apiPoll {
switch apiPoll {
case let .poll(id, flags, question, answers, closePeriod, _):
case let .poll(pollData):
let (id, flags, question, answers, closePeriod) = (pollData.id, pollData.flags, pollData.question, pollData.answers, pollData.closePeriod)
let publicity: TelegramMediaPollPublicity
if (flags & (1 << 1)) != 0 {
publicity = .public

View file

@ -330,10 +330,12 @@ public enum CallSessionConnection: Equatable {
private func parseConnection(_ apiConnection: Api.PhoneConnection) -> CallSessionConnection {
switch apiConnection {
case let .phoneConnection(flags, id, ip, ipv6, port, peerTag):
case let .phoneConnection(phoneConnectionData):
let (flags, id, ip, ipv6, port, peerTag) = (phoneConnectionData.flags, phoneConnectionData.id, phoneConnectionData.ip, phoneConnectionData.ipv6, phoneConnectionData.port, phoneConnectionData.peerTag)
let isTcp = (flags & (1 << 0)) != 0
return .reflector(CallSessionConnection.Reflector(id: id, ip: ip, ipv6: ipv6, isTcp: isTcp, port: port, peerTag: peerTag.makeData()))
case let .phoneConnectionWebrtc(flags, id, ip, ipv6, port, username, password):
case let .phoneConnectionWebrtc(phoneConnectionWebrtcData):
let (flags, id, ip, ipv6, port, username, password) = (phoneConnectionWebrtcData.flags, phoneConnectionWebrtcData.id, phoneConnectionWebrtcData.ip, phoneConnectionWebrtcData.ipv6, phoneConnectionWebrtcData.port, phoneConnectionWebrtcData.username, phoneConnectionWebrtcData.password)
return .webRtcReflector(CallSessionConnection.WebRtcReflector(
id: id,
hasStun: (flags & (1 << 1)) != 0,
@ -1078,7 +1080,8 @@ private final class CallSessionManagerContext {
let (id, gB, remoteProtocol) = (phoneCallAcceptedData.id, phoneCallAcceptedData.gB, phoneCallAcceptedData.protocol)
let remoteVersions: [String]
switch remoteProtocol {
case let .phoneCallProtocol(_, _, _, versions):
case let .phoneCallProtocol(phoneCallProtocolData):
let versions = phoneCallProtocolData.libraryVersions
remoteVersions = versions
}
if let internalId = self.contextIdByStableId[id] {
@ -1205,7 +1208,8 @@ private final class CallSessionManagerContext {
if let (key, calculatedKeyId, keyVisualHash) = self.makeSessionEncryptionKey(config: config, gAHash: gAHash, b: b, gA: gAOrB.makeData()) {
if keyFingerprint == calculatedKeyId {
switch callProtocol {
case let .phoneCallProtocol(_, _, maxLayer, versions):
case let .phoneCallProtocol(phoneCallProtocolData):
let (maxLayer, versions) = (phoneCallProtocolData.maxLayer, phoneCallProtocolData.libraryVersions)
if !versions.isEmpty {
var customParametersValue: String?
switch customParameters {
@ -1233,7 +1237,8 @@ private final class CallSessionManagerContext {
}
case let .confirming(id, accessHash, key, keyId, keyVisualHash, _):
switch callProtocol {
case let .phoneCallProtocol(_, _, maxLayer, versions):
case let .phoneCallProtocol(phoneCallProtocolData):
let (maxLayer, versions) = (phoneCallProtocolData.maxLayer, phoneCallProtocolData.libraryVersions)
if !versions.isEmpty {
var customParametersValue: String?
switch customParameters {
@ -1263,7 +1268,8 @@ private final class CallSessionManagerContext {
let isVideo = (flags & (1 << 6)) != 0
let versions: [String]
switch requestedProtocol {
case let .phoneCallProtocol(_, _, _, libraryVersions):
case let .phoneCallProtocol(phoneCallProtocolData):
let libraryVersions = phoneCallProtocolData.libraryVersions
versions = libraryVersions
}
if self.contextIdByStableId[id] == nil {
@ -1607,7 +1613,7 @@ private func acceptCallSession(accountPeerId: PeerId, postbox: Postbox, network:
return .single(.failed)
}
return network.request(Api.functions.phone.acceptCall(peer: .inputPhoneCall(.init(id: stableId, accessHash: accessHash)), gB: Buffer(data: gb), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions)))
return network.request(Api.functions.phone.acceptCall(peer: .inputPhoneCall(.init(id: stableId, accessHash: accessHash)), gB: Buffer(data: gb), protocol: .phoneCallProtocol(.init(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.phone.PhoneCall?, NoError> in
return .single(nil)
@ -1628,7 +1634,8 @@ private func acceptCallSession(accountPeerId: PeerId, postbox: Postbox, network:
let (flags, id, gAOrB, callProtocol, connections, startDate, customParameters) = (phoneCallData.flags, phoneCallData.id, phoneCallData.gAOrB, phoneCallData.protocol, phoneCallData.connections, phoneCallData.startDate, phoneCallData.customParameters)
if id == stableId {
switch callProtocol{
case let .phoneCallProtocol(_, _, maxLayer, versions):
case let .phoneCallProtocol(phoneCallProtocolData):
let (maxLayer, versions) = (phoneCallProtocolData.maxLayer, phoneCallProtocolData.libraryVersions)
if !versions.isEmpty {
var customParametersValue: String?
switch customParameters {
@ -1683,7 +1690,7 @@ private func requestCallSession(postbox: Postbox, network: Network, peerId: Peer
callFlags |= 1 << 0
}
return network.request(Api.functions.phone.requestCall(flags: callFlags, userId: inputUser, randomId: Int32(bitPattern: arc4random()), gAHash: Buffer(data: gAHash), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions)))
return network.request(Api.functions.phone.requestCall(flags: callFlags, userId: inputUser, randomId: Int32(bitPattern: arc4random()), gAHash: Buffer(data: gAHash), protocol: .phoneCallProtocol(.init(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions))))
|> map { result -> RequestCallSessionResult in
switch result {
case let .phoneCall(phoneCall, _):
@ -1722,7 +1729,7 @@ private func requestCallSession(postbox: Postbox, network: Network, peerId: Peer
}
private func confirmCallSession(network: Network, stableId: CallSessionStableId, accessHash: Int64, gA: Data, keyFingerprint: Int64, maxLayer: Int32, versions: [String]) -> Signal<Api.PhoneCall?, NoError> {
return network.request(Api.functions.phone.confirmCall(peer: Api.InputPhoneCall.inputPhoneCall(.init(id: stableId, accessHash: accessHash)), gA: Buffer(data: gA), keyFingerprint: keyFingerprint, protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions)))
return network.request(Api.functions.phone.confirmCall(peer: Api.InputPhoneCall.inputPhoneCall(.init(id: stableId, accessHash: accessHash)), gA: Buffer(data: gA), keyFingerprint: keyFingerprint, protocol: .phoneCallProtocol(.init(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.phone.PhoneCall?, NoError> in
return .single(nil)

View file

@ -358,7 +358,8 @@ private func pushDeviceContactData(accountPeerId: PeerId, postbox: Postbox, netw
}
for item in popularInvites {
switch item {
case let .popularContact(clientId, importers):
case let .popularContact(popularContactData):
let (clientId, importers) = (popularContactData.clientId, popularContactData.importers)
importedCounts[Int(clientId)] = importers
}
}

View file

@ -5,10 +5,12 @@ import TelegramApi
private func collectPreCachedResources(for photo: Api.Photo) -> [(MediaResource, Data)]? {
switch photo {
case let .photo(_, id, accessHash, fileReference, _, sizes, _, dcId):
case let .photo(photoData):
let (id, accessHash, fileReference, sizes, dcId) = (photoData.id, photoData.accessHash, photoData.fileReference, photoData.sizes, photoData.dcId)
for size in sizes {
switch size {
case let .photoCachedSize(type, _, _, bytes):
case let .photoCachedSize(photoCachedSizeData):
let (type, bytes) = (photoCachedSizeData.type, photoCachedSizeData.bytes)
let resource = CloudPhotoSizeMediaResource(datacenterId: dcId, photoId: id, accessHash: accessHash, sizeSpec: type, size: nil, fileReference: fileReference.makeData())
let data = bytes.makeData()
return [(resource, data)]
@ -29,7 +31,8 @@ private func collectPreCachedResources(for document: Api.Document) -> [(MediaRes
if let thumbs = thumbs {
for thumb in thumbs {
switch thumb {
case let .photoCachedSize(type, _, _, bytes):
case let .photoCachedSize(photoCachedSizeData):
let (type, bytes) = (photoCachedSizeData.type, photoCachedSizeData.bytes)
let resource = CloudDocumentSizeMediaResource(datacenterId: dcId, documentId: id, accessHash: accessHash, sizeSpec: type, fileReference: fileReference.makeData())
let data = bytes.makeData()
return [(resource, data)]

View file

@ -31,7 +31,8 @@ func _internal_requestMessageSelectPollOption(account: Account, messageId: Messa
resultPoll = transaction.getMedia(pollId) as? TelegramMediaPoll
if let poll = poll {
switch poll {
case let .poll(_, flags, question, answers, closePeriod, _):
case let .poll(pollData):
let (flags, question, answers, closePeriod) = (pollData.flags, pollData.question, pollData.answers, pollData.closePeriod)
let publicity: TelegramMediaPollPublicity
if (flags & (1 << 1)) != 0 {
publicity = .public
@ -57,7 +58,8 @@ func _internal_requestMessageSelectPollOption(account: Account, messageId: Messa
let resultsMin: Bool
switch results {
case let .pollResults(flags, _, _, _, _, _):
case let .pollResults(pollResultsData):
let flags = pollResultsData.flags
resultsMin = (flags & (1 << 0)) != 0
}
resultPoll = resultPoll?.withUpdatedResults(TelegramMediaPollResults(apiResults: results), min: resultsMin)
@ -142,7 +144,7 @@ func _internal_requestClosePoll(postbox: Postbox, network: Network, stateManager
pollMediaFlags |= 1 << 1
}
return network.request(Api.functions.messages.editMessage(flags: flags, peer: inputPeer, id: messageId.id, message: nil, media: .inputMediaPoll(.init(flags: pollMediaFlags, poll: .poll(id: poll.pollId.id, flags: pollFlags, question: .textWithEntities(text: poll.text, entities: apiEntitiesFromMessageTextEntities(poll.textEntities, associatedPeers: SimpleDictionary())), answers: poll.options.map({ $0.apiOption }), closePeriod: poll.deadlineTimeout, closeDate: nil), correctAnswers: correctAnswers, solution: mappedSolution, solutionEntities: mappedSolutionEntities)), replyMarkup: nil, entities: nil, scheduleDate: nil, scheduleRepeatPeriod: nil, quickReplyShortcutId: nil))
return network.request(Api.functions.messages.editMessage(flags: flags, peer: inputPeer, id: messageId.id, message: nil, media: .inputMediaPoll(.init(flags: pollMediaFlags, poll: .poll(.init(id: poll.pollId.id, flags: pollFlags, question: .textWithEntities(text: poll.text, entities: apiEntitiesFromMessageTextEntities(poll.textEntities, associatedPeers: SimpleDictionary())), answers: poll.options.map({ $0.apiOption }), closePeriod: poll.deadlineTimeout, closeDate: nil)), correctAnswers: correctAnswers, solution: mappedSolution, solutionEntities: mappedSolutionEntities)), replyMarkup: nil, entities: nil, scheduleDate: nil, scheduleRepeatPeriod: nil, quickReplyShortcutId: nil))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
return .single(nil)

View file

@ -242,7 +242,8 @@ extension BotPaymentRequestedInfo {
var parsedShippingAddress: BotPaymentShippingAddress?
if let shippingAddress = shippingAddress {
switch shippingAddress {
case let .postAddress(streetLine1, streetLine2, city, state, countryIso2, postCode):
case let .postAddress(postAddressData):
let (streetLine1, streetLine2, city, state, countryIso2, postCode) = (postAddressData.streetLine1, postAddressData.streetLine2, postAddressData.city, postAddressData.state, postAddressData.countryIso2, postAddressData.postCode)
parsedShippingAddress = BotPaymentShippingAddress(streetLine1: streetLine1, streetLine2: streetLine2, city: city, state: state, countryIso2: countryIso2, postCode: postCode)
}
}
@ -656,7 +657,7 @@ func _internal_validateBotPaymentForm(account: Account, saveInfo: Bool, source:
var apiShippingAddress: Api.PostAddress?
if let address = formInfo.shippingAddress {
infoFlags |= (1 << 3)
apiShippingAddress = .postAddress(streetLine1: address.streetLine1, streetLine2: address.streetLine2, city: address.city, state: address.state, countryIso2: address.countryIso2, postCode: address.postCode)
apiShippingAddress = .postAddress(.init(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(.init(flags: infoFlags, name: formInfo.name, phone: formInfo.phone, email: formInfo.email, shippingAddress: apiShippingAddress))))
|> mapError { error -> ValidateBotPaymentFormError in

View file

@ -240,17 +240,20 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
switch apiPhoto {
case .photoEmpty:
break
case let .photo(_, id, accessHash, fileReference, _, sizes, videoSizes, dcId):
var sizes = sizes
case let .photo(photoData):
let (id, accessHash, fileReference, apiSizes, videoSizes, dcId) = (photoData.id, photoData.accessHash, photoData.fileReference, photoData.sizes, photoData.videoSizes, photoData.dcId)
var sizes = apiSizes
if sizes.count == 3 {
sizes.remove(at: 1)
}
for size in sizes {
switch size {
case let .photoSize(_, w, h, _):
case let .photoSize(photoSizeData):
let (w, h) = (photoSizeData.w, photoSizeData.h)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(_, w, h, sizes):
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: sizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(photoSizeProgressiveData):
let (w, h, progressiveSizes) = (photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: progressiveSizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
default:
break
}
@ -452,17 +455,20 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
switch apiPhoto {
case .photoEmpty:
break
case let .photo(_, id, _, _, _, sizes, _, dcId):
var sizes = sizes
case let .photo(photoData):
let (id, apiSizes, dcId) = (photoData.id, photoData.sizes, photoData.dcId)
var sizes = apiSizes
if sizes.count == 3 {
sizes.remove(at: 1)
}
for size in sizes {
switch size {
case let .photoSize(_, w, h, _):
case let .photoSize(photoSizeData):
let (w, h) = (photoSizeData.w, photoSizeData.h)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(_, w, h, sizes):
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: sizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(photoSizeProgressiveData):
let (w, h, progressiveSizes) = (photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: progressiveSizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
default:
break
}

View file

@ -53,7 +53,8 @@ func _internal_requestPeerPhotos(accountPeerId: PeerId, postbox: Postbox, networ
if let image = telegramMediaImageFromApiPhoto(photos[i]), let reference = image.reference {
var date: Int32 = 0
switch photos[i] {
case let .photo(_, _, _, _, apiDate, _, _, _):
case let .photo(photoData):
let apiDate = photoData.date
date = apiDate
case .photoEmpty:
break

View file

@ -21,16 +21,20 @@ func telegramStickerPackThumbnailRepresentationFromApiSizes(datacenterId: Int32,
var representations: [TelegramMediaImageRepresentation] = []
for size in sizes {
switch size {
case let .photoCachedSize(type, w, h, _):
case let .photoCachedSize(photoCachedSizeData):
let (type, w, h) = (photoCachedSizeData.type, photoCachedSizeData.w, photoCachedSizeData.h)
let resource = CloudStickerPackThumbnailMediaResource(datacenterId: datacenterId, thumbVersion: thumbVersion, volumeId: nil, localId: nil)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, typeHint: stickerTypeHint(for: type)))
case let .photoSize(type, w, h, _):
case let .photoSize(photoSizeData):
let (type, w, h) = (photoSizeData.type, photoSizeData.w, photoSizeData.h)
let resource = CloudStickerPackThumbnailMediaResource(datacenterId: datacenterId, thumbVersion: thumbVersion, volumeId: nil, localId: nil)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, typeHint: stickerTypeHint(for: type)))
case let .photoSizeProgressive(type, w, h, sizes):
case let .photoSizeProgressive(photoSizeProgressiveData):
let (type, w, h, sizes) = (photoSizeProgressiveData.type, photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
let resource = CloudStickerPackThumbnailMediaResource(datacenterId: datacenterId, thumbVersion: thumbVersion, volumeId: nil, localId: nil)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: sizes, immediateThumbnailData: nil, typeHint: stickerTypeHint(for: type)))
case let .photoPathSize(_, data):
case let .photoPathSize(photoPathSizeData):
let data = photoPathSizeData.bytes
immediateThumbnailData = data.makeData()
case .photoStrippedSize:
break