Various improvements

This commit is contained in:
Ilya Laktyushin
2024-09-01 16:03:17 +04:00
parent a5aac7fcd7
commit e27bb3a220
18 changed files with 215 additions and 76 deletions

View File

@@ -200,7 +200,7 @@ private final class ChannelBoostersContextImpl {
var result: [ChannelBoostersContext.State.Boost] = []
for boost in cachedResult.boosts {
let peer = boost.peerId.flatMap { transaction.getPeer($0) }
result.append(ChannelBoostersContext.State.Boost(flags: ChannelBoostersContext.State.Boost.Flags(rawValue: boost.flags), id: boost.id, peer: peer.flatMap { EnginePeer($0) }, date: boost.date, expires: boost.expires, multiplier: boost.multiplier, slug: boost.slug))
result.append(ChannelBoostersContext.State.Boost(flags: ChannelBoostersContext.State.Boost.Flags(rawValue: boost.flags), id: boost.id, peer: peer.flatMap { EnginePeer($0) }, date: boost.date, expires: boost.expires, multiplier: boost.multiplier, stars: boost.stars, slug: boost.slug, giveawayMessageId: boost.giveawayMessageId))
}
return (result, cachedResult.count, true)
} else {
@@ -452,6 +452,7 @@ private final class CachedChannelBoosters: Codable {
case date
case expires
case multiplier
case stars
case slug
case channelPeerId
case giveawayMessageId
@@ -463,17 +464,19 @@ private final class CachedChannelBoosters: Codable {
var date: Int32
var expires: Int32
var multiplier: Int32
var stars: Int64?
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?, channelPeerId: EnginePeer.Id, giveawayMessageId: EngineMessage.Id?) {
init(flags: Int32, id: String, peerId: EnginePeer.Id?, date: Int32, expires: Int32, multiplier: Int32, stars: Int64?, slug: String?, channelPeerId: EnginePeer.Id, giveawayMessageId: EngineMessage.Id?) {
self.flags = flags
self.id = id
self.peerId = peerId
self.date = date
self.expires = expires
self.multiplier = multiplier
self.stars = stars
self.slug = slug
self.channelPeerId = channelPeerId
self.giveawayMessageId = giveawayMessageId
@@ -488,6 +491,7 @@ private final class CachedChannelBoosters: Codable {
self.date = try container.decode(Int32.self, forKey: .date)
self.expires = try container.decode(Int32.self, forKey: .expires)
self.multiplier = try container.decode(Int32.self, forKey: .multiplier)
self.stars = try container.decodeIfPresent(Int64.self, forKey: .stars)
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) }
@@ -502,6 +506,7 @@ private final class CachedChannelBoosters: Codable {
try container.encode(self.date, forKey: .date)
try container.encode(self.expires, forKey: .expires)
try container.encode(self.multiplier, forKey: .multiplier)
try container.encodeIfPresent(self.stars, forKey: .stars)
try container.encodeIfPresent(self.slug, forKey: .slug)
try container.encode(self.channelPeerId.toInt64(), forKey: .channelPeerId)
try container.encodeIfPresent(self.giveawayMessageId?.id, forKey: .giveawayMessageId)
@@ -518,7 +523,7 @@ private final class CachedChannelBoosters: Codable {
}
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.boosts = boosts.map { CachedBoost(flags: $0.flags.rawValue, id: $0.id, peerId: $0.peer?.id, date: $0.date, expires: $0.expires, multiplier: $0.multiplier, stars: $0.stars, slug: $0.slug, channelPeerId: channelPeerId, giveawayMessageId: $0.giveawayMessageId) }
self.count = count
}