Update Ghostgram features

This commit is contained in:
ichmagmaus 812
2026-03-07 18:19:16 +01:00
parent 32b0dddcd9
commit 13a43b9068
902 changed files with 148295 additions and 62348 deletions
@@ -164,7 +164,7 @@ private final class GiftAuctionViewSheetContent: CombinedComponent {
}).shuffled().prefix(5))
self.previewSymbols = randomSymbols
for case let .model(_, file, _) in self.previewModels where !self.fetchedFiles.contains(file.fileId.id) {
for case let .model(_, file, _, _) in self.previewModels where !self.fetchedFiles.contains(file.fileId.id) {
self.disposables.add(freeMediaFileResourceInteractiveFetched(account: context.account, userLocation: .other, fileReference: .standalone(media: file), resource: file.resource).start())
self.fetchedFiles.insert(file.fileId.id)
}
@@ -725,9 +725,9 @@ private final class GiftAuctionViewSheetContent: CombinedComponent {
if let genericGift {
var attributes: [StarGift.UniqueGift.Attribute] = []
if state.previewModelIndex == -1 {
attributes.append(.model(name: "", file: genericGift.file, rarity: 0))
attributes.append(.model(name: "", file: genericGift.file, rarity: .permille(0), crafted: false))
if let background = genericGift.background {
attributes.append(.backdrop(name: "", id: 0, innerColor: background.centerColor, outerColor: background.edgeColor, patternColor: 0, textColor: 0, rarity: 0))
attributes.append(.backdrop(name: "", id: 0, innerColor: background.centerColor, outerColor: background.edgeColor, patternColor: 0, textColor: 0, rarity: .permille(0)))
}
} else if !state.previewModels.isEmpty {
attributes.append(state.previewModels[state.previewModelIndex])
@@ -1082,7 +1082,7 @@ private final class GiftAuctionViewSheetContent: CombinedComponent {
guard let state, let attributes = state.giftUpgradeAttributes else {
return
}
let variantsController = component.context.sharedContext.makeGiftUpgradeVariantsScreen(context: component.context, gift: .generic(gift), attributes: attributes, selectedAttributes: nil, focusedAttribute: nil)
let variantsController = component.context.sharedContext.makeGiftUpgradeVariantsScreen(context: component.context, gift: .generic(gift), crafted: false, attributes: attributes, selectedAttributes: nil, focusedAttribute: nil)
environment.controller()?.push(variantsController)
}, animateScale: false),
availableSize: CGSize(width: context.availableSize.width - 64.0, height: context.availableSize.height),
@@ -83,23 +83,23 @@ public func giftOfferAlertController(
let tag: AnyObject?
switch attribute {
case let .model(name, _, rarity):
case let .model(name, _, rarity, _):
id = "model"
title = strings.Gift_Unique_Model
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = modelButtonTag
case let .backdrop(name, _, _, _, _, _, rarity):
id = "backdrop"
title = strings.Gift_Unique_Backdrop
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = backdropButtonTag
case let .pattern(name, _, rarity):
id = "pattern"
title = strings.Gift_Unique_Symbol
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = symbolButtonTag
case .originalInfo:
continue
@@ -68,23 +68,23 @@ public func giftTransferAlertController(
let tag: AnyObject?
switch attribute {
case let .model(name, _, rarity):
case let .model(name, _, rarity, _):
id = "model"
title = strings.Gift_Unique_Model
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = modelButtonTag
case let .backdrop(name, _, _, _, _, _, rarity):
id = "backdrop"
title = strings.Gift_Unique_Backdrop
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = backdropButtonTag
case let .pattern(name, _, rarity):
id = "pattern"
title = strings.Gift_Unique_Symbol
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = symbolButtonTag
case .originalInfo:
continue
@@ -419,11 +419,11 @@ private final class GiftUpgradePreviewScreenComponent: Component {
var isSelected = false
for attribute in attributeList {
switch attribute {
case let .model(name, file, rarityValue):
case let .model(name, file, rarityValue, _):
itemId += "\(file.fileId.id)"
if self.selectedSection == .models {
title = name
rarity = rarityValue
rarity = rarityValue.permilleValue
modelAttribute = attribute
isSelected = self.selectedModel == attribute
@@ -432,7 +432,7 @@ private final class GiftUpgradePreviewScreenComponent: Component {
itemId += "\(id)"
if self.selectedSection == .backdrops {
title = name
rarity = rarityValue
rarity = rarityValue.permilleValue
backdropAttribute = attribute
isSelected = self.selectedBackdrop == attribute
@@ -441,7 +441,7 @@ private final class GiftUpgradePreviewScreenComponent: Component {
itemId += "\(file.fileId.id)"
if self.selectedSection == .symbols {
title = name
rarity = rarityValue
rarity = rarityValue.permilleValue
symbolAttribute = attribute
isSelected = self.selectedSymbol == attribute
@@ -1210,18 +1210,18 @@ private final class AttributeInfoComponent: Component {
let subtitle: String
let rarity: Int32
switch component.attribute {
case let .model(name, _, rarityValue):
case let .model(name, _, rarityValue, _):
title = name
subtitle = component.strings.Gift_Variants_Model
rarity = rarityValue
rarity = rarityValue.permilleValue
case let .backdrop(name, _, _, _, _, _, rarityValue):
title = name
subtitle = component.strings.Gift_Variants_Backdrop
rarity = rarityValue
rarity = rarityValue.permilleValue
case let .pattern(name, _, rarityValue):
title = name
subtitle = component.strings.Gift_Variants_Symbol
rarity = rarityValue
rarity = rarityValue.permilleValue
default:
title = ""
subtitle = ""
@@ -425,14 +425,14 @@ private final class GiftUpgradeVariantsScreenComponent: Component {
var isSelected = false
for attribute in attributeList {
switch attribute {
case let .model(name, file, rarityValue):
case let .model(name, file, rarityValue, _):
itemId += "\(file.fileId.id)"
if self.selectedSection == .models {
title = name
rarity = rarityValue
rarity = rarityValue.permilleValue
modelAttribute = attribute
if case let .model(_, selectedFile, _) = self.selectedModel {
if case let .model(_, selectedFile, _, _) = self.selectedModel {
isSelected = file.fileId == selectedFile.fileId
} else {
isSelected = false
@@ -442,7 +442,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component {
itemId += "\(id)"
if self.selectedSection == .backdrops {
title = name
rarity = rarityValue
rarity = rarityValue.permilleValue
backdropAttribute = attribute
if case let .backdrop(_, selectedId, _, _, _, _, _) = self.selectedBackdrop {
@@ -455,7 +455,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component {
itemId += "\(file.fileId.id)"
if self.selectedSection == .symbols {
title = name
rarity = rarityValue
rarity = rarityValue.permilleValue
symbolAttribute = attribute
if case let .pattern(_, selectedFile, _) = self.selectedSymbol {
@@ -1270,18 +1270,18 @@ private final class AttributeInfoComponent: Component {
let subtitle: String
let rarity: Int32
switch component.attribute {
case let .model(name, _, rarityValue):
case let .model(name, _, rarityValue, _):
title = name
subtitle = component.strings.Gift_Variants_Model
rarity = rarityValue
rarity = rarityValue.permilleValue
case let .backdrop(name, _, _, _, _, _, rarityValue):
title = name
subtitle = component.strings.Gift_Variants_Backdrop
rarity = rarityValue
rarity = rarityValue.permilleValue
case let .pattern(name, _, rarityValue):
title = name
subtitle = component.strings.Gift_Variants_Symbol
rarity = rarityValue
rarity = rarityValue.permilleValue
default:
title = ""
subtitle = ""
@@ -214,7 +214,7 @@ private final class GiftValueSheetContent: CombinedComponent {
giftIconSubject = .starGift(gift: gift, price: "")
case let .unique(gift):
for attribute in gift.attributes {
if case let .model(_, file, _) = attribute {
if case let .model(_, file, _, _) = attribute {
animationFile = file
}
}
@@ -234,8 +234,9 @@ private final class GiftViewSheetContent: CombinedComponent {
if self.testUpgradeAnimation {
if gift.giftId != 0 {
self.upgradePreviewDisposable.add((context.engine.payments.starGiftUpgradePreview(giftId: gift.giftId)
|> deliverOnMainQueue).start(next: { [weak self] upgradePreview in
let upgradePreviewSignal = context.engine.payments.starGiftUpgradePreview(giftId: gift.giftId)
|> deliverOnMainQueue
self.upgradePreviewDisposable.add(upgradePreviewSignal.start(next: { [weak self] upgradePreview in
guard let self, let upgradePreview else {
return
}
@@ -243,7 +244,7 @@ private final class GiftViewSheetContent: CombinedComponent {
for attribute in upgradePreview.attributes {
switch attribute {
case let .model(_, file, _):
case let .model(_, file, _, _):
self.upgradePreviewDisposable.add(freeMediaFileResourceInteractiveFetched(account: self.context.account, userLocation: .other, fileReference: .standalone(media: file), resource: file.resource).start())
case let .pattern(_, file, _):
self.upgradePreviewDisposable.add(freeMediaFileResourceInteractiveFetched(account: self.context.account, userLocation: .other, fileReference: .standalone(media: file), resource: file.resource).start())
@@ -261,8 +262,9 @@ private final class GiftViewSheetContent: CombinedComponent {
peerIds.append(releasedBy)
}
if arguments.canUpgrade || arguments.upgradeStars != nil || arguments.prepaidUpgradeHash != nil {
self.upgradePreviewDisposable.add((context.engine.payments.starGiftUpgradePreview(giftId: gift.id)
|> deliverOnMainQueue).start(next: { [weak self] upgradePreview in
let upgradePreviewSignal = context.engine.payments.starGiftUpgradePreview(giftId: gift.id)
|> deliverOnMainQueue
self.upgradePreviewDisposable.add(upgradePreviewSignal.start(next: { [weak self] upgradePreview in
guard let self, let upgradePreview else {
return
}
@@ -270,7 +272,7 @@ private final class GiftViewSheetContent: CombinedComponent {
for attribute in upgradePreview.attributes {
switch attribute {
case let .model(_, file, _):
case let .model(_, file, _, _):
self.upgradePreviewDisposable.add(freeMediaFileResourceInteractiveFetched(account: self.context.account, userLocation: .other, fileReference: .standalone(media: file), resource: file.resource).start())
case let .pattern(_, file, _):
self.upgradePreviewDisposable.add(freeMediaFileResourceInteractiveFetched(account: self.context.account, userLocation: .other, fileReference: .standalone(media: file), resource: file.resource).start())
@@ -501,7 +503,7 @@ private final class GiftViewSheetContent: CombinedComponent {
animationFile = gift.file
case let .unique(gift):
for attribute in gift.attributes {
if case let .model(_, file, _) = attribute {
if case let .model(_, file, _, _) = attribute {
animationFile = file
break
}
@@ -718,7 +720,7 @@ private final class GiftViewSheetContent: CombinedComponent {
let context = self.context
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let proceed = { [weak self, weak starsContext, weak controller] in
let proceed: () -> Void = { [weak self, weak starsContext, weak controller] in
guard let self, let controller else {
return
}
@@ -745,7 +747,7 @@ private final class GiftViewSheetContent: CombinedComponent {
let updatedAttributes = uniqueGift.attributes.filter { $0.attributeType != .originalInfo }
self.subject = .profileGift(peerId, gift.withGift(.unique(uniqueGift.withAttributes(updatedAttributes))))
case let .message(message):
if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case let .starGiftUnique(gift, isUpgrade, isTransferred, savedToProfile, canExportDate, transferStars, isRefunded, isPrepaidUpgrade, peerId, senderId, savedId, resaleAmount, canTransferDate, canResaleDate, _, assigned, fromOffer) = action.action, case let .unique(uniqueGift) = gift {
if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case let .starGiftUnique(gift, isUpgrade, isTransferred, savedToProfile, canExportDate, transferStars, isRefunded, isPrepaidUpgrade, peerId, senderId, savedId, resaleAmount, canTransferDate, canResaleDate, _, assigned, fromOffer, _, _) = action.action, case let .unique(uniqueGift) = gift {
let updatedAttributes = uniqueGift.attributes.filter { $0.attributeType != .originalInfo }
let updatedMedia: [Media] = [
TelegramMediaAction(
@@ -766,7 +768,9 @@ private final class GiftViewSheetContent: CombinedComponent {
canResaleDate: canResaleDate,
dropOriginalDetailsStars: nil,
assigned: assigned,
fromOffer: fromOffer
fromOffer: fromOffer,
canCraftAt: nil,
isCrafted: false
)
)
]
@@ -1008,7 +1012,10 @@ private final class GiftViewSheetContent: CombinedComponent {
|> then(
context.engine.payments.getUniqueStarGift(slug: gift.slug)
|> map { gift in
return gift?.themePeerId
return gift.themePeerId
}
|> `catch` { _ -> Signal<EnginePeer.Id?, NoError> in
return .single(nil)
}
)
)
@@ -1376,6 +1383,7 @@ private final class GiftViewSheetContent: CombinedComponent {
let variantsController = self.context.sharedContext.makeGiftUpgradeVariantsScreen(
context: self.context,
gift: arguments.gift,
crafted: false,
attributes: attributes,
selectedAttributes: selectedAttributes,
focusedAttribute: attribute
@@ -1443,7 +1451,7 @@ private final class GiftViewSheetContent: CombinedComponent {
}
if case let .unique(gift) = arguments.gift, let resellAmount = gift.resellAmounts?.first, resellAmount.amount.value > 0 {
if arguments.reference != nil || gift.owner.peerId == context.account.peerId {
if arguments.reference != nil || gift.owner?.peerId == context.account.peerId {
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Gift_View_Context_ChangePrice, icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/PriceTag"), color: theme.contextMenu.primaryColor)
}, action: { [weak self] c, _ in
@@ -1703,7 +1711,7 @@ private final class GiftViewSheetContent: CombinedComponent {
let giftTitle = "\(uniqueGift.title) #\(formatCollectibleNumber(uniqueGift.number, dateTimeFormat: presentationData.dateTimeFormat))"
let recipientPeerId = self.recipientPeerId ?? self.context.account.peerId
let action: (CurrencyAmount.Currency) -> Void = { currency in
let action: (CurrencyAmount.Currency) -> Void = { (currency: CurrencyAmount.Currency) in
guard let resellAmount = uniqueGift.resellAmounts?.first(where: { $0.currency == currency }) else {
guard let controller = self.getController() as? GiftViewScreen else {
return
@@ -1802,10 +1810,10 @@ private final class GiftViewSheetContent: CombinedComponent {
var animationFile: TelegramMediaFile?
for attribute in uniqueGift.attributes {
if case let .model(_, file, _) = attribute {
animationFile = file
break
}
if case let .model(_, file, _, _) = attribute {
animationFile = file
break
}
}
if let navigationController = controller.navigationController as? NavigationController {
@@ -3671,7 +3679,7 @@ private final class GiftViewSheetContent: CombinedComponent {
if state.pendingWear {
var fileId: Int64?
for attribute in uniqueGift.attributes {
if case let .model(_, file, _) = attribute {
if case let .model(_, file, _, _) = attribute {
fileId = file.fileId.id
}
if case let .backdrop(_, _, innerColor, _, _, _, _) = attribute {
@@ -3780,6 +3788,8 @@ private final class GiftViewSheetContent: CombinedComponent {
)
)
))
case .none:
break
}
if let peerId = uniqueGift.hostPeerId, let peer = state.peerMap[peerId] {
@@ -4113,17 +4123,17 @@ private final class GiftViewSheetContent: CombinedComponent {
var otherValuesAndPercentages: [(value: String, percentage: Float)] = []
switch attribute {
case let .model(name, _, rarity):
case let .model(name, _, rarity, _):
id = "model"
title = strings.Gift_Unique_Model
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = state.modelButtonTag
if state.justUpgraded, let sampleAttributes = state.upgradePreview?.attributes {
for sampleAttribute in sampleAttributes {
if case let .model(name, _, rarity) = sampleAttribute {
otherValuesAndPercentages.append((name, Float(rarity) * 0.1))
if case let .model(name, _, rarity, _) = sampleAttribute {
otherValuesAndPercentages.append((name, Float(rarity.permilleValue) * 0.1))
}
}
}
@@ -4131,13 +4141,13 @@ private final class GiftViewSheetContent: CombinedComponent {
id = "backdrop"
title = strings.Gift_Unique_Backdrop
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = state.backdropButtonTag
if state.justUpgraded, let sampleAttributes = state.upgradePreview?.attributes {
for sampleAttribute in sampleAttributes {
if case let .backdrop(name, _, _, _, _, _, rarity) = sampleAttribute {
otherValuesAndPercentages.append((name, Float(rarity) * 0.1))
otherValuesAndPercentages.append((name, Float(rarity.permilleValue) * 0.1))
}
}
}
@@ -4145,13 +4155,13 @@ private final class GiftViewSheetContent: CombinedComponent {
id = "pattern"
title = strings.Gift_Unique_Symbol
value = NSAttributedString(string: name, font: tableFont, textColor: tableTextColor)
percentage = Float(rarity) * 0.1
percentage = Float(rarity.permilleValue) * 0.1
tag = state.symbolButtonTag
if state.justUpgraded, let sampleAttributes = state.upgradePreview?.attributes {
for sampleAttribute in sampleAttributes {
if case let .pattern(name, _, rarity) = sampleAttribute {
otherValuesAndPercentages.append((name, Float(rarity) * 0.1))
otherValuesAndPercentages.append((name, Float(rarity.permilleValue) * 0.1))
}
}
}
@@ -5500,7 +5510,7 @@ public class GiftViewScreen: ViewControllerComponentContainer {
let fromPeerId = senderId ?? message.author?.id
return (message.id.peerId, fromPeerId, message.author?.debugDisplayTitle, message.author?.compactDisplayTitle, message.id, reference, message.flags.contains(.Incoming), gift, message.timestamp, convertStars, text, entities, nameHidden, savedToProfile, nil, converted, upgraded, isRefunded, canUpgrade, upgradeStars, nil, nil, nil, upgradeMessageId, nil, nil, prepaidUpgradeHash, upgradeSeparate, nil, toPeerId, number)
case let .starGiftUnique(gift, isUpgrade, isTransferred, savedToProfile, canExportDate, transferStars, _, _, peerId, senderId, savedId, _, canTransferDate, canResaleDate, dropOriginalDetailsStars, _, _):
case let .starGiftUnique(gift, isUpgrade, isTransferred, savedToProfile, canExportDate, transferStars, _, _, peerId, senderId, savedId, _, canTransferDate, canResaleDate, dropOriginalDetailsStars, _, _, _, _):
var reference: StarGiftReference
if let peerId, let savedId {
reference = .peer(peerId: peerId, id: savedId)