Update API

This commit is contained in:
Ilya Laktyushin 2025-04-10 16:55:02 +04:00
parent d92ac9275f
commit 829ccedc80
12 changed files with 180 additions and 16 deletions

View File

@ -391,6 +391,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-625298705] = { return Api.InputInvoice.parse_inputInvoicePremiumGiftStars($0) } dict[-625298705] = { return Api.InputInvoice.parse_inputInvoicePremiumGiftStars($0) }
dict[-1020867857] = { return Api.InputInvoice.parse_inputInvoiceSlug($0) } dict[-1020867857] = { return Api.InputInvoice.parse_inputInvoiceSlug($0) }
dict[-396206446] = { return Api.InputInvoice.parse_inputInvoiceStarGift($0) } dict[-396206446] = { return Api.InputInvoice.parse_inputInvoiceStarGift($0) }
dict[1674298252] = { return Api.InputInvoice.parse_inputInvoiceStarGiftResale($0) }
dict[1247763417] = { return Api.InputInvoice.parse_inputInvoiceStarGiftTransfer($0) } dict[1247763417] = { return Api.InputInvoice.parse_inputInvoiceStarGiftTransfer($0) }
dict[1300335965] = { return Api.InputInvoice.parse_inputInvoiceStarGiftUpgrade($0) } dict[1300335965] = { return Api.InputInvoice.parse_inputInvoiceStarGiftUpgrade($0) }
dict[1710230755] = { return Api.InputInvoice.parse_inputInvoiceStars($0) } dict[1710230755] = { return Api.InputInvoice.parse_inputInvoiceStars($0) }
@ -933,7 +934,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) } dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) }
dict[-963180333] = { return Api.SponsoredPeer.parse_sponsoredPeer($0) } dict[-963180333] = { return Api.SponsoredPeer.parse_sponsoredPeer($0) }
dict[46953416] = { return Api.StarGift.parse_starGift($0) } dict[46953416] = { return Api.StarGift.parse_starGift($0) }
dict[1549979985] = { return Api.StarGift.parse_starGiftUnique($0) } dict[1678891913] = { return Api.StarGift.parse_starGiftUnique($0) }
dict[-1809377438] = { return Api.StarGiftAttribute.parse_starGiftAttributeBackdrop($0) } dict[-1809377438] = { return Api.StarGiftAttribute.parse_starGiftAttributeBackdrop($0) }
dict[970559507] = { return Api.StarGiftAttribute.parse_starGiftAttributeModel($0) } dict[970559507] = { return Api.StarGiftAttribute.parse_starGiftAttributeModel($0) }
dict[-524291476] = { return Api.StarGiftAttribute.parse_starGiftAttributeOriginalDetails($0) } dict[-524291476] = { return Api.StarGiftAttribute.parse_starGiftAttributeOriginalDetails($0) }

View File

