From 51a7348db61fe1a109ad13df59458c3e03f86d2f Mon Sep 17 00:00:00 2001 From: isaac <> Date: Tue, 28 Apr 2026 16:57:44 +0400 Subject: [PATCH] Separate failed message events between main and scheduled --- .../Sources/State/PendingMessageManager.swift | 20 +++- .../Chat/ChatControllerLoadDisplayNode.swift | 106 ++++++++++-------- 2 files changed, 73 insertions(+), 53 deletions(-) diff --git a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift index fc6a80983e..02d29d7a6b 100644 --- a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift +++ b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift @@ -117,7 +117,7 @@ public struct PeerPendingMessageDelivered { private final class PeerPendingMessagesSummaryContext { var messageDeliveredSubscribers = Bag<([PeerPendingMessageDelivered]) -> Void>() - var messageFailedSubscribers = Bag<(PendingMessageFailureReason) -> Void>() + var messageFailedSubscribers = Bag<(MessageId.Namespace, PendingMessageFailureReason) -> Void>() var newTopicEvents = Bag<(PendingMessageManager.NewTopicEvent) -> Void>() var isEmpty: Bool { @@ -1413,7 +1413,7 @@ public final class PendingMessageManager { if let context = strongSelf.peerSummaryContexts[message.id.peerId] { for subscriber in context.messageFailedSubscribers.copyItems() { - subscriber(failureReason) + subscriber(message.id.namespace, failureReason) } } } @@ -2029,7 +2029,7 @@ public final class PendingMessageManager { if let context = strongSelf.peerSummaryContexts[message.id.peerId] { for subscriber in context.messageFailedSubscribers.copyItems() { - subscriber(failureReason) + subscriber(message.id.namespace, failureReason) } } } @@ -2232,7 +2232,7 @@ public final class PendingMessageManager { } } - public func failedMessageEvents(peerId: PeerId) -> Signal { + public func failedMessageEvents(peerId: PeerId, isScheduled: Bool) -> Signal { return Signal { subscriber in let disposable = MetaDisposable() @@ -2245,8 +2245,16 @@ public final class PendingMessageManager { self.peerSummaryContexts[peerId] = summaryContext } - let index = summaryContext.messageFailedSubscribers.add({ reason in - subscriber.putNext(reason) + let index = summaryContext.messageFailedSubscribers.add({ namespace, reason in + if isScheduled { + if Namespaces.Message.allScheduled.contains(namespace) { + subscriber.putNext(reason) + } + } else { + if !Namespaces.Message.allScheduled.contains(namespace) { + subscriber.putNext(reason) + } + } }) disposable.set(ActionDisposable { diff --git a/submodules/TelegramUI/Sources/Chat/ChatControllerLoadDisplayNode.swift b/submodules/TelegramUI/Sources/Chat/ChatControllerLoadDisplayNode.swift index bf272f5846..b36b81a3ca 100644 --- a/submodules/TelegramUI/Sources/Chat/ChatControllerLoadDisplayNode.swift +++ b/submodules/TelegramUI/Sources/Chat/ChatControllerLoadDisplayNode.swift @@ -5123,56 +5123,68 @@ extension ChatControllerImpl { } } })) + + let isScheduledMessages: Bool + if case .scheduledMessages = self.presentationInterfaceState.subject { + isScheduledMessages = true + } else { + isScheduledMessages = false + } - self.failedMessageEventsDisposable.set((self.context.account.pendingMessageManager.failedMessageEvents(peerId: peerId) + self.failedMessageEventsDisposable.set((self.context.account.pendingMessageManager.failedMessageEvents(peerId: peerId, isScheduled: isScheduledMessages) |> deliverOnMainQueue).startStrict(next: { [weak self] reason in - if let strongSelf = self, strongSelf.currentFailedMessagesAlertController == nil { - let text: String - var title: String? - let moreInfo: Bool - switch reason { - case .flood: - text = strongSelf.presentationData.strings.Conversation_SendMessageErrorFlood - moreInfo = true - case .sendingTooFast: - text = strongSelf.presentationData.strings.Conversation_SendMessageErrorTooFast - title = strongSelf.presentationData.strings.Conversation_SendMessageErrorTooFastTitle - moreInfo = false - case .publicBan: - text = strongSelf.presentationData.strings.Conversation_SendMessageErrorGroupRestricted - moreInfo = true - case .mediaRestricted: - text = strongSelf.restrictedSendingContentsText() - moreInfo = false - case .slowmodeActive: - text = strongSelf.presentationData.strings.Chat_SlowmodeSendError - moreInfo = false - case .tooMuchScheduled: - text = strongSelf.presentationData.strings.Conversation_SendMessageErrorTooMuchScheduled - moreInfo = false - case .voiceMessagesForbidden: - strongSelf.interfaceInteraction?.displayRestrictedInfo(.premiumVoiceMessages, .alert) - return - case .nonPremiumMessagesForbidden: - if let peer = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer { - text = strongSelf.presentationData.strings.Conversation_SendMessageErrorNonPremiumForbidden(EnginePeer(peer).compactDisplayTitle).string - moreInfo = false - } else { - return - } - } - let actions: [TextAlertAction] - if moreInfo { - actions = [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Generic_ErrorMoreInfo, action: { - self?.openPeerMention("spambot", navigation: .chat(textInputState: nil, subject: nil, peekData: nil)) - }), TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_OK, action: {})] - } else { - actions = [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})] - } - let controller = textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: title, text: text, actions: actions) - strongSelf.currentFailedMessagesAlertController = controller - strongSelf.present(controller, in: .window(.root)) + guard let strongSelf = self else { + return } + guard strongSelf.currentFailedMessagesAlertController == nil else { + return + } + + let text: String + var title: String? + let moreInfo: Bool + switch reason { + case .flood: + text = strongSelf.presentationData.strings.Conversation_SendMessageErrorFlood + moreInfo = true + case .sendingTooFast: + text = strongSelf.presentationData.strings.Conversation_SendMessageErrorTooFast + title = strongSelf.presentationData.strings.Conversation_SendMessageErrorTooFastTitle + moreInfo = false + case .publicBan: + text = strongSelf.presentationData.strings.Conversation_SendMessageErrorGroupRestricted + moreInfo = true + case .mediaRestricted: + text = strongSelf.restrictedSendingContentsText() + moreInfo = false + case .slowmodeActive: + text = strongSelf.presentationData.strings.Chat_SlowmodeSendError + moreInfo = false + case .tooMuchScheduled: + text = strongSelf.presentationData.strings.Conversation_SendMessageErrorTooMuchScheduled + moreInfo = false + case .voiceMessagesForbidden: + strongSelf.interfaceInteraction?.displayRestrictedInfo(.premiumVoiceMessages, .alert) + return + case .nonPremiumMessagesForbidden: + if let peer = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer { + text = strongSelf.presentationData.strings.Conversation_SendMessageErrorNonPremiumForbidden(EnginePeer(peer).compactDisplayTitle).string + moreInfo = false + } else { + return + } + } + let actions: [TextAlertAction] + if moreInfo { + actions = [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Generic_ErrorMoreInfo, action: { + self?.openPeerMention("spambot", navigation: .chat(textInputState: nil, subject: nil, peekData: nil)) + }), TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_OK, action: {})] + } else { + actions = [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})] + } + let controller = textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: title, text: text, actions: actions) + strongSelf.currentFailedMessagesAlertController = controller + strongSelf.present(controller, in: .window(.root)) })) self.sentPeerMediaMessageEventsDisposable.dispose()