diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 81f106c17..287ea28df 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -115,7 +115,7 @@ 7B4EF25A2934743000CB351D /* SessionTableViewTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4EF2592934743000CB351D /* SessionTableViewTitleView.swift */; }; 7B50D64D28AC7CF80086CCEC /* silence.aiff in Resources */ = {isa = PBXBuildFile; fileRef = 7B50D64C28AC7CF80086CCEC /* silence.aiff */; }; 7B5233C42900E90F00F8F375 /* SessionLabelCarouselView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B5233C32900E90F00F8F375 /* SessionLabelCarouselView.swift */; }; - 7B5233C6290636D700F8F375 /* _011_DisappearingMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B5233C5290636D700F8F375 /* _011_DisappearingMessage.swift */; }; + 7B5233C6290636D700F8F375 /* _011_DisappearingMessagesConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B5233C5290636D700F8F375 /* _011_DisappearingMessagesConfiguration.swift */; }; 7B7037432834B81F000DCF35 /* ReactionContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7037422834B81F000DCF35 /* ReactionContainerView.swift */; }; 7B7037452834BCC0000DCF35 /* ReactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7037442834BCC0000DCF35 /* ReactionView.swift */; }; 7B71A98F2925E2A600E54854 /* SessionFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B71A98E2925E2A600E54854 /* SessionFooterView.swift */; }; @@ -1188,7 +1188,7 @@ 7B4EF2592934743000CB351D /* SessionTableViewTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionTableViewTitleView.swift; sourceTree = ""; }; 7B50D64C28AC7CF80086CCEC /* silence.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; path = silence.aiff; sourceTree = ""; }; 7B5233C32900E90F00F8F375 /* SessionLabelCarouselView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionLabelCarouselView.swift; sourceTree = ""; }; - 7B5233C5290636D700F8F375 /* _011_DisappearingMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _011_DisappearingMessage.swift; sourceTree = ""; }; + 7B5233C5290636D700F8F375 /* _011_DisappearingMessagesConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _011_DisappearingMessagesConfiguration.swift; sourceTree = ""; }; 7B7037422834B81F000DCF35 /* ReactionContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionContainerView.swift; sourceTree = ""; }; 7B7037442834BCC0000DCF35 /* ReactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionView.swift; sourceTree = ""; }; 7B71A98E2925E2A600E54854 /* SessionFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionFooterView.swift; sourceTree = ""; }; @@ -3559,7 +3559,7 @@ FD09B7E4288670BB00ED0B66 /* _008_EmojiReacts.swift */, 7BAA7B6528D2DE4700AE1489 /* _009_OpenGroupPermission.swift */, FD7115F128C6CB3900B47552 /* _010_AddThreadIdToFTS.swift */, - 7B5233C5290636D700F8F375 /* _011_DisappearingMessage.swift */, + 7B5233C5290636D700F8F375 /* _011_DisappearingMessagesConfiguration.swift */, ); path = Migrations; sourceTree = ""; @@ -5519,7 +5519,7 @@ FDC4387827B5C35400C60D73 /* SendMessageRequest.swift in Sources */, FDC4381527B329CE00C60D73 /* NonceGenerator.swift in Sources */, 7B93D07027CF194000811CB6 /* ConfigurationMessage+Convenience.swift in Sources */, - 7B5233C6290636D700F8F375 /* _011_DisappearingMessage.swift in Sources */, + 7B5233C6290636D700F8F375 /* _011_DisappearingMessagesConfiguration.swift in Sources */, FD5C72FD284F0EC90029977D /* MessageReceiver+ExpirationTimers.swift in Sources */, C3D9E3BE25676AD70040E4F3 /* (null) in Sources */, C32C5A88256DBCF9003C73A2 /* MessageReceiver+ClosedGroups.swift in Sources */, diff --git a/SessionMessagingKit/Configuration.swift b/SessionMessagingKit/Configuration.swift index eebace01b..e9ffcc274 100644 --- a/SessionMessagingKit/Configuration.swift +++ b/SessionMessagingKit/Configuration.swift @@ -25,7 +25,7 @@ public enum SNMessagingKit { // Just to make the external API nice _008_EmojiReacts.self, _009_OpenGroupPermission.self, _010_AddThreadIdToFTS.self, - _011_DisappearingMessage.self + _011_DisappearingMessagesConfiguration.self ] ] ) diff --git a/SessionMessagingKit/Database/Migrations/_011_DisappearingMessage.swift b/SessionMessagingKit/Database/Migrations/_011_DisappearingMessagesConfiguration.swift similarity index 87% rename from SessionMessagingKit/Database/Migrations/_011_DisappearingMessage.swift rename to SessionMessagingKit/Database/Migrations/_011_DisappearingMessagesConfiguration.swift index c25e7d2e6..d251c3e5e 100644 --- a/SessionMessagingKit/Database/Migrations/_011_DisappearingMessage.swift +++ b/SessionMessagingKit/Database/Migrations/_011_DisappearingMessagesConfiguration.swift @@ -4,9 +4,9 @@ import Foundation import GRDB import SessionUtilitiesKit -enum _011_DisappearingMessage: Migration { +enum _011_DisappearingMessagesConfiguration: Migration { static let target: TargetMigrations.Identifier = .messagingKit - static let identifier: String = "DisappearingMessageType" + static let identifier: String = "DisappearingMessagesWithTypes" static let needsConfigSync: Bool = false static let minExpectedRunDuration: TimeInterval = 0.1 @@ -17,6 +17,11 @@ enum _011_DisappearingMessage: Migration { .defaults(to: 0) } + try db.alter(table: Contact.self) { t in + t.add(.isUsingOutdatedClient, .boolean) + .defaults(to: false) + } + func updateDisappearingMessageType(_ db: GRDB.Database, id: String, type: DisappearingMessagesConfiguration.DisappearingMessageType) throws { _ = try DisappearingMessagesConfiguration .filter(DisappearingMessagesConfiguration.Columns.threadId == id) diff --git a/SessionMessagingKit/Database/Models/Contact.swift b/SessionMessagingKit/Database/Models/Contact.swift index ab85bb808..25cf3feac 100644 --- a/SessionMessagingKit/Database/Models/Contact.swift +++ b/SessionMessagingKit/Database/Models/Contact.swift @@ -16,6 +16,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis case isTrusted case isApproved case isBlocked + case isUsingOutdatedClient case didApproveMe case hasBeenBlocked } @@ -32,6 +33,9 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis /// This flag is used to determine whether message requests from this contact are blocked public let isBlocked: Bool + /// This flag is used to determine whether this contact is using an outdated client regarding disappearing messages configuration + public let isUsingOutdatedClient: Bool + /// This flag is used to determine whether this contact has approved the current users message request public let didApproveMe: Bool @@ -51,6 +55,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis isTrusted: Bool = false, isApproved: Bool = false, isBlocked: Bool = false, + isUsingOutdatedClient: Bool = false, didApproveMe: Bool = false, hasBeenBlocked: Bool = false ) { @@ -61,6 +66,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis ) self.isApproved = isApproved self.isBlocked = isBlocked + self.isUsingOutdatedClient = isUsingOutdatedClient self.didApproveMe = didApproveMe self.hasBeenBlocked = (isBlocked || hasBeenBlocked) } @@ -73,6 +79,7 @@ public extension Contact { isTrusted: Updatable = .existing, isApproved: Updatable = .existing, isBlocked: Updatable = .existing, + isUsingOutdatedClient: Updatable = .existing, didApproveMe: Updatable = .existing ) -> Contact { return Contact( @@ -83,6 +90,7 @@ public extension Contact { ), isApproved: (isApproved ?? self.isApproved), isBlocked: (isBlocked ?? self.isBlocked), + isUsingOutdatedClient: (isUsingOutdatedClient ?? self.isUsingOutdatedClient), didApproveMe: (didApproveMe ?? self.didApproveMe), hasBeenBlocked: ((isBlocked ?? self.isBlocked) || self.hasBeenBlocked) ) diff --git a/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift b/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift index 51ff3aaec..68ff7aa8c 100644 --- a/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift +++ b/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift @@ -21,6 +21,7 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat public static let threadCreationDateTimestampKey: SQL = SQL(stringLiteral: CodingKeys.threadCreationDateTimestamp.stringValue) public static let threadMemberNamesKey: SQL = SQL(stringLiteral: CodingKeys.threadMemberNames.stringValue) public static let threadIsNoteToSelfKey: SQL = SQL(stringLiteral: CodingKeys.threadIsNoteToSelf.stringValue) + public static let contactIsUsingOutdatedClientKey: SQL = SQL(stringLiteral: CodingKeys.contactIsUsingOutdatedClient.stringValue) public static let threadIsMessageRequestKey: SQL = SQL(stringLiteral: CodingKeys.threadIsMessageRequest.stringValue) public static let threadRequiresApprovalKey: SQL = SQL(stringLiteral: CodingKeys.threadRequiresApproval.stringValue) public static let threadShouldBeVisibleKey: SQL = SQL(stringLiteral: CodingKeys.threadShouldBeVisible.stringValue) @@ -85,6 +86,11 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat public let threadIsNoteToSelf: Bool + /// This flag indicated whether the contact in this thread is using an outdated client regarding + /// disappearing messages configuration. We can use this flag in the future for other features + /// as well. + public let contactIsUsingOutdatedClient: Bool + /// This flag indicates whether the thread is an outgoing message request public let threadIsMessageRequest: Bool? @@ -259,6 +265,7 @@ public extension SessionThreadViewModel { self.threadMemberNames = nil self.threadIsNoteToSelf = threadIsNoteToSelf + self.contactIsUsingOutdatedClient = false self.threadIsMessageRequest = false self.threadRequiresApproval = false self.threadShouldBeVisible = false @@ -327,6 +334,7 @@ public extension SessionThreadViewModel { threadCreationDateTimestamp: self.threadCreationDateTimestamp, threadMemberNames: self.threadMemberNames, threadIsNoteToSelf: self.threadIsNoteToSelf, + contactIsUsingOutdatedClient: self.contactIsUsingOutdatedClient, threadIsMessageRequest: self.threadIsMessageRequest, threadRequiresApproval: self.threadRequiresApproval, threadShouldBeVisible: self.threadShouldBeVisible, @@ -383,6 +391,7 @@ public extension SessionThreadViewModel { threadCreationDateTimestamp: self.threadCreationDateTimestamp, threadMemberNames: self.threadMemberNames, threadIsNoteToSelf: self.threadIsNoteToSelf, + contactIsUsingOutdatedClient: self.contactIsUsingOutdatedClient, threadIsMessageRequest: self.threadIsMessageRequest, threadRequiresApproval: self.threadRequiresApproval, threadShouldBeVisible: self.threadShouldBeVisible, @@ -751,6 +760,7 @@ public extension SessionThreadViewModel { \(thread[.creationDateTimestamp]) AS \(ViewModel.threadCreationDateTimestampKey), (\(SQL("\(thread[.id]) = \(userPublicKey)"))) AS \(ViewModel.threadIsNoteToSelfKey), + \(contact[.isUsingOutdatedClient]) AS \(ViewModel.contactIsUsingOutdatedClientKey), ( \(SQL("\(thread[.variant]) = \(SessionThread.Variant.contact)")) AND \(SQL("\(thread[.id]) != \(userPublicKey)")) AND