Update API [skip ci]

This commit is contained in:
Ilya Laktyushin 2025-01-17 18:13:42 +04:00
parent 1f8d34b0c0
commit a8fd8c6085
12 changed files with 223 additions and 79 deletions

View File

@ -587,8 +587,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1434950843] = { return Api.MessageAction.parse_messageActionSetChatTheme($0) } dict[-1434950843] = { return Api.MessageAction.parse_messageActionSetChatTheme($0) }
dict[1348510708] = { return Api.MessageAction.parse_messageActionSetChatWallPaper($0) } dict[1348510708] = { return Api.MessageAction.parse_messageActionSetChatWallPaper($0) }
dict[1007897979] = { return Api.MessageAction.parse_messageActionSetMessagesTTL($0) } dict[1007897979] = { return Api.MessageAction.parse_messageActionSetMessagesTTL($0) }
dict[-1555785491] = { return Api.MessageAction.parse_messageActionStarGift($0) } dict[1192749220] = { return Api.MessageAction.parse_messageActionStarGift($0) }
dict[638024601] = { return Api.MessageAction.parse_messageActionStarGiftUnique($0) } dict[-1394619519] = { return Api.MessageAction.parse_messageActionStarGiftUnique($0) }
dict[1474192222] = { return Api.MessageAction.parse_messageActionSuggestProfilePhoto($0) } dict[1474192222] = { return Api.MessageAction.parse_messageActionSuggestProfilePhoto($0) }
dict[228168278] = { return Api.MessageAction.parse_messageActionTopicCreate($0) } dict[228168278] = { return Api.MessageAction.parse_messageActionTopicCreate($0) }
dict[-1064024032] = { return Api.MessageAction.parse_messageActionTopicEdit($0) } dict[-1064024032] = { return Api.MessageAction.parse_messageActionTopicEdit($0) }
@ -851,7 +851,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[289586518] = { return Api.SavedContact.parse_savedPhoneContact($0) } dict[289586518] = { return Api.SavedContact.parse_savedPhoneContact($0) }
dict[-1115174036] = { return Api.SavedDialog.parse_savedDialog($0) } dict[-1115174036] = { return Api.SavedDialog.parse_savedDialog($0) }
dict[-881854424] = { return Api.SavedReactionTag.parse_savedReactionTag($0) } dict[-881854424] = { return Api.SavedReactionTag.parse_savedReactionTag($0) }
dict[1002989455] = { return Api.SavedStarGift.parse_savedStarGift($0) } dict[1616305061] = { return Api.SavedStarGift.parse_savedStarGift($0) }
dict[-911191137] = { return Api.SearchResultsCalendarPeriod.parse_searchResultsCalendarPeriod($0) } dict[-911191137] = { return Api.SearchResultsCalendarPeriod.parse_searchResultsCalendarPeriod($0) }
dict[2137295719] = { return Api.SearchResultsPosition.parse_searchResultPosition($0) } dict[2137295719] = { return Api.SearchResultsPosition.parse_searchResultPosition($0) }
dict[871426631] = { return Api.SecureCredentialsEncrypted.parse_secureCredentialsEncrypted($0) } dict[871426631] = { return Api.SecureCredentialsEncrypted.parse_secureCredentialsEncrypted($0) }

View File

