mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Fix paid message resend
This commit is contained in:
parent
8ddd793a36
commit
15c181bc52
@ -404,6 +404,19 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal<
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
var removeMessageIds: [MessageId] = []
|
||||
for (peerId, ids) in messagesIdsGroupedByPeerId(messageIds) {
|
||||
var sendPaidMessageStars: StarsAmount?
|
||||
let peer = transaction.getPeer(peerId)
|
||||
if let user = peer as? TelegramUser, user.flags.contains(.requireStars) {
|
||||
if let cachedUserData = transaction.getPeerCachedData(peerId: user.id) as? CachedUserData {
|
||||
sendPaidMessageStars = cachedUserData.sendPaidMessageStars
|
||||
}
|
||||
} else if let channel = peer as? TelegramChannel {
|
||||
if channel.flags.contains(.isCreator) || channel.adminRights != nil {
|
||||
} else {
|
||||
sendPaidMessageStars = channel.sendPaidMessageStars
|
||||
}
|
||||
}
|
||||
|
||||
var messages: [EnqueueMessage] = []
|
||||
for id in ids {
|
||||
if let message = transaction.getMessage(id), !message.flags.contains(.Incoming) {
|
||||
@ -425,9 +438,16 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal<
|
||||
} else if let attribute = attribute as? ForwardSourceInfoAttribute {
|
||||
forwardSource = attribute.messageId
|
||||
} else {
|
||||
filteredAttributes.append(attribute)
|
||||
if attribute is PaidStarsMessageAttribute {
|
||||
} else {
|
||||
filteredAttributes.append(attribute)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let sendPaidMessageStars {
|
||||
filteredAttributes.append(PaidStarsMessageAttribute(stars: sendPaidMessageStars, postponeSending: false))
|
||||
}
|
||||
|
||||
if let forwardSource = forwardSource {
|
||||
messages.append(.forward(source: forwardSource, threadId: nil, grouping: .auto, attributes: filteredAttributes, correlationId: nil))
|
||||
|
@ -311,10 +311,10 @@ public final class ChatUserInfoItemNode: ListViewItemNode, ASGestureRecognizerDe
|
||||
} else {
|
||||
var countryName = ""
|
||||
let countriesConfiguration = item.context.currentCountriesConfiguration.with { $0 }
|
||||
if let country = countriesConfiguration.countries.first(where: { $0.id == phoneCountry }) {
|
||||
countryName = country.localizedName ?? country.name
|
||||
} else if phoneCountry == "FT" {
|
||||
if phoneCountry == "FT" {
|
||||
countryName = item.presentationData.strings.Chat_NonContactUser_AnonymousNumber
|
||||
} else if let country = countriesConfiguration.countries.first(where: { $0.id == phoneCountry }) {
|
||||
countryName = country.localizedName ?? country.name
|
||||
} else if phoneCountry == "TS" {
|
||||
countryName = "Test"
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import TelegramPresentationData
|
||||
import TelegramNotices
|
||||
|
||||
extension ChatControllerImpl {
|
||||
func presentPaidMessageAlertIfNeeded(count: Int32 = 1, forceDark: Bool = false, completion: @escaping (Bool) -> Void) {
|
||||
func presentPaidMessageAlertIfNeeded(count: Int32 = 1, forceDark: Bool = false, alwaysAsk: Bool = false, completion: @escaping (Bool) -> Void) {
|
||||
guard let peer = self.presentationInterfaceState.renderedPeer?.peer.flatMap(EnginePeer.init) else {
|
||||
completion(false)
|
||||
return
|
||||
@ -24,11 +24,12 @@ extension ChatControllerImpl {
|
||||
let totalAmount = sendPaidMessageStars.value * Int64(count)
|
||||
|
||||
let _ = (ApplicationSpecificNotice.dismissedPaidMessageWarningNamespace(accountManager: self.context.sharedContext.accountManager, peerId: peer.id)
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] dismissedAmount in
|
||||
guard let self, let starsContext = self.context.starsContext else {
|
||||
return
|
||||
}
|
||||
if let dismissedAmount, dismissedAmount == sendPaidMessageStars.value, let currentState = starsContext.currentState, currentState.balance.value > totalAmount {
|
||||
if !alwaysAsk, let dismissedAmount, dismissedAmount == sendPaidMessageStars.value, let currentState = starsContext.currentState, currentState.balance.value > totalAmount {
|
||||
if count < 3 && totalAmount < 100 {
|
||||
completion(false)
|
||||
} else {
|
||||
@ -52,6 +53,7 @@ extension ChatControllerImpl {
|
||||
count: count,
|
||||
amount: sendPaidMessageStars,
|
||||
totalAmount: nil,
|
||||
hasCheck: !alwaysAsk,
|
||||
navigationController: self.navigationController as? NavigationController,
|
||||
completion: { [weak self] dontAskAgain in
|
||||
guard let self else {
|
||||
|
@ -3140,19 +3140,29 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
actions.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.Conversation_MessageDialogRetry, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Resend"), color: theme.actionSheet.primaryTextColor)
|
||||
}, action: { [weak self] _, f in
|
||||
if let strongSelf = self {
|
||||
let _ = resendMessages(account: strongSelf.context.account, messageIds: selectedGroup.map({ $0.id })).startStandalone()
|
||||
if let self {
|
||||
self.presentPaidMessageAlertIfNeeded(count: Int32(selectedGroup.count), alwaysAsk: true, completion: { [weak self] _ in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
let _ = resendMessages(account: self.context.account, messageIds: selectedGroup.map({ $0.id })).startStandalone()
|
||||
})
|
||||
f(self.presentationInterfaceState.sendPaidMessageStars == nil ? .dismissWithoutContent : .default)
|
||||
}
|
||||
f(.dismissWithoutContent)
|
||||
})))
|
||||
if totalGroupCount != 1 {
|
||||
actions.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.Conversation_MessageDialogRetryAll(totalGroupCount).string, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Resend"), color: theme.actionSheet.primaryTextColor)
|
||||
}, action: { [weak self] _, f in
|
||||
if let strongSelf = self {
|
||||
let _ = resendMessages(account: strongSelf.context.account, messageIds: messages.map({ $0.id })).startStandalone()
|
||||
if let self {
|
||||
self.presentPaidMessageAlertIfNeeded(count: Int32(messages.count), alwaysAsk: true, completion: { [weak self] _ in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
let _ = resendMessages(account: self.context.account, messageIds: messages.map({ $0.id })).startStandalone()
|
||||
})
|
||||
f(self.presentationInterfaceState.sendPaidMessageStars == nil ? .dismissWithoutContent : .default)
|
||||
}
|
||||
f(.dismissWithoutContent)
|
||||
})))
|
||||
}
|
||||
actions.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.Conversation_ContextMenuDelete, textColor: .destructive, icon: { theme in
|
||||
|
Loading…
x
Reference in New Issue
Block a user