From 8641ca95ee6655a1d4b311bbc0a201fe83ee3952 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Wed, 1 Nov 2023 22:25:30 +0400 Subject: [PATCH 1/5] Backport one more fix --- .../AccountManager/AccountManagerImpl.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift b/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift index 9e9c5c96d8..9918b92bbf 100644 --- a/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift +++ b/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift @@ -133,12 +133,16 @@ final class AccountManagerImpl { } } catch let e { postboxLog("load atomic state error: \(e)") - var legacyRecordDict: [AccountRecordId: AccountRecord] = [:] - for record in self.legacyRecordTable.getRecords() { - legacyRecordDict[record.id] = record + if removeDatabaseOnError { + var legacyRecordDict: [AccountRecordId: AccountRecord] = [:] + for record in self.legacyRecordTable.getRecords() { + legacyRecordDict[record.id] = record + } + self.currentAtomicState = AccountManagerAtomicState(records: legacyRecordDict, currentRecordId: self.legacyMetadataTable.getCurrentAccountId(), currentAuthRecord: self.legacyMetadataTable.getCurrentAuthAccount(), accessChallengeData: self.legacyMetadataTable.getAccessChallengeData()) + self.syncAtomicStateToFile() + } else { + preconditionFailure() } - self.currentAtomicState = AccountManagerAtomicState(records: legacyRecordDict, currentRecordId: self.legacyMetadataTable.getCurrentAccountId(), currentAuthRecord: self.legacyMetadataTable.getCurrentAuthAccount(), accessChallengeData: self.legacyMetadataTable.getAccessChallengeData()) - self.syncAtomicStateToFile() } let tableAccessChallengeData = self.legacyMetadataTable.getAccessChallengeData() From 33891effcca760138456d1c15c4d5e99ff6b0283 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Wed, 1 Nov 2023 22:35:17 +0400 Subject: [PATCH 2/5] Sync with master --- .../Sources/AccountManager/AccountManagerImpl.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift b/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift index 9918b92bbf..47e50411d9 100644 --- a/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift +++ b/submodules/TelegramCore/Sources/AccountManager/AccountManagerImpl.swift @@ -133,6 +133,8 @@ final class AccountManagerImpl { } } catch let e { postboxLog("load atomic state error: \(e)") + postboxLogSync() + if removeDatabaseOnError { var legacyRecordDict: [AccountRecordId: AccountRecord] = [:] for record in self.legacyRecordTable.getRecords() { From 1310237ab5adda6f394246d45d43e1050a5f010a Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 2 Nov 2023 17:44:07 +0400 Subject: [PATCH 3/5] Add more logs --- .../Sources/NotificationService.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Telegram/NotificationService/Sources/NotificationService.swift b/Telegram/NotificationService/Sources/NotificationService.swift index 5fcced7b3a..f79918f225 100644 --- a/Telegram/NotificationService/Sources/NotificationService.swift +++ b/Telegram/NotificationService/Sources/NotificationService.swift @@ -2013,6 +2013,15 @@ private final class NotificationServiceHandler { } |> deliverOn(strongSelf.queue)).start(completed: { UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { notifications in + let notificationDebugList = notifications.map { notification -> String in + if let peerIdString = notification.request.content.userInfo["peerId"] as? String, let peerIdValue = Int64(peerIdString), let messageIdString = notification.request.content.userInfo["msg_id"] as? String, let messageIdValue = Int32(messageIdString) { + return "peerId: \(peerIdValue), messageId: \(messageIdValue)" + } else { + return "unknown: \(String(describing: notification.request.content.userInfo))" + } + }.joined(separator: "\n") + Logger.shared.log("NotificationService \(episode)", "Filtering delivered notifications: \(notificationDebugList)") + var removeIdentifiers: [String] = [] for notification in notifications { if let peerIdString = notification.request.content.userInfo["peerId"] as? String, let peerIdValue = Int64(peerIdString), let messageIdString = notification.request.content.userInfo["msg_id"] as? String, let messageIdValue = Int32(messageIdString) { From c7f5d9082c74b04ebf54fe38fabd5f892b9c6756 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 2 Nov 2023 17:59:23 +0400 Subject: [PATCH 4/5] Fix video story crash --- .../Sources/StoryItemSetContainerComponent.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift index ae22b144ec..5598bab0db 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift @@ -430,6 +430,8 @@ public final class StoryItemSetContainerComponent: Component { let inputPanelContainer = SparseContainerView() private let inputPanelBackground = ComponentView() + var isUpdatingComponent: Bool = false + var preparingToDisplayViewList: Bool = false var viewListDisplayState: ViewListDisplayState = .hidden @@ -1510,7 +1512,7 @@ public final class StoryItemSetContainerComponent: Component { sharedState: component.storyItemSharedState, theme: component.theme, presentationProgressUpdated: { [weak self, weak visibleItem] progress, isBuffering, canSwitch in - guard let self = self, let component = self.component else { + guard let self, let component = self.component else { return } guard let visibleItem else { @@ -1526,7 +1528,7 @@ public final class StoryItemSetContainerComponent: Component { navigationStripView.updateCurrentItemProgress(value: progress, isBuffering: isBuffering, transition: .immediate) } - if isBufferingUpdated { + if isBufferingUpdated && !self.isUpdatingComponent { self.state?.updated(transition: .immediate) } @@ -2514,6 +2516,11 @@ public final class StoryItemSetContainerComponent: Component { } func update(component: StoryItemSetContainerComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { + self.isUpdatingComponent = true + defer { + self.isUpdatingComponent = false + } + let isFirstTime = self.component == nil let startTime1 = CFAbsoluteTimeGetCurrent() From 6bddf8ac4730c6959165fa391b85970b8ee91f23 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 2 Nov 2023 18:18:46 +0400 Subject: [PATCH 5/5] Don't treat outgoing messages as incoming --- submodules/TelegramCore/Sources/Utils/MessageUtils.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/submodules/TelegramCore/Sources/Utils/MessageUtils.swift b/submodules/TelegramCore/Sources/Utils/MessageUtils.swift index 1d3cb2680c..371dcbb67a 100644 --- a/submodules/TelegramCore/Sources/Utils/MessageUtils.swift +++ b/submodules/TelegramCore/Sources/Utils/MessageUtils.swift @@ -287,6 +287,8 @@ public extension Message { } else { return false } + } else if self.author?.id == accountPeerId { + return false } else if self.flags.contains(.Incoming) { return true } else if let channel = self.peers[self.id.peerId] as? TelegramChannel, case .broadcast = channel.info {