// // 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 tableRowIds: [String: Set] public let didUpdateInteractions: Bool public let didUpdateThreads: Bool public let lastError: Error? init( threadUniqueIds: Set, threadUniqueIdsForChatListUpdate: Set, interactionUniqueIds: Set, storyMessageUniqueIds: Set, storyMessageRowIds: Set, interactionDeletedUniqueIds: Set, storyMessageDeletedUniqueIds: Set, tableNames: Set, tableRowIds: [String: Set], didUpdateInteractions: Bool, didUpdateThreads: 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.tableRowIds = tableRowIds self.didUpdateInteractions = didUpdateInteractions self.didUpdateThreads = didUpdateThreads self.lastError = lastError } public var isEmpty: Bool { return threadUniqueIds.isEmpty && interactionUniqueIds.isEmpty && storyMessageUniqueIds.isEmpty && storyMessageRowIds.isEmpty && interactionDeletedUniqueIds.isEmpty && storyMessageDeletedUniqueIds.isEmpty && tableNames.isEmpty && tableRowIds.isEmpty && lastError == nil } public func didUpdate(tableName: String) -> Bool { return tableNames.contains(tableName) } public func didUpdate(interaction: TSInteraction) -> Bool { interactionUniqueIds.contains(interaction.uniqueId) } public func didUpdate(thread: TSThread) -> Bool { threadUniqueIds.contains(thread.uniqueId) } }