Various fixes

This commit is contained in:
Ilya Laktyushin 2023-10-25 19:04:54 +04:00
parent b04766d36b
commit b26c434e61
4 changed files with 75 additions and 10 deletions

View file

@ -234,7 +234,11 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
link = nil
}
date = boost.date
toPeerId = boost.peer?.id
if boost.flags.contains(.isUnclaimed) {
toPeerId = nil
} else {
toPeerId = boost.peer?.id
}
fromPeer = state.peerMap[channelId]
months = Int32(round(Float(boost.expires - boost.date) / (86400.0 * 30.0)))
}
@ -378,6 +382,28 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
)
)
))
} else if case let .boost(_, boost) = component.subject {
if boost.flags.contains(.isUnclaimed) {
let giftReason = strings.GiftLink_Reason_Unclaimed
tableItems.append(.init(
id: "reason",
title: strings.GiftLink_Reason,
component: AnyComponent(
Button(
content: AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: giftReason, font: tableFont, textColor: boost.giveawayMessageId != nil ? tableLinkColor : tableTextColor)))),
isEnabled: true,
action: {
if let messageId = boost.giveawayMessageId {
component.openMessage(messageId)
}
Queue.mainQueue().after(1.0) {
component.cancel(false)
}
}
)
)
))
}
}
tableItems.append(.init(
id: "date",

View file

@ -910,6 +910,8 @@ public func channelStatsController(context: AccountContext, updatedPresentationD
var dismissAllTooltipsImpl: (() -> Void)?
var presentImpl: ((ViewController) -> Void)?
var pushImpl: ((ViewController) -> Void)?
var navigateToChatImpl: ((EnginePeer) -> Void)?
var navigateToMessageImpl: ((EngineMessage.Id) -> Void)?
let arguments = ChannelStatsControllerArguments(context: context, loadDetailedGraph: { graph, x -> Signal<StatsGraph?, NoError> in
return statsContext.loadDetailedGraph(graph, x: x)
@ -972,7 +974,16 @@ public func channelStatsController(context: AccountContext, updatedPresentationD
return
}
let controller = PremiumGiftCodeScreen(context: context, subject: .boost(peerId, boost), action: {})
let controller = PremiumGiftCodeScreen(
context: context,
subject: .boost(peerId, boost),
action: {},
openPeer: { peer in
navigateToChatImpl?(peer)
},
openMessage: { messageId in
navigateToMessageImpl?(messageId)
})
pushImpl?(controller)
},
expandBoosters: {
@ -1120,6 +1131,24 @@ public func channelStatsController(context: AccountContext, updatedPresentationD
pushImpl = { [weak controller] c in
controller?.push(c)
}
navigateToChatImpl = { [weak controller] peer in
if let navigationController = controller?.navigationController as? NavigationController {
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peer), keepStack: .always, purposefulAction: {}, peekData: nil))
}
}
navigateToMessageImpl = { [weak controller] messageId in
let _ = (context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.Peer(id: messageId.peerId)
)
|> deliverOnMainQueue).start(next: { peer in
guard let peer = peer else {
return
}
if let navigationController = controller?.navigationController as? NavigationController {
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peer), subject: .message(id: .id(messageId), highlight: ChatControllerSubject.MessageHighlight(quote: nil), timecode: nil), keepStack: .always, useExisting: false, purposefulAction: {}, peekData: nil))
}
})
}
return controller
}

View file

