diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index f2152f33bb..6e797cb7ce 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -2516,6 +2516,8 @@ public final class ShareController: ViewController { peers.append(EngineRenderedPeer(entryData.renderedPeer)) if let user = peer as? TelegramUser, user.flags.contains(.requirePremium) || user.flags.contains(.requireStars) { possiblePremiumRequiredPeers.insert(user.id) + } else if let channel = peer as? TelegramChannel, let _ = channel.sendPaidMessageStars { + possiblePremiumRequiredPeers.insert(channel.id) } } default: @@ -2529,6 +2531,7 @@ public final class ShareController: ViewController { keys.append(peerPresencesKey) for id in possiblePremiumRequiredPeers { + keys.append(.basicPeer(id)) keys.append(.cachedPeerData(peerId: id)) } @@ -2546,6 +2549,8 @@ public final class ShareController: ViewController { if let view = views.views[.cachedPeerData(peerId: id)] as? CachedPeerDataView, let data = view.cachedPeerData as? CachedUserData { requiresPremiumForMessaging[id] = data.flags.contains(.premiumRequired) requiresStars[id] = data.sendPaidMessageStars?.value + } else if let view = views.views[.basicPeer(id)] as? BasicPeerView, let channel = view.peer as? TelegramChannel { + requiresStars[id] = channel.sendPaidMessageStars?.value } else { requiresPremiumForMessaging[id] = false } diff --git a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift index 732f492b57..2f1b40d99f 100644 --- a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift +++ b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift @@ -254,6 +254,7 @@ public final class PendingMessageManager { context.sendDisposable.dispose() context.uploadDisposable.dispose() context.activityDisposable.dispose() + context.postponeDisposable.dispose() if context.status != nil { context.status = nil diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 1dcb20b20f..700eba94c2 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -9041,40 +9041,45 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G guard let strongSelf = self else { return } - let replyMessageSubject = strongSelf.presentationInterfaceState.interfaceState.replyMessageSubject - strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({ - if let strongSelf = self { - strongSelf.chatDisplayNode.collapseInput() - - strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, { - $0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedSendMessageEffect(nil) } - }) + strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in + guard let strongSelf = self else { + return } - }, nil) - let message: EnqueueMessage = .message( - text: "", - attributes: [], - inlineStickers: [:], - mediaReference: .standalone(media: TelegramMediaPoll( - pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: Int64.random(in: Int64.min ... Int64.max)), - publicity: poll.publicity, - kind: poll.kind, - text: poll.text.string, - textEntities: poll.text.entities, - options: poll.options, - correctAnswers: poll.correctAnswers, - results: poll.results, - isClosed: false, - deadlineTimeout: poll.deadlineTimeout - )), - threadId: strongSelf.chatLocation.threadId, - replyToMessageId: nil, - replyToStoryId: nil, - localGroupingKey: nil, - correlationId: nil, - bubbleUpEmojiOrStickersets: [] - ) - strongSelf.sendMessages([message.withUpdatedReplyToMessageId(replyMessageSubject?.subjectModel)]) + let replyMessageSubject = strongSelf.presentationInterfaceState.interfaceState.replyMessageSubject + strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({ + if let strongSelf = self { + strongSelf.chatDisplayNode.collapseInput() + + strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, { + $0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedSendMessageEffect(nil) } + }) + } + }, nil) + let message: EnqueueMessage = .message( + text: "", + attributes: [], + inlineStickers: [:], + mediaReference: .standalone(media: TelegramMediaPoll( + pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: Int64.random(in: Int64.min ... Int64.max)), + publicity: poll.publicity, + kind: poll.kind, + text: poll.text.string, + textEntities: poll.text.entities, + options: poll.options, + correctAnswers: poll.correctAnswers, + results: poll.results, + isClosed: false, + deadlineTimeout: poll.deadlineTimeout + )), + threadId: strongSelf.chatLocation.threadId, + replyToMessageId: nil, + replyToStoryId: nil, + localGroupingKey: nil, + correlationId: nil, + bubbleUpEmojiOrStickersets: [] + ) + strongSelf.sendMessages([message.withUpdatedReplyToMessageId(replyMessageSubject?.subjectModel)]) + }) }) } @@ -9283,6 +9288,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var attributes = attributes if let sendPaidMessageStars = self.presentationInterfaceState.sendPaidMessageStars { + for i in (0 ..< attributes.count).reversed() { + if attributes[i] is PaidStarsMessageAttribute { + attributes.remove(at: i) + } + } attributes.append(PaidStarsMessageAttribute(stars: sendPaidMessageStars, postponeSending: postpone)) } diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 043144bae6..f6aeb45830 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -886,12 +886,14 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate { self.controllerInteraction.scheduleCurrentMessage(nil) } else { if let _ = self.chatPresentationInterfaceState.sendPaidMessageStars { - var count: Int32 = 1 + var count: Int32 if let forwardedCount = self.chatPresentationInterfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 { count = Int32(forwardedCount) if self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length > 0 { count += 1 } + } else { + count = Int32(ceil(CGFloat(self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length) / 4096.0)) } controller.presentPaidMessageAlertIfNeeded(count: count, completion: { [weak self] postpone in self?.sendCurrentMessage(postpone: postpone) diff --git a/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift b/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift index 770371f44d..85bba67ea7 100644 --- a/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift +++ b/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift @@ -566,11 +566,11 @@ extension ChatControllerImpl { } } enqueueMessages.append(.message(text: "", attributes: attributes, inlineStickers: [:], mediaReference: .standalone(media: media), threadId: strongSelf.chatLocation.threadId, replyToMessageId: replyMessageSubject?.subjectModel, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: [])) - strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in + strongSelf.presentPaidMessageAlertIfNeeded(count: Int32(enqueueMessages.count), completion: { [weak self] postpone in guard let strongSelf = self else { return } - strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime), postpone: postpone) + strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime, postpone: postpone), postpone: postpone) }) } else { let contactController = strongSelf.context.sharedContext.makeDeviceContactInfoController(context: ShareControllerAppAccountContext(context: strongSelf.context), environment: ShareControllerAppEnvironment(sharedContext: strongSelf.context.sharedContext), subject: .filter(peer: peerAndContactData.0, contactId: nil, contactData: contactData, completion: { peer, contactData in @@ -596,11 +596,11 @@ extension ChatControllerImpl { enqueueMessages.append(textEnqueueMessage) } enqueueMessages.append(.message(text: "", attributes: [], inlineStickers: [:], mediaReference: .standalone(media: media), threadId: strongSelf.chatLocation.threadId, replyToMessageId: replyMessageSubject?.subjectModel, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: [])) - strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in + strongSelf.presentPaidMessageAlertIfNeeded(count: Int32(enqueueMessages.count), completion: { [weak self] postpone in guard let strongSelf = self else { return } - strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime), postpone: postpone) + strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime, postpone: postpone), postpone: postpone) }) } }), completed: nil, cancelled: nil) diff --git a/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift b/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift index a831f1cab1..b54ea987e4 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift @@ -276,12 +276,19 @@ final class ChatTextInputActionButtonsNode: ASDisplayNode, ChatSendMessageAction self.sendButton.imageNode.alpha = 0.0 self.textNode.isHidden = false - var amount = sendPaidMessageStars.value + var amount: Int64 if let forwardedCount = interfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 { amount = sendPaidMessageStars.value * Int64(forwardedCount) if interfaceState.interfaceState.effectiveInputState.inputText.length > 0 { amount += sendPaidMessageStars.value } + } else { + if interfaceState.interfaceState.effectiveInputState.inputText.length > 4096 { + let messageCount = Int32(ceil(CGFloat(interfaceState.interfaceState.effectiveInputState.inputText.length) / 4096.0)) + amount = sendPaidMessageStars.value * Int64(messageCount) + } else { + amount = sendPaidMessageStars.value + } } let text = "\(amount)"