Skip to content

Commit 3f8152d

Browse files
committed
Various fixes
1 parent e139342 commit 3f8152d

File tree

6 files changed

+64
-39
lines changed

6 files changed

+64
-39
lines changed

submodules/ShareController/Sources/ShareController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,8 @@ public final class ShareController: ViewController {
25162516
peers.append(EngineRenderedPeer(entryData.renderedPeer))
25172517
if let user = peer as? TelegramUser, user.flags.contains(.requirePremium) || user.flags.contains(.requireStars) {
25182518
possiblePremiumRequiredPeers.insert(user.id)
2519+
} else if let channel = peer as? TelegramChannel, let _ = channel.sendPaidMessageStars {
2520+
possiblePremiumRequiredPeers.insert(channel.id)
25192521
}
25202522
}
25212523
default:
@@ -2529,6 +2531,7 @@ public final class ShareController: ViewController {
25292531
keys.append(peerPresencesKey)
25302532

25312533
for id in possiblePremiumRequiredPeers {
2534+
keys.append(.basicPeer(id))
25322535
keys.append(.cachedPeerData(peerId: id))
25332536
}
25342537

@@ -2546,6 +2549,8 @@ public final class ShareController: ViewController {
25462549
if let view = views.views[.cachedPeerData(peerId: id)] as? CachedPeerDataView, let data = view.cachedPeerData as? CachedUserData {
25472550
requiresPremiumForMessaging[id] = data.flags.contains(.premiumRequired)
25482551
requiresStars[id] = data.sendPaidMessageStars?.value
2552+
} else if let view = views.views[.basicPeer(id)] as? BasicPeerView, let channel = view.peer as? TelegramChannel {
2553+
requiresStars[id] = channel.sendPaidMessageStars?.value
25492554
} else {
25502555
requiresPremiumForMessaging[id] = false
25512556
}

submodules/TelegramCore/Sources/State/PendingMessageManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public final class PendingMessageManager {
254254
context.sendDisposable.dispose()
255255
context.uploadDisposable.dispose()
256256
context.activityDisposable.dispose()
257+
context.postponeDisposable.dispose()
257258

258259
if context.status != nil {
259260
context.status = nil

submodules/TelegramUI/Sources/ChatController.swift

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9041,40 +9041,45 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
90419041
guard let strongSelf = self else {
90429042
return
90439043
}
9044-
let replyMessageSubject = strongSelf.presentationInterfaceState.interfaceState.replyMessageSubject
9045-
strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({
9046-
if let strongSelf = self {
9047-
strongSelf.chatDisplayNode.collapseInput()
9048-
9049-
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, {
9050-
$0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedSendMessageEffect(nil) }
9051-
})
9044+
strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in
9045+
guard let strongSelf = self else {
9046+
return
90529047
}
9053-
}, nil)
9054-
let message: EnqueueMessage = .message(
9055-
text: "",
9056-
attributes: [],
9057-
inlineStickers: [:],
9058-
mediaReference: .standalone(media: TelegramMediaPoll(
9059-
pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: Int64.random(in: Int64.min ... Int64.max)),
9060-
publicity: poll.publicity,
9061-
kind: poll.kind,
9062-
text: poll.text.string,
9063-
textEntities: poll.text.entities,
9064-
options: poll.options,
9065-
correctAnswers: poll.correctAnswers,
9066-
results: poll.results,
9067-
isClosed: false,
9068-
deadlineTimeout: poll.deadlineTimeout
9069-
)),
9070-
threadId: strongSelf.chatLocation.threadId,
9071-
replyToMessageId: nil,
9072-
replyToStoryId: nil,
9073-
localGroupingKey: nil,
9074-
correlationId: nil,
9075-
bubbleUpEmojiOrStickersets: []
9076-
)
9077-
strongSelf.sendMessages([message.withUpdatedReplyToMessageId(replyMessageSubject?.subjectModel)])
9048+
let replyMessageSubject = strongSelf.presentationInterfaceState.interfaceState.replyMessageSubject
9049+
strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({
9050+
if let strongSelf = self {
9051+
strongSelf.chatDisplayNode.collapseInput()
9052+
9053+
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, {
9054+
$0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedSendMessageEffect(nil) }
9055+
})
9056+
}
9057+
}, nil)
9058+
let message: EnqueueMessage = .message(
9059+
text: "",
9060+
attributes: [],
9061+
inlineStickers: [:],
9062+
mediaReference: .standalone(media: TelegramMediaPoll(
9063+
pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: Int64.random(in: Int64.min ... Int64.max)),
9064+
publicity: poll.publicity,
9065+
kind: poll.kind,
9066+
text: poll.text.string,
9067+
textEntities: poll.text.entities,
9068+
options: poll.options,
9069+
correctAnswers: poll.correctAnswers,
9070+
results: poll.results,
9071+
isClosed: false,
9072+
deadlineTimeout: poll.deadlineTimeout
9073+
)),
9074+
threadId: strongSelf.chatLocation.threadId,
9075+
replyToMessageId: nil,
9076+
replyToStoryId: nil,
9077+
localGroupingKey: nil,
9078+
correlationId: nil,
9079+
bubbleUpEmojiOrStickersets: []
9080+
)
9081+
strongSelf.sendMessages([message.withUpdatedReplyToMessageId(replyMessageSubject?.subjectModel)])
9082+
})
90789083
})
90799084
}
90809085