@ -263,7 +263,6 @@ private final class ChannelBoostersContextImpl {
for boost in boosts {
switch boost {
case let .boost(flags, id, userId, giveawayMessageId, date, expires, usedGiftSlug, multiplier):
let _ = giveawayMessageId
var boostFlags: ChannelBoostersContext.State.Boost.Flags = []
var boostPeer: EnginePeer?
if let userId = userId {
@ -281,11 +280,11 @@ private final class ChannelBoostersContextImpl {
if (flags & (1 << 3)) != 0 {
boostFlags.insert(.isUnclaimed)
}
resultBoosts.append(ChannelBoostersContext.State.Boost(flags: boostFlags, id: id, peer: boostPeer, date: date, expires: expires, multiplier: multiplier ?? 1, slug: usedGiftSlug))
resultBoosts.append(ChannelBoostersContext.State.Boost(flags: boostFlags, id: id, peer: boostPeer, date: date, expires: expires, multiplier: multiplier ?? 1, slug: usedGiftSlug, giveawayMessageId: giveawayMessageId.flatMap { EngineMessage.Id(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }))
}
}
if populateCache {
if let entry = CodableEntry(CachedChannelBoosters(boosts: resultBoosts, count: count)) {
if let entry = CodableEntry(CachedChannelBoosters(channelPeerId: peerId, boosts: resultBoosts, count: count)) {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedChannelBoosts, key: CachedChannelBoosters.key(peerId: peerId)), entry: entry)
}
}
@ -340,7 +339,7 @@ private final class ChannelBoostersContextImpl {
let resultBoosts = Array(self.results.prefix(50))
let count = self.count
self.updateDisposables.add(self.account.postbox.transaction({ transaction in
if let entry = CodableEntry(CachedChannelBoosters(boosts: resultBoosts, count: count)) {
if let entry = CodableEntry(CachedChannelBoosters(channelPeerId: peerId, boosts: resultBoosts, count: count)) {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedChannelBoosts, key: CachedChannelBoosters.key(peerId: peerId)), entry: entry)
}
}).start())
@ -373,6 +372,7 @@ public final class ChannelBoostersContext {
public var expires: Int32
public var multiplier: Int32
public var slug: String?
public var giveawayMessageId: EngineMessage.Id?
}
public var boosts: [Boost]
public var isLoadingMore: Bool
@ -435,6 +435,8 @@ private final class CachedChannelBoosters: Codable {
case expires
case multiplier
case slug
case channelPeerId
case giveawayMessageId
}
var flags: Int32
@ -444,8 +446,10 @@ private final class CachedChannelBoosters: Codable {
var expires: Int32
var multiplier: Int32
var slug: String?
var channelPeerId: EnginePeer.Id
var giveawayMessageId: EngineMessage.Id?
init(flags: Int32, id: String, peerId: EnginePeer.Id?, date: Int32, expires: Int32, multiplier: Int32, slug: String?) {
init(flags: Int32, id: String, peerId: EnginePeer.Id?, date: Int32, expires: Int32, multiplier: Int32, slug: String?, channelPeerId: EnginePeer.Id, giveawayMessageId: EngineMessage.Id?) {
self.flags = flags
self.id = id
self.peerId = peerId
@ -453,6 +457,8 @@ private final class CachedChannelBoosters: Codable {
self.expires = expires
self.multiplier = multiplier
self.slug = slug
self.channelPeerId = channelPeerId
self.giveawayMessageId = giveawayMessageId
}
init(from decoder: Decoder) throws {
@ -465,6 +471,8 @@ private final class CachedChannelBoosters: Codable {
self.expires = try container.decode(Int32.self, forKey: .expires)
self.multiplier = try container.decode(Int32.self, forKey: .multiplier)
self.slug = try container.decodeIfPresent(String.self, forKey: .slug)
self.channelPeerId = EnginePeer.Id(try container.decode(Int64.self, forKey: .channelPeerId))
self.giveawayMessageId = try container.decodeIfPresent(Int32.self, forKey: .giveawayMessageId).flatMap { EngineMessage.Id(peerId: self.channelPeerId, namespace: Namespaces.Message.Cloud, id: $0) }
}
func encode(to encoder: Encoder) throws {
@ -477,6 +485,8 @@ private final class CachedChannelBoosters: Codable {
try container.encode(self.expires, forKey: .expires)
try container.encode(self.multiplier, forKey: .multiplier)
try container.encodeIfPresent(self.slug, forKey: .slug)
try container.encode(self.channelPeerId.toInt64(), forKey: .channelPeerId)
try container.encodeIfPresent(self.giveawayMessageId?.id, forKey: .giveawayMessageId)
}
}
@ -489,8 +499,8 @@ private final class CachedChannelBoosters: Codable {
return key
}
init(boosts: [ChannelBoostersContext.State.Boost], count: Int32) {
self.boosts = boosts.map { CachedBoost(flags: $0.flags.rawValue, id: $0.id, peerId: $0.peer?.id, date: $0.date, expires: $0.expires, multiplier: $0.multiplier, slug: $0.slug) }
init(channelPeerId: EnginePeer.Id, boosts: [ChannelBoostersContext.State.Boost], count: Int32) {
self.boosts = boosts.map { CachedBoost(flags: $0.flags.rawValue, id: $0.id, peerId: $0.peer?.id, date: $0.date, expires: $0.expires, multiplier: $0.multiplier, slug: $0.slug, channelPeerId: channelPeerId, giveawayMessageId: $0.giveawayMessageId) }
self.count = count
}

View file

@ -429,7 +429,7 @@ public class ChatMessageGiveawayBubbleContentNode: ChatMessageBubbleContentNode
}
}
}
let (channelsWidth, continueChannelLayout) = makeChannelsLayout(item.context, 250.0, channelPeers, accentColor, accentColor.withAlphaComponent(0.1))
let (channelsWidth, continueChannelLayout) = makeChannelsLayout(item.context, 240.0, channelPeers, accentColor, accentColor.withAlphaComponent(0.1))
maxContentWidth = max(maxContentWidth, channelsWidth)
maxContentWidth += 30.0