@ -373,8 +373,8 @@ public extension Api {
case messageActionSetChatTheme(emoticon: String) case messageActionSetChatTheme(emoticon: String)
case messageActionSetChatWallPaper(flags: Int32, wallpaper: Api.WallPaper) case messageActionSetChatWallPaper(flags: Int32, wallpaper: Api.WallPaper)
case messageActionSetMessagesTTL(flags: Int32, period: Int32, autoSettingFrom: Int64?) case messageActionSetMessagesTTL(flags: Int32, period: Int32, autoSettingFrom: Int64?)
case messageActionStarGift(flags: Int32, gift: Api.StarGift, message: Api.TextWithEntities?, convertStars: Int64?, upgradeMsgId: Int32?, upgradeStars: Int64?, fromId: Int64?, peer: Api.Peer?, savedId: Int64?) case messageActionStarGift(flags: Int32, gift: Api.StarGift, message: Api.TextWithEntities?, convertStars: Int64?, upgradeMsgId: Int32?, upgradeStars: Int64?, fromId: Api.Peer?, peer: Api.Peer?, savedId: Int64?)
case messageActionStarGiftUnique(flags: Int32, gift: Api.StarGift, canExportAt: Int32?, transferStars: Int64?) case messageActionStarGiftUnique(flags: Int32, gift: Api.StarGift, canExportAt: Int32?, transferStars: Int64?, fromId: Api.Peer?, peer: Api.Peer?, savedId: Int64?)
case messageActionSuggestProfilePhoto(photo: Api.Photo) case messageActionSuggestProfilePhoto(photo: Api.Photo)
case messageActionTopicCreate(flags: Int32, title: String, iconColor: Int32, iconEmojiId: Int64?) case messageActionTopicCreate(flags: Int32, title: String, iconColor: Int32, iconEmojiId: Int64?)
case messageActionTopicEdit(flags: Int32, title: String?, iconEmojiId: Int64?, closed: Api.Bool?, hidden: Api.Bool?) case messageActionTopicEdit(flags: Int32, title: String?, iconEmojiId: Int64?, closed: Api.Bool?, hidden: Api.Bool?)
@ -722,7 +722,7 @@ public extension Api {
break break
case .messageActionStarGift(let flags, let gift, let message, let convertStars, let upgradeMsgId, let upgradeStars, let fromId, let peer, let savedId): case .messageActionStarGift(let flags, let gift, let message, let convertStars, let upgradeMsgId, let upgradeStars, let fromId, let peer, let savedId):
if boxed { if boxed {
buffer.appendInt32(-1555785491) buffer.appendInt32(1192749220)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
gift.serialize(buffer, true) gift.serialize(buffer, true)
@ -730,18 +730,21 @@ public extension Api {
if Int(flags) & Int(1 << 4) != 0 {serializeInt64(convertStars!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 4) != 0 {serializeInt64(convertStars!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 5) != 0 {serializeInt32(upgradeMsgId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 5) != 0 {serializeInt32(upgradeMsgId!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 8) != 0 {serializeInt64(upgradeStars!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 8) != 0 {serializeInt64(upgradeStars!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 11) != 0 {serializeInt64(fromId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 11) != 0 {fromId!.serialize(buffer, true)}
if Int(flags) & Int(1 << 11) != 0 {peer!.serialize(buffer, true)} if Int(flags) & Int(1 << 12) != 0 {peer!.serialize(buffer, true)}
if Int(flags) & Int(1 << 11) != 0 {serializeInt64(savedId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 12) != 0 {serializeInt64(savedId!, buffer: buffer, boxed: false)}
break break
case .messageActionStarGiftUnique(let flags, let gift, let canExportAt, let transferStars): case .messageActionStarGiftUnique(let flags, let gift, let canExportAt, let transferStars, let fromId, let peer, let savedId):
if boxed { if boxed {
buffer.appendInt32(638024601) buffer.appendInt32(-1394619519)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
gift.serialize(buffer, true) gift.serialize(buffer, true)
if Int(flags) & Int(1 << 3) != 0 {serializeInt32(canExportAt!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 3) != 0 {serializeInt32(canExportAt!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 4) != 0 {serializeInt64(transferStars!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 4) != 0 {serializeInt64(transferStars!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 6) != 0 {fromId!.serialize(buffer, true)}
if Int(flags) & Int(1 << 7) != 0 {peer!.serialize(buffer, true)}
if Int(flags) & Int(1 << 7) != 0 {serializeInt64(savedId!, buffer: buffer, boxed: false)}
break break
case .messageActionSuggestProfilePhoto(let photo): case .messageActionSuggestProfilePhoto(let photo):
if boxed { if boxed {
@ -870,8 +873,8 @@ public extension Api {
return ("messageActionSetMessagesTTL", [("flags", flags as Any), ("period", period as Any), ("autoSettingFrom", autoSettingFrom as Any)]) return ("messageActionSetMessagesTTL", [("flags", flags as Any), ("period", period as Any), ("autoSettingFrom", autoSettingFrom as Any)])
case .messageActionStarGift(let flags, let gift, let message, let convertStars, let upgradeMsgId, let upgradeStars, let fromId, let peer, let savedId): case .messageActionStarGift(let flags, let gift, let message, let convertStars, let upgradeMsgId, let upgradeStars, let fromId, let peer, let savedId):
return ("messageActionStarGift", [("flags", flags as Any), ("gift", gift as Any), ("message", message as Any), ("convertStars", convertStars as Any), ("upgradeMsgId", upgradeMsgId as Any), ("upgradeStars", upgradeStars as Any), ("fromId", fromId as Any), ("peer", peer as Any), ("savedId", savedId as Any)]) return ("messageActionStarGift", [("flags", flags as Any), ("gift", gift as Any), ("message", message as Any), ("convertStars", convertStars as Any), ("upgradeMsgId", upgradeMsgId as Any), ("upgradeStars", upgradeStars as Any), ("fromId", fromId as Any), ("peer", peer as Any), ("savedId", savedId as Any)])
case .messageActionStarGiftUnique(let flags, let gift, let canExportAt, let transferStars): case .messageActionStarGiftUnique(let flags, let gift, let canExportAt, let transferStars, let fromId, let peer, let savedId):
return ("messageActionStarGiftUnique", [("flags", flags as Any), ("gift", gift as Any), ("canExportAt", canExportAt as Any), ("transferStars", transferStars as Any)]) return ("messageActionStarGiftUnique", [("flags", flags as Any), ("gift", gift as Any), ("canExportAt", canExportAt as Any), ("transferStars", transferStars as Any), ("fromId", fromId as Any), ("peer", peer as Any), ("savedId", savedId as Any)])
case .messageActionSuggestProfilePhoto(let photo): case .messageActionSuggestProfilePhoto(let photo):
return ("messageActionSuggestProfilePhoto", [("photo", photo as Any)]) return ("messageActionSuggestProfilePhoto", [("photo", photo as Any)])
case .messageActionTopicCreate(let flags, let title, let iconColor, let iconEmojiId): case .messageActionTopicCreate(let flags, let title, let iconColor, let iconEmojiId):
@ -1536,14 +1539,16 @@ public extension Api {
if Int(_1!) & Int(1 << 5) != 0 {_5 = reader.readInt32() } if Int(_1!) & Int(1 << 5) != 0 {_5 = reader.readInt32() }
var _6: Int64? var _6: Int64?
if Int(_1!) & Int(1 << 8) != 0 {_6 = reader.readInt64() } if Int(_1!) & Int(1 << 8) != 0 {_6 = reader.readInt64() }
var _7: Int64? var _7: Api.Peer?
if Int(_1!) & Int(1 << 11) != 0 {_7 = reader.readInt64() }
var _8: Api.Peer?
if Int(_1!) & Int(1 << 11) != 0 {if let signature = reader.readInt32() { if Int(_1!) & Int(1 << 11) != 0 {if let signature = reader.readInt32() {
_7 = Api.parse(reader, signature: signature) as? Api.Peer
} }
var _8: Api.Peer?
if Int(_1!) & Int(1 << 12) != 0 {if let signature = reader.readInt32() {
_8 = Api.parse(reader, signature: signature) as? Api.Peer _8 = Api.parse(reader, signature: signature) as? Api.Peer
} } } }
var _9: Int64? var _9: Int64?
if Int(_1!) & Int(1 << 11) != 0 {_9 = reader.readInt64() } if Int(_1!) & Int(1 << 12) != 0 {_9 = reader.readInt64() }
let _c1 = _1 != nil let _c1 = _1 != nil
let _c2 = _2 != nil let _c2 = _2 != nil
let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil
@ -1551,8 +1556,8 @@ public extension Api {
let _c5 = (Int(_1!) & Int(1 << 5) == 0) || _5 != nil let _c5 = (Int(_1!) & Int(1 << 5) == 0) || _5 != nil
let _c6 = (Int(_1!) & Int(1 << 8) == 0) || _6 != nil let _c6 = (Int(_1!) & Int(1 << 8) == 0) || _6 != nil
let _c7 = (Int(_1!) & Int(1 << 11) == 0) || _7 != nil let _c7 = (Int(_1!) & Int(1 << 11) == 0) || _7 != nil
let _c8 = (Int(_1!) & Int(1 << 11) == 0) || _8 != nil let _c8 = (Int(_1!) & Int(1 << 12) == 0) || _8 != nil
let _c9 = (Int(_1!) & Int(1 << 11) == 0) || _9 != nil let _c9 = (Int(_1!) & Int(1 << 12) == 0) || _9 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 {
return Api.MessageAction.messageActionStarGift(flags: _1!, gift: _2!, message: _3, convertStars: _4, upgradeMsgId: _5, upgradeStars: _6, fromId: _7, peer: _8, savedId: _9) return Api.MessageAction.messageActionStarGift(flags: _1!, gift: _2!, message: _3, convertStars: _4, upgradeMsgId: _5, upgradeStars: _6, fromId: _7, peer: _8, savedId: _9)
} }
@ -1571,12 +1576,25 @@ public extension Api {
if Int(_1!) & Int(1 << 3) != 0 {_3 = reader.readInt32() } if Int(_1!) & Int(1 << 3) != 0 {_3 = reader.readInt32() }
var _4: Int64? var _4: Int64?
if Int(_1!) & Int(1 << 4) != 0 {_4 = reader.readInt64() } if Int(_1!) & Int(1 << 4) != 0 {_4 = reader.readInt64() }
var _5: Api.Peer?
if Int(_1!) & Int(1 << 6) != 0 {if let signature = reader.readInt32() {
_5 = Api.parse(reader, signature: signature) as? Api.Peer
} }
var _6: Api.Peer?
if Int(_1!) & Int(1 << 7) != 0 {if let signature = reader.readInt32() {
_6 = Api.parse(reader, signature: signature) as? Api.Peer
} }
var _7: Int64?
if Int(_1!) & Int(1 << 7) != 0 {_7 = reader.readInt64() }
let _c1 = _1 != nil let _c1 = _1 != nil
let _c2 = _2 != nil let _c2 = _2 != nil
let _c3 = (Int(_1!) & Int(1 << 3) == 0) || _3 != nil let _c3 = (Int(_1!) & Int(1 << 3) == 0) || _3 != nil
let _c4 = (Int(_1!) & Int(1 << 4) == 0) || _4 != nil let _c4 = (Int(_1!) & Int(1 << 4) == 0) || _4 != nil
if _c1 && _c2 && _c3 && _c4 { let _c5 = (Int(_1!) & Int(1 << 6) == 0) || _5 != nil
return Api.MessageAction.messageActionStarGiftUnique(flags: _1!, gift: _2!, canExportAt: _3, transferStars: _4) let _c6 = (Int(_1!) & Int(1 << 7) == 0) || _6 != nil
let _c7 = (Int(_1!) & Int(1 << 7) == 0) || _7 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 {
return Api.MessageAction.messageActionStarGiftUnique(flags: _1!, gift: _2!, canExportAt: _3, transferStars: _4, fromId: _5, peer: _6, savedId: _7)
} }
else { else {
return nil return nil

View File

@ -144,16 +144,16 @@ public extension Api {
} }
public extension Api { public extension Api {
enum SavedStarGift: TypeConstructorDescription { enum SavedStarGift: TypeConstructorDescription {
case savedStarGift(flags: Int32, fromId: Int64?, date: Int32, gift: Api.StarGift, message: Api.TextWithEntities?, msgId: Int32?, savedId: Int64?, convertStars: Int64?, upgradeStars: Int64?, canExportAt: Int32?, transferStars: Int64?) case savedStarGift(flags: Int32, fromId: Api.Peer?, date: Int32, gift: Api.StarGift, message: Api.TextWithEntities?, msgId: Int32?, savedId: Int64?, convertStars: Int64?, upgradeStars: Int64?, canExportAt: Int32?, transferStars: Int64?)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self { switch self {
case .savedStarGift(let flags, let fromId, let date, let gift, let message, let msgId, let savedId, let convertStars, let upgradeStars, let canExportAt, let transferStars): case .savedStarGift(let flags, let fromId, let date, let gift, let message, let msgId, let savedId, let convertStars, let upgradeStars, let canExportAt, let transferStars):
if boxed { if boxed {
buffer.appendInt32(1002989455) buffer.appendInt32(1616305061)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 1) != 0 {serializeInt64(fromId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 1) != 0 {fromId!.serialize(buffer, true)}
serializeInt32(date, buffer: buffer, boxed: false) serializeInt32(date, buffer: buffer, boxed: false)
gift.serialize(buffer, true) gift.serialize(buffer, true)
if Int(flags) & Int(1 << 2) != 0 {message!.serialize(buffer, true)} if Int(flags) & Int(1 << 2) != 0 {message!.serialize(buffer, true)}
@ -177,8 +177,10 @@ public extension Api {
public static func parse_savedStarGift(_ reader: BufferReader) -> SavedStarGift? { public static func parse_savedStarGift(_ reader: BufferReader) -> SavedStarGift? {
var _1: Int32? var _1: Int32?
_1 = reader.readInt32() _1 = reader.readInt32()
var _2: Int64? var _2: Api.Peer?
if Int(_1!) & Int(1 << 1) != 0 {_2 = reader.readInt64() } if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() {
_2 = Api.parse(reader, signature: signature) as? Api.Peer
} }
var _3: Int32? var _3: Int32?
_3 = reader.readInt32() _3 = reader.readInt32()
var _4: Api.StarGift? var _4: Api.StarGift?

View File

@ -9632,9 +9632,9 @@ public extension Api.functions.payments {
} }
} }
public extension Api.functions.payments { public extension Api.functions.payments {
static func transferStarGift(stargift: Api.InputSavedStarGift, toId: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) { static func transferStarGift(stargift: Api.InputSavedStarGift, toId: Api.InputPeer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(-279379968) buffer.appendInt32(2132285290)
stargift.serialize(buffer, true) stargift.serialize(buffer, true)
toId.serialize(buffer, true) toId.serialize(buffer, true)
return (FunctionDescription(name: "payments.transferStarGift", parameters: [("stargift", String(describing: stargift)), ("toId", String(describing: toId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in return (FunctionDescription(name: "payments.transferStarGift", parameters: [("stargift", String(describing: stargift)), ("toId", String(describing: toId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in

View File

@ -351,9 +351,8 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI
let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil, venueType: nil, liveBroadcastingTimeout: period, liveProximityNotificationRadius: proximityNotificationRadius, heading: heading) let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil, venueType: nil, liveBroadcastingTimeout: period, liveProximityNotificationRadius: proximityNotificationRadius, heading: heading)
return (mediaMap, nil, nil, nil, nil) return (mediaMap, nil, nil, nil, nil)
case let .messageMediaDocument(flags, document, altDocuments, coverPhoto, ttlSeconds): case let .messageMediaDocument(flags, document, altDocuments, coverPhoto, ttlSeconds):
let _ = coverPhoto
if let document = document { if let document = document {
if let mediaFile = telegramMediaFileFromApiDocument(document, altDocuments: altDocuments) { if let mediaFile = telegramMediaFileFromApiDocument(document, altDocuments: altDocuments, videoCover: coverPhoto) {
return (mediaFile, ttlSeconds, (flags & (1 << 3)) != 0, (flags & (1 << 4)) != 0, nil) return (mediaFile, ttlSeconds, (flags & (1 << 3)) != 0, (flags & (1 << 4)) != 0, nil)
} }
} else { } else {

View File

@ -185,12 +185,12 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
guard let gift = StarGift(apiStarGift: apiGift) else { guard let gift = StarGift(apiStarGift: apiGift) else {
return nil return nil
} }
return TelegramMediaAction(action: .starGift(gift: gift, convertStars: convertStars, text: text, entities: entities, nameHidden: (flags & (1 << 0)) != 0, savedToProfile: (flags & (1 << 2)) != 0, converted: (flags & (1 << 3)) != 0, upgraded: (flags & (1 << 5)) != 0, canUpgrade: (flags & (1 << 10)) != 0, upgradeStars: upgradeStars, isRefunded: (flags & (1 << 9)) != 0, upgradeMessageId: upgradeMessageId, peerId: peer?.peerId, senderId: fromId.flatMap { EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value($0)) }, savedId: savedId)) return TelegramMediaAction(action: .starGift(gift: gift, convertStars: convertStars, text: text, entities: entities, nameHidden: (flags & (1 << 0)) != 0, savedToProfile: (flags & (1 << 2)) != 0, converted: (flags & (1 << 3)) != 0, upgraded: (flags & (1 << 5)) != 0, canUpgrade: (flags & (1 << 10)) != 0, upgradeStars: upgradeStars, isRefunded: (flags & (1 << 9)) != 0, upgradeMessageId: upgradeMessageId, peerId: peer?.peerId, senderId: fromId?.peerId, savedId: savedId))
case let .messageActionStarGiftUnique(flags, apiGift, canExportAt, transferStars): case let .messageActionStarGiftUnique(flags, apiGift, canExportAt, transferStars, fromId, peer, savedId):
guard let gift = StarGift(apiStarGift: apiGift) else { guard let gift = StarGift(apiStarGift: apiGift) else {
return nil return nil
} }
return TelegramMediaAction(action: .starGiftUnique(gift: gift, isUpgrade: (flags & (1 << 0)) != 0, isTransferred: (flags & (1 << 1)) != 0, savedToProfile: (flags & (1 << 2)) != 0, canExportDate: canExportAt, transferStars: transferStars, isRefunded: (flags & (1 << 5)) != 0)) return TelegramMediaAction(action: .starGiftUnique(gift: gift, isUpgrade: (flags & (1 << 0)) != 0, isTransferred: (flags & (1 << 1)) != 0, savedToProfile: (flags & (1 << 2)) != 0, canExportDate: canExportAt, transferStars: transferStars, isRefunded: (flags & (1 << 5)) != 0, peerId: peer?.peerId, senderId: fromId?.peerId, savedId: savedId))
} }
} }

View File

@ -158,7 +158,7 @@ func telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: Int32,
return (immediateThumbnailData, representations) return (immediateThumbnailData, representations)
} }
func telegramMediaFileFromApiDocument(_ document: Api.Document, altDocuments: [Api.Document]?) -> TelegramMediaFile? { func telegramMediaFileFromApiDocument(_ document: Api.Document, altDocuments: [Api.Document]?, videoCover: Api.Photo? = nil) -> TelegramMediaFile? {
switch document { switch document {
case let .document(_, id, accessHash, fileReference, _, mimeType, size, thumbs, videoThumbs, dcId, attributes): case let .document(_, id, accessHash, fileReference, _, mimeType, size, thumbs, videoThumbs, dcId, attributes):
var parsedAttributes = telegramMediaFileAttributesFromApiAttributes(attributes) var parsedAttributes = telegramMediaFileAttributesFromApiAttributes(attributes)
@ -188,7 +188,7 @@ func telegramMediaFileFromApiDocument(_ document: Api.Document, altDocuments: [A
alternativeRepresentations = altDocuments.compactMap { telegramMediaFileFromApiDocument($0, altDocuments: []) } alternativeRepresentations = altDocuments.compactMap { telegramMediaFileFromApiDocument($0, altDocuments: []) }
} }
return TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.CloudFile, id: id), partialReference: nil, resource: CloudDocumentMediaResource(datacenterId: Int(dcId), fileId: id, accessHash: accessHash, size: size, fileReference: fileReference.makeData(), fileName: fileNameFromFileAttributes(parsedAttributes)), previewRepresentations: previewRepresentations, videoThumbnails: videoThumbnails, immediateThumbnailData: immediateThumbnail, mimeType: mimeType, size: size, attributes: parsedAttributes, alternativeRepresentations: alternativeRepresentations) return TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.CloudFile, id: id), partialReference: nil, resource: CloudDocumentMediaResource(datacenterId: Int(dcId), fileId: id, accessHash: accessHash, size: size, fileReference: fileReference.makeData(), fileName: fileNameFromFileAttributes(parsedAttributes)), previewRepresentations: previewRepresentations, videoThumbnails: videoThumbnails, videoCover: videoCover.flatMap(telegramMediaImageFromApiPhoto), immediateThumbnailData: immediateThumbnail, mimeType: mimeType, size: size, attributes: parsedAttributes, alternativeRepresentations: alternativeRepresentations)
case .documentEmpty: case .documentEmpty:
return nil return nil
} }

View File

@ -761,12 +761,13 @@ private enum UploadedMediaTransform {
private enum UploadedMediaThumbnailResult { private enum UploadedMediaThumbnailResult {
case file(Api.InputFile) case file(Api.InputFile)
case photo(Api.InputPhoto)
case none case none
} }
private enum UploadedMediaFileAndThumbnail { private enum UploadedMediaFileAndThumbnail {
case pending case pending
case done(TelegramMediaFile, UploadedMediaThumbnailResult) case done(TelegramMediaFile, UploadedMediaThumbnailResult, UploadedMediaThumbnailResult)
} }
private func uploadedThumbnail(network: Network, postbox: Postbox, resourceReference: MediaResourceReference, forceNoBigParts: Bool = false) -> Signal<Api.InputFile?, PendingMessageUploadError> { private func uploadedThumbnail(network: Network, postbox: Postbox, resourceReference: MediaResourceReference, forceNoBigParts: Bool = false) -> Signal<Api.InputFile?, PendingMessageUploadError> {
@ -784,6 +785,43 @@ private func uploadedThumbnail(network: Network, postbox: Postbox, resourceRefer
} }
} }
private func uploadedVideoCover(network: Network, postbox: Postbox, resourceReference: MediaResourceReference, peerId: PeerId) -> Signal<Api.InputPhoto?, PendingMessageUploadError> {
return postbox.transaction { transaction -> Api.InputPeer? in
return transaction.getPeer(peerId).flatMap(apiInputPeer)
}
|> castError(PendingMessageUploadError.self)
|> mapToSignal { inputPeer -> Signal<Api.InputPhoto?, PendingMessageUploadError> in
guard let inputPeer else {
return .single(.inputPhotoEmpty)
}
return multipartUpload(network: network, postbox: postbox, source: .resource(resourceReference), encrypt: false, tag: TelegramMediaResourceFetchTag(statsCategory: .image, userContentType: .image), hintFileSize: nil, hintFileIsLarge: false, forceNoBigParts: true)
|> mapError { _ -> PendingMessageUploadError in return .generic }
|> mapToSignal { result -> Signal<Api.InputPhoto?, PendingMessageUploadError> in
switch result {
case .progress:
return .complete()
case let .inputFile(file):
return network.request(Api.functions.messages.uploadMedia(flags: 0, businessConnectionId: nil, peer: inputPeer, media: Api.InputMedia.inputMediaUploadedPhoto(flags: 0, file: file, stickers: [], ttlSeconds: nil)))
|> mapError { _ -> PendingMessageUploadError in return .generic }
|> map { uploadResult in
switch uploadResult {
case let .messageMediaPhoto(_, photo, _):
if case let .photo(_, id, accessHash, fileReference, _, _, _, _) = photo {
return .inputPhoto(id: id, accessHash: accessHash, fileReference: fileReference)
} else {
return .inputPhotoEmpty
}
default:
return .inputPhotoEmpty
}
}
case .inputSecretFile:
return .single(nil)
}
}
}
}
public func statsCategoryForFileWithAttributes(_ attributes: [TelegramMediaFileAttribute]) -> MediaResourceStatsCategory { public func statsCategoryForFileWithAttributes(_ attributes: [TelegramMediaFileAttribute]) -> MediaResourceStatsCategory {
for attribute in attributes { for attribute in attributes {
switch attribute { switch attribute {
@ -956,29 +994,57 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
case .pending: case .pending:
return .single(.pending) return .single(.pending)
case let .done(media): case let .done(media):
if let media = media as? TelegramMediaFile, let smallestThumbnail = smallestImageRepresentation(media.previewRepresentations) {
if peerId.namespace == Namespaces.Peer.SecretChat { if peerId.namespace == Namespaces.Peer.SecretChat {
return .single(.done(media, .none)) return .single(.done(file, .none, .none))
} else { } else {
var thumbnailSignal: Signal<UploadedMediaThumbnailResult, PendingMessageUploadError> = .single(.none)
var videoCoverSignal: Signal<UploadedMediaThumbnailResult, PendingMessageUploadError> = .single(.none)
if let media = media as? TelegramMediaFile {
if let smallestThumbnail = smallestImageRepresentation(media.previewRepresentations) {
let fileReference: AnyMediaReference let fileReference: AnyMediaReference
if let partialReference = media.partialReference { if let partialReference = media.partialReference {
fileReference = partialReference.mediaReference(media) fileReference = partialReference.mediaReference(media)
} else { } else {
fileReference = .standalone(media: media) fileReference = .standalone(media: media)
} }
thumbnailSignal = uploadedThumbnail(network: network, postbox: postbox, resourceReference: fileReference.resourceReference(smallestThumbnail.resource), forceNoBigParts: forceNoBigParts)
return uploadedThumbnail(network: network, postbox: postbox, resourceReference: fileReference.resourceReference(smallestThumbnail.resource), forceNoBigParts: forceNoBigParts)
|> mapError { _ -> PendingMessageUploadError in return .generic } |> mapError { _ -> PendingMessageUploadError in return .generic }
|> map { result in |> map { result in
if let result = result { if let result = result {
return .done(media, .file(result)) return .file(result)
} else { } else {
return .done(media, .none) return .none
} }
} }
} }
if let cover = media.videoCover, let resource = cover.representations.first?.resource {
let fileReference: AnyMediaReference
if let partialReference = media.partialReference {
fileReference = partialReference.mediaReference(media)
} else {
fileReference = .standalone(media: media)
}
videoCoverSignal = uploadedVideoCover(network: network, postbox: postbox, resourceReference: fileReference.resourceReference(resource), peerId: peerId)
|> mapError { _ -> PendingMessageUploadError in return .generic }
|> map { result in
if let result = result {
return .photo(result)
} else {
return .none
}
}
}
return combineLatest(
thumbnailSignal,
videoCoverSignal
)
|> map { thumbnail, videoCover in
return .done(media, thumbnail, videoCover)
}
} else { } else {
return .single(.done(file, .none)) return .single(.done(file, .none, .none))
}
} }
} }
}) })
@ -999,18 +1065,25 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
} }
return .single(.progress(PendingMessageUploadedContentProgress(progress: progress))) return .single(.progress(PendingMessageUploadedContentProgress(progress: progress)))
case let .inputFile(inputFile): case let .inputFile(inputFile):
if case let .done(file, thumbnail) = fileAndThumbnailResult { if case let .done(file, thumbnail, videoCover) = fileAndThumbnailResult {
var flags: Int32 = 0 var flags: Int32 = 0
var hasSpoiler = false var hasSpoiler = false
var thumbnailFile: Api.InputFile? var thumbnailFile: Api.InputFile?
var videoCoverPhoto: Api.InputPhoto?
if case let .file(file) = thumbnail { if case let .file(file) = thumbnail {
thumbnailFile = file thumbnailFile = file
} }
if case let .photo(photo) = videoCover {
videoCoverPhoto = photo
}
if let _ = thumbnailFile { if let _ = thumbnailFile {
flags |= 1 << 2 flags |= 1 << 2
} }
if let _ = videoCoverPhoto {
flags |= 1 << 6
}
var ttlSeconds: Int32? var ttlSeconds: Int32?
for attribute in attributes { for attribute in attributes {
@ -1049,11 +1122,11 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
} }
if ttlSeconds != nil { if ttlSeconds != nil {
return .single(.content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, videoCover: nil, ttlSeconds: ttlSeconds), text), reuploadInfo: nil, cacheReferenceKey: referenceKey))) return .single(.content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, videoCover: videoCoverPhoto, ttlSeconds: ttlSeconds), text), reuploadInfo: nil, cacheReferenceKey: referenceKey)))
} }
if !isGrouped { if !isGrouped {
let resultInfo = PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, videoCover: nil, ttlSeconds: ttlSeconds), text), reuploadInfo: nil, cacheReferenceKey: referenceKey) let resultInfo = PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, videoCover: videoCoverPhoto, ttlSeconds: ttlSeconds), text), reuploadInfo: nil, cacheReferenceKey: referenceKey)
return .single(.content(resultInfo)) return .single(.content(resultInfo))
} }
@ -1064,7 +1137,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
|> mapError { _ -> PendingMessageUploadError in } |> mapError { _ -> PendingMessageUploadError in }
|> mapToSignal { inputPeer -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in |> mapToSignal { inputPeer -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in
if let inputPeer = inputPeer { if let inputPeer = inputPeer {
return network.request(Api.functions.messages.uploadMedia(flags: 0, businessConnectionId: nil, peer: inputPeer, media: .inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, videoCover: nil, ttlSeconds: ttlSeconds))) return network.request(Api.functions.messages.uploadMedia(flags: 0, businessConnectionId: nil, peer: inputPeer, media: .inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, videoCover: videoCoverPhoto, ttlSeconds: ttlSeconds)))
|> mapError { _ -> PendingMessageUploadError in return .generic } |> mapError { _ -> PendingMessageUploadError in return .generic }
|> mapToSignal { result -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in |> mapToSignal { result -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in
switch result { switch result {
@ -1079,8 +1152,11 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
if hasSpoiler { if hasSpoiler {
flags |= (1 << 2) flags |= (1 << 2)
} }
if let _ = videoCoverPhoto {
flags |= (1 << 3)
}
let result: PendingMessageUploadedContentResult = .content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaDocument(flags: flags, id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: fileReference)), videoCover: nil, ttlSeconds: ttlSeconds, query: nil), text), reuploadInfo: nil, cacheReferenceKey: nil)) let result: PendingMessageUploadedContentResult = .content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaDocument(flags: flags, id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: fileReference)), videoCover: videoCoverPhoto, ttlSeconds: ttlSeconds, query: nil), text), reuploadInfo: nil, cacheReferenceKey: nil))
if let _ = ttlSeconds { if let _ = ttlSeconds {
return .single(result) return .single(result)
} else { } else {

View File

@ -131,7 +131,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case giftStars(currency: String, amount: Int64, count: Int64, cryptoCurrency: String?, cryptoAmount: Int64?, transactionId: String?) case giftStars(currency: String, amount: Int64, count: Int64, cryptoCurrency: String?, cryptoAmount: Int64?, transactionId: String?)
case prizeStars(amount: Int64, isUnclaimed: Bool, boostPeerId: PeerId?, transactionId: String?, giveawayMessageId: MessageId?) case prizeStars(amount: Int64, isUnclaimed: Bool, boostPeerId: PeerId?, transactionId: String?, giveawayMessageId: MessageId?)
case starGift(gift: StarGift, convertStars: Int64?, text: String?, entities: [MessageTextEntity]?, nameHidden: Bool, savedToProfile: Bool, converted: Bool, upgraded: Bool, canUpgrade: Bool, upgradeStars: Int64?, isRefunded: Bool, upgradeMessageId: Int32?, peerId: EnginePeer.Id?, senderId: EnginePeer.Id?, savedId: Int64?) case starGift(gift: StarGift, convertStars: Int64?, text: String?, entities: [MessageTextEntity]?, nameHidden: Bool, savedToProfile: Bool, converted: Bool, upgraded: Bool, canUpgrade: Bool, upgradeStars: Int64?, isRefunded: Bool, upgradeMessageId: Int32?, peerId: EnginePeer.Id?, senderId: EnginePeer.Id?, savedId: Int64?)
case starGiftUnique(gift: StarGift, isUpgrade: Bool, isTransferred: Bool, savedToProfile: Bool, canExportDate: Int32?, transferStars: Int64?, isRefunded: Bool) case starGiftUnique(gift: StarGift, isUpgrade: Bool, isTransferred: Bool, savedToProfile: Bool, canExportDate: Int32?, transferStars: Int64?, isRefunded: Bool, peerId: EnginePeer.Id?, senderId: EnginePeer.Id?, savedId: Int64?)
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
@ -255,7 +255,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case 44: case 44:
self = .starGift(gift: decoder.decodeObjectForKey("gift", decoder: { StarGift(decoder: $0) }) as! StarGift, convertStars: decoder.decodeOptionalInt64ForKey("convertStars"), text: decoder.decodeOptionalStringForKey("text"), entities: decoder.decodeOptionalObjectArrayWithDecoderForKey("entities"), nameHidden: decoder.decodeBoolForKey("nameHidden", orElse: false), savedToProfile: decoder.decodeBoolForKey("savedToProfile", orElse: false), converted: decoder.decodeBoolForKey("converted", orElse: false), upgraded: decoder.decodeBoolForKey("upgraded", orElse: false), canUpgrade: decoder.decodeBoolForKey("canUpgrade", orElse: false), upgradeStars: decoder.decodeOptionalInt64ForKey("upgradeStars"), isRefunded: decoder.decodeBoolForKey("isRefunded", orElse: false), upgradeMessageId: decoder.decodeOptionalInt32ForKey("upgradeMessageId"), peerId: decoder.decodeOptionalInt64ForKey("peerId").flatMap { EnginePeer.Id($0) }, senderId: decoder.decodeOptionalInt64ForKey("senderId").flatMap { EnginePeer.Id($0) }, savedId: decoder.decodeOptionalInt64ForKey("savedId")) self = .starGift(gift: decoder.decodeObjectForKey("gift", decoder: { StarGift(decoder: $0) }) as! StarGift, convertStars: decoder.decodeOptionalInt64ForKey("convertStars"), text: decoder.decodeOptionalStringForKey("text"), entities: decoder.decodeOptionalObjectArrayWithDecoderForKey("entities"), nameHidden: decoder.decodeBoolForKey("nameHidden", orElse: false), savedToProfile: decoder.decodeBoolForKey("savedToProfile", orElse: false), converted: decoder.decodeBoolForKey("converted", orElse: false), upgraded: decoder.decodeBoolForKey("upgraded", orElse: false), canUpgrade: decoder.decodeBoolForKey("canUpgrade", orElse: false), upgradeStars: decoder.decodeOptionalInt64ForKey("upgradeStars"), isRefunded: decoder.decodeBoolForKey("isRefunded", orElse: false), upgradeMessageId: decoder.decodeOptionalInt32ForKey("upgradeMessageId"), peerId: decoder.decodeOptionalInt64ForKey("peerId").flatMap { EnginePeer.Id($0) }, senderId: decoder.decodeOptionalInt64ForKey("senderId").flatMap { EnginePeer.Id($0) }, savedId: decoder.decodeOptionalInt64ForKey("savedId"))
case 45: case 45:
self = .starGiftUnique(gift: decoder.decodeObjectForKey("gift", decoder: { StarGift(decoder: $0) }) as! StarGift, isUpgrade: decoder.decodeBoolForKey("isUpgrade", orElse: false), isTransferred: decoder.decodeBoolForKey("isTransferred", orElse: false), savedToProfile: decoder.decodeBoolForKey("savedToProfile", orElse: false), canExportDate: decoder.decodeOptionalInt32ForKey("canExportDate"), transferStars: decoder.decodeOptionalInt64ForKey("transferStars"), isRefunded: decoder.decodeBoolForKey("isRefunded", orElse: false)) self = .starGiftUnique(gift: decoder.decodeObjectForKey("gift", decoder: { StarGift(decoder: $0) }) as! StarGift, isUpgrade: decoder.decodeBoolForKey("isUpgrade", orElse: false), isTransferred: decoder.decodeBoolForKey("isTransferred", orElse: false), savedToProfile: decoder.decodeBoolForKey("savedToProfile", orElse: false), canExportDate: decoder.decodeOptionalInt32ForKey("canExportDate"), transferStars: decoder.decodeOptionalInt64ForKey("transferStars"), isRefunded: decoder.decodeBoolForKey("isRefunded", orElse: false), peerId: decoder.decodeOptionalInt64ForKey("peerId").flatMap { EnginePeer.Id($0) }, senderId: decoder.decodeOptionalInt64ForKey("senderId").flatMap { EnginePeer.Id($0) }, savedId: decoder.decodeOptionalInt64ForKey("savedId"))
default: default:
self = .unknown self = .unknown
} }
@ -594,7 +594,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
} else { } else {
encoder.encodeNil(forKey: "savedId") encoder.encodeNil(forKey: "savedId")
} }
case let .starGiftUnique(gift, isUpgrade, isTransferred, savedToProfile, canExportDate, transferStars, isRefunded): case let .starGiftUnique(gift, isUpgrade, isTransferred, savedToProfile, canExportDate, transferStars, isRefunded, peerId, senderId, savedId):
encoder.encodeInt32(45, forKey: "_rawValue") encoder.encodeInt32(45, forKey: "_rawValue")
encoder.encodeObject(gift, forKey: "gift") encoder.encodeObject(gift, forKey: "gift")
encoder.encodeBool(isUpgrade, forKey: "isUpgrade") encoder.encodeBool(isUpgrade, forKey: "isUpgrade")
@ -611,6 +611,21 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
encoder.encodeNil(forKey: "transferStars") encoder.encodeNil(forKey: "transferStars")
} }
encoder.encodeBool(isRefunded, forKey: "isRefunded") encoder.encodeBool(isRefunded, forKey: "isRefunded")
if let peerId {
encoder.encodeInt64(peerId.toInt64(), forKey: "peerId")
} else {
encoder.encodeNil(forKey: "peerId")
}
if let senderId {
encoder.encodeInt64(senderId.toInt64(), forKey: "senderId")
} else {
encoder.encodeNil(forKey: "senderId")
}
if let savedId {
encoder.encodeInt64(savedId, forKey: "savedId")
} else {
encoder.encodeNil(forKey: "savedId")
}
} }
} }
@ -638,6 +653,15 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
return [peerId] return [peerId]
case let .prizeStars(_, _, boostPeerId, _, _): case let .prizeStars(_, _, boostPeerId, _, _):
return boostPeerId.flatMap { [$0] } ?? [] return boostPeerId.flatMap { [$0] } ?? []
case let .starGift(_, _, _, _, _, _, _, _, _, _, _, _, peerId, senderId, _):
var peerIds: [PeerId] = []
if let peerId {
peerIds.append(peerId)
}
if let senderId {
peerIds.append(senderId)
}
return peerIds
default: default:
return [] return []
} }

View File

@ -441,6 +441,7 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
public let resource: TelegramMediaResource public let resource: TelegramMediaResource
public let previewRepresentations: [TelegramMediaImageRepresentation] public let previewRepresentations: [TelegramMediaImageRepresentation]
public let videoThumbnails: [TelegramMediaFile.VideoThumbnail] public let videoThumbnails: [TelegramMediaFile.VideoThumbnail]
public let videoCover: TelegramMediaImage?
public let immediateThumbnailData: Data? public let immediateThumbnailData: Data?
public let mimeType: String public let mimeType: String
public let size: Int64? public let size: Int64?
@ -465,12 +466,25 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
return result.isEmpty ? nil : result return result.isEmpty ? nil : result
} }
public init(fileId: MediaId, partialReference: PartialMediaReference?, resource: TelegramMediaResource, previewRepresentations: [TelegramMediaImageRepresentation], videoThumbnails: [TelegramMediaFile.VideoThumbnail], immediateThumbnailData: Data?, mimeType: String, size: Int64?, attributes: [TelegramMediaFileAttribute], alternativeRepresentations: [Media]) { public init(
fileId: MediaId,
partialReference: PartialMediaReference?,
resource: TelegramMediaResource,
previewRepresentations: [TelegramMediaImageRepresentation],
videoThumbnails: [TelegramMediaFile.VideoThumbnail],
videoCover: TelegramMediaImage? = nil,
immediateThumbnailData: Data?,
mimeType: String,
size: Int64?,
attributes: [TelegramMediaFileAttribute],
alternativeRepresentations: [Media]
) {
self.fileId = fileId self.fileId = fileId
self.partialReference = partialReference self.partialReference = partialReference
self.resource = resource self.resource = resource
self.previewRepresentations = previewRepresentations self.previewRepresentations = previewRepresentations
self.videoThumbnails = videoThumbnails self.videoThumbnails = videoThumbnails
self.videoCover = videoCover
self.immediateThumbnailData = immediateThumbnailData self.immediateThumbnailData = immediateThumbnailData
self.mimeType = mimeType self.mimeType = mimeType
self.size = size self.size = size
@ -484,6 +498,7 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource()
self.previewRepresentations = decoder.decodeObjectArrayForKey("pr") self.previewRepresentations = decoder.decodeObjectArrayForKey("pr")
self.videoThumbnails = decoder.decodeObjectArrayForKey("vr") self.videoThumbnails = decoder.decodeObjectArrayForKey("vr")
self.videoCover = decoder.decodeObjectForKey("cv", decoder: { TelegramMediaImage(decoder: $0) }) as? TelegramMediaImage
self.immediateThumbnailData = decoder.decodeDataForKey("itd") self.immediateThumbnailData = decoder.decodeDataForKey("itd")
self.mimeType = decoder.decodeStringForKey("mt", orElse: "") self.mimeType = decoder.decodeStringForKey("mt", orElse: "")
if let size = decoder.decodeOptionalInt64ForKey("s64") { if let size = decoder.decodeOptionalInt64ForKey("s64") {
@ -515,6 +530,11 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
encoder.encodeObject(self.resource, forKey: "r") encoder.encodeObject(self.resource, forKey: "r")
encoder.encodeObjectArray(self.previewRepresentations, forKey: "pr") encoder.encodeObjectArray(self.previewRepresentations, forKey: "pr")
encoder.encodeObjectArray(self.videoThumbnails, forKey: "vr") encoder.encodeObjectArray(self.videoThumbnails, forKey: "vr")
if let videoCover = self.videoCover {
encoder.encodeObject(videoCover, forKey: "cv")
} else {
encoder.encodeNil(forKey: "cv")
}
if let immediateThumbnailData = self.immediateThumbnailData { if let immediateThumbnailData = self.immediateThumbnailData {
encoder.encodeData(immediateThumbnailData, forKey: "itd") encoder.encodeData(immediateThumbnailData, forKey: "itd")
} else { } else {
@ -544,6 +564,7 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
self.resource = object.resource self.resource = object.resource
self.previewRepresentations = object.previewRepresentations self.previewRepresentations = object.previewRepresentations
self.videoThumbnails = object.videoThumbnails self.videoThumbnails = object.videoThumbnails
self.videoCover = object.videoCover
self.immediateThumbnailData = object.immediateThumbnailData self.immediateThumbnailData = object.immediateThumbnailData
self.mimeType = object.mimeType self.mimeType = object.mimeType
self.size = object.size self.size = object.size
@ -805,6 +826,10 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
return false return false
} }
if self.videoCover != other.videoCover {
return false
}
if self.immediateThumbnailData != other.immediateThumbnailData { if self.immediateThumbnailData != other.immediateThumbnailData {
return false return false
} }
@ -879,23 +904,23 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
} }
public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaFile { public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations) return TelegramMediaFile(fileId: self.fileId, partialReference: partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: self.videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations)
} }
public func withUpdatedResource(_ resource: TelegramMediaResource) -> TelegramMediaFile { public func withUpdatedResource(_ resource: TelegramMediaResource) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations) return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: self.videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations)
} }
public func withUpdatedSize(_ size: Int64?) -> TelegramMediaFile { public func withUpdatedSize(_ size: Int64?) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations) return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: self.videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations)
} }
public func withUpdatedPreviewRepresentations(_ previewRepresentations: [TelegramMediaImageRepresentation]) -> TelegramMediaFile { public func withUpdatedPreviewRepresentations(_ previewRepresentations: [TelegramMediaImageRepresentation]) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: previewRepresentations, videoThumbnails: self.videoThumbnails, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations) return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: self.videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations)
} }
public func withUpdatedAttributes(_ attributes: [TelegramMediaFileAttribute]) -> TelegramMediaFile { public func withUpdatedAttributes(_ attributes: [TelegramMediaFileAttribute]) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: attributes, alternativeRepresentations: self.alternativeRepresentations) return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: self.videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: attributes, alternativeRepresentations: self.alternativeRepresentations)
} }
} }

