mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Stars giveaways [skip ci]
This commit is contained in:
@@ -123,12 +123,13 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
case setChatWallpaper(wallpaper: TelegramWallpaper, forBoth: Bool)
|
||||
case setSameChatWallpaper(wallpaper: TelegramWallpaper)
|
||||
case giftCode(slug: String, fromGiveaway: Bool, isUnclaimed: Bool, boostPeerId: PeerId?, months: Int32, currency: String?, amount: Int64?, cryptoCurrency: String?, cryptoAmount: Int64?)
|
||||
case giveawayLaunched
|
||||
case giveawayLaunched(stars: Int64?)
|
||||
case joinedChannel
|
||||
case giveawayResults(winners: Int32, unclaimed: Int32)
|
||||
case boostsApplied(boosts: Int32)
|
||||
case paymentRefunded(peerId: PeerId, currency: String, totalAmount: Int64, payload: Data?, transactionId: String)
|
||||
case giftStars(currency: String, amount: Int64, count: Int64, cryptoCurrency: String?, cryptoAmount: Int64?, transactionId: String?)
|
||||
case prizeStars(amount: Int64, isUnclaimed: Bool, boostPeerId: PeerId?, transactionId: String?, giveawayMessageId: MessageId?)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
|
||||
@@ -230,7 +231,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
case 36:
|
||||
self = .giftCode(slug: decoder.decodeStringForKey("slug", orElse: ""), fromGiveaway: decoder.decodeBoolForKey("give", orElse: false), isUnclaimed: decoder.decodeBoolForKey("unclaimed", orElse: false), boostPeerId: decoder.decodeOptionalInt64ForKey("pi").flatMap { PeerId($0) }, months: decoder.decodeInt32ForKey("months", orElse: 0), currency: decoder.decodeOptionalStringForKey("currency"), amount: decoder.decodeOptionalInt64ForKey("amount"), cryptoCurrency: decoder.decodeOptionalStringForKey("cryptoCurrency"), cryptoAmount: decoder.decodeOptionalInt64ForKey("cryptoAmount"))
|
||||
case 37:
|
||||
self = .giveawayLaunched
|
||||
self = .giveawayLaunched(stars: decoder.decodeOptionalInt64ForKey("stars"))
|
||||
case 38:
|
||||
self = .joinedChannel
|
||||
case 39:
|
||||
@@ -241,6 +242,14 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
self = .paymentRefunded(peerId: PeerId(decoder.decodeInt64ForKey("pi", orElse: 0)), currency: decoder.decodeStringForKey("currency", orElse: ""), totalAmount: decoder.decodeInt64ForKey("amount", orElse: 0), payload: decoder.decodeDataForKey("payload"), transactionId: decoder.decodeStringForKey("transactionId", orElse: ""))
|
||||
case 42:
|
||||
self = .giftStars(currency: decoder.decodeStringForKey("currency", orElse: ""), amount: decoder.decodeInt64ForKey("amount", orElse: 0), count: decoder.decodeInt64ForKey("count", orElse: 0), cryptoCurrency: decoder.decodeOptionalStringForKey("cryptoCurrency"), cryptoAmount: decoder.decodeOptionalInt64ForKey("cryptoAmount"), transactionId: decoder.decodeOptionalStringForKey("transactionId"))
|
||||
case 43:
|
||||
let boostPeerId = decoder.decodeOptionalInt64ForKey("pi").flatMap { PeerId($0) }
|
||||
let giveawayMsgId = decoder.decodeOptionalInt32ForKey("giveawayMsgId")
|
||||
var giveawayMessageId: MessageId?
|
||||
if let boostPeerId, let giveawayMsgId {
|
||||
giveawayMessageId = MessageId(peerId: boostPeerId, namespace: Namespaces.Message.Cloud, id: giveawayMsgId)
|
||||
}
|
||||
self = .prizeStars(amount: decoder.decodeInt64ForKey("amount", orElse: 0), isUnclaimed: decoder.decodeBoolForKey("unclaimed", orElse: false), boostPeerId: boostPeerId, transactionId: decoder.decodeOptionalStringForKey("transactionId"), giveawayMessageId: giveawayMessageId)
|
||||
default:
|
||||
self = .unknown
|
||||
}
|
||||
@@ -452,8 +461,13 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "cryptoAmount")
|
||||
}
|
||||
case .giveawayLaunched:
|
||||
case let .giveawayLaunched(stars):
|
||||
encoder.encodeInt32(37, forKey: "_rawValue")
|
||||
if let stars = stars {
|
||||
encoder.encodeInt64(stars, forKey: "stars")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "stars")
|
||||
}
|
||||
case .joinedChannel:
|
||||
encoder.encodeInt32(38, forKey: "_rawValue")
|
||||
case let .giveawayResults(winners, unclaimed):
|
||||
@@ -491,6 +505,25 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "transactionId")
|
||||
}
|
||||
case let .prizeStars(amount, isUnclaimed, boostPeerId, transactionId, giveawayMessageId):
|
||||
encoder.encodeInt32(43, forKey: "_rawValue")
|
||||
encoder.encodeInt64(amount, forKey: "amount")
|
||||
encoder.encodeBool(isUnclaimed, forKey: "unclaimed")
|
||||
if let boostPeerId = boostPeerId {
|
||||
encoder.encodeInt64(boostPeerId.toInt64(), forKey: "pi")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "pi")
|
||||
}
|
||||
if let transactionId {
|
||||
encoder.encodeString(transactionId, forKey: "transactionId")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "transactionId")
|
||||
}
|
||||
if let giveawayMessageId {
|
||||
encoder.encodeInt32(giveawayMessageId.id, forKey: "giveawayMsgId")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "giveawayMsgId")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,6 +549,8 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
return boostPeerId.flatMap { [$0] } ?? []
|
||||
case let .paymentRefunded(peerId, _, _, _, _):
|
||||
return [peerId]
|
||||
case let .prizeStars(_, _, boostPeerId, _, _):
|
||||
return boostPeerId.flatMap { [$0] } ?? []
|
||||
default:
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ public final class TelegramMediaGiveaway: Media, Equatable {
|
||||
public static let showWinners = Flags(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
public enum Prize: Equatable {
|
||||
case premium(months: Int32)
|
||||
case stars(amount: Int64)
|
||||
}
|
||||
|
||||
public var id: MediaId? {
|
||||
return nil
|
||||
}
|
||||
@@ -23,16 +28,16 @@ public final class TelegramMediaGiveaway: Media, Equatable {
|
||||
public let channelPeerIds: [PeerId]
|
||||
public let countries: [String]
|
||||
public let quantity: Int32
|
||||
public let months: Int32
|
||||
public let prize: Prize
|
||||
public let untilDate: Int32
|
||||
public let prizeDescription: String?
|
||||
|
||||
public init(flags: Flags, channelPeerIds: [PeerId], countries: [String], quantity: Int32, months: Int32, untilDate: Int32, prizeDescription: String?) {
|
||||
public init(flags: Flags, channelPeerIds: [PeerId], countries: [String], quantity: Int32, prize: Prize, untilDate: Int32, prizeDescription: String?) {
|
||||
self.flags = flags
|
||||
self.channelPeerIds = channelPeerIds
|
||||
self.countries = countries
|
||||
self.quantity = quantity
|
||||
self.months = months
|
||||
self.prize = prize
|
||||
self.untilDate = untilDate
|
||||
self.prizeDescription = prizeDescription
|
||||
}
|
||||
@@ -42,7 +47,13 @@ public final class TelegramMediaGiveaway: Media, Equatable {
|
||||
self.channelPeerIds = decoder.decodeInt64ArrayForKey("cns").map { PeerId($0) }
|
||||
self.countries = decoder.decodeStringArrayForKey("cnt")
|
||||
self.quantity = decoder.decodeInt32ForKey("qty", orElse: 0)
|
||||
self.months = decoder.decodeInt32ForKey("mts", orElse: 0)
|
||||
if let months = decoder.decodeOptionalInt32ForKey("mts") {
|
||||
self.prize = .premium(months: months)
|
||||
} else if let stars = decoder.decodeOptionalInt64ForKey("str") {
|
||||
self.prize = .stars(amount: stars)
|
||||
} else {
|
||||
self.prize = .premium(months: 0)
|
||||
}
|
||||
self.untilDate = decoder.decodeInt32ForKey("unt", orElse: 0)
|
||||
self.prizeDescription = decoder.decodeOptionalStringForKey("des")
|
||||
}
|
||||
@@ -52,7 +63,12 @@ public final class TelegramMediaGiveaway: Media, Equatable {
|
||||
encoder.encodeInt64Array(self.channelPeerIds.map { $0.toInt64() }, forKey: "cns")
|
||||
encoder.encodeStringArray(self.countries, forKey: "cnt")
|
||||
encoder.encodeInt32(self.quantity, forKey: "qty")
|
||||
encoder.encodeInt32(self.months, forKey: "mts")
|
||||
switch self.prize {
|
||||
case let .premium(months):
|
||||
encoder.encodeInt32(months, forKey: "mts")
|
||||
case let .stars(amount):
|
||||
encoder.encodeInt64(amount, forKey: "str")
|
||||
}
|
||||
encoder.encodeInt32(self.untilDate, forKey: "unt")
|
||||
if let prizeDescription = self.prizeDescription {
|
||||
encoder.encodeString(prizeDescription, forKey: "des")
|
||||
@@ -81,7 +97,7 @@ public final class TelegramMediaGiveaway: Media, Equatable {
|
||||
if self.quantity != other.quantity {
|
||||
return false
|
||||
}
|
||||
if self.months != other.months {
|
||||
if self.prize != other.prize {
|
||||
return false
|
||||
}
|
||||
if self.untilDate != other.untilDate {
|
||||
|
||||
@@ -12,6 +12,11 @@ public final class TelegramMediaGiveawayResults: Media, Equatable {
|
||||
public static let onlyNewSubscribers = Flags(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
public enum Prize: Equatable {
|
||||
case premium(months: Int32)
|
||||
case stars(amount: Int64)
|
||||
}
|
||||
|
||||
public var id: MediaId? {
|
||||
return nil
|
||||
}
|
||||
@@ -25,18 +30,18 @@ public final class TelegramMediaGiveawayResults: Media, Equatable {
|
||||
public let winnersPeerIds: [PeerId]
|
||||
public let winnersCount: Int32
|
||||
public let unclaimedCount: Int32
|
||||
public let months: Int32
|
||||
public let prize: Prize
|
||||
public let untilDate: Int32
|
||||
public let prizeDescription: String?
|
||||
|
||||
public init(flags: Flags, launchMessageId: MessageId, additionalChannelsCount: Int32, winnersPeerIds: [PeerId], winnersCount: Int32, unclaimedCount: Int32, months: Int32, untilDate: Int32, prizeDescription: String?) {
|
||||
public init(flags: Flags, launchMessageId: MessageId, additionalChannelsCount: Int32, winnersPeerIds: [PeerId], winnersCount: Int32, unclaimedCount: Int32, prize: Prize, untilDate: Int32, prizeDescription: String?) {
|
||||
self.flags = flags
|
||||
self.launchMessageId = launchMessageId
|
||||
self.additionalChannelsCount = additionalChannelsCount
|
||||
self.winnersPeerIds = winnersPeerIds
|
||||
self.winnersCount = winnersCount
|
||||
self.unclaimedCount = unclaimedCount
|
||||
self.months = months
|
||||
self.prize = prize
|
||||
self.untilDate = untilDate
|
||||
self.prizeDescription = prizeDescription
|
||||
}
|
||||
@@ -48,7 +53,13 @@ public final class TelegramMediaGiveawayResults: Media, Equatable {
|
||||
self.winnersPeerIds = decoder.decodeInt64ArrayForKey("wnr").map { PeerId($0) }
|
||||
self.winnersCount = decoder.decodeInt32ForKey("wnc", orElse: 0)
|
||||
self.unclaimedCount = decoder.decodeInt32ForKey("unc", orElse: 0)
|
||||
self.months = decoder.decodeInt32ForKey("mts", orElse: 0)
|
||||
if let months = decoder.decodeOptionalInt32ForKey("mts") {
|
||||
self.prize = .premium(months: months)
|
||||
} else if let stars = decoder.decodeOptionalInt64ForKey("str") {
|
||||
self.prize = .stars(amount: stars)
|
||||
} else {
|
||||
self.prize = .premium(months: 0)
|
||||
}
|
||||
self.untilDate = decoder.decodeInt32ForKey("unt", orElse: 0)
|
||||
self.prizeDescription = decoder.decodeOptionalStringForKey("des")
|
||||
}
|
||||
@@ -61,7 +72,12 @@ public final class TelegramMediaGiveawayResults: Media, Equatable {
|
||||
encoder.encodeInt64Array(self.winnersPeerIds.map { $0.toInt64() }, forKey: "wnr")
|
||||
encoder.encodeInt32(self.winnersCount, forKey: "wnc")
|
||||
encoder.encodeInt32(self.unclaimedCount, forKey: "unc")
|
||||
encoder.encodeInt32(self.months, forKey: "mts")
|
||||
switch self.prize {
|
||||
case let .premium(months):
|
||||
encoder.encodeInt32(months, forKey: "mts")
|
||||
case let .stars(amount):
|
||||
encoder.encodeInt64(amount, forKey: "str")
|
||||
}
|
||||
encoder.encodeInt32(self.untilDate, forKey: "unt")
|
||||
if let prizeDescription = self.prizeDescription {
|
||||
encoder.encodeString(prizeDescription, forKey: "des")
|
||||
@@ -96,7 +112,7 @@ public final class TelegramMediaGiveawayResults: Media, Equatable {
|
||||
if self.unclaimedCount != other.unclaimedCount {
|
||||
return false
|
||||
}
|
||||
if self.months != other.months {
|
||||
if self.prize != other.prize {
|
||||
return false
|
||||
}
|
||||
if self.untilDate != other.untilDate {
|
||||
|
||||
Reference in New Issue
Block a user