mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Various improvements
This commit is contained in:
@@ -971,51 +971,87 @@ public class GiftViewScreen: ViewControllerComponentContainer {
|
||||
return
|
||||
}
|
||||
|
||||
let controller = textAlertController(
|
||||
context: self.context,
|
||||
title: presentationData.strings.Gift_Convert_Title,
|
||||
text: presentationData.strings.Gift_Convert_Text(fromPeerName, presentationData.strings.Gift_Convert_Stars(Int32(arguments.convertStars))).string,
|
||||
actions: [
|
||||
TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}),
|
||||
TextAlertAction(type: .defaultAction, title: presentationData.strings.Gift_Convert_Convert, action: { [weak self, weak navigationController] in
|
||||
if let convertToStars {
|
||||
convertToStars()
|
||||
} else {
|
||||
let _ = (context.engine.payments.convertStarGift(messageId: messageId)
|
||||
|> deliverOnMainQueue).startStandalone()
|
||||
}
|
||||
self?.dismissAnimated()
|
||||
|
||||
if let navigationController {
|
||||
Queue.mainQueue().after(0.5) {
|
||||
if let starsContext = context.starsContext {
|
||||
navigationController.pushViewController(context.sharedContext.makeStarsTransactionsScreen(context: context, starsContext: starsContext), animated: true)
|
||||
}
|
||||
|
||||
if let lastController = navigationController.viewControllers.last as? ViewController {
|
||||
let resultController = UndoOverlayController(
|
||||
presentationData: presentationData,
|
||||
content: .universal(
|
||||
animation: "StarsBuy",
|
||||
scale: 0.066,
|
||||
colors: [:],
|
||||
title: presentationData.strings.Gift_Convert_Success_Title,
|
||||
text: presentationData.strings.Gift_Convert_Success_Text(presentationData.strings.Gift_Convert_Success_Text_Stars(Int32(arguments.convertStars))).string,
|
||||
customUndoText: nil,
|
||||
timeout: nil
|
||||
),
|
||||
elevatedLayout: lastController is ChatController,
|
||||
action: { _ in return true}
|
||||
)
|
||||
lastController.present(resultController, in: .window(.root))
|
||||
let configuration = GiftConfiguration.with(appConfiguration: context.currentAppConfiguration.with { $0 })
|
||||
let starsConvertMaxDate = arguments.date + configuration.convertToStarsPeriod
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
|
||||
if currentTime > starsConvertMaxDate {
|
||||
//TODO:localize
|
||||
|
||||
let duration: String
|
||||
if starsConvertMaxDate == 300 {
|
||||
duration = "5 minutes"
|
||||
} else {
|
||||
duration = "90 days"
|
||||
}
|
||||
|
||||
let controller = textAlertController(
|
||||
context: self.context,
|
||||
title: presentationData.strings.Gift_Convert_Title,
|
||||
text: "Sorry, you can't convert this gift.\n\nStars can only be claimed within \(duration) after receiving a gift.",
|
||||
actions: [
|
||||
TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})
|
||||
],
|
||||
parseMarkdown: true
|
||||
)
|
||||
self.present(controller, in: .window(.root))
|
||||
} else {
|
||||
let delta = starsConvertMaxDate - currentTime
|
||||
let duration: String
|
||||
if starsConvertMaxDate == 300 {
|
||||
duration = "\(delta / 60) minutes"
|
||||
} else {
|
||||
duration = "\(delta / 86400) days"
|
||||
}
|
||||
//TODO:localize
|
||||
let text = "Do you want to convert this gift from **\(fromPeerName)** to **\(presentationData.strings.Gift_Convert_Stars(Int32(arguments.convertStars)))**?\n\nConversion is available for the next \(duration).\n\nThis will permanently destroy the gift."
|
||||
let controller = textAlertController(
|
||||
context: self.context,
|
||||
title: presentationData.strings.Gift_Convert_Title,
|
||||
text: text,
|
||||
actions: [
|
||||
TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}),
|
||||
TextAlertAction(type: .defaultAction, title: presentationData.strings.Gift_Convert_Convert, action: { [weak self, weak navigationController] in
|
||||
if let convertToStars {
|
||||
convertToStars()
|
||||
} else {
|
||||
let _ = (context.engine.payments.convertStarGift(messageId: messageId)
|
||||
|> deliverOnMainQueue).startStandalone()
|
||||
}
|
||||
self?.dismissAnimated()
|
||||
|
||||
if let navigationController {
|
||||
Queue.mainQueue().after(0.5) {
|
||||
if let starsContext = context.starsContext {
|
||||
navigationController.pushViewController(context.sharedContext.makeStarsTransactionsScreen(context: context, starsContext: starsContext), animated: true)
|
||||
}
|
||||
|
||||
if let lastController = navigationController.viewControllers.last as? ViewController {
|
||||
let resultController = UndoOverlayController(
|
||||
presentationData: presentationData,
|
||||
content: .universal(
|
||||
animation: "StarsBuy",
|
||||
scale: 0.066,
|
||||
colors: [:],
|
||||
title: presentationData.strings.Gift_Convert_Success_Title,
|
||||
text: presentationData.strings.Gift_Convert_Success_Text(presentationData.strings.Gift_Convert_Success_Text_Stars(Int32(arguments.convertStars))).string,
|
||||
customUndoText: nil,
|
||||
timeout: nil
|
||||
),
|
||||
elevatedLayout: lastController is ChatController,
|
||||
action: { _ in return true}
|
||||
)
|
||||
lastController.present(resultController, in: .window(.root))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
],
|
||||
parseMarkdown: true
|
||||
)
|
||||
self.present(controller, in: .window(.root))
|
||||
})
|
||||
],
|
||||
parseMarkdown: true
|
||||
)
|
||||
self.present(controller, in: .window(.root))
|
||||
}
|
||||
}
|
||||
openStarsIntroImpl = { [weak self] in
|
||||
guard let self else {
|
||||
@@ -1566,3 +1602,27 @@ private final class ButtonContentComponent: Component {
|
||||
return view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
private struct GiftConfiguration {
|
||||
static var defaultValue: GiftConfiguration {
|
||||
return GiftConfiguration(convertToStarsPeriod: 90 * 86400)
|
||||
}
|
||||
|
||||
let convertToStarsPeriod: Int32
|
||||
|
||||
fileprivate init(convertToStarsPeriod: Int32) {
|
||||
self.convertToStarsPeriod = convertToStarsPeriod
|
||||
}
|
||||
|
||||
static func with(appConfiguration: AppConfiguration) -> GiftConfiguration {
|
||||
if let data = appConfiguration.data {
|
||||
var convertToStarsPeriod: Int32?
|
||||
if let value = data["stargifts_convert_period_max"] as? Double {
|
||||
convertToStarsPeriod = Int32(value)
|
||||
}
|
||||
return GiftConfiguration(convertToStarsPeriod: convertToStarsPeriod ?? GiftConfiguration.defaultValue.convertToStarsPeriod)
|
||||
} else {
|
||||
return .defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user