Update API

This commit is contained in:
Isaac 2024-11-29 11:31:37 +04:00
parent 1322c4364e
commit 997134f82c
10 changed files with 83 additions and 108 deletions

View File

@ -903,7 +903,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[1301522832] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) }
dict[1237678029] = { return Api.StarGift.parse_starGift($0) }
dict[708628759] = { return Api.StarRefProgram.parse_starRefProgram($0) }
dict[-586389774] = { return Api.StarRefProgram.parse_starRefProgram($0) }
dict[-1145654109] = { return Api.StarsAmount.parse_starsAmount($0) }
dict[1577421297] = { return Api.StarsGiftOption.parse_starsGiftOption($0) }
dict[-1798404822] = { return Api.StarsGiveawayOption.parse_starsGiveawayOption($0) }
@ -950,7 +950,6 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1870436597] = { return Api.StoryView.parse_storyViewPublicForward($0) }
dict[-1116418231] = { return Api.StoryView.parse_storyViewPublicRepost($0) }
dict[-1923523370] = { return Api.StoryViews.parse_storyViews($0) }
dict[642695037] = { return Api.SuggestedBotStarRef.parse_suggestedBotStarRef($0) }
dict[1964978502] = { return Api.TextWithEntities.parse_textWithEntities($0) }
dict[-1609668650] = { return Api.Theme.parse_theme($0) }
dict[-94849324] = { return Api.ThemeSettings.parse_themeSettings($0) }
@ -1371,7 +1370,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-919881925] = { return Api.payments.StarsRevenueStats.parse_starsRevenueStats($0) }
dict[497778871] = { return Api.payments.StarsRevenueWithdrawalUrl.parse_starsRevenueWithdrawalUrl($0) }
dict[1822222573] = { return Api.payments.StarsStatus.parse_starsStatus($0) }
dict[-937776981] = { return Api.payments.SuggestedStarRefBots.parse_suggestedStarRefBots($0) }
dict[-1261053863] = { return Api.payments.SuggestedStarRefBots.parse_suggestedStarRefBots($0) }
dict[1801827607] = { return Api.payments.UserStarGifts.parse_userStarGifts($0) }
dict[-784000893] = { return Api.payments.ValidatedRequestedInfo.parse_validatedRequestedInfo($0) }
dict[541839704] = { return Api.phone.ExportedGroupCallInvite.parse_exportedGroupCallInvite($0) }
@ -2111,8 +2110,6 @@ public extension Api {
_1.serialize(buffer, boxed)
case let _1 as Api.StoryViews:
_1.serialize(buffer, boxed)
case let _1 as Api.SuggestedBotStarRef:
_1.serialize(buffer, boxed)
case let _1 as Api.TextWithEntities:
_1.serialize(buffer, boxed)
case let _1 as Api.Theme:

View File

@ -644,44 +644,54 @@ public extension Api {
}
public extension Api {
enum StarRefProgram: TypeConstructorDescription {
case starRefProgram(flags: Int32, commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?)
case starRefProgram(flags: Int32, botId: Int64, commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?, dailyRevenuePerUser: Api.StarsAmount?)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .starRefProgram(let flags, let commissionPermille, let durationMonths, let endDate):
case .starRefProgram(let flags, let botId, let commissionPermille, let durationMonths, let endDate, let dailyRevenuePerUser):
if boxed {
buffer.appendInt32(708628759)
buffer.appendInt32(-586389774)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt64(botId, buffer: buffer, boxed: false)
serializeInt32(commissionPermille, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(durationMonths!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 1) != 0 {serializeInt32(endDate!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 2) != 0 {dailyRevenuePerUser!.serialize(buffer, true)}
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .starRefProgram(let flags, let commissionPermille, let durationMonths, let endDate):
return ("starRefProgram", [("flags", flags as Any), ("commissionPermille", commissionPermille as Any), ("durationMonths", durationMonths as Any), ("endDate", endDate as Any)])
case .starRefProgram(let flags, let botId, let commissionPermille, let durationMonths, let endDate, let dailyRevenuePerUser):
return ("starRefProgram", [("flags", flags as Any), ("botId", botId as Any), ("commissionPermille", commissionPermille as Any), ("durationMonths", durationMonths as Any), ("endDate", endDate as Any), ("dailyRevenuePerUser", dailyRevenuePerUser as Any)])
}
}
public static func parse_starRefProgram(_ reader: BufferReader) -> StarRefProgram? {
var _1: Int32?
_1 = reader.readInt32()
var _2: Int32?
_2 = reader.readInt32()
var _2: Int64?
_2 = reader.readInt64()
var _3: Int32?
if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt32() }
_3 = reader.readInt32()
var _4: Int32?
if Int(_1!) & Int(1 << 1) != 0 {_4 = reader.readInt32() }
if Int(_1!) & Int(1 << 0) != 0 {_4 = reader.readInt32() }
var _5: Int32?
if Int(_1!) & Int(1 << 1) != 0 {_5 = reader.readInt32() }
var _6: Api.StarsAmount?
if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() {
_6 = Api.parse(reader, signature: signature) as? Api.StarsAmount
} }
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil
let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil
if _c1 && _c2 && _c3 && _c4 {
return Api.StarRefProgram.starRefProgram(flags: _1!, commissionPermille: _2!, durationMonths: _3, endDate: _4)
let _c3 = _3 != nil
let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil
let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil
let _c6 = (Int(_1!) & Int(1 << 2) == 0) || _6 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 {
return Api.StarRefProgram.starRefProgram(flags: _1!, botId: _2!, commissionPermille: _3!, durationMonths: _4, endDate: _5, dailyRevenuePerUser: _6)
}
else {
return nil

View File

@ -272,54 +272,6 @@ public extension Api {
}
}
public extension Api {
enum SuggestedBotStarRef: TypeConstructorDescription {
case suggestedBotStarRef(flags: Int32, botId: Int64, commissionPermille: Int32, durationMonths: Int32?)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .suggestedBotStarRef(let flags, let botId, let commissionPermille, let durationMonths):
if boxed {
buffer.appendInt32(642695037)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt64(botId, buffer: buffer, boxed: false)
serializeInt32(commissionPermille, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(durationMonths!, buffer: buffer, boxed: false)}
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .suggestedBotStarRef(let flags, let botId, let commissionPermille, let durationMonths):
return ("suggestedBotStarRef", [("flags", flags as Any), ("botId", botId as Any), ("commissionPermille", commissionPermille as Any), ("durationMonths", durationMonths as Any)])
}
}
public static func parse_suggestedBotStarRef(_ reader: BufferReader) -> SuggestedBotStarRef? {
var _1: Int32?
_1 = reader.readInt32()
var _2: Int64?
_2 = reader.readInt64()
var _3: Int32?
_3 = reader.readInt32()
var _4: Int32?
if Int(_1!) & Int(1 << 0) != 0 {_4 = reader.readInt32() }
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil
if _c1 && _c2 && _c3 && _c4 {
return Api.SuggestedBotStarRef.suggestedBotStarRef(flags: _1!, botId: _2!, commissionPermille: _3!, durationMonths: _4)
}
else {
return nil
}
}
}
}
public extension Api {
enum TextWithEntities: TypeConstructorDescription {
case textWithEntities(text: String, entities: [Api.MessageEntity])

View File

@ -214,13 +214,13 @@ public extension Api.payments {
}
public extension Api.payments {
enum SuggestedStarRefBots: TypeConstructorDescription {
case suggestedStarRefBots(flags: Int32, count: Int32, suggestedBots: [Api.SuggestedBotStarRef], users: [Api.User], nextOffset: String?)
case suggestedStarRefBots(flags: Int32, count: Int32, suggestedBots: [Api.StarRefProgram], users: [Api.User], nextOffset: String?)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .suggestedStarRefBots(let flags, let count, let suggestedBots, let users, let nextOffset):
if boxed {
buffer.appendInt32(-937776981)
buffer.appendInt32(-1261053863)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt32(count, buffer: buffer, boxed: false)
@ -251,9 +251,9 @@ public extension Api.payments {
_1 = reader.readInt32()
var _2: Int32?
_2 = reader.readInt32()
var _3: [Api.SuggestedBotStarRef]?
var _3: [Api.StarRefProgram]?
if let _ = reader.readInt32() {
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.SuggestedBotStarRef.self)
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StarRefProgram.self)
}
var _4: [Api.User]?
if let _ = reader.readInt32() {

View File

@ -7873,16 +7873,21 @@ public extension Api.functions.messages {
}
}
public extension Api.functions.messages {
static func searchStickers(flags: Int32, q: String, langCode: String, offset: Int32, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.FoundStickers>) {
static func searchStickers(flags: Int32, q: String, emoticon: String, langCode: [String], offset: Int32, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.FoundStickers>) {
let buffer = Buffer()
buffer.appendInt32(1277568311)
buffer.appendInt32(699516522)
serializeInt32(flags, buffer: buffer, boxed: false)
serializeString(q, buffer: buffer, boxed: false)
serializeString(langCode, buffer: buffer, boxed: false)
serializeString(emoticon, buffer: buffer, boxed: false)
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(langCode.count))
for item in langCode {
serializeString(item, buffer: buffer, boxed: false)
}
serializeInt32(offset, buffer: buffer, boxed: false)
serializeInt32(limit, buffer: buffer, boxed: false)
serializeInt64(hash, buffer: buffer, boxed: false)
return (FunctionDescription(name: "messages.searchStickers", parameters: [("flags", String(describing: flags)), ("q", String(describing: q)), ("langCode", String(describing: langCode)), ("offset", String(describing: offset)), ("limit", String(describing: limit)), ("hash", String(describing: hash))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.FoundStickers? in
return (FunctionDescription(name: "messages.searchStickers", parameters: [("flags", String(describing: flags)), ("q", String(describing: q)), ("emoticon", String(describing: emoticon)), ("langCode", String(describing: langCode)), ("offset", String(describing: offset)), ("limit", String(describing: limit)), ("hash", String(describing: hash))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.FoundStickers? in
let reader = BufferReader(buffer)
var result: Api.messages.FoundStickers?
if let signature = reader.readInt32() {

View File

@ -627,17 +627,24 @@ extension TelegramBusinessChatLinks {
}
public final class TelegramStarRefProgram: Codable, Equatable {
public let botId: PeerId
public let commissionPermille: Int32
public let durationMonths: Int32?
public let endDate: Int32?
public let dailyRevenuePerUser: StarsAmount?
public init(commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?) {
public init(botId: PeerId, commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?, dailyRevenuePerUser: StarsAmount?) {
self.botId = botId
self.commissionPermille = commissionPermille
self.durationMonths = durationMonths
self.endDate = endDate
self.dailyRevenuePerUser = dailyRevenuePerUser
}
public static func ==(lhs: TelegramStarRefProgram, rhs: TelegramStarRefProgram) -> Bool {
if lhs.botId != rhs.botId {
return false
}
if lhs.commissionPermille != rhs.commissionPermille {
return false
}
@ -647,6 +654,9 @@ public final class TelegramStarRefProgram: Codable, Equatable {
if lhs.endDate != rhs.endDate {
return false
}
if lhs.dailyRevenuePerUser != rhs.dailyRevenuePerUser {
return false
}
return true
}
}
@ -654,8 +664,8 @@ public final class TelegramStarRefProgram: Codable, Equatable {
extension TelegramStarRefProgram {
convenience init(apiStarRefProgram: Api.StarRefProgram) {
switch apiStarRefProgram {
case let .starRefProgram(_, commissionPermille, durationMonths, endDate):
self.init(commissionPermille: commissionPermille, durationMonths: durationMonths, endDate: endDate)
case let .starRefProgram(_, botId, commissionPermille, durationMonths, endDate, dailyRevenuePerUser):
self.init(botId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)), commissionPermille: commissionPermille, durationMonths: durationMonths, endDate: endDate, dailyRevenuePerUser: dailyRevenuePerUser.flatMap(StarsAmount.init(apiAmount:)))
}
}
}

View File

@ -753,27 +753,23 @@ public final class TelegramSuggestedStarRefBotList: Equatable {
public enum SortMode {
case date
case commission
case revenue
}
public final class Item: Equatable {
public let peer: EnginePeer
public let commissionPermille: Int32
public let durationMonths: Int32?
public let program: TelegramStarRefProgram
public init(peer: EnginePeer, commissionPermille: Int32, durationMonths: Int32?) {
public init(peer: EnginePeer, program: TelegramStarRefProgram) {
self.peer = peer
self.commissionPermille = commissionPermille
self.durationMonths = durationMonths
self.program = program
}
public static func ==(lhs: Item, rhs: Item) -> Bool {
if lhs.peer != rhs.peer {
return false
}
if lhs.commissionPermille != rhs.commissionPermille {
return false
}
if lhs.durationMonths != rhs.durationMonths {
if lhs.program != rhs.program {
return false
}
return true
@ -795,7 +791,7 @@ public final class TelegramSuggestedStarRefBotList: Equatable {
}
}
func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id, orderByCommission: Bool, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id, sortMode: TelegramSuggestedStarRefBotList.SortMode, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
return account.postbox.transaction { transaction -> Api.InputPeer? in
return transaction.getPeer(id).flatMap(apiInputPeer)
}
@ -804,8 +800,13 @@ func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id,
return .single(nil)
}
var flags: Int32 = 0
if orderByCommission {
flags |= 1 << 2
switch sortMode {
case .revenue:
flags |= 1 << 0
case .date:
flags |= 1 << 1
case .commission:
break
}
return account.network.request(Api.functions.payments.getSuggestedStarRefBots(
flags: flags,
@ -827,18 +828,15 @@ func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id,
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
var items: [TelegramSuggestedStarRefBotList.Item] = []
for suggestedBot in suggestedBots {
switch suggestedBot {
case let .suggestedBotStarRef(_, botId, commissionPermille, durationMonths):
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
continue
}
items.append(TelegramSuggestedStarRefBotList.Item(
peer: EnginePeer(botPeer),
commissionPermille: commissionPermille,
durationMonths: durationMonths
))
for starRefProgram in suggestedBots {
let parsedProgram = TelegramStarRefProgram(apiStarRefProgram: starRefProgram)
guard let botPeer = transaction.getPeer(parsedProgram.botId) else {
continue
}
items.append(TelegramSuggestedStarRefBotList.Item(
peer: EnginePeer(botPeer),
program: parsedProgram
))
}
return TelegramSuggestedStarRefBotList(items: items, totalCount: Int(count), nextOffset: nextOffset)

View File

@ -1641,8 +1641,8 @@ public extension TelegramEngine {
return _internal_requestConnectedStarRefBots(account: self.account, id: id, offset: offset, limit: limit)
}
public func requestSuggestedStarRefBots(id: EnginePeer.Id, orderByCommission: Bool, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
return _internal_requestSuggestedStarRefBots(account: self.account, id: id, orderByCommission: orderByCommission, offset: offset, limit: limit)
public func requestSuggestedStarRefBots(id: EnginePeer.Id, sortMode: TelegramSuggestedStarRefBotList.SortMode, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
return _internal_requestSuggestedStarRefBots(account: self.account, id: id, sortMode: sortMode, offset: offset, limit: limit)
}
public func connectStarRefBot(id: EnginePeer.Id, botId: EnginePeer.Id) -> Signal<TelegramConnectedStarRefBotList.Item, ConnectStarRefBotError> {

View File

@ -412,6 +412,7 @@ If you end your affiliate program:
let availableModes: [(TelegramSuggestedStarRefBotList.SortMode, String)] = [
(.date, "Date"),
(.revenue, "Revenue"),
(.commission, "Commission")
]
for (mode, title) in availableModes {
@ -436,7 +437,7 @@ If you end your affiliate program:
self.suggestedStarBotListDisposable?.dispose()
self.suggestedStarBotListDisposable = (component.context.engine.peers.requestSuggestedStarRefBots(
id: component.initialContent.peerId,
orderByCommission: self.suggestedSortMode == .commission,
sortMode: self.suggestedSortMode,
offset: nil,
limit: 100)
|> deliverOnMainQueue).startStrict(next: { [weak self] list in
@ -559,7 +560,7 @@ If you end your affiliate program:
self.suggestedStarBotListDisposable = (component.context.engine.peers.requestSuggestedStarRefBots(
id: component.initialContent.peerId,
orderByCommission: false,
sortMode: self.suggestedSortMode,
offset: nil,
limit: 100)
|> deliverOnMainQueue).startStrict(next: { [weak self] list in
@ -1344,9 +1345,9 @@ If you end your affiliate program:
do {
var suggestedSectionItems: [AnyComponentWithIdentity<Empty>] = []
for item in suggestedStarBotListItems {
let commissionTitle = "\(item.commissionPermille / 10)%"
let commissionTitle = "\(item.program.commissionPermille / 10)%"
let durationTitle: String
if let durationMonths = item.durationMonths {
if let durationMonths = item.program.durationMonths {
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (24 * 60 * 60))
} else {
durationTitle = "Lifetime"
@ -1401,8 +1402,8 @@ If you end your affiliate program:
self.environment?.controller()?.push(JoinAffiliateProgramScreen(
context: component.context,
sourcePeer: botPeer,
commissionPermille: item.commissionPermille,
programDuration: item.durationMonths,
commissionPermille: item.program.commissionPermille,
programDuration: item.program.durationMonths,
mode: .join(JoinAffiliateProgramScreenMode.Join(
initialTargetPeer: targetPeer,
canSelectTargetPeer: false,

View File

@ -1636,6 +1636,8 @@ final class BotSectionSortButtonComponent: Component {
sortByString = "SORT BY [DATE]()"
case .commission:
sortByString = "SORT BY [COMMISSION]()"
case .revenue:
sortByString = "SORT BY [REVENUE]()"
}
let textSize = self.text.update(
transition: .immediate,