diff --git a/submodules/AppLock/Sources/AppLock.swift b/submodules/AppLock/Sources/AppLock.swift index c8cdc58649..3311d7e7d7 100644 --- a/submodules/AppLock/Sources/AppLock.swift +++ b/submodules/AppLock/Sources/AppLock.swift @@ -69,6 +69,7 @@ public final class AppLockContextImpl: AppLockContext { private let accountManager: AccountManager private let presentationDataSignal: Signal private let window: Window1? + private let rootController: UIViewController? private var coveringView: LockedWindowCoveringView? private var passcodeController: PasscodeEntryController? @@ -89,7 +90,7 @@ public final class AppLockContextImpl: AppLockContext { private var lastActiveTimestamp: Double? private var lastActiveValue: Bool = false - public init(rootPath: String, window: Window1?, applicationBindings: TelegramApplicationBindings, accountManager: AccountManager, presentationDataSignal: Signal, lockIconInitialFrame: @escaping () -> CGRect?) { + public init(rootPath: String, window: Window1?, rootController: UIViewController?, applicationBindings: TelegramApplicationBindings, accountManager: AccountManager, presentationDataSignal: Signal, lockIconInitialFrame: @escaping () -> CGRect?) { assert(Queue.mainQueue().isCurrent()) self.applicationBindings = applicationBindings @@ -97,6 +98,7 @@ public final class AppLockContextImpl: AppLockContext { self.presentationDataSignal = presentationDataSignal self.rootPath = rootPath self.window = window + self.rootController = rootController if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: self.rootPath))), let current = try? JSONDecoder().decode(LockState.self, from: data) { self.currentStateValue = current @@ -185,6 +187,9 @@ public final class AppLockContextImpl: AppLockContext { } passcodeController.presentedOverCoveringView = true strongSelf.passcodeController = passcodeController + if let rootViewController = strongSelf.rootController { + rootViewController.dismiss(animated: false, completion: nil) + } strongSelf.window?.present(passcodeController, on: .passcode) } } else if let passcodeController = strongSelf.passcodeController { @@ -202,6 +207,10 @@ public final class AppLockContextImpl: AppLockContext { coveringView.updateSnapshot(getCoveringViewSnaphot(window: window)) strongSelf.coveringView = coveringView window.coveringView = coveringView + + if let rootViewController = strongSelf.rootController { + rootViewController.dismiss(animated: false, completion: nil) + } } } else { if let coveringView = strongSelf.coveringView { diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index 4e23b1f107..3b5aa04e44 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -1420,7 +1420,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { strongSelf.secretIconNode = iconNode } iconNode.image = currentSecretIconImage - transition.updateFrame(node: iconNode, frame: CGRect(origin: CGPoint(x: contentRect.origin.x, y: contentRect.origin.y + floor((strongSelf.titleNode.frame.height - currentSecretIconImage.size.height) / 2.0)), size: currentSecretIconImage.size)) + transition.updateFrame(node: iconNode, frame: CGRect(origin: CGPoint(x: contentRect.origin.x, y: contentRect.origin.y + floor((titleLayout.size.height - currentSecretIconImage.size.height) / 2.0)), size: currentSecretIconImage.size)) titleOffset += currentSecretIconImage.size.width + 3.0 } else if let secretIconNode = strongSelf.secretIconNode { strongSelf.secretIconNode = nil diff --git a/submodules/Display/Display/ActionSheetTextItem.swift b/submodules/Display/Display/ActionSheetTextItem.swift index 7b65015f8d..65f0be42b0 100644 --- a/submodules/Display/Display/ActionSheetTextItem.swift +++ b/submodules/Display/Display/ActionSheetTextItem.swift @@ -61,7 +61,7 @@ public class ActionSheetTextNode: ActionSheetItemNode { func setItem(_ item: ActionSheetTextItem) { self.item = item - let defaultFont = Font.regular(floor(theme.baseFontSize * 20.0 / 17.0)) + let defaultFont = Font.regular(floor(theme.baseFontSize * 13.0 / 17.0)) self.label.attributedText = NSAttributedString(string: item.title, font: defaultFont, textColor: self.theme.secondaryTextColor, paragraphAlignment: .center) self.accessibilityArea.accessibilityLabel = item.title diff --git a/submodules/Display/Display/TabBarNode.swift b/submodules/Display/Display/TabBarNode.swift index 03e54f3807..47a91dcc36 100644 --- a/submodules/Display/Display/TabBarNode.swift +++ b/submodules/Display/Display/TabBarNode.swift @@ -425,7 +425,10 @@ class TabBarNode: ASDisplayNode { } if !container.badgeContainerNode.isHidden { - let hasSingleLetterValue = container.badgeTextNode.attributedText?.string.count == 1 + var hasSingleLetterValue: Bool = false + if let string = container.badgeTextNode.attributedText?.string { + hasSingleLetterValue = string.count == 1 + } let badgeSize = container.badgeTextNode.updateLayout(CGSize(width: 200.0, height: 100.0)) let backgroundSize = CGSize(width: hasSingleLetterValue ? 18.0 : max(18.0, badgeSize.width + 10.0 + 1.0), height: 18.0) let backgroundFrame: CGRect diff --git a/submodules/Display/Display/UIKitUtils.swift b/submodules/Display/Display/UIKitUtils.swift index cf8459ae97..a8ad19277a 100644 --- a/submodules/Display/Display/UIKitUtils.swift +++ b/submodules/Display/Display/UIKitUtils.swift @@ -318,6 +318,8 @@ private func makeSubtreeSnapshot(layer: CALayer, keepTransform: Bool = false) -> maskLayer.contentsScale = mask.contentsScale maskLayer.contentsCenter = mask.contentsCenter maskLayer.contentsGravity = mask.contentsGravity + maskLayer.frame = mask.frame + maskLayer.bounds = mask.bounds view.layer.mask = maskLayer } view.layer.cornerRadius = layer.cornerRadius diff --git a/submodules/Postbox/Sources/MessageHistoryMetadataTable.swift b/submodules/Postbox/Sources/MessageHistoryMetadataTable.swift index 5fe138ec64..7032f2bce6 100644 --- a/submodules/Postbox/Sources/MessageHistoryMetadataTable.swift +++ b/submodules/Postbox/Sources/MessageHistoryMetadataTable.swift @@ -10,6 +10,7 @@ private enum MetadataPrefix: Int8 { case GroupFeedIndexInitialized = 7 case ShouldReindexUnreadCounts = 8 case PeerHistoryInitialized = 9 + case ShouldReindexUnreadCountsState = 10 } public struct ChatListTotalUnreadCounters: PostboxCoding, Equatable { @@ -148,6 +149,21 @@ final class MessageHistoryMetadataTable: Table { } } + func setShouldReindexUnreadCountsState(value: Int32) { + var value = value + self.valueBox.set(self.table, key: self.key(MetadataPrefix.ShouldReindexUnreadCountsState), value: MemoryBuffer(memory: &value, capacity: 4, length: 4, freeWhenDone: false)) + } + + func getShouldReindexUnreadCountsState() -> Int32? { + if let value = self.valueBox.get(self.table, key: self.key(MetadataPrefix.ShouldReindexUnreadCountsState)) { + var version: Int32 = 0 + value.read(&version, offset: 0, length: 4) + return version + } else { + return nil + } + } + func setInitialized(_ peerId: PeerId) { self.initializedHistoryPeerIds.insert(peerId) self.sharedBuffer.reset() diff --git a/submodules/Postbox/Sources/Postbox.swift b/submodules/Postbox/Sources/Postbox.swift index 1c8abe8ff9..b185d8a599 100644 --- a/submodules/Postbox/Sources/Postbox.swift +++ b/submodules/Postbox/Sources/Postbox.swift @@ -919,6 +919,11 @@ public final class Transaction { assert(!self.disposed) self.postbox?.addHolesEverywhere(peerNamespaces: peerNamespaces, holeNamespace: holeNamespace) } + + public func reindexUnreadCounters() { + assert(!self.disposed) + self.postbox?.reindexUnreadCounters() + } } public enum PostboxResult { @@ -1341,6 +1346,12 @@ public final class Postbox { print("(Postbox initialization took \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") let _ = self.transaction({ transaction -> Void in + let reindexUnreadVersion: Int32 = 1 + if self.messageHistoryMetadataTable.getShouldReindexUnreadCountsState() != reindexUnreadVersion { + self.messageHistoryMetadataTable.setShouldReindexUnreadCounts(value: true) + self.messageHistoryMetadataTable.setShouldReindexUnreadCountsState(value: reindexUnreadVersion) + } + if self.messageHistoryMetadataTable.shouldReindexUnreadCounts() { self.groupMessageStatsTable.removeAll() let startTime = CFAbsoluteTimeGetCurrent() @@ -3158,4 +3169,17 @@ public final class Postbox { } } } + + fileprivate func reindexUnreadCounters() { + self.groupMessageStatsTable.removeAll() + let startTime = CFAbsoluteTimeGetCurrent() + let (rootState, summaries) = self.chatListIndexTable.debugReindexUnreadCounts(postbox: self) + + self.messageHistoryMetadataTable.setChatListTotalUnreadState(rootState) + self.currentUpdatedTotalUnreadState = rootState + for (groupId, summary) in summaries { + self.groupMessageStatsTable.set(groupId: groupId, summary: summary) + self.currentUpdatedGroupTotalUnreadSummaries[groupId] = summary + } + } } diff --git a/submodules/SettingsUI/Sources/DebugController.swift b/submodules/SettingsUI/Sources/DebugController.swift index 7ccce12457..9d7e830613 100644 --- a/submodules/SettingsUI/Sources/DebugController.swift +++ b/submodules/SettingsUI/Sources/DebugController.swift @@ -68,6 +68,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { case resetData(PresentationTheme) case resetDatabase(PresentationTheme) case resetHoles(PresentationTheme) + case reindexUnread(PresentationTheme) case resetBiometricsData(PresentationTheme) case optimizeDatabase(PresentationTheme) case photoPreview(PresentationTheme, Bool) @@ -85,7 +86,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { return DebugControllerSection.logging.rawValue case .enableRaiseToSpeak, .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries: return DebugControllerSection.experiments.rawValue - case .clearTips, .reimport, .resetData, .resetDatabase, .resetHoles, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper: + case .clearTips, .reimport, .resetData, .resetDatabase, .resetHoles, .reindexUnread, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper: return DebugControllerSection.experiments.rawValue case .hostInfo, .versionInfo: return DebugControllerSection.info.rawValue @@ -128,8 +129,10 @@ private enum DebugControllerEntry: ItemListNodeEntry { return 15 case .resetHoles: return 16 - case .resetBiometricsData: + case .reindexUnread: return 17 + case .resetBiometricsData: + return 18 case .optimizeDatabase: return 20 case .photoPreview: @@ -462,6 +465,21 @@ private enum DebugControllerEntry: ItemListNodeEntry { controller.dismiss() }) }) + case let .reindexUnread(theme): + return ItemListActionItem(presentationData: presentationData, title: "Reindex Unread Counters", kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { + guard let context = arguments.context else { + return + } + let presentationData = arguments.sharedContext.currentPresentationData.with { $0 } + let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) + arguments.presentController(controller, nil) + let _ = (context.account.postbox.transaction { transaction -> Void in + transaction.reindexUnreadCounters() + } + |> deliverOnMainQueue).start(completed: { + controller.dismiss() + }) + }) case let .resetBiometricsData(theme): return ItemListActionItem(presentationData: presentationData, title: "Reset Biometrics Data", kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { let _ = updatePresentationPasscodeSettingsInteractively(accountManager: arguments.sharedContext.accountManager, { settings in @@ -542,6 +560,7 @@ private func debugControllerEntries(presentationData: PresentationData, loggingS entries.append(.resetData(presentationData.theme)) entries.append(.resetDatabase(presentationData.theme)) entries.append(.resetHoles(presentationData.theme)) + entries.append(.reindexUnread(presentationData.theme)) entries.append(.optimizeDatabase(presentationData.theme)) entries.append(.photoPreview(presentationData.theme, experimentalSettings.chatListPhotos)) entries.append(.knockoutWallpaper(presentationData.theme, experimentalSettings.knockoutWallpaper)) diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index d7942cd458..2b7b8130a7 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -753,7 +753,7 @@ final class SharedApplicationContext { let legacyCache = LegacyCache(path: legacyBasePath + "/Caches") let presentationDataPromise = Promise() - let appLockContext = AppLockContextImpl(rootPath: rootPath, window: self.mainWindow!, applicationBindings: applicationBindings, accountManager: accountManager, presentationDataSignal: presentationDataPromise.get(), lockIconInitialFrame: { + let appLockContext = AppLockContextImpl(rootPath: rootPath, window: self.mainWindow!, rootController: self.window?.rootViewController, applicationBindings: applicationBindings, accountManager: accountManager, presentationDataSignal: presentationDataPromise.get(), lockIconInitialFrame: { return (self.mainWindow?.viewController as? TelegramRootController)?.chatListController?.lockViewFrame }) diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index 3e9ce21790..65d0fb2e10 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -2503,14 +2503,30 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode return (nil, nil) } if strongSelf.backgroundNode.supernode != nil, let backgroundView = strongSelf.backgroundNode.view.snapshotContentTree(unhide: true) { + let backgroundContainer = UIView() + + let backdropView = strongSelf.backgroundWallpaperNode.view.snapshotContentTree(unhide: true) + if let backdropView = backdropView { + backdropView.backgroundColor = .green + let backdropFrame = strongSelf.backgroundWallpaperNode.layer.convert(strongSelf.backgroundWallpaperNode.bounds, to: strongSelf.backgroundNode.layer) + backdropView.frame = backdropFrame + } + + if let backdropView = backdropView { + backgroundContainer.addSubview(backdropView) + } + + backgroundContainer.addSubview(backgroundView) + let backgroundFrame = strongSelf.backgroundNode.layer.convert(strongSelf.backgroundNode.bounds, to: result.0.layer) - backgroundView.frame = backgroundFrame + backgroundView.frame = CGRect(origin: CGPoint(), size: backgroundFrame.size) + backgroundContainer.frame = backgroundFrame let viewWithBackground = UIView() - viewWithBackground.addSubview(backgroundView) + viewWithBackground.addSubview(backgroundContainer) viewWithBackground.frame = resultView.frame resultView.frame = CGRect(origin: CGPoint(), size: resultView.frame.size) viewWithBackground.addSubview(resultView) - return (viewWithBackground, backgroundView) + return (viewWithBackground, backgroundContainer) } return (resultView, nil) }) diff --git a/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift b/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift index 27f5c533c0..4950f319d8 100644 --- a/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift +++ b/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift @@ -150,7 +150,7 @@ public final class NotificationViewControllerImpl { let presentationDataPromise = Promise() - let appLockContext = AppLockContextImpl(rootPath: rootPath, window: nil, applicationBindings: applicationBindings, accountManager: accountManager, presentationDataSignal: presentationDataPromise.get(), lockIconInitialFrame: { + let appLockContext = AppLockContextImpl(rootPath: rootPath, window: nil, rootController: nil, applicationBindings: applicationBindings, accountManager: accountManager, presentationDataSignal: presentationDataPromise.get(), lockIconInitialFrame: { return nil }) diff --git a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift index 7d99cfd0f1..4f732a036a 100644 --- a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift +++ b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift @@ -188,7 +188,7 @@ public class ShareRootControllerImpl { let presentationDataPromise = Promise() - let appLockContext = AppLockContextImpl(rootPath: rootPath, window: nil, applicationBindings: applicationBindings, accountManager: accountManager, presentationDataSignal: presentationDataPromise.get(), lockIconInitialFrame: { + let appLockContext = AppLockContextImpl(rootPath: rootPath, window: nil, rootController: nil, applicationBindings: applicationBindings, accountManager: accountManager, presentationDataSignal: presentationDataPromise.get(), lockIconInitialFrame: { return nil })