@ -255,6 +255,7 @@ public extension Api {
case inputInvoicePremiumGiftStars(flags: Int32, userId: Api.InputUser, months: Int32, message: Api.TextWithEntities?) case inputInvoicePremiumGiftStars(flags: Int32, userId: Api.InputUser, months: Int32, message: Api.TextWithEntities?)
case inputInvoiceSlug(slug: String) case inputInvoiceSlug(slug: String)
case inputInvoiceStarGift(flags: Int32, peer: Api.InputPeer, giftId: Int64, message: Api.TextWithEntities?) case inputInvoiceStarGift(flags: Int32, peer: Api.InputPeer, giftId: Int64, message: Api.TextWithEntities?)
case inputInvoiceStarGiftResale(slug: String, toId: Api.InputPeer)
case inputInvoiceStarGiftTransfer(stargift: Api.InputSavedStarGift, toId: Api.InputPeer) case inputInvoiceStarGiftTransfer(stargift: Api.InputSavedStarGift, toId: Api.InputPeer)
case inputInvoiceStarGiftUpgrade(flags: Int32, stargift: Api.InputSavedStarGift) case inputInvoiceStarGiftUpgrade(flags: Int32, stargift: Api.InputSavedStarGift)
case inputInvoiceStars(purpose: Api.InputStorePaymentPurpose) case inputInvoiceStars(purpose: Api.InputStorePaymentPurpose)
@ -312,6 +313,13 @@ public extension Api {
serializeInt64(giftId, buffer: buffer, boxed: false) serializeInt64(giftId, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 1) != 0 {message!.serialize(buffer, true)} if Int(flags) & Int(1 << 1) != 0 {message!.serialize(buffer, true)}
break break
case .inputInvoiceStarGiftResale(let slug, let toId):
if boxed {
buffer.appendInt32(1674298252)
}
serializeString(slug, buffer: buffer, boxed: false)
toId.serialize(buffer, true)
break
case .inputInvoiceStarGiftTransfer(let stargift, let toId): case .inputInvoiceStarGiftTransfer(let stargift, let toId):
if boxed { if boxed {
buffer.appendInt32(1247763417) buffer.appendInt32(1247763417)
@ -351,6 +359,8 @@ public extension Api {
return ("inputInvoiceSlug", [("slug", slug as Any)]) return ("inputInvoiceSlug", [("slug", slug as Any)])
case .inputInvoiceStarGift(let flags, let peer, let giftId, let message): case .inputInvoiceStarGift(let flags, let peer, let giftId, let message):
return ("inputInvoiceStarGift", [("flags", flags as Any), ("peer", peer as Any), ("giftId", giftId as Any), ("message", message as Any)]) return ("inputInvoiceStarGift", [("flags", flags as Any), ("peer", peer as Any), ("giftId", giftId as Any), ("message", message as Any)])
case .inputInvoiceStarGiftResale(let slug, let toId):
return ("inputInvoiceStarGiftResale", [("slug", slug as Any), ("toId", toId as Any)])
case .inputInvoiceStarGiftTransfer(let stargift, let toId): case .inputInvoiceStarGiftTransfer(let stargift, let toId):
return ("inputInvoiceStarGiftTransfer", [("stargift", stargift as Any), ("toId", toId as Any)]) return ("inputInvoiceStarGiftTransfer", [("stargift", stargift as Any), ("toId", toId as Any)])
case .inputInvoiceStarGiftUpgrade(let flags, let stargift): case .inputInvoiceStarGiftUpgrade(let flags, let stargift):
@ -480,6 +490,22 @@ public extension Api {
return nil return nil
} }
} }
public static func parse_inputInvoiceStarGiftResale(_ reader: BufferReader) -> InputInvoice? {
var _1: String?
_1 = parseString(reader)
var _2: Api.InputPeer?
if let signature = reader.readInt32() {
_2 = Api.parse(reader, signature: signature) as? Api.InputPeer
}
let _c1 = _1 != nil
let _c2 = _2 != nil
if _c1 && _c2 {
return Api.InputInvoice.inputInvoiceStarGiftResale(slug: _1!, toId: _2!)
}
else {
return nil
}
}
public static func parse_inputInvoiceStarGiftTransfer(_ reader: BufferReader) -> InputInvoice? { public static func parse_inputInvoiceStarGiftTransfer(_ reader: BufferReader) -> InputInvoice? {
var _1: Api.InputSavedStarGift? var _1: Api.InputSavedStarGift?
if let signature = reader.readInt32() { if let signature = reader.readInt32() {

View File

@ -629,7 +629,7 @@ public extension Api {
public extension Api { public extension Api {
enum StarGift: TypeConstructorDescription { enum StarGift: TypeConstructorDescription {
case starGift(flags: Int32, id: Int64, sticker: Api.Document, stars: Int64, availabilityRemains: Int32?, availabilityTotal: Int32?, convertStars: Int64, firstSaleDate: Int32?, lastSaleDate: Int32?, upgradeStars: Int64?) case starGift(flags: Int32, id: Int64, sticker: Api.Document, stars: Int64, availabilityRemains: Int32?, availabilityTotal: Int32?, convertStars: Int64, firstSaleDate: Int32?, lastSaleDate: Int32?, upgradeStars: Int64?)
case starGiftUnique(flags: Int32, id: Int64, title: String, slug: String, num: Int32, ownerId: Api.Peer?, ownerName: String?, ownerAddress: String?, attributes: [Api.StarGiftAttribute], availabilityIssued: Int32, availabilityTotal: Int32, giftAddress: String?) case starGiftUnique(flags: Int32, id: Int64, title: String, slug: String, num: Int32, ownerId: Api.Peer?, ownerName: String?, ownerAddress: String?, attributes: [Api.StarGiftAttribute], availabilityIssued: Int32, availabilityTotal: Int32, giftAddress: String?, resellStars: Int64?)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self { switch self {
@ -648,9 +648,9 @@ public extension Api {
if Int(flags) & Int(1 << 1) != 0 {serializeInt32(lastSaleDate!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 1) != 0 {serializeInt32(lastSaleDate!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 3) != 0 {serializeInt64(upgradeStars!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 3) != 0 {serializeInt64(upgradeStars!, buffer: buffer, boxed: false)}
break break
case .starGiftUnique(let flags, let id, let title, let slug, let num, let ownerId, let ownerName, let ownerAddress, let attributes, let availabilityIssued, let availabilityTotal, let giftAddress): case .starGiftUnique(let flags, let id, let title, let slug, let num, let ownerId, let ownerName, let ownerAddress, let attributes, let availabilityIssued, let availabilityTotal, let giftAddress, let resellStars):
if boxed { if boxed {
buffer.appendInt32(1549979985) buffer.appendInt32(1678891913)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt64(id, buffer: buffer, boxed: false) serializeInt64(id, buffer: buffer, boxed: false)
@ -668,6 +668,7 @@ public extension Api {
serializeInt32(availabilityIssued, buffer: buffer, boxed: false) serializeInt32(availabilityIssued, buffer: buffer, boxed: false)
serializeInt32(availabilityTotal, buffer: buffer, boxed: false) serializeInt32(availabilityTotal, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 3) != 0 {serializeString(giftAddress!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 3) != 0 {serializeString(giftAddress!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 4) != 0 {serializeInt64(resellStars!, buffer: buffer, boxed: false)}
break break
} }
} }
@ -676,8 +677,8 @@ public extension Api {
switch self { switch self {
case .starGift(let flags, let id, let sticker, let stars, let availabilityRemains, let availabilityTotal, let convertStars, let firstSaleDate, let lastSaleDate, let upgradeStars): case .starGift(let flags, let id, let sticker, let stars, let availabilityRemains, let availabilityTotal, let convertStars, let firstSaleDate, let lastSaleDate, let upgradeStars):
return ("starGift", [("flags", flags as Any), ("id", id as Any), ("sticker", sticker as Any), ("stars", stars as Any), ("availabilityRemains", availabilityRemains as Any), ("availabilityTotal", availabilityTotal as Any), ("convertStars", convertStars as Any), ("firstSaleDate", firstSaleDate as Any), ("lastSaleDate", lastSaleDate as Any), ("upgradeStars", upgradeStars as Any)]) return ("starGift", [("flags", flags as Any), ("id", id as Any), ("sticker", sticker as Any), ("stars", stars as Any), ("availabilityRemains", availabilityRemains as Any), ("availabilityTotal", availabilityTotal as Any), ("convertStars", convertStars as Any), ("firstSaleDate", firstSaleDate as Any), ("lastSaleDate", lastSaleDate as Any), ("upgradeStars", upgradeStars as Any)])
case .starGiftUnique(let flags, let id, let title, let slug, let num, let ownerId, let ownerName, let ownerAddress, let attributes, let availabilityIssued, let availabilityTotal, let giftAddress): case .starGiftUnique(let flags, let id, let title, let slug, let num, let ownerId, let ownerName, let ownerAddress, let attributes, let availabilityIssued, let availabilityTotal, let giftAddress, let resellStars):
return ("starGiftUnique", [("flags", flags as Any), ("id", id as Any), ("title", title as Any), ("slug", slug as Any), ("num", num as Any), ("ownerId", ownerId as Any), ("ownerName", ownerName as Any), ("ownerAddress", ownerAddress as Any), ("attributes", attributes as Any), ("availabilityIssued", availabilityIssued as Any), ("availabilityTotal", availabilityTotal as Any), ("giftAddress", giftAddress as Any)]) return ("starGiftUnique", [("flags", flags as Any), ("id", id as Any), ("title", title as Any), ("slug", slug as Any), ("num", num as Any), ("ownerId", ownerId as Any), ("ownerName", ownerName as Any), ("ownerAddress", ownerAddress as Any), ("attributes", attributes as Any), ("availabilityIssued", availabilityIssued as Any), ("availabilityTotal", availabilityTotal as Any), ("giftAddress", giftAddress as Any), ("resellStars", resellStars as Any)])
} }
} }
@ -750,6 +751,8 @@ public extension Api {
_11 = reader.readInt32() _11 = reader.readInt32()
var _12: String? var _12: String?
if Int(_1!) & Int(1 << 3) != 0 {_12 = parseString(reader) } if Int(_1!) & Int(1 << 3) != 0 {_12 = parseString(reader) }
var _13: Int64?
if Int(_1!) & Int(1 << 4) != 0 {_13 = reader.readInt64() }
let _c1 = _1 != nil let _c1 = _1 != nil
let _c2 = _2 != nil let _c2 = _2 != nil
let _c3 = _3 != nil let _c3 = _3 != nil
@ -762,8 +765,9 @@ public extension Api {
let _c10 = _10 != nil let _c10 = _10 != nil
let _c11 = _11 != nil let _c11 = _11 != nil
let _c12 = (Int(_1!) & Int(1 << 3) == 0) || _12 != nil let _c12 = (Int(_1!) & Int(1 << 3) == 0) || _12 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 { let _c13 = (Int(_1!) & Int(1 << 4) == 0) || _13 != nil
return Api.StarGift.starGiftUnique(flags: _1!, id: _2!, title: _3!, slug: _4!, num: _5!, ownerId: _6, ownerName: _7, ownerAddress: _8, attributes: _9!, availabilityIssued: _10!, availabilityTotal: _11!, giftAddress: _12) if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 {
return Api.StarGift.starGiftUnique(flags: _1!, id: _2!, title: _3!, slug: _4!, num: _5!, ownerId: _6, ownerName: _7, ownerAddress: _8, attributes: _9!, availabilityIssued: _10!, availabilityTotal: _11!, giftAddress: _12, resellStars: _13)
} }
else { else {
return nil return nil

View File

@ -9766,6 +9766,22 @@ public extension Api.functions.payments {
}) })
} }
} }
public extension Api.functions.payments {
static func updateStarGiftPrice(slug: String, resellStars: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer()
buffer.appendInt32(-489360582)
serializeString(slug, buffer: buffer, boxed: false)
serializeInt64(resellStars, buffer: buffer, boxed: false)
return (FunctionDescription(name: "payments.updateStarGiftPrice", parameters: [("slug", String(describing: slug)), ("resellStars", String(describing: resellStars))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer)
var result: Api.Updates?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.Updates
}
return result
})
}
}
public extension Api.functions.payments { public extension Api.functions.payments {
static func upgradeStarGift(flags: Int32, stargift: Api.InputSavedStarGift) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) { static func upgradeStarGift(flags: Int32, stargift: Api.InputSavedStarGift) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer() let buffer = Buffer()

View File

@ -109,6 +109,10 @@ func messageFilterForTagMask(_ tagMask: MessageTags) -> Api.MessagesFilter? {
return Api.MessagesFilter.inputMessagesFilterGif return Api.MessagesFilter.inputMessagesFilterGif
} else if tagMask == .pinned { } else if tagMask == .pinned {
return Api.MessagesFilter.inputMessagesFilterPinned return Api.MessagesFilter.inputMessagesFilterPinned
} else if tagMask == .voice {
return Api.MessagesFilter.inputMessagesFilterVoice
} else if tagMask == .roundVideo {
return Api.MessagesFilter.inputMessagesFilterRoundVideo
} else { } else {
return nil return nil
} }

View File

@ -353,7 +353,8 @@ func managedUniqueStarGifts(accountPeerId: PeerId, postbox: Postbox, network: Ne
.backdrop(name: "", innerColor: innerColor, outerColor: outerColor, patternColor: patternColor, textColor: textColor, rarity: 0) .backdrop(name: "", innerColor: innerColor, outerColor: outerColor, patternColor: patternColor, textColor: textColor, rarity: 0)
], ],
availability: StarGift.UniqueGift.Availability(issued: 0, total: 0), availability: StarGift.UniqueGift.Availability(issued: 0, total: 0),
giftAddress: nil giftAddress: nil,
resellStars: nil
) )
if let entry = CodableEntry(RecentStarGiftItem(gift)) { if let entry = CodableEntry(RecentStarGiftItem(gift)) {
items.append(OrderedItemListEntry(id: RecentStarGiftItemId(id).rawValue, contents: entry)) items.append(OrderedItemListEntry(id: RecentStarGiftItemId(id).rawValue, contents: entry))

View File

@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {
public class Serialization: NSObject, MTSerialization { public class Serialization: NSObject, MTSerialization {
public func currentLayer() -> UInt { public func currentLayer() -> UInt {
return 202 return 203
} }
public func parseMessage(_ data: Data!) -> Any! { public func parseMessage(_ data: Data!) -> Any! {

View File

@ -170,8 +170,10 @@ public extension MessageTags {
static let video = MessageTags(rawValue: 1 << 9) static let video = MessageTags(rawValue: 1 << 9)
static let pinned = MessageTags(rawValue: 1 << 10) static let pinned = MessageTags(rawValue: 1 << 10)
static let unseenReaction = MessageTags(rawValue: 1 << 11) static let unseenReaction = MessageTags(rawValue: 1 << 11)
static let voice = MessageTags(rawValue: 1 << 12)
static let roundVideo = MessageTags(rawValue: 1 << 13)
static let all: MessageTags = [.photoOrVideo, .file, .music, .webPage, .voiceOrInstantVideo, .unseenPersonalMessage, .liveLocation, .gif, .photo, .video, .pinned, .unseenReaction] static let all: MessageTags = [.photoOrVideo, .file, .music, .webPage, .voiceOrInstantVideo, .unseenPersonalMessage, .liveLocation, .gif, .photo, .video, .pinned, .unseenReaction, .voice, .roundVideo]
} }
public extension GlobalMessageTags { public extension GlobalMessageTags {

View File

@ -17,6 +17,7 @@ public enum BotPaymentInvoiceSource {
case starGiftUpgrade(keepOriginalInfo: Bool, reference: StarGiftReference) case starGiftUpgrade(keepOriginalInfo: Bool, reference: StarGiftReference)
case starGiftTransfer(reference: StarGiftReference, toPeerId: EnginePeer.Id) case starGiftTransfer(reference: StarGiftReference, toPeerId: EnginePeer.Id)
case premiumGift(peerId: EnginePeer.Id, option: CachedPremiumGiftOption, text: String?, entities: [MessageTextEntity]?) case premiumGift(peerId: EnginePeer.Id, option: CachedPremiumGiftOption, text: String?, entities: [MessageTextEntity]?)
case starGiftResale(slug: String, toPeerId: EnginePeer.Id)
} }
public struct BotPaymentInvoiceFields: OptionSet { public struct BotPaymentInvoiceFields: OptionSet {
@ -400,6 +401,11 @@ func _internal_parseInputInvoice(transaction: Transaction, source: BotPaymentInv
message = .textWithEntities(text: text, entities: entities.flatMap { apiEntitiesFromMessageTextEntities($0, associatedPeers: SimpleDictionary()) } ?? []) message = .textWithEntities(text: text, entities: entities.flatMap { apiEntitiesFromMessageTextEntities($0, associatedPeers: SimpleDictionary()) } ?? [])
} }
return .inputInvoicePremiumGiftStars(flags: flags, userId: inputUser, months: option.months, message: message) return .inputInvoicePremiumGiftStars(flags: flags, userId: inputUser, months: option.months, message: message)
case let .starGiftResale(slug, toPeerId):
guard let peer = transaction.getPeer(toPeerId), let inputPeer = apiInputPeer(peer) else {
return nil
}
return .inputInvoiceStarGiftResale(slug: slug, toId: inputPeer)
} }
} }
@ -733,7 +739,7 @@ func _internal_sendBotPaymentForm(account: Account, formId: Int64, source: BotPa
receiptMessageId = id receiptMessageId = id
} }
} }
case .giftCode, .stars, .starsGift, .starsChatSubscription, .starGift, .starGiftUpgrade, .starGiftTransfer, .premiumGift: case .giftCode, .stars, .starsGift, .starsChatSubscription, .starGift, .starGiftUpgrade, .starGiftTransfer, .premiumGift, .starGiftResale:
receiptMessageId = nil receiptMessageId = nil
} }
} }

View File

@ -211,6 +211,7 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
case attributes case attributes
case availability case availability
case giftAddress case giftAddress
case resellStars
} }
public enum Attribute: Equatable, Codable, PostboxCoding { public enum Attribute: Equatable, Codable, PostboxCoding {
@ -451,8 +452,9 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
public let attributes: [Attribute] public let attributes: [Attribute]
public let availability: Availability public let availability: Availability
public let giftAddress: String? public let giftAddress: String?
public let resellStars: Int64?
public init(id: Int64, title: String, number: Int32, slug: String, owner: Owner, attributes: [Attribute], availability: Availability, giftAddress: String?) { public init(id: Int64, title: String, number: Int32, slug: String, owner: Owner, attributes: [Attribute], availability: Availability, giftAddress: String?, resellStars: Int64?) {
self.id = id self.id = id
self.title = title self.title = title
self.number = number self.number = number
@ -461,6 +463,7 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
self.attributes = attributes self.attributes = attributes
self.availability = availability self.availability = availability
self.giftAddress = giftAddress self.giftAddress = giftAddress
self.resellStars = resellStars
} }
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
@ -481,6 +484,7 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
self.attributes = try container.decode([UniqueGift.Attribute].self, forKey: .attributes) self.attributes = try container.decode([UniqueGift.Attribute].self, forKey: .attributes)
self.availability = try container.decode(UniqueGift.Availability.self, forKey: .availability) self.availability = try container.decode(UniqueGift.Availability.self, forKey: .availability)
self.giftAddress = try container.decodeIfPresent(String.self, forKey: .giftAddress) self.giftAddress = try container.decodeIfPresent(String.self, forKey: .giftAddress)
self.resellStars = try container.decodeIfPresent(Int64.self, forKey: .resellStars)
} }
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
@ -500,6 +504,7 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
self.attributes = (try? decoder.decodeObjectArrayWithCustomDecoderForKey(CodingKeys.attributes.rawValue, decoder: { UniqueGift.Attribute(decoder: $0) })) ?? [] self.attributes = (try? decoder.decodeObjectArrayWithCustomDecoderForKey(CodingKeys.attributes.rawValue, decoder: { UniqueGift.Attribute(decoder: $0) })) ?? []
self.availability = decoder.decodeObjectForKey(CodingKeys.availability.rawValue, decoder: { UniqueGift.Availability(decoder: $0) }) as! UniqueGift.Availability self.availability = decoder.decodeObjectForKey(CodingKeys.availability.rawValue, decoder: { UniqueGift.Availability(decoder: $0) }) as! UniqueGift.Availability
self.giftAddress = decoder.decodeOptionalStringForKey(CodingKeys.giftAddress.rawValue) self.giftAddress = decoder.decodeOptionalStringForKey(CodingKeys.giftAddress.rawValue)
self.resellStars = decoder.decodeOptionalInt64ForKey(CodingKeys.resellStars.rawValue)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -519,6 +524,7 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
try container.encode(self.attributes, forKey: .attributes) try container.encode(self.attributes, forKey: .attributes)
try container.encode(self.availability, forKey: .availability) try container.encode(self.availability, forKey: .availability)
try container.encodeIfPresent(self.giftAddress, forKey: .giftAddress) try container.encodeIfPresent(self.giftAddress, forKey: .giftAddress)
try container.encodeIfPresent(self.resellStars, forKey: .resellStars)
} }
public func encode(_ encoder: PostboxEncoder) { public func encode(_ encoder: PostboxEncoder) {
@ -541,6 +547,25 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
} else { } else {
encoder.encodeNil(forKey: CodingKeys.giftAddress.rawValue) encoder.encodeNil(forKey: CodingKeys.giftAddress.rawValue)
} }
if let resellStars = self.resellStars {
encoder.encodeInt64(resellStars, forKey: CodingKeys.resellStars.rawValue)
} else {
encoder.encodeNil(forKey: CodingKeys.resellStars.rawValue)
}
}
public func withResellStars(_ resellStars: Int64?) -> UniqueGift {
return UniqueGift(
id: self.id,
title: self.title,
number: self.number,
slug: self.slug,
owner: self.owner,
attributes: self.attributes,
availability: self.availability,
giftAddress: self.giftAddress,
resellStars: resellStars
)
} }
} }
@ -626,7 +651,7 @@ extension StarGift {
return nil return nil
} }
self = .generic(StarGift.Gift(id: id, file: file, price: stars, convertStars: convertStars, availability: availability, soldOut: soldOut, flags: flags, upgradeStars: upgradeStars)) self = .generic(StarGift.Gift(id: id, file: file, price: stars, convertStars: convertStars, availability: availability, soldOut: soldOut, flags: flags, upgradeStars: upgradeStars))
case let .starGiftUnique(_, id, title, slug, num, ownerPeerId, ownerName, ownerAddress, attributes, availabilityIssued, availabilityTotal, giftAddress): case let .starGiftUnique(_, id, title, slug, num, ownerPeerId, ownerName, ownerAddress, attributes, availabilityIssued, availabilityTotal, giftAddress, reselltars):
let owner: StarGift.UniqueGift.Owner let owner: StarGift.UniqueGift.Owner
if let ownerAddress { if let ownerAddress {
owner = .address(ownerAddress) owner = .address(ownerAddress)
@ -637,7 +662,7 @@ extension StarGift {
} else { } else {
return nil return nil
} }
self = .unique(StarGift.UniqueGift(id: id, title: title, number: num, slug: slug, owner: owner, attributes: attributes.compactMap { UniqueGift.Attribute(apiAttribute: $0) }, availability: UniqueGift.Availability(issued: availabilityIssued, total: availabilityTotal), giftAddress: giftAddress)) self = .unique(StarGift.UniqueGift(id: id, title: title, number: num, slug: slug, owner: owner, attributes: attributes.compactMap { UniqueGift.Attribute(apiAttribute: $0) }, availability: UniqueGift.Availability(issued: availabilityIssued, total: availabilityTotal), giftAddress: giftAddress, resellStars: reselltars))
} }
} }
} }
@ -1388,6 +1413,41 @@ private final class ProfileGiftsContextImpl {
} }
} }
func updateStarGiftResellPrice(slug: String, price: Int64?) {
self.actionDisposable.set(
_internal_updateStarGiftResalePrice(account: self.account, slug: slug, price: price).startStrict()
)
if let index = self.gifts.firstIndex(where: { gift in
if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug {
return true
}
return false
}) {
if case let .unique(uniqueGift) = self.gifts[index].gift {
let updatedUniqueGift = uniqueGift.withResellStars(price)
let updatedGift = self.gifts[index].withGift(.unique(updatedUniqueGift))
self.gifts[index] = updatedGift
}
}
if let index = self.filteredGifts.firstIndex(where: { gift in
if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug {
return true
}
return false
}) {
if case let .unique(uniqueGift) = self.filteredGifts[index].gift {
let updatedUniqueGift = uniqueGift.withResellStars(price)
let updatedGift = self.filteredGifts[index].withGift(.unique(updatedUniqueGift))
self.filteredGifts[index] = updatedGift
}
}
self.pushState()
}
func toggleStarGiftsNotifications(enabled: Bool) { func toggleStarGiftsNotifications(enabled: Bool) {
self.actionDisposable.set( self.actionDisposable.set(
_internal_toggleStarGiftsNotifications(account: self.account, peerId: self.peerId, enabled: enabled).startStrict() _internal_toggleStarGiftsNotifications(account: self.account, peerId: self.peerId, enabled: enabled).startStrict()
@ -1583,6 +1643,25 @@ public final class ProfileGiftsContext {
try container.encodeIfPresent(self.transferStars, forKey: .transferStars) try container.encodeIfPresent(self.transferStars, forKey: .transferStars)
} }
public func withGift(_ gift: TelegramCore.StarGift) -> StarGift {
return StarGift(
gift: gift,
reference: self.reference,
fromPeer: self.fromPeer,
date: self.date,
text: self.text,
entities: self.entities,
nameHidden: self.nameHidden,
savedToProfile: self.savedToProfile,
pinnedToTop: self.pinnedToTop,
convertStars: self.convertStars,
canUpgrade: self.canUpgrade,
canExportDate: self.canExportDate,
upgradeStars: self.upgradeStars,
transferStars: self.transferStars
)
}
public func withSavedToProfile(_ savedToProfile: Bool) -> StarGift { public func withSavedToProfile(_ savedToProfile: Bool) -> StarGift {
return StarGift( return StarGift(
gift: self.gift, gift: self.gift,
@ -1750,6 +1829,12 @@ public final class ProfileGiftsContext {
} }
} }
public func updateStarGiftResellPrice(slug: String, price: Int64?) {
self.impl.with { impl in
impl.updateStarGiftResellPrice(slug: slug, price: price)
}
}
public func toggleStarGiftsNotifications(enabled: Bool) { public func toggleStarGiftsNotifications(enabled: Bool) {
self.impl.with { impl in self.impl.with { impl in
impl.toggleStarGiftsNotifications(enabled: enabled) impl.toggleStarGiftsNotifications(enabled: enabled)
@ -2070,6 +2155,21 @@ func _internal_toggleStarGiftsNotifications(account: Account, peerId: EnginePeer
} }
} }
func _internal_updateStarGiftResalePrice(account: Account, slug: String, price: Int64?) -> Signal<Never, NoError> {
return account.network.request(Api.functions.payments.updateStarGiftPrice(slug: slug, resellStars: price ?? 0))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
return .single(nil)
}
|> mapToSignal { updates -> Signal<Void, NoError> in
if let updates {
account.stateManager.addUpdates(updates)
}
return .complete()
}
|> ignoreValues
}
public extension StarGift.UniqueGift { public extension StarGift.UniqueGift {
var itemFile: TelegramMediaFile? { var itemFile: TelegramMediaFile? {
for attribute in self.attributes { for attribute in self.attributes {

View File

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

View File

@ -148,6 +148,10 @@ public extension TelegramEngine {
public func toggleStarGiftsNotifications(peerId: EnginePeer.Id, enabled: Bool) -> Signal<Never, NoError> { public func toggleStarGiftsNotifications(peerId: EnginePeer.Id, enabled: Bool) -> Signal<Never, NoError> {
return _internal_toggleStarGiftsNotifications(account: self.account, peerId: peerId, enabled: enabled) return _internal_toggleStarGiftsNotifications(account: self.account, peerId: peerId, enabled: enabled)
} }
public func updateStarGiftResalePrice(slug: String, price: Int64?) -> Signal<Never, NoError> {
return _internal_updateStarGiftResalePrice(account: self.account, slug: slug, price: price)
}
} }
} }