diff --git a/Scripts/sds_codegen/sds_config/sds_record_type_map.json b/Scripts/sds_codegen/sds_config/sds_record_type_map.json index 68fe477bb5..287b074301 100644 --- a/Scripts/sds_codegen/sds_config/sds_record_type_map.json +++ b/Scripts/sds_codegen/sds_config/sds_record_type_map.json @@ -53,10 +53,8 @@ "SignalRecipient": 31, "StickerPack": 14, "TSCall": 20, - "TSContactThread": 27, "TSErrorMessage": 9, "TSGroupMember": 69, - "TSGroupThread": 26, "TSIncomingMessage": 19, "TSInfoMessage": 10, "TSInteraction": 16, @@ -68,9 +66,7 @@ "TSOutgoingMessage": 21, "TSPaymentModel": 67, "TSPaymentRequestModel": 66, - "TSPrivateStoryThread": 72, "TSRecipientReadReceipt": 12, - "TSThread": 2, "TSUnreadIndicatorInteraction": 4, "TestModel": 59 } \ No newline at end of file diff --git a/SignalServiceKit/Contacts/TSThread.swift b/SignalServiceKit/Contacts/TSThread.swift index fa31ec5838..c0730bf867 100644 --- a/SignalServiceKit/Contacts/TSThread.swift +++ b/SignalServiceKit/Contacts/TSThread.swift @@ -19,19 +19,27 @@ public enum TSThreadStoryViewMode: UInt { case disabled = 3 } +public enum TSThreadType: UInt { + case thread = 2 + case contactThread = 27 + case groupThread = 26 + case privateStoryThread = 72 + case releaseNotesThread = 80 +} + @objc open class TSThread: NSObject, SDSCodableModel, InheritableRecord { public static let databaseTableName: String = "model_TSThread" - public class var recordType: SDSRecordType { .thread } + public class var recordType: TSThreadType { .thread } static func concreteType(forRecordType recordType: UInt) -> (any InheritableRecord.Type)? { - switch recordType { - case SDSRecordType.thread.rawValue: TSThread.self - case SDSRecordType.contactThread.rawValue: TSContactThread.self - case SDSRecordType.groupThread.rawValue: TSGroupThread.self - case SDSRecordType.privateStoryThread.rawValue: TSPrivateStoryThread.self - case SDSRecordType.releaseNotesThread.rawValue: TSReleaseNotesThread.self - default: nil + switch TSThreadType(rawValue: recordType) { + case .thread: TSThread.self + case .contactThread: TSContactThread.self + case .groupThread: TSGroupThread.self + case .privateStoryThread: TSPrivateStoryThread.self + case .releaseNotesThread: TSReleaseNotesThread.self + case nil: nil } } diff --git a/SignalServiceKit/Groups/TSGroupModel.swift b/SignalServiceKit/Groups/TSGroupModel.swift index db8540f2f9..9951ed43f7 100644 --- a/SignalServiceKit/Groups/TSGroupModel.swift +++ b/SignalServiceKit/Groups/TSGroupModel.swift @@ -541,7 +541,7 @@ extension TSGroupModel { TSThread.anyEnumerate( transaction: transaction, sql: "SELECT * FROM \(TSThread.databaseTableName) WHERE \(threadColumn: .recordType) = ?", - arguments: [SDSRecordType.groupThread.rawValue], + arguments: [TSThreadType.groupThread.rawValue], block: { thread, stop in // [SDS] TODO: Fetch TSGroupThreads directly. guard let avatarHash = (thread as? TSGroupThread)?.groupModel.avatarHash else { diff --git a/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift b/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift index e1144f8f52..43ca64412e 100644 --- a/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift +++ b/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift @@ -5277,7 +5277,7 @@ public class GRDBSchemaMigrator { sql: """ SELECT * FROM \(TSThread.databaseTableName) - WHERE \(threadColumn: .recordType) = \(SDSRecordType.groupThread.rawValue) + WHERE \(threadColumn: .recordType) = \(TSThreadType.groupThread.rawValue) """, arguments: [], ) { thread, _ in @@ -5369,7 +5369,7 @@ public class GRDBSchemaMigrator { migrator.registerMigration(.dataMigration_reindexGroupMembershipAndMigrateLegacyAvatarDataFixed) { transaction in TSThread.anyEnumerate( transaction: transaction, - sql: "SELECT * FROM \(TSThread.databaseTableName) WHERE \(threadColumn: .recordType) = \(SDSRecordType.groupThread.rawValue)", + sql: "SELECT * FROM \(TSThread.databaseTableName) WHERE \(threadColumn: .recordType) = \(TSThreadType.groupThread.rawValue)", arguments: [], ) { thread, _ in // [SDS] TODO: Fetch TSGroupThreads directly. diff --git a/SignalServiceKit/Storage/Database/Records/ThreadFinder.swift b/SignalServiceKit/Storage/Database/Records/ThreadFinder.swift index 774d1c22ea..ab7003e339 100644 --- a/SignalServiceKit/Storage/Database/Records/ThreadFinder.swift +++ b/SignalServiceKit/Storage/Database/Records/ThreadFinder.swift @@ -61,7 +61,7 @@ public class ThreadFinder { let sql = """ SELECT * FROM \(TSThread.databaseTableName) - WHERE \(threadColumn: .recordType) = \(SDSRecordType.privateStoryThread.rawValue) + WHERE \(threadColumn: .recordType) = \(TSThreadType.privateStoryThread.rawValue) """ var cursor = FailIfThrowsRecordCursor { @@ -85,7 +85,7 @@ public class ThreadFinder { let sql = """ SELECT * FROM \(TSThread.databaseTableName) - WHERE \(threadColumn: .recordType) = \(SDSRecordType.groupThread.rawValue) + WHERE \(threadColumn: .recordType) = \(TSThreadType.groupThread.rawValue) ORDER BY \(threadColumn: .lastInteractionRowId) DESC """ @@ -117,7 +117,7 @@ public class ThreadFinder { return try TSThread.fetchCursor( tx.database, sql: sql, - arguments: [SDSRecordType.privateStoryThread.rawValue], + arguments: [TSThreadType.privateStoryThread.rawValue], ) } @@ -301,7 +301,7 @@ public class ThreadFinder { LIMIT 1 ) """ - let arguments: StatementArguments = [SDSRecordType.groupThread.rawValue] + let arguments: StatementArguments = [TSThreadType.groupThread.rawValue] return failIfThrows { return try Bool.fetchOne( transaction.database, @@ -353,7 +353,7 @@ public class ThreadFinder { AND \(threadColumn: .storyViewMode) != \(TSThreadStoryViewMode.default.rawValue) OR ( \(threadColumn: .storyViewMode) = \(TSThreadStoryViewMode.default.rawValue) - AND \(threadColumn: .recordType) = \(SDSRecordType.groupThread.rawValue) + AND \(threadColumn: .recordType) = \(TSThreadType.groupThread.rawValue) AND \(threadColumn: .uniqueId) IN (\(allowedDefaultThreadIds.map { "\"\($0)\"" }.joined(separator: ", "))) ) ORDER BY \(threadColumn: .lastSentStoryTimestamp) DESC diff --git a/SignalServiceKit/Storage/Database/SDSRecordType.swift b/SignalServiceKit/Storage/Database/SDSRecordType.swift index bb6f107cb7..d8c5453121 100644 --- a/SignalServiceKit/Storage/Database/SDSRecordType.swift +++ b/SignalServiceKit/Storage/Database/SDSRecordType.swift @@ -12,7 +12,6 @@ import GRDB @objc public enum SDSRecordType: UInt, CaseIterable { case invalidIdentityKeyReceivingErrorMessage = 1 - case thread = 2 case unreadIndicatorInteraction = 4 case unknownContactBlockOfferMessage = 5 case addToProfileWhitelistOfferMessage = 7 @@ -32,8 +31,6 @@ public enum SDSRecordType: UInt, CaseIterable { case invalidIdentityKeySendingErrorMessage = 23 case installedSticker = 24 case addToContactsOfferMessage = 25 - case groupThread = 26 - case contactThread = 27 case disappearingConfigurationUpdateInfoMessage = 28 case signalAccount = 30 case signalRecipient = 31 @@ -76,7 +73,6 @@ public enum SDSRecordType: UInt, CaseIterable { case groupMember = 69 case recoverableDecryptionPlaceholder = 70 case receiptCredentialRedemptionJobRecord = 71 - case privateStoryThread = 72 case sendGiftBadgeJobRecord = 73 case localUserLeaveGroupJobRecord = 74 case incomingPaymentMessage = 75 @@ -84,5 +80,4 @@ public enum SDSRecordType: UInt, CaseIterable { case paymentActivationRequestFinishedMessage = 77 case incomingArchivedPaymentMessage = 78 case outgoingArchivedPaymentMessage = 79 - case releaseNotesThread = 80 } diff --git a/SignalServiceKit/Threads/TSContactThread.swift b/SignalServiceKit/Threads/TSContactThread.swift index 4c120053b6..3fc4685c60 100644 --- a/SignalServiceKit/Threads/TSContactThread.swift +++ b/SignalServiceKit/Threads/TSContactThread.swift @@ -7,7 +7,7 @@ public import GRDB import LibSignalClient open class TSContactThread: TSThread { - override public class var recordType: SDSRecordType { .contactThread } + override public class var recordType: TSThreadType { .contactThread } /// Represents the uppercase ServiceId string for this contact. /// - Note diff --git a/SignalServiceKit/Threads/TSGroupThread.swift b/SignalServiceKit/Threads/TSGroupThread.swift index 52e9f813a3..6f813fe392 100644 --- a/SignalServiceKit/Threads/TSGroupThread.swift +++ b/SignalServiceKit/Threads/TSGroupThread.swift @@ -13,7 +13,7 @@ extension Notification.Name { public let TSGroupThread_NotificationKey_UniqueId = "TSGroupThread_NotificationKey_UniqueId" open class TSGroupThread: TSThread { - override public class var recordType: SDSRecordType { .groupThread } + override public class var recordType: TSThreadType { .groupThread } public private(set) var groupModel: TSGroupModel diff --git a/SignalServiceKit/Threads/TSPrivateStoryThread.swift b/SignalServiceKit/Threads/TSPrivateStoryThread.swift index 622016af57..c78beec5af 100644 --- a/SignalServiceKit/Threads/TSPrivateStoryThread.swift +++ b/SignalServiceKit/Threads/TSPrivateStoryThread.swift @@ -8,7 +8,7 @@ public import GRDB /// Represents a story distribution list. public final class TSPrivateStoryThread: TSThread { - override public class var recordType: SDSRecordType { .privateStoryThread } + override public class var recordType: TSThreadType { .privateStoryThread } public private(set) var allowsReplies: Bool public private(set) var _name: String diff --git a/SignalServiceKit/Threads/TSReleaseNotesThread.swift b/SignalServiceKit/Threads/TSReleaseNotesThread.swift index a6241b7efd..2c7638827b 100644 --- a/SignalServiceKit/Threads/TSReleaseNotesThread.swift +++ b/SignalServiceKit/Threads/TSReleaseNotesThread.swift @@ -7,7 +7,7 @@ import Foundation /// Represents the Release Notes thread. public final class TSReleaseNotesThread: TSThread { - override public class var recordType: SDSRecordType { .releaseNotesThread } + override public class var recordType: TSThreadType { .releaseNotesThread } @objc public class var releaseNotesUniqueId: String {