@@ -9283,6 +9288,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
92839288
var attributes = attributes
92849289

92859290
if let sendPaidMessageStars = self.presentationInterfaceState.sendPaidMessageStars {
9291+
for i in (0 ..< attributes.count).reversed() {
9292+
if attributes[i] is PaidStarsMessageAttribute {
9293+
attributes.remove(at: i)
9294+
}
9295+
}
92869296
attributes.append(PaidStarsMessageAttribute(stars: sendPaidMessageStars, postponeSending: postpone))
92879297
}
92889298

submodules/TelegramUI/Sources/ChatControllerNode.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,14 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate {
886886
self.controllerInteraction.scheduleCurrentMessage(nil)
887887
} else {
888888
if let _ = self.chatPresentationInterfaceState.sendPaidMessageStars {
889-
var count: Int32 = 1
889+
var count: Int32
890890
if let forwardedCount = self.chatPresentationInterfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 {
891891
count = Int32(forwardedCount)
892892
if self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length > 0 {
893893
count += 1
894894
}
895+
} else {
896+
count = Int32(ceil(CGFloat(self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.length) / 4096.0))
895897
}
896898
controller.presentPaidMessageAlertIfNeeded(count: count, completion: { [weak self] postpone in
897899
self?.sendCurrentMessage(postpone: postpone)

submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ extension ChatControllerImpl {
566566
}
567567
}
568568
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: []))
569-
strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in
569+
strongSelf.presentPaidMessageAlertIfNeeded(count: Int32(enqueueMessages.count), completion: { [weak self] postpone in
570570
guard let strongSelf = self else {
571571
return
572572
}
573-
strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime), postpone: postpone)
573+
strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime, postpone: postpone), postpone: postpone)
574574
})
575575
} else {
576576
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 {
596596
enqueueMessages.append(textEnqueueMessage)
597597
}
598598
enqueueMessages.append(.message(text: "", attributes: [], inlineStickers: [:], mediaReference: .standalone(media: media), threadId: strongSelf.chatLocation.threadId, replyToMessageId: replyMessageSubject?.subjectModel, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: []))
599-
strongSelf.presentPaidMessageAlertIfNeeded(completion: { [weak self] postpone in
599+
strongSelf.presentPaidMessageAlertIfNeeded(count: Int32(enqueueMessages.count), completion: { [weak self] postpone in
600600
guard let strongSelf = self else {
601601
return
602602
}
603-
strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime), postpone: postpone)
603+
strongSelf.sendMessages(strongSelf.transformEnqueueMessages(enqueueMessages, silentPosting: silent, scheduleTime: scheduleTime, postpone: postpone), postpone: postpone)
604604
})
605605
}
606606
}), completed: nil, cancelled: nil)

submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,19 @@ final class ChatTextInputActionButtonsNode: ASDisplayNode, ChatSendMessageAction
276276
self.sendButton.imageNode.alpha = 0.0
277277
self.textNode.isHidden = false
278278

279-
var amount = sendPaidMessageStars.value
279+
var amount: Int64
280280
if let forwardedCount = interfaceState.interfaceState.forwardMessageIds?.count, forwardedCount > 0 {
281281
amount = sendPaidMessageStars.value * Int64(forwardedCount)
282282
if interfaceState.interfaceState.effectiveInputState.inputText.length > 0 {
283283
amount += sendPaidMessageStars.value
284284
}
285+
} else {
286+
if interfaceState.interfaceState.effectiveInputState.inputText.length > 4096 {
287+
let messageCount = Int32(ceil(CGFloat(interfaceState.interfaceState.effectiveInputState.inputText.length) / 4096.0))
288+
amount = sendPaidMessageStars.value * Int64(messageCount)
289+
} else {
290+
amount = sendPaidMessageStars.value
291+
}
285292
}
286293

287294
let text = "\(amount)"

0 commit comments

Comments
 (0)