// // Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only // import Foundation public struct DatabaseChangesSnapshot: DatabaseChanges { public let threadUniqueIds: Set public let threadUniqueIdsForChatListUpdate: Set public let interactionUniqueIds: Set public let storyMessageUniqueIds: Set public let storyMessageRowIds: Set public let interactionDeletedUniqueIds: Set public let storyMessageDeletedUniqueIds: Set public let tableNames: Set public let collections: Set public let didUpdateInteractions: Bool public let didUpdateThreads: Bool public let didUpdateInteractionsOrThreads: Bool public let lastError: Error? init( threadUniqueIds: Set, threadUniqueIdsForChatListUpdate: Set, interactionUniqueIds: Set, storyMessageUniqueIds: Set, storyMessageRowIds: Set, interactionDeletedUniqueIds: Set, storyMessageDeletedUniqueIds: Set, tableNames: Set, collections: Set, didUpdateInteractions: Bool, didUpdateThreads: Bool, didUpdateInteractionsOrThreads: Bool, lastError: Error? ) { self.threadUniqueIds = threadUniqueIds self.threadUniqueIdsForChatListUpdate = threadUniqueIdsForChatListUpdate self.interactionUniqueIds = interactionUniqueIds self.storyMessageUniqueIds = storyMessageUniqueIds self.storyMessageRowIds = storyMessageRowIds self.interactionDeletedUniqueIds = interactionDeletedUniqueIds self.storyMessageDeletedUniqueIds = storyMessageDeletedUniqueIds self.tableNames = tableNames self.collections = collections self.didUpdateInteractions = didUpdateInteractions self.didUpdateThreads = didUpdateThreads self.didUpdateInteractionsOrThreads = didUpdateInteractionsOrThreads self.lastError = lastError } public var isEmpty: Bool { return threadUniqueIds.isEmpty && interactionUniqueIds.isEmpty && storyMessageUniqueIds.isEmpty && storyMessageRowIds.isEmpty && interactionDeletedUniqueIds.isEmpty && storyMessageDeletedUniqueIds.isEmpty && tableNames.isEmpty && collections.isEmpty && lastError == nil } private func didUpdate(collection: String) -> Bool { collections.contains(collection) } public func didUpdateModel(collection: String) -> Bool { return didUpdate(collection: collection) } public func didUpdate(keyValueStore: SDSKeyValueStore) -> Bool { // GRDB: SDSKeyValueStore.dataStoreCollection return (didUpdate(collection: keyValueStore.collection) || didUpdate(collection: SDSKeyValueStore.dataStoreCollection)) } public func didUpdate(interaction: TSInteraction) -> Bool { interactionUniqueIds.contains(interaction.uniqueId) } public func didUpdate(thread: TSThread) -> Bool { threadUniqueIds.contains(thread.uniqueId) } }