Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2025-06-24 01:25:12 +02:00
commit 0da5f08f22
10 changed files with 97 additions and 44 deletions

View File

@ -1074,13 +1074,7 @@ public final class StarsContext {
return peerId!
}
var ton: Bool {
var ton = false
self.impl.syncWith { impl in
ton = impl.ton
}
return ton
}
let ton: Bool
public var currentState: StarsContext.State? {
var state: StarsContext.State?
@ -1122,6 +1116,7 @@ public final class StarsContext {
}
init(account: Account, ton: Bool) {
self.ton = ton
self.impl = QueueLocalObject(queue: Queue.mainQueue(), generate: {
return StarsContextImpl(account: account, ton: ton)
})

View File

@ -1444,27 +1444,25 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
}
attributedString = NSAttributedString(string: string, font: titleFont, textColor: primaryTextColor)
case let .giftTon(currency, amount, _, _, _):
let _ = currency
let _ = amount
attributedString = nil
// if !forAdditionalServiceMessage {
// attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor)
// } else {
// let price = formatCurrencyAmount(amount, currency: currency)
// if message.author?.id == accountPeerId {
// attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
// } else {
// var authorName = compactAuthorName
// var peerIds: [(Int, EnginePeer.Id?)] = [(0, message.author?.id)]
// if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 {
// authorName = strings.Notification_StarsGift_UnknownUser
// peerIds = []
// }
// var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds)
// attributes[1] = boldAttributes
// attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
// }
// }
if !forAdditionalServiceMessage {
attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor)
} else {
let price = formatCurrencyAmount(amount, currency: currency)
if message.author?.id == accountPeerId {
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
} else {
var authorName = compactAuthorName
var peerIds: [(Int, EnginePeer.Id?)] = [(0, message.author?.id)]
if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 {
authorName = strings.Notification_StarsGift_UnknownUser
peerIds = []
}
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds)
attributes[1] = boldAttributes
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
}
}
case .unknown:
attributedString = nil
}

View File