View File

@ -727,19 +727,19 @@ public enum TransferStarGiftError {
} }
func _internal_transferStarGift(account: Account, prepaid: Bool, reference: StarGiftReference, peerId: EnginePeer.Id) -> Signal<Never, TransferStarGiftError> { func _internal_transferStarGift(account: Account, prepaid: Bool, reference: StarGiftReference, peerId: EnginePeer.Id) -> Signal<Never, TransferStarGiftError> {
return account.postbox.transaction { transaction -> (Api.InputUser, Api.InputSavedStarGift)? in return account.postbox.transaction { transaction -> (Api.InputPeer, Api.InputSavedStarGift)? in
guard let inputUser = transaction.getPeer(peerId).flatMap(apiInputUser), let starGift = reference.apiStarGiftReference(transaction: transaction) else { guard let inputPeer = transaction.getPeer(peerId).flatMap(apiInputPeer), let starGift = reference.apiStarGiftReference(transaction: transaction) else {
return nil return nil
} }
return (inputUser, starGift) return (inputPeer, starGift)
} }
|> castError(TransferStarGiftError.self) |> castError(TransferStarGiftError.self)
|> mapToSignal { inputUserAndStarGift -> Signal<Never, TransferStarGiftError> in |> mapToSignal { inputPeerAndStarGift -> Signal<Never, TransferStarGiftError> in
guard let (inputUser, starGift) = inputUserAndStarGift else { guard let (inputPeer, starGift) = inputPeerAndStarGift else {
return .complete() return .complete()
} }
if prepaid { if prepaid {
return account.network.request(Api.functions.payments.transferStarGift(stargift: starGift, toId: inputUser)) return account.network.request(Api.functions.payments.transferStarGift(stargift: starGift, toId: inputPeer))
|> mapError { _ -> TransferStarGiftError in |> mapError { _ -> TransferStarGiftError in
return .generic return .generic
} }
@ -815,7 +815,7 @@ func _internal_upgradeStarGift(account: Account, formId: Int64?, reference: Star
case let .updateNewMessage(message, _, _): case let .updateNewMessage(message, _, _):
if let message = StoreMessage(apiMessage: message, accountPeerId: account.peerId, peerIsForum: false) { if let message = StoreMessage(apiMessage: message, accountPeerId: account.peerId, peerIsForum: false) {
for media in message.media { for media in message.media {
if let action = media as? TelegramMediaAction, case let .starGiftUnique(gift, _, _, savedToProfile, canExportDate, transferStars, _) = action.action, case let .Id(messageId) = message.id { if let action = media as? TelegramMediaAction, case let .starGiftUnique(gift, _, _, savedToProfile, canExportDate, transferStars, _, _, _, _) = action.action, case let .Id(messageId) = message.id {
let _ = messageId let _ = messageId
return .single(ProfileGiftsContext.State.StarGift( return .single(ProfileGiftsContext.State.StarGift(
gift: gift, gift: gift,
@ -1329,7 +1329,7 @@ extension ProfileGiftsContext.State.StarGift {
return nil return nil
} }
self.gift = gift self.gift = gift
if let fromPeerId = fromId.flatMap({ EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value($0)) }) { if let fromPeerId = fromId?.peerId {
self.fromPeer = transaction.getPeer(fromPeerId).flatMap(EnginePeer.init) self.fromPeer = transaction.getPeer(fromPeerId).flatMap(EnginePeer.init)
} else { } else {
self.fromPeer = nil self.fromPeer = nil

View File

@ -1464,7 +1464,7 @@ func _internal_sendStarsPaymentForm(account: Account, formId: Int64, source: Bot
case .giftCode, .stars, .starsGift, .starsChatSubscription, .starGift, .starGiftUpgrade, .starGiftTransfer: case .giftCode, .stars, .starsGift, .starsChatSubscription, .starGift, .starGiftUpgrade, .starGiftTransfer:
receiptMessageId = nil receiptMessageId = nil
} }
} else if case let .starGiftUnique(gift, _, _, savedToProfile, canExportDate, transferStars, _) = action.action, case let .Id(messageId) = message.id { } else if case let .starGiftUnique(gift, _, _, savedToProfile, canExportDate, transferStars, _, _, _, _) = action.action, case let .Id(messageId) = message.id {
resultGift = ProfileGiftsContext.State.StarGift( resultGift = ProfileGiftsContext.State.StarGift(
gift: gift, gift: gift,
reference: .message(messageId: messageId), reference: .message(messageId: messageId),