Update API

This commit is contained in:
Ilya Laktyushin 2024-09-20 15:15:50 +04:00
parent e29a1a1c77
commit 164824d1e5
7 changed files with 104 additions and 88 deletions

View File

@ -890,7 +890,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-425595208] = { return Api.SmsJob.parse_smsJob($0) }
dict[1301522832] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) }
dict[-384008227] = { return Api.StarGift.parse_starGift($0) }
dict[-1365150482] = { return Api.StarGift.parse_starGift($0) }
dict[1577421297] = { return Api.StarsGiftOption.parse_starsGiftOption($0) }
dict[-1798404822] = { return Api.StarsGiveawayOption.parse_starsGiveawayOption($0) }
dict[1411605001] = { return Api.StarsGiveawayWinnersOption.parse_starsGiveawayWinnersOption($0) }

View File

@ -574,13 +574,13 @@ public extension Api {
}
public extension Api {
enum StarGift: TypeConstructorDescription {
case starGift(flags: Int32, id: Int64, sticker: Api.Document, stars: Int64, availabilityRemains: Int32?, availabilityTotal: Int32?)
case starGift(flags: Int32, id: Int64, sticker: Api.Document, stars: Int64, availabilityRemains: Int32?, availabilityTotal: Int32?, convertStars: Int64)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .starGift(let flags, let id, let sticker, let stars, let availabilityRemains, let availabilityTotal):
case .starGift(let flags, let id, let sticker, let stars, let availabilityRemains, let availabilityTotal, let convertStars):
if boxed {
buffer.appendInt32(-384008227)
buffer.appendInt32(-1365150482)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt64(id, buffer: buffer, boxed: false)
@ -588,14 +588,15 @@ public extension Api {
serializeInt64(stars, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(availabilityRemains!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(availabilityTotal!, buffer: buffer, boxed: false)}
serializeInt64(convertStars, buffer: buffer, boxed: false)
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .starGift(let flags, let id, let sticker, let stars, let availabilityRemains, let availabilityTotal):
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)])
case .starGift(let flags, let id, let sticker, let stars, let availabilityRemains, let availabilityTotal, let convertStars):
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)])
}
}
@ -614,14 +615,17 @@ public extension Api {
if Int(_1!) & Int(1 << 0) != 0 {_5 = reader.readInt32() }
var _6: Int32?
if Int(_1!) & Int(1 << 0) != 0 {_6 = reader.readInt32() }
var _7: Int64?
_7 = reader.readInt64()
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
let _c4 = _4 != nil
let _c5 = (Int(_1!) & Int(1 << 0) == 0) || _5 != nil
let _c6 = (Int(_1!) & Int(1 << 0) == 0) || _6 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 {
return Api.StarGift.starGift(flags: _1!, id: _2!, sticker: _3!, stars: _4!, availabilityRemains: _5, availabilityTotal: _6)
let _c7 = _7 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 {
return Api.StarGift.starGift(flags: _1!, id: _2!, sticker: _3!, stars: _4!, availabilityRemains: _5, availabilityTotal: _6, convertStars: _7!)
}
else {
return nil

View File

@ -32,6 +32,7 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
case id
case file
case price
case convertStars
case availability
}
@ -67,12 +68,14 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
public let id: Int64
public let file: TelegramMediaFile
public let price: Int64
public let convertStars: Int64
public let availability: Availability?
public init(id: Int64, file: TelegramMediaFile, price: Int64, availability: Availability?) {
public init(id: Int64, file: TelegramMediaFile, price: Int64, convertStars: Int64, availability: Availability?) {
self.id = id
self.file = file
self.price = price
self.convertStars = convertStars
self.availability = availability
}
@ -87,6 +90,7 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
}
self.price = try container.decode(Int64.self, forKey: .price)
self.convertStars = try container.decodeIfPresent(Int64.self, forKey: .convertStars) ?? 0
self.availability = try container.decodeIfPresent(Availability.self, forKey: .availability)
}
@ -94,6 +98,7 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
self.id = decoder.decodeInt64ForKey(CodingKeys.id.rawValue, orElse: 0)
self.file = decoder.decodeObjectForKey(CodingKeys.file.rawValue) as! TelegramMediaFile
self.price = decoder.decodeInt64ForKey(CodingKeys.price.rawValue, orElse: 0)
self.convertStars = decoder.decodeInt64ForKey(CodingKeys.convertStars.rawValue, orElse: 0)
self.availability = decoder.decodeObjectForKey(CodingKeys.availability.rawValue, decoder: { StarGift.Availability(decoder: $0) }) as? StarGift.Availability
}
@ -107,6 +112,7 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
try container.encode(fileData, forKey: .file)
try container.encode(self.price, forKey: .price)
try container.encode(self.convertStars, forKey: .convertStars)
try container.encodeIfPresent(self.availability, forKey: .availability)
}
@ -114,6 +120,7 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
encoder.encodeInt64(self.id, forKey: CodingKeys.id.rawValue)
encoder.encodeObject(self.file, forKey: CodingKeys.file.rawValue)
encoder.encodeInt64(self.price, forKey: CodingKeys.price.rawValue)
encoder.encodeInt64(self.convertStars, forKey: CodingKeys.convertStars.rawValue)
if let availability = self.availability {
encoder.encodeObject(availability, forKey: CodingKeys.availability.rawValue)
} else {
@ -125,7 +132,7 @@ public struct StarGift: Equatable, Codable, PostboxCoding {
extension StarGift {
init?(apiStarGift: Api.StarGift) {
switch apiStarGift {
case let .starGift(_, id, sticker, stars, availabilityRemains, availabilityTotal):
case let .starGift(_, id, sticker, stars, availabilityRemains, availabilityTotal, convertStars):
var availability: Availability?
if let availabilityRemains, let availabilityTotal {
availability = Availability(remains: availabilityRemains, total: availabilityTotal)
@ -133,7 +140,7 @@ extension StarGift {
guard let file = telegramMediaFileFromApiDocument(sticker, altDocuments: nil) else {
return nil
}
self.init(id: id, file: file, price: stars, availability: availability)
self.init(id: id, file: file, price: stars, convertStars: convertStars, availability: availability)
}
}
}
@ -323,6 +330,7 @@ public final class ProfileGiftsContext {
public let entities: [MessageTextEntity]?
public let messageId: EngineMessage.Id?
public let nameHidden: Bool
public let savedToProfile: Bool
public let convertStars: Int64?
}
@ -398,6 +406,7 @@ private extension ProfileGiftsContext.State.StarGift {
self.messageId = nil
}
self.nameHidden = (flags & (1 << 0)) != 0
self.savedToProfile = (flags & (1 << 5)) == 0
self.convertStars = convertStars
}
}

View File

@ -69,7 +69,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
}
}
private var animationDisposable: Disposable?
private var fetchDisposable: Disposable?
private var setupTimestamp: Double?
required public init() {
@ -144,7 +144,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
}
deinit {
self.animationDisposable?.dispose()
self.fetchDisposable?.dispose()
self.currentProgressDisposable?.dispose()
}
@ -318,7 +318,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
case let .starGift(gift, convertStars, giftText, entities, nameHidden, savedToProfile, converted)://(amount, giftId, nameHidden, limitNumber, limitTotal, giftText, _):
let _ = nameHidden
let authorName = item.message.author.flatMap { EnginePeer($0) }?.compactDisplayTitle ?? ""
title = nameHidden ? "Anonymous Gift" : "Gift from \(authorName)"
title = "Gift from \(authorName)"
if let giftText, !giftText.isEmpty {
text = giftText
let _ = entities
@ -429,6 +429,9 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if let file = animationFile {
strongSelf.animationNode.setup(source: AnimatedStickerResourceSource(account: item.context.account, resource: file.resource), width: 384, height: 384, playbackMode: .once, mode: .direct(cachePathPrefix: nil))
if strongSelf.fetchDisposable == nil {
strongSelf.fetchDisposable = freeMediaFileResourceInteractiveFetched(postbox: item.context.account.postbox, userLocation: .other, fileReference: .message(message: MessageReference(item.message), media: file), resource: file.resource).start()
}
} else if animationName.hasPrefix("Gift") {
strongSelf.animationNode.setup(source: AnimatedStickerNodeLocalFileSource(name: animationName), width: 384, height: 384, playbackMode: .still(.end), mode: .direct(cachePathPrefix: nil))
}

View File

@ -62,13 +62,32 @@ final class GiftOptionsScreenComponent: Component {
}
}
public enum StarsFilter: Int {
public enum StarsFilter: Equatable {
case all
case limited
case stars10
case stars25
case stars50
case stars100
case stars(Int64)
init(rawValue: Int64) {
switch rawValue {
case 0:
self = .all
case -1:
self = .limited
default:
self = .stars(rawValue)
}
}
public var rawValue: Int64 {
switch self {
case .all:
return 0
case .limited:
return -1
case let .stars(stars):
return stars
}
}
}
final class View: UIView, UIScrollViewDelegate {
@ -212,30 +231,16 @@ final class GiftOptionsScreenComponent: Component {
}
if isVisible {
if self.starsFilter != .all {
switch self.starsFilter {
case .all:
break
case .limited:
if gift.availability == nil {
continue
}
case .stars10:
if gift.price != 10 {
continue
}
case .stars25:
if gift.price != 25 {
continue
}
case .stars50:
if gift.price != 50 {
continue
}
case .stars100:
if gift.price != 100 {
continue
}
switch self.starsFilter {
case .all:
break
case .limited:
if gift.availability == nil {
continue
}
case let .stars(stars):
if gift.price != stars {
continue
}
}
@ -670,6 +675,30 @@ final class GiftOptionsScreenComponent: Component {
contentHeight += starsDescriptionSize.height
contentHeight += 16.0
var tabSelectorItems: [TabSelectorComponent.Item] = []
tabSelectorItems.append(TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.all.rawValue),
title: "All Gifts"
))
tabSelectorItems.append(TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.limited.rawValue),
title: "Limited"
))
var starsAmountsSet = Set<Int64>()
if let starGifts = self.state?.starGifts {
for product in starGifts {
starsAmountsSet.insert(product.price)
}
}
let starsAmounts = Array(starsAmountsSet).sorted()
for amount in starsAmounts {
tabSelectorItems.append(TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.stars(amount).rawValue),
title: "⭐️\(amount)"
))
}
let tabSelectorSize = self.tabSelector.update(
transition: transition,
component: AnyComponent(TabSelectorComponent(
@ -679,37 +708,13 @@ final class GiftOptionsScreenComponent: Component {
selection: theme.list.itemSecondaryTextColor.withMultipliedAlpha(0.15),
simple: true
),
items: [
TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.all.rawValue),
title: "All Gifts"
),
TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.limited.rawValue),
title: "Limited"
),
TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.stars10.rawValue),
title: "10"
),
TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.stars25.rawValue),
title: "25"
),
TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.stars50.rawValue),
title: "50"
),
TabSelectorComponent.Item(
id: AnyHashable(StarsFilter.stars100.rawValue),
title: "100"
)
],
items: tabSelectorItems,
selectedId: AnyHashable(self.starsFilter.rawValue),
setSelectedId: { [weak self] id in
guard let self, let idValue = id.base as? Int, let starsFilter = StarsFilter(rawValue: idValue) else {
guard let self, let idValue = id.base as? Int64 else {
return
}
let starsFilter = StarsFilter(rawValue: idValue)
if self.starsFilter != starsFilter {
self.starsFilter = starsFilter
self.state?.updated(transition: .easeInOut(duration: 0.25))

View File

@ -199,8 +199,7 @@ final class ChatGiftPreviewItemNode: ListViewItemNode {
peers[authorPeerId] = item.accountPeer?._asPeer()
let media: [Media] = [
TelegramMediaAction(action: .starGift(gift: item.gift, convertStars: item.gift.price, text: item.text, entities: [], nameHidden: false, savedToProfile: false, converted: false))
//TelegramMediaAction(action: .starGift(amount: item.gift.price, giftId: item.gift.id, nameHidden: false, limitNumber: item.gift.availability != nil ? 1 : nil, limitTotal: item.gift.availability?.total, text: item.text, entities: []))
TelegramMediaAction(action: .starGift(gift: item.gift, convertStars: item.gift.convertStars, text: item.text, entities: [], nameHidden: false, savedToProfile: false, converted: false))
]
let message = Message(stableId: 1, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 1), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, threadId: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], customTags: [], forwardInfo: nil, author: peers[authorPeerId], text: "", attributes: [], media: media, peers: peers, associatedMessages: messages, associatedMessageIds: [], associatedMedia: [:], associatedThreadInfo: nil, associatedStories: [:])
items.append(item.context.sharedContext.makeChatMessagePreviewItem(context: item.context, messages: [message], theme: item.componentTheme, strings: item.strings, wallpaper: item.wallpaper, fontSize: item.fontSize, chatBubbleCorners: item.chatBubbleCorners, dateTimeFormat: item.dateTimeFormat, nameOrder: item.nameDisplayOrder, forcedResourceStatus: nil, tapMessage: nil, clickThroughMessage: nil, backgroundNode: currentBackgroundNode, availableReactions: nil, accountPeer: nil, isCentered: false, isPreview: true, isStandalone: false))

View File

@ -1258,17 +1258,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
return (starsRevenueStatsContext, state.stats)
}
}
let profileGiftsCount: Signal<Int32, NoError>
if let profileGiftsContext {
profileGiftsCount = profileGiftsContext.state
|> map { state in
return state.count ?? 0
}
} else {
profileGiftsCount = .single(0)
}
return combineLatest(
context.account.viewTracker.peerView(peerId, updateData: true),
peerInfoAvailableMediaPanes(context: context, peerId: peerId, chatLocation: chatLocation, isMyProfile: isMyProfile, chatLocationContextHolder: chatLocationContextHolder),
@ -1285,23 +1275,29 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
hasBotPreviewItems,
peerInfoPersonalChannel(context: context, peerId: peerId, isSettings: false),
privacySettings,
starsRevenueContextAndState,
profileGiftsCount
starsRevenueContextAndState
)
|> map { peerView, availablePanes, globalNotificationSettings, encryptionKeyFingerprint, status, hasStories, hasStoryArchive, accountIsPremium, savedMessagesPeer, hasSavedMessagesChats, hasSavedMessages, hasSavedMessageTags, hasBotPreviewItems, personalChannel, privacySettings, starsRevenueContextAndState, profileGiftsCount -> PeerInfoScreenData in
|> map { peerView, availablePanes, globalNotificationSettings, encryptionKeyFingerprint, status, hasStories, hasStoryArchive, accountIsPremium, savedMessagesPeer, hasSavedMessagesChats, hasSavedMessages, hasSavedMessageTags, hasBotPreviewItems, personalChannel, privacySettings, starsRevenueContextAndState -> PeerInfoScreenData in
var availablePanes = availablePanes
if isMyProfile {
availablePanes?.insert(.stories, at: 0)
if let hasStoryArchive, hasStoryArchive {
availablePanes?.insert(.storyArchive, at: 1)
}
if availablePanes != nil, profileGiftsContext != nil, let cachedData = peerView.cachedData as? CachedUserData {
if let starGiftsCount = cachedData.starGiftsCount, starGiftsCount > 0 {
availablePanes?.insert(.gifts, at: hasStoryArchive == true ? 2 : 1)
}
}
} else if let hasStories {
if hasStories, peerView.peers[peerView.peerId] is TelegramUser, peerView.peerId != context.account.peerId {
availablePanes?.insert(.stories, at: 0)
}
if profileGiftsCount > 0 {
availablePanes?.insert(.gifts, at: hasStories ? 1 : 0)
if availablePanes != nil, profileGiftsContext != nil, let cachedData = peerView.cachedData as? CachedUserData {
if let starGiftsCount = cachedData.starGiftsCount, starGiftsCount > 0 {
availablePanes?.insert(.gifts, at: hasStories ? 1 : 0)
}
}
if availablePanes != nil, groupsInCommon != nil, let cachedData = peerView.cachedData as? CachedUserData {