@ -258,38 +258,52 @@ public class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
}
)).string
let amountString: String
var pricePart = ""
if let amount, amount.amount != .zero {
let amountString: String
switch amount.currency {
case .stars:
amountString = amount.amount.value == 1 ? "\(amount.amount) Star" : "\(amount.amount) Stars"
case .ton:
amountString = "\(amount.amount) TON"
amountString = "\(formatTonAmountText(amount.amount.value, dateTimeFormat: item.presentationData.dateTimeFormat)) TON"
}
switch amount.currency {
case .stars:
if !item.message.effectivelyIncoming(item.context.account.peerId) {
pricePart = "\n\n💰 The user have been charged \(amountString).\n\n⌛ **\(channelName)** will receive the Stars once the post has been live for 24 hours.\n\n🔄 If your remove the post before it has been live for 24 hours, the user's Stars will be refunded."
} else {
pricePart = "\n\n💰 You have been charged \(amountString).\n\n⌛ **\(channelName)** will receive your Stars once the post has been live for 24 hours.\n\n🔄 If **\(channelName)** removes the post before it has been live for 24 hours, your Stars will be refunded."
}
case .ton:
if !item.message.effectivelyIncoming(item.context.account.peerId) {
pricePart = "\n\n💰 The user have been charged \(amountString).\n\n⌛ **\(channelName)** will receive TON once the post has been live for 24 hours.\n\n🔄 If your remove the post before it has been live for 24 hours, the user's TON will be refunded."
} else {
pricePart = "\n\n💰 You have been charged \(amountString).\n\n⌛ **\(channelName)** will receive your TON once the post has been live for 24 hours.\n\n🔄 If **\(channelName)** removes the post before it has been live for 24 hours, your TON will be refunded."
}
}
} else {
amountString = "0 Stars"
}
let rawString: String
if let timestamp {
if Int32(Date().timeIntervalSince1970) >= timestamp {
if !item.message.effectivelyIncoming(item.context.account.peerId) {
rawString = "📅 The post has been automatically published in **\(channelName)** **\(timeString)**.\n\n💰 The user have been charged \(amountString).\n\n⌛ **\(channelName)** will receive the Stars once the post has been live for 24 hours.\n\n🔄 If your remove the post before it has been live for 24 hours, the user's Stars will be refunded."
rawString = "📅 The post has been automatically published in **\(channelName)** **\(timeString)**." + pricePart
} else {
rawString = "📅 Your post has been automatically published in **\(channelName)** **\(timeString)**.\n\n💰 You have been charged \(amountString).\n\n⌛ **\(channelName)** will receive your Stars once the post has been live for 24 hours.\n\n🔄 If **\(channelName)** removes the post before it has been live for 24 hours, your Stars will be refunded."
rawString = "📅 Your post has been automatically published in **\(channelName)** **\(timeString)**." + pricePart
}
} else {
if !item.message.effectivelyIncoming(item.context.account.peerId) {
rawString = "📅 The post will be automatically published in **\(channelName)** **\(timeString)**.\n\n💰 The user have been charged \(amountString).\n\n⌛ **\(channelName)** will receive the Stars once the post has been live for 24 hours.\n\n🔄 If your remove the post before it has been live for 24 hours, the user's Stars will be refunded."
rawString = "📅 The post will be automatically published in **\(channelName)** **\(timeString)**." + pricePart
} else {
rawString = "📅 Your post will be automatically published in **\(channelName)** **\(timeString)**.\n\n💰 You have been charged \(amountString).\n\n⌛ **\(channelName)** will receive your Stars once the post has been live for 24 hours.\n\n🔄 If **\(channelName)** removes the post before it has been live for 24 hours, your Stars will be refunded."
rawString = "📅 Your post will be automatically published in **\(channelName)** **\(timeString)**." + pricePart
}
}
} else {
if !item.message.effectivelyIncoming(item.context.account.peerId) {
rawString = "📅 The post has been automatically published in **\(channelName)**.\n\n💰 The user have been charged \(amountString).\n\n⌛ **\(channelName)** will receive the Stars once the post has been live for 24 hours.\n\n🔄 If your remove the post before it has been live for 24 hours, the user's Stars will be refunded."
rawString = "📅 The post has been automatically published in **\(channelName)**." + pricePart
} else {
rawString = "📅 Your post has been automatically published in **\(channelName)**.\n\n💰 You have been charged \(amountString).\n\n⌛ **\(channelName)** will receive your Stars once the post has been live for 24 hours.\n\n🔄 If **\(channelName)** removes the post before it has been live for 24 hours, your Stars will be refunded."
rawString = "📅 Your post has been automatically published in **\(channelName)**." + pricePart
}
}
updatedAttributedString = parseMarkdownIntoAttributedString(rawString, attributes: MarkdownAttributes(

View File

@ -222,6 +222,8 @@ private func contentNodeMessagesAndClassesForItem(_ item: ChatMessageItem) -> ([
result.append((message, ChatMessageGiftBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .text, neighborSpacing: .default)))
} else if case .giftStars = action.action {
result.append((message, ChatMessageGiftBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .text, neighborSpacing: .default)))
} else if case .giftTon = action.action {
result.append((message, ChatMessageGiftBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .text, neighborSpacing: .default)))
} else if case .starGift = action.action {
result.append((message, ChatMessageGiftBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .text, neighborSpacing: .default)))
skipText = true

View File

@ -413,6 +413,20 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
}
title = item.presentationData.strings.Notification_StarsGift_Title(Int32(count))
text = incoming ? item.presentationData.strings.Notification_StarsGift_Subtitle : item.presentationData.strings.Notification_StarsGift_SubtitleYou(peerName).string
case let .giftTon(currency, amount, cryptoCurrency, cryptoAmount, _):
var peerName = ""
if let peer = item.message.peers[item.message.id.peerId] {
peerName = EnginePeer(peer).compactDisplayTitle
}
//TODO:localize
let _ = currency
let _ = amount
let _ = cryptoCurrency
let cryptoAmount = cryptoAmount ?? 0
title = item.presentationData.strings.Notification_StarsGift_Title(Int32(cryptoAmount))
text = incoming ? item.presentationData.strings.Notification_StarsGift_Subtitle : item.presentationData.strings.Notification_StarsGift_SubtitleYou(peerName).string
case let .prizeStars(count, _, channelId, _, _):
if count <= 1000 {
months = 3

View File

@ -60,19 +60,19 @@ public final class ChatMessageSuggestedPostInfoNode: ASDisplayNode {
//TODO:localize
let amountString: String
if let amount, amount.amount.value != 0, amount.amount.nanos != 0 {
if let amount, amount.amount != .zero {
switch amount.currency {
case .stars:
if amount.amount.value == 1 {
amountString = "1 Star"
} else {
amountString = "\(amount) Stars"
amountString = "\(amount.amount) Stars"
}
case .ton:
if amount.amount.value == 1 {
amountString = "1 TON"
} else {
amountString = "\(amount) TON"
amountString = "\(formatTonAmountText(amount.amount.value, dateTimeFormat: item.presentationData.dateTimeFormat)) TON"
}
}
} else {
@ -81,7 +81,7 @@ public final class ChatMessageSuggestedPostInfoNode: ASDisplayNode {
var timestampString: String
if let timestamp {
timestampString = humanReadableStringForTimestamp(strings: item.presentationData.strings, dateTimeFormat: PresentationDateTimeFormat(), timestamp: timestamp, alwaysShowTime: true).string
timestampString = humanReadableStringForTimestamp(strings: item.presentationData.strings, dateTimeFormat: item.presentationData.dateTimeFormat, timestamp: timestamp, alwaysShowTime: true).string
if timestampString.count > 1 {
timestampString = String(timestampString[timestampString.startIndex]).capitalized + timestampString[timestampString.index(after: timestampString.startIndex)...]
}

View File

@ -35,6 +35,7 @@ public final class SuggestPostAccessoryPanelNode: AccessoryPanelNode {
private let context: AccountContext
public var theme: PresentationTheme
public var strings: PresentationStrings
private let dateTimeFormat: PresentationDateTimeFormat
private var textIsOptions: Bool = false
@ -47,6 +48,7 @@ public final class SuggestPostAccessoryPanelNode: AccessoryPanelNode {
self.context = context
self.theme = theme
self.strings = strings
self.dateTimeFormat = dateTimeFormat
self.closeButton = HighlightableButtonNode()
self.closeButton.accessibilityLabel = strings.VoiceOver_DiscardPreparedContent
@ -241,11 +243,14 @@ public final class SuggestPostAccessoryPanelNode: AccessoryPanelNode {
let textString: NSAttributedString
if let postSuggestionState = interfaceState.interfaceState.postSuggestionState, let price = postSuggestionState.price, price.amount != .zero {
let currencySymbol: String
let amountString: String
switch price.currency {
case .stars:
currencySymbol = "#"
amountString = "\(price.amount)"
case .ton:
currencySymbol = "$"
amountString = formatTonAmountText(price.amount.value, dateTimeFormat: self.dateTimeFormat)
}
if let timestamp = postSuggestionState.timestamp {
let timeString = humanReadableStringForTimestamp(strings: interfaceState.strings, dateTimeFormat: interfaceState.dateTimeFormat, timestamp: timestamp, alwaysShowTime: true, allowYesterday: false, format: HumanReadableStringFormat(
@ -262,9 +267,9 @@ public final class SuggestPostAccessoryPanelNode: AccessoryPanelNode {
return PresentationStrings.FormattedString(string: interfaceState.strings.SuggestPost_SetTimeFormat_TodayAt(value).string, ranges: [])
}
)).string
textString = NSAttributedString(string: "\(currencySymbol)\(price.amount) 📅 \(timeString)", font: textFont, textColor: self.theme.chat.inputPanel.primaryTextColor)
textString = NSAttributedString(string: "\(currencySymbol)\(amountString) 📅 \(timeString)", font: textFont, textColor: self.theme.chat.inputPanel.primaryTextColor)
} else {
textString = NSAttributedString(string: "\(currencySymbol)\(price.amount) for publishing anytime", font: textFont, textColor: self.theme.chat.inputPanel.primaryTextColor)
textString = NSAttributedString(string: "\(currencySymbol)\(amountString) for publishing anytime", font: textFont, textColor: self.theme.chat.inputPanel.primaryTextColor)
}
} else {
textString = NSAttributedString(string: "Tap to offer a price for publishing", font: textFont, textColor: self.theme.chat.inputPanel.primaryTextColor)

View File

@ -383,6 +383,7 @@ final class PeerInfoScreenData {
let personalChannel: PeerInfoPersonalChannelData?
let tonState: StarsContext.State?
let starsState: StarsContext.State?
let tonState: StarsContext.State?
let starsRevenueStatsState: StarsRevenueStats?
let starsRevenueStatsContext: StarsRevenueStatsContext?
let revenueStatsState: RevenueStats?
@ -435,6 +436,7 @@ final class PeerInfoScreenData {
personalChannel: PeerInfoPersonalChannelData?,
tonState: StarsContext.State?,
starsState: StarsContext.State?,
tonState: StarsContext.State?,
starsRevenueStatsState: StarsRevenueStats?,
starsRevenueStatsContext: StarsRevenueStatsContext?,
revenueStatsState: RevenueStats?,
@ -475,6 +477,7 @@ final class PeerInfoScreenData {
self.personalChannel = personalChannel
self.tonState = tonState
self.starsState = starsState
self.tonState = tonState
self.starsRevenueStatsState = starsRevenueStatsState
self.starsRevenueStatsContext = starsRevenueStatsContext
self.revenueStatsState = revenueStatsState
@ -862,6 +865,12 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: EnginePeer.Id,
} else {
starsState = .single(nil)
}
let tonState: Signal<StarsContext.State?, NoError>
if let tonContext {
tonState = tonContext.state
} else {
tonState = .single(nil)
}
let profileGiftsContext = ProfileGiftsContext(account: context.account, peerId: peerId)
@ -972,6 +981,7 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: EnginePeer.Id,
personalChannel: personalChannel,
tonState: tonState,
starsState: starsState,
tonState: tonState,
starsRevenueStatsState: nil,
starsRevenueStatsContext: nil,
revenueStatsState: nil,
@ -1023,6 +1033,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
personalChannel: nil,
tonState: nil,
starsState: nil,
tonState: nil,
starsRevenueStatsState: nil,
starsRevenueStatsContext: nil,
revenueStatsState: nil,
@ -1483,6 +1494,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
personalChannel: personalChannel,
tonState: nil,
starsState: nil,
tonState: nil,
starsRevenueStatsState: starsRevenueContextAndState.1,
starsRevenueStatsContext: starsRevenueContextAndState.0,
revenueStatsState: revenueContextAndState.1,
@ -1715,6 +1727,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
personalChannel: personalChannel,
tonState: nil,
starsState: nil,
tonState: nil,
starsRevenueStatsState: starsRevenueContextAndState.1,
starsRevenueStatsContext: starsRevenueContextAndState.0,
revenueStatsState: revenueContextAndState.1,
@ -2048,6 +2061,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
personalChannel: nil,
tonState: nil,
starsState: nil,
tonState: nil,
starsRevenueStatsState: starsRevenueContextAndState.1,
starsRevenueStatsContext: starsRevenueContextAndState.0,
revenueStatsState: nil,

View File

@ -1048,6 +1048,7 @@ private func settingsItems(data: PeerInfoScreenData?, context: AccountContext, p
} else {
balanceText = NSAttributedString()
}
//TODO:localize
items[.payment]!.append(PeerInfoScreenDisclosureItem(id: 103, label: .attributedText(balanceText), text: "My TON", icon: PresentationResourcesSettings.ton, action: {
interaction.openSettings(.ton)
}))
@ -10669,7 +10670,11 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
}
case .ton:
if let tonContext = self.controller?.tonContext {
<<<<<<< HEAD
push(self.context.sharedContext.makeTonTransactionsScreen(context: self.context, tonContext: tonContext))
=======
push(self.context.sharedContext.makeStarsTransactionsScreen(context: self.context, starsContext: tonContext))
>>>>>>> 51a16c711078fab6940623bf1de0ec85516ba699
}
}
}
@ -12987,6 +12992,12 @@ public final class PeerInfoScreenImpl: ViewController, PeerInfoScreen, KeyShortc
self.starsContext = nil
self.tonContext = nil
}
if isSettings, let tonContext = context.tonContext {
self.tonContext = tonContext
tonContext.load(force: true)
} else {
self.tonContext = nil
}
if isMyProfile, let profileGiftsContext {
profileGiftsContext.updateFilter(.All)

View File

@ -481,7 +481,7 @@ private final class SheetContent: CombinedComponent {
accentColor: theme.list.itemAccentColor,
value: state.amount?.value,
minValue: minAmount?.value,
maxValue: maxAmount?.value,
maxValue: state.currency == .ton ? nil : maxAmount?.value,
placeholderText: amountPlaceholder,
labelText: amountLabel,
currency: state.currency,