Various fixes

This commit is contained in:
Ilya Laktyushin 2025-03-01 17:14:17 +04:00
parent e13934209c
commit 3f8152d0b1
6 changed files with 64 additions and 39 deletions

View File

@ -2516,6 +2516,8 @@ public final class ShareController: ViewController {
peers.append(EngineRenderedPeer(entryData.renderedPeer)) peers.append(EngineRenderedPeer(entryData.renderedPeer))
if let user = peer as? TelegramUser, user.flags.contains(.requirePremium) || user.flags.contains(.requireStars) { if let user = peer as? TelegramUser, user.flags.contains(.requirePremium) || user.flags.contains(.requireStars) {
possiblePremiumRequiredPeers.insert(user.id) possiblePremiumRequiredPeers.insert(user.id)
} else if let channel = peer as? TelegramChannel, let _ = channel.sendPaidMessageStars {
possiblePremiumRequiredPeers.insert(channel.id)
} }
} }
default: default:
@ -2529,6 +2531,7 @@ public final class ShareController: ViewController {
keys.append(peerPresencesKey) keys.append(peerPresencesKey)
for id in possiblePremiumRequiredPeers { for id in possiblePremiumRequiredPeers {
keys.append(.basicPeer(id))
keys.append(.cachedPeerData(peerId: 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 { if let view = views.views[.cachedPeerData(peerId: id)] as? CachedPeerDataView, let data = view.cachedPeerData as? CachedUserData {
requiresPremiumForMessaging[id] = data.flags.contains(.premiumRequired) requiresPremiumForMessaging[id] = data.flags.contains(.premiumRequired)
requiresStars[id] = data.sendPaidMessageStars?.value 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 { } else {
requiresPremiumForMessaging[id] = false requiresPremiumForMessaging[id] = false
} }

View File

@ -254,6 +254,7 @@ public final class PendingMessageManager {
context.sendDisposable.dispose() context.sendDisposable.dispose()
context.uploadDisposable.dispose() context.uploadDisposable.dispose()
context.activityDisposable.dispose() context.activityDisposable.dispose()
context.postponeDisposable.dispose()
if context.status != nil { if context.status != nil {
context.status = nil context.status = nil

View File

@ -9041,40 +9041,45 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
let replyMessageSubject = strongSelf.presentationInterfaceState.interfaceState.replyMessageSubject strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in
strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({ guard let strongSelf = self else {
if let strongSelf = self { return
strongSelf.chatDisplayNode.collapseInput()
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, {
$0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedSendMessageEffect(nil) }
})
} }
}, nil) let replyMessageSubject = strongSelf.presentationInterfaceState.interfaceState.replyMessageSubject
let message: EnqueueMessage = .message( strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({
text: "", if let strongSelf = self {
attributes: [], strongSelf.chatDisplayNode.collapseInput()
inlineStickers: [:],
mediaReference: .standalone(media: TelegramMediaPoll( strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, {
pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: Int64.random(in: Int64.min ... Int64.max)), $0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedSendMessageEffect(nil) }
publicity: poll.publicity, })
kind: poll.kind, }
text: poll.text.string, }, nil)
textEntities: poll.text.entities, let message: EnqueueMessage = .message(
options: poll.options, text: "",
correctAnswers: poll.correctAnswers, attributes: [],
results: poll.results, inlineStickers: [:],
isClosed: false, mediaReference: .standalone(media: TelegramMediaPoll(
deadlineTimeout: poll.deadlineTimeout pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: Int64.random(in: Int64.min ... Int64.max)),
)), publicity: poll.publicity,
threadId: strongSelf.chatLocation.threadId, kind: poll.kind,
replyToMessageId: nil, text: poll.text.string,
replyToStoryId: nil, textEntities: poll.text.entities,
localGroupingKey: nil, options: poll.options,
correlationId: nil, correctAnswers: poll.correctAnswers,
bubbleUpEmojiOrStickersets: [] results: poll.results,
) isClosed: false,
strongSelf.sendMessages([message.withUpdatedReplyToMessageId(replyMessageSubject?.subjectModel)]) 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 var attributes = attributes
if let sendPaidMessageStars = self.presentationInterfaceState.sendPaidMessageStars { 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)) attributes.append(PaidStarsMessageAttribute(stars: sendPaidMessageStars, postponeSending: postpone))
} }

View File

@ -886,12 +886,14 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate {
self.controllerInteraction.scheduleCurrentMessage(nil) self.controllerInteraction.scheduleCurrentMessage(nil)
} else { } else {
if let _ = self.chatPresentationInterfaceState.sendPaidMessageStars { if let _ = self.chatPresentationInterfaceState.sendPaidMessageStars {
var count: Int32 = 1 var count: Int32
if let forwardedCount = self.chatPresentationInterfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 { if let forwardedCount = self.chatPresentationInterfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 {
count = Int32(forwardedCount) count = Int32(forwardedCount)
if self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length > 0 { if self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length > 0 {
count += 1 count += 1
} }
} else {
count = Int32(ceil(CGFloat(self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length) / 4096.0))
} }
controller.presentPaidMessageAlertIfNeeded(count: count, completion: { [weak self] postpone in controller.presentPaidMessageAlertIfNeeded(count: count, completion: { [weak self] postpone in
self?.sendCurrentMessage(postpone: postpone) self?.sendCurrentMessage(postpone: postpone)

View File

@ -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: [])) 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 { guard let strongSelf = self else {
return 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 { } 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 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(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: [])) 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 { guard let strongSelf = self else {
return 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) }), completed: nil, cancelled: nil)

View File

@ -276,12 +276,19 @@ final class ChatTextInputActionButtonsNode: ASDisplayNode, ChatSendMessageAction
self.sendButton.imageNode.alpha = 0.0 self.sendButton.imageNode.alpha = 0.0
self.textNode.isHidden = false self.textNode.isHidden = false
var amount = sendPaidMessageStars.value var amount: Int64
if let forwardedCount = interfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 { if let forwardedCount = interfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 {
amount = sendPaidMessageStars.value * Int64(forwardedCount) amount = sendPaidMessageStars.value * Int64(forwardedCount)
if interfaceState.interfaceState.effectiveInputState.inputText.length > 0 { if interfaceState.interfaceState.effectiveInputState.inputText.length > 0 {
amount += sendPaidMessageStars.value 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)" let text = "\(amount)"