diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 494261eb4..718cb0e62 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -54,7 +54,6 @@ 4503F1BE20470A5B00CEE724 /* classic-quiet.aifc in Resources */ = {isa = PBXBuildFile; fileRef = 4503F1BB20470A5B00CEE724 /* classic-quiet.aifc */; }; 4503F1BF20470A5B00CEE724 /* classic.aifc in Resources */ = {isa = PBXBuildFile; fileRef = 4503F1BC20470A5B00CEE724 /* classic.aifc */; }; 450DF2091E0DD2C6003D14BE /* UserNotificationsAdaptee.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450DF2081E0DD2C6003D14BE /* UserNotificationsAdaptee.swift */; }; - 451166C01FD86B98000739BA /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451166BF1FD86B98000739BA /* AccountManager.swift */; }; 451A13B11E13DED2000A50FD /* AppNotifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451A13B01E13DED2000A50FD /* AppNotifications.swift */; }; 4520D8D51D417D8E00123472 /* Photos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4520D8D41D417D8E00123472 /* Photos.framework */; }; 4521C3C01F59F3BA00B4C582 /* TextFieldHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4521C3BF1F59F3BA00B4C582 /* TextFieldHelper.swift */; }; @@ -287,16 +286,12 @@ C32C5A88256DBCF9003C73A2 /* MessageReceiver+Handling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32C5A87256DBCF9003C73A2 /* MessageReceiver+Handling.swift */; }; C32C5B48256DC211003C73A2 /* NSNotificationCenter+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB6C255A580F00E217F9 /* NSNotificationCenter+OWS.m */; }; C32C5B51256DC219003C73A2 /* NSNotificationCenter+OWS.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB3B255A580B00E217F9 /* NSNotificationCenter+OWS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C32C5B84256DC54F003C73A2 /* SSKEnvironment.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDAF4255A580600E217F9 /* SSKEnvironment.m */; }; - C32C5B8D256DC565003C73A2 /* SSKEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB31255A580A00E217F9 /* SSKEnvironment.h */; settings = {ATTRIBUTES = (Public, ); }; }; C32C5BCC256DC830003C73A2 /* Storage+ClosedGroups.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8F1372566120F0092EF10 /* Storage+ClosedGroups.swift */; }; C32C5C3D256DCBAF003C73A2 /* AppReadiness.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB75255A581000E217F9 /* AppReadiness.m */; }; C32C5C46256DCBB2003C73A2 /* AppReadiness.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB01255A580700E217F9 /* AppReadiness.h */; settings = {ATTRIBUTES = (Public, ); }; }; C32C5C4F256DCC36003C73A2 /* Storage+OpenGroups.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8F18825661BA50092EF10 /* Storage+OpenGroups.swift */; }; C32C5C88256DD0D2003C73A2 /* Storage+Messaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8F19225661BF80092EF10 /* Storage+Messaging.swift */; }; C32C5C89256DD0D2003C73A2 /* Storage+Jobs.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8F17625661AFA0092EF10 /* Storage+Jobs.swift */; }; - C32C5CA4256DD1DC003C73A2 /* TSAccountManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB88255A581200E217F9 /* TSAccountManager.m */; }; - C32C5CAD256DD1DF003C73A2 /* TSAccountManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB94255A581300E217F9 /* TSAccountManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; C32C5CF0256DD3E4003C73A2 /* Storage+Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F0A5FD255C988A007BE2A3 /* Storage+Shared.swift */; }; C32C5D19256DD493003C73A2 /* LinkPreviewDraft.swift in Sources */ = {isa = PBXBuildFile; fileRef = C33FDBA8255A581500E217F9 /* LinkPreviewDraft.swift */; }; C32C5D83256DD5B6003C73A2 /* SSKKeychainStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C33FDBBC255A581600E217F9 /* SSKKeychainStorage.swift */; }; @@ -410,7 +405,6 @@ C3548F0824456AB6009433A8 /* UIView+Wrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3548F0724456AB6009433A8 /* UIView+Wrapping.swift */; }; C354E75A23FE2A7600CE22E3 /* BaseVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C354E75923FE2A7600CE22E3 /* BaseVC.swift */; }; C35D0DB525AE5F1200B6BF49 /* UIEdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35D0DB425AE5F1200B6BF49 /* UIEdgeInsets.swift */; }; - C35D76DB26606304009AA5FB /* ThreadUpdateBatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35D76DA26606303009AA5FB /* ThreadUpdateBatcher.swift */; }; C35E8AAE2485E51D00ACB629 /* IP2Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35E8AAD2485E51D00ACB629 /* IP2Country.swift */; }; C374EEE225DA26740073A857 /* LinkPreviewModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C374EEE125DA26740073A857 /* LinkPreviewModal.swift */; }; C374EEEB25DA3CA70073A857 /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C374EEEA25DA3CA70073A857 /* ConversationTitleView.swift */; }; @@ -521,10 +515,6 @@ C3A01E07261D24C400290BEB /* storage-seed-3.der in Resources */ = {isa = PBXBuildFile; fileRef = C3A01E04261D24C400290BEB /* storage-seed-3.der */; }; C3A3A08F256E1728004D228D /* FullTextSearchFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB7F255A581100E217F9 /* FullTextSearchFinder.swift */; }; C3A3A0FE256E1A3C004D228D /* TSDatabaseSecondaryIndexes.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB20255A580900E217F9 /* TSDatabaseSecondaryIndexes.m */; }; - C3A3A107256E1A5C004D228D /* OWSDisappearingMessagesFinder.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDA86255A57FC00E217F9 /* OWSDisappearingMessagesFinder.m */; }; - C3A3A108256E1A5C004D228D /* OWSIncomingMessageFinder.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB1E255A580900E217F9 /* OWSIncomingMessageFinder.m */; }; - C3A3A111256E1A93004D228D /* OWSIncomingMessageFinder.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAC0255A580100E217F9 /* OWSIncomingMessageFinder.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C3A3A122256E1A97004D228D /* OWSDisappearingMessagesFinder.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDC05255A581D00E217F9 /* OWSDisappearingMessagesFinder.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3A3A12B256E1AD5004D228D /* TSDatabaseSecondaryIndexes.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB25255A580900E217F9 /* TSDatabaseSecondaryIndexes.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3A3A171256E1D25004D228D /* SSKReachabilityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A3A170256E1D25004D228D /* SSKReachabilityManager.swift */; }; C3A71D0B2558989C0043A11F /* MessageWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A71D0A2558989C0043A11F /* MessageWrapper.swift */; }; @@ -981,7 +971,6 @@ 4503F1BC20470A5B00CEE724 /* classic.aifc */ = {isa = PBXFileReference; lastKnownFileType = file; path = classic.aifc; sourceTree = ""; }; 4509E7991DD653700025A59F /* WebRTC.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebRTC.framework; path = ThirdParty/WebRTC/Build/WebRTC.framework; sourceTree = ""; }; 450DF2081E0DD2C6003D14BE /* UserNotificationsAdaptee.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UserNotificationsAdaptee.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 451166BF1FD86B98000739BA /* AccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountManager.swift; sourceTree = ""; }; 451A13B01E13DED2000A50FD /* AppNotifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppNotifications.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 4520D8D41D417D8E00123472 /* Photos.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Photos.framework; path = System/Library/Frameworks/Photos.framework; sourceTree = SDKROOT; }; 4521C3BF1F59F3BA00B4C582 /* TextFieldHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldHelper.swift; sourceTree = ""; }; @@ -1259,7 +1248,6 @@ C33FDA6F255A57FA00E217F9 /* ReachabilityManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReachabilityManager.swift; sourceTree = ""; }; C33FDA73255A57FA00E217F9 /* ECKeyPair+Hexadecimal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ECKeyPair+Hexadecimal.swift"; sourceTree = ""; }; C33FDA7A255A57FB00E217F9 /* NSRegularExpression+SSK.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSRegularExpression+SSK.swift"; sourceTree = ""; }; - C33FDA86255A57FC00E217F9 /* OWSDisappearingMessagesFinder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDisappearingMessagesFinder.m; sourceTree = ""; }; C33FDA87255A57FC00E217F9 /* TypingIndicators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypingIndicators.swift; sourceTree = ""; }; C33FDA88255A57FD00E217F9 /* YapDatabaseTransaction+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YapDatabaseTransaction+OWS.h"; sourceTree = ""; }; C33FDA8B255A57FD00E217F9 /* AppVersion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppVersion.m; sourceTree = ""; }; @@ -1275,7 +1263,6 @@ C33FDAB8255A580100E217F9 /* NSArray+Functional.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Functional.m"; sourceTree = ""; }; C33FDAB9255A580100E217F9 /* OWSStorage+Subclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "OWSStorage+Subclass.h"; sourceTree = ""; }; C33FDABE255A580100E217F9 /* TSConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSConstants.m; sourceTree = ""; }; - C33FDAC0255A580100E217F9 /* OWSIncomingMessageFinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSIncomingMessageFinder.h; sourceTree = ""; }; C33FDAC1255A580100E217F9 /* NSSet+Functional.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSSet+Functional.m"; sourceTree = ""; }; C33FDAC3255A580200E217F9 /* OWSDispatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDispatch.m; sourceTree = ""; }; C33FDADC255A580400E217F9 /* NSObject+Casting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+Casting.h"; sourceTree = ""; }; @@ -1285,7 +1272,6 @@ C33FDAEF255A580500E217F9 /* NSData+Image.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Image.m"; sourceTree = ""; }; C33FDAF1255A580500E217F9 /* OWSThumbnailService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSThumbnailService.swift; sourceTree = ""; }; C33FDAF2255A580500E217F9 /* ProxiedContentDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxiedContentDownloader.swift; sourceTree = ""; }; - C33FDAF4255A580600E217F9 /* SSKEnvironment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSKEnvironment.m; sourceTree = ""; }; C33FDAFC255A580600E217F9 /* MIMETypeUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIMETypeUtil.h; sourceTree = ""; }; C33FDAFD255A580600E217F9 /* LRUCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LRUCache.swift; sourceTree = ""; }; C33FDAFE255A580600E217F9 /* OWSStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSStorage.h; sourceTree = ""; }; @@ -1296,13 +1282,11 @@ C33FDB14255A580800E217F9 /* OWSMath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMath.h; sourceTree = ""; }; C33FDB17255A580800E217F9 /* FunctionalUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FunctionalUtil.m; sourceTree = ""; }; C33FDB1C255A580900E217F9 /* UIImage+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+OWS.h"; sourceTree = ""; }; - C33FDB1E255A580900E217F9 /* OWSIncomingMessageFinder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSIncomingMessageFinder.m; sourceTree = ""; }; C33FDB20255A580900E217F9 /* TSDatabaseSecondaryIndexes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSDatabaseSecondaryIndexes.m; sourceTree = ""; }; C33FDB22255A580900E217F9 /* OWSMediaUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSMediaUtils.swift; sourceTree = ""; }; C33FDB25255A580900E217F9 /* TSDatabaseSecondaryIndexes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSDatabaseSecondaryIndexes.h; sourceTree = ""; }; C33FDB29255A580A00E217F9 /* NSData+Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Image.h"; sourceTree = ""; }; C33FDB2C255A580A00E217F9 /* TSDatabaseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSDatabaseView.h; sourceTree = ""; }; - C33FDB31255A580A00E217F9 /* SSKEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSKEnvironment.h; sourceTree = ""; }; C33FDB34255A580B00E217F9 /* ClosedGroupPoller.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClosedGroupPoller.swift; sourceTree = ""; }; C33FDB36255A580B00E217F9 /* Storage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = ""; }; C33FDB38255A580B00E217F9 /* OWSBackgroundTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSBackgroundTask.h; sourceTree = ""; }; @@ -1332,10 +1316,8 @@ C33FDB80255A581100E217F9 /* Notification+Loki.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Notification+Loki.swift"; sourceTree = ""; }; C33FDB81255A581100E217F9 /* UIImage+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+OWS.m"; sourceTree = ""; }; C33FDB85255A581100E217F9 /* AppContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppContext.m; sourceTree = ""; }; - C33FDB88255A581200E217F9 /* TSAccountManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSAccountManager.m; sourceTree = ""; }; C33FDB8A255A581200E217F9 /* AppContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppContext.h; sourceTree = ""; }; C33FDB8F255A581200E217F9 /* ParamParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParamParser.swift; sourceTree = ""; }; - C33FDB94255A581300E217F9 /* TSAccountManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSAccountManager.h; sourceTree = ""; }; C33FDBA1255A581400E217F9 /* OWSOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSOperation.h; sourceTree = ""; }; C33FDBA8255A581500E217F9 /* LinkPreviewDraft.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkPreviewDraft.swift; sourceTree = ""; }; C33FDBAB255A581500E217F9 /* OWSFileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSFileSystem.h; sourceTree = ""; }; @@ -1354,7 +1336,6 @@ C33FDBFE255A581C00E217F9 /* NSSet+Functional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSSet+Functional.h"; sourceTree = ""; }; C33FDC02255A581D00E217F9 /* OWSPrimaryStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSPrimaryStorage.m; sourceTree = ""; }; C33FDC03255A581D00E217F9 /* ByteParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ByteParser.h; sourceTree = ""; }; - C33FDC05255A581D00E217F9 /* OWSDisappearingMessagesFinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDisappearingMessagesFinder.h; sourceTree = ""; }; C33FDC0B255A581D00E217F9 /* OWSError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSError.m; sourceTree = ""; }; C33FDC12255A581E00E217F9 /* TSConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSConstants.h; sourceTree = ""; }; C33FDC16255A581E00E217F9 /* FunctionalUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionalUtil.h; sourceTree = ""; }; @@ -1379,7 +1360,6 @@ C3548F0724456AB6009433A8 /* UIView+Wrapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Wrapping.swift"; sourceTree = ""; }; C354E75923FE2A7600CE22E3 /* BaseVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseVC.swift; sourceTree = ""; }; C35D0DB425AE5F1200B6BF49 /* UIEdgeInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIEdgeInsets.swift; sourceTree = ""; }; - C35D76DA26606303009AA5FB /* ThreadUpdateBatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadUpdateBatcher.swift; sourceTree = ""; }; C35E8AA22485C72300ACB629 /* SwiftCSV.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftCSV.framework; path = ThirdParty/Carthage/Build/iOS/SwiftCSV.framework; sourceTree = ""; }; C35E8AAD2485E51D00ACB629 /* IP2Country.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IP2Country.swift; sourceTree = ""; }; C374EEE125DA26740073A857 /* LinkPreviewModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewModal.swift; sourceTree = ""; }; @@ -1946,7 +1926,6 @@ 76EB03C118170B33006006FC /* Utilities */ = { isa = PBXGroup; children = ( - 451166BF1FD86B98000739BA /* AccountManager.swift */, 4C090A1A210FD9C7001FD7F9 /* HapticFeedback.swift */, 34D5CCA71EAE3D30005515DB /* AvatarViewHelper.h */, 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */, @@ -2485,15 +2464,6 @@ path = Quotes; sourceTree = ""; }; - C32C5BB9256DC7C4003C73A2 /* To Do */ = { - isa = PBXGroup; - children = ( - C33FDB94255A581300E217F9 /* TSAccountManager.h */, - C33FDB88255A581200E217F9 /* TSAccountManager.m */, - ); - path = "To Do"; - sourceTree = ""; - }; C32C5BCB256DC818003C73A2 /* Database */ = { isa = PBXGroup; children = ( @@ -2960,10 +2930,6 @@ C38EF281255B6D84007E1867 /* OWSAudioSession.swift */, C33FDB38255A580B00E217F9 /* OWSBackgroundTask.h */, C33FDC1B255A581F00E217F9 /* OWSBackgroundTask.m */, - C33FDC05255A581D00E217F9 /* OWSDisappearingMessagesFinder.h */, - C33FDA86255A57FC00E217F9 /* OWSDisappearingMessagesFinder.m */, - C33FDAC0255A580100E217F9 /* OWSIncomingMessageFinder.h */, - C33FDB1E255A580900E217F9 /* OWSIncomingMessageFinder.m */, C38EF2F1255B6DBB007E1867 /* OWSPreferences.h */, C38EF308255B6DBE007E1867 /* OWSPreferences.m */, FDF0B75D280AAF35004C14C5 /* Preferences.swift */, @@ -2974,12 +2940,9 @@ C38EF2EC255B6DBA007E1867 /* ProximityMonitoringManager.swift */, C3BBE0B42554F0E10050F1E3 /* ProofOfWork.swift */, C38EEF09255B49A8007E1867 /* SNProtoEnvelope+Conversion.swift */, - C33FDB31255A580A00E217F9 /* SSKEnvironment.h */, - C33FDAF4255A580600E217F9 /* SSKEnvironment.m */, FDF0B7542807C4BB004C14C5 /* SSKEnvironment.swift */, C3A3A170256E1D25004D228D /* SSKReachabilityManager.swift */, C3ECBF7A257056B700EA7FCE /* Threading.swift */, - C35D76DA26606303009AA5FB /* ThreadUpdateBatcher.swift */, C33FDB5F255A580E00E217F9 /* YapDatabaseConnection+OWS.h */, C33FDB43255A580C00E217F9 /* YapDatabaseConnection+OWS.m */, C33FDA88255A57FD00E217F9 /* YapDatabaseTransaction+OWS.h */, @@ -3060,7 +3023,6 @@ children = ( C3C2A7802553AA6300C340D1 /* Protos */, C3C2A70A25539DF900C340D1 /* Meta */, - C32C5BB9256DC7C4003C73A2 /* To Do */, C3BBE07F2554CDD70050F1E3 /* Storage.swift */, C32C5BCB256DC818003C73A2 /* Database */, C300A5BB2554AFFB00555489 /* Messages */, @@ -3672,11 +3634,9 @@ buildActionMask = 2147483647; files = ( C32C5EE5256DF506003C73A2 /* YapDatabaseConnection+OWS.h in Headers */, - C32C5B8D256DC565003C73A2 /* SSKEnvironment.h in Headers */, C3C2A6F425539DE700C340D1 /* SessionMessagingKit.h in Headers */, C32C5C46256DCBB2003C73A2 /* AppReadiness.h in Headers */, B8856CB1256F0F47001CE70E /* OWSBackupFragment.h in Headers */, - C3A3A122256E1A97004D228D /* OWSDisappearingMessagesFinder.h in Headers */, C3A3A12B256E1AD5004D228D /* TSDatabaseSecondaryIndexes.h in Headers */, C32C5FC4256E0209003C73A2 /* OWSBackgroundTask.h in Headers */, C32C5EF7256DF567003C73A2 /* TSDatabaseView.h in Headers */, @@ -3686,9 +3646,7 @@ B8856CF7256F105E001CE70E /* OWSAudioPlayer.h in Headers */, B8856D3D256F11B2001CE70E /* Environment.h in Headers */, C32C5E7E256DE023003C73A2 /* YapDatabaseTransaction+OWS.h in Headers */, - C32C5CAD256DD1DF003C73A2 /* TSAccountManager.h in Headers */, C32C5EA0256DE0D6003C73A2 /* OWSPrimaryStorage.h in Headers */, - C3A3A111256E1A93004D228D /* OWSIncomingMessageFinder.h in Headers */, B8856E33256F18D5001CE70E /* OWSStorage+Subclass.h in Headers */, C32C5E64256DDFD6003C73A2 /* OWSStorage.h in Headers */, ); @@ -4636,8 +4594,6 @@ FDD250702837199200198BDA /* GarbageCollectionJob.swift in Sources */, C32A026325A801AA000ED5D4 /* NSData+messagePadding.m in Sources */, FD6A7A6B2818C17C00035AC1 /* UpdateProfilePictureJob.swift in Sources */, - C32C5B84256DC54F003C73A2 /* SSKEnvironment.m in Sources */, - C3A3A108256E1A5C004D228D /* OWSIncomingMessageFinder.m in Sources */, C352A31325574F5200338F3E /* MessageReceiveJob.swift in Sources */, C3C2A7562553A3AB00C340D1 /* VisibleMessage+Quote.swift in Sources */, C3227FF6260AAD66006EA627 /* OpenGroupMessageV2.swift in Sources */, @@ -4648,7 +4604,6 @@ C32C5A76256DBBCF003C73A2 /* SignalAttachment.swift in Sources */, FDA8EB00280E8D58002B68E5 /* FailedAttachmentDownloadsJob.swift in Sources */, FD09798927FD1C5A00936362 /* OpenGroup.swift in Sources */, - C32C5CA4256DD1DC003C73A2 /* TSAccountManager.m in Sources */, C3BBE0B52554F0E10050F1E3 /* ProofOfWork.swift in Sources */, C3A3A08F256E1728004D228D /* FullTextSearchFinder.swift in Sources */, FDF0B7472804F0CE004C14C5 /* DisappearingMessagesJob.swift in Sources */, @@ -4666,7 +4621,6 @@ FD09798327FD1A1500936362 /* ClosedGroup.swift in Sources */, B8856D34256F1192001CE70E /* Environment.m in Sources */, B8B320B7258C30D70020074B /* HTMLMetadata.swift in Sources */, - C3A3A107256E1A5C004D228D /* OWSDisappearingMessagesFinder.m in Sources */, FD09798727FD1B7800936362 /* GroupMember.swift in Sources */, FD09799127FD499200936362 /* BoxKeyPair+Utilities.swift in Sources */, FDB4BBC92839BEF000B7C95D /* ProfileManagerError.swift in Sources */, @@ -4703,7 +4657,6 @@ FDF0B75A2807F3A3004C14C5 /* MessageSenderError.swift in Sources */, C32C5EDC256DF501003C73A2 /* YapDatabaseConnection+OWS.m in Sources */, C3BBE0762554CDA60050F1E3 /* Configuration.swift in Sources */, - C35D76DB26606304009AA5FB /* ThreadUpdateBatcher.swift in Sources */, B8856D69256F141F001CE70E /* OWSWindowManager.m in Sources */, C3ECBF7B257056B700EA7FCE /* Threading.swift in Sources */, C32C5A88256DBCF9003C73A2 /* MessageReceiver+Handling.swift in Sources */, @@ -4782,7 +4735,6 @@ B84A89BC25DE328A0040017D /* ProfilePictureVC.swift in Sources */, 34386A54207D271D009F5D9C /* NeverClearView.swift in Sources */, FDCDB8E02811007F00352A0C /* HomeViewModel.swift in Sources */, - 451166C01FD86B98000739BA /* AccountManager.swift in Sources */, C374EEF425DB31D40073A857 /* VoiceMessageRecordingView.swift in Sources */, B83F2B88240CB75A000A54AB /* UIImage+Scaling.swift in Sources */, 3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */, diff --git a/Session/Conversations/ConversationViewItem.m b/Session/Conversations/ConversationViewItem.m index 5be802798..102803dfc 100644 --- a/Session/Conversations/ConversationViewItem.m +++ b/Session/Conversations/ConversationViewItem.m @@ -6,11 +6,8 @@ #import "ConversationViewItem.h" #import "Session-Swift.h" #import "AnyPromise.h" -#import #import #import -#import -#import #import NS_ASSUME_NONNULL_BEGIN diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 47d2e3805..c8bfee916 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -67,24 +67,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // Setup the UI self?.ensureRootViewController() - - // Every time the user upgrades to a new version: - // - // * Update account attributes. - // * Sync configuration. if Identity.userExists() { - // TODO: This -// AppVersion *appVersion = AppVersion.sharedInstance; -// if (appVersion.lastAppVersion.length > 0 -// && ![appVersion.lastAppVersion isEqualToString:appVersion.currentAppVersion]) { -// [[self.tsAccountManager updateAccountAttributes] retainUntilComplete]; -// } - } - - // If we need a config sync then trigger it now - if (needsConfigSync) { - GRDBStorage.shared.write { db in - try MessageSender.syncConfiguration(db, forceSyncNow: true).retainUntilComplete() + let appVersion: AppVersion = AppVersion.sharedInstance() + + // If the device needs to sync config or the user updated to a new version + if + needsConfigSync || ( // TODO: 'needsConfigSync' logic for migrations + (appVersion.lastAppVersion?.count ?? 0) > 0 && + appVersion.lastAppVersion != appVersion.currentAppVersion + ) + { + GRDBStorage.shared.write { db in + try MessageSender.syncConfiguration(db, forceSyncNow: true).retainUntilComplete() + } } } } diff --git a/Session/Meta/AppEnvironment.swift b/Session/Meta/AppEnvironment.swift index f6226f557..f2fa40af4 100644 --- a/Session/Meta/AppEnvironment.swift +++ b/Session/Meta/AppEnvironment.swift @@ -25,9 +25,6 @@ import SignalUtilitiesKit } } - @objc - public var accountManager: AccountManager - @objc public var notificationPresenter: NotificationPresenter @@ -47,7 +44,6 @@ import SignalUtilitiesKit } private override init() { - self.accountManager = AccountManager() self.notificationPresenter = NotificationPresenter() self.pushRegistrationManager = PushRegistrationManager() self._userNotificationActionHandler = UserNotificationActionHandler() diff --git a/Session/Meta/Signal-Bridging-Header.h b/Session/Meta/Signal-Bridging-Header.h index f5f701a8b..42da6bcad 100644 --- a/Session/Meta/Signal-Bridging-Header.h +++ b/Session/Meta/Signal-Bridging-Header.h @@ -56,7 +56,6 @@ #import #import #import -#import #import #import #import diff --git a/Session/Notifications/SyncPushTokensJob.swift b/Session/Notifications/SyncPushTokensJob.swift index 85e276feb..fbcfd8657 100644 --- a/Session/Notifications/SyncPushTokensJob.swift +++ b/Session/Notifications/SyncPushTokensJob.swift @@ -50,8 +50,8 @@ public enum SyncPushTokensJob: JobExecutor { PushRegistrationManager.shared.requestPushTokens() .then { (pushToken: String, voipToken: String) -> Promise in - let lastPushToken: String? = GRDBStorage.shared.read { db in db[.lastRecordedPushToken] } - let lastVoipToken: String? = GRDBStorage.shared.read { db in db[.lastRecordedVoipToken] } + let lastPushToken: String? = GRDBStorage.shared[.lastRecordedPushToken] + let lastVoipToken: String? = GRDBStorage.shared[.lastRecordedVoipToken] let shouldUploadTokens: Bool = ( !uploadOnlyIfStale || ( lastPushToken != pushToken || @@ -64,14 +64,13 @@ public enum SyncPushTokensJob: JobExecutor { let (promise, seal) = Promise.pending() - SSKEnvironment.shared.tsAccountManager - .registerForPushNotifications( - pushToken: pushToken, - voipToken: voipToken, - isForcedUpdate: shouldUploadTokens, - success: { seal.fulfill(()) }, - failure: seal.reject - ) + SyncPushTokensJob.registerForPushNotifications( + pushToken: pushToken, + voipToken: voipToken, + isForcedUpdate: shouldUploadTokens, + success: { seal.fulfill(()) }, + failure: seal.reject + ) return promise .done { _ in @@ -119,6 +118,46 @@ private func redact(_ string: String) -> String { return OWSIsDebugBuild() ? string : "[ READACTED \(string.prefix(2))...\(string.suffix(2)) ]" } +extension SyncPushTokensJob { + fileprivate static func registerForPushNotifications( + pushToken: String, + voipToken: String, + isForcedUpdate: Bool, + success: @escaping () -> (), + failure: @escaping (Error) -> (), + remainingRetries: Int = 3 + ) { + let isUsingFullAPNs: Bool = UserDefaults.standard[.isUsingFullAPNs] + let pushTokenAsData = Data(hex: pushToken) + let promise: Promise = (isUsingFullAPNs ? + PushNotificationAPI.register( + with: pushTokenAsData, + publicKey: getUserHexEncodedPublicKey(), + isForcedUpdate: isForcedUpdate + ) : + PushNotificationAPI.unregister(pushTokenAsData) + ) + + promise + .done { success() } + .catch { error in + guard remainingRetries == 0 else { + SyncPushTokensJob.registerForPushNotifications( + pushToken: pushToken, + voipToken: voipToken, + isForcedUpdate: isForcedUpdate, + success: success, + failure: failure, + remainingRetries: (remainingRetries - 1) + ) + return + } + + failure(error) + } + } +} + // MARK: - Objective C Support @objc(OWSSyncPushTokensJob) diff --git a/Session/Onboarding/LinkDeviceVC.swift b/Session/Onboarding/LinkDeviceVC.swift index 9c5edaeae..14d4a4f3b 100644 --- a/Session/Onboarding/LinkDeviceVC.swift +++ b/Session/Onboarding/LinkDeviceVC.swift @@ -136,7 +136,7 @@ final class LinkDeviceVC : BaseVC, UIPageViewControllerDataSource, UIPageViewCon } let (ed25519KeyPair, x25519KeyPair) = try! Identity.generate(from: seed) Onboarding.Flow.link.preregister(with: seed, ed25519KeyPair: ed25519KeyPair, x25519KeyPair: x25519KeyPair) - TSAccountManager.sharedInstance().didRegister() + Identity.didRegister() NotificationCenter.default.addObserver(self, selector: #selector(handleInitialConfigurationMessageReceived), name: .initialConfigurationMessageReceived, object: nil) ModalActivityIndicatorViewController.present(fromViewController: navigationController!) { [weak self] modal in self?.activityIndicatorModal = modal @@ -144,8 +144,6 @@ final class LinkDeviceVC : BaseVC, UIPageViewControllerDataSource, UIPageViewCon } @objc private func handleInitialConfigurationMessageReceived(_ notification: Notification) { - TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = getUserHexEncodedPublicKey() - DispatchQueue.main.async { self.navigationController!.dismiss(animated: true) { let pnModeVC = PNModeVC() diff --git a/Session/Onboarding/Onboarding.swift b/Session/Onboarding/Onboarding.swift index f8772252f..aad20b279 100644 --- a/Session/Onboarding/Onboarding.swift +++ b/Session/Onboarding/Onboarding.swift @@ -16,7 +16,7 @@ enum Onboarding { let userDefaults = UserDefaults.standard Identity.store(seed: seed, ed25519KeyPair: ed25519KeyPair, x25519KeyPair: x25519KeyPair) let x25519PublicKey = x25519KeyPair.hexEncodedPublicKey - TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = x25519PublicKey + GRDBStorage.shared.write { db in try Contact(id: x25519PublicKey) .with( diff --git a/Session/Onboarding/PNModeVC.swift b/Session/Onboarding/PNModeVC.swift index 371701e02..833520bbe 100644 --- a/Session/Onboarding/PNModeVC.swift +++ b/Session/Onboarding/PNModeVC.swift @@ -1,4 +1,6 @@ +import UIKit import PromiseKit +import SessionMessagingKit final class PNModeVC : BaseVC, OptionViewDelegate { @@ -94,7 +96,7 @@ final class PNModeVC : BaseVC, OptionViewDelegate { return present(alert, animated: true, completion: nil) } UserDefaults.standard[.isUsingFullAPNs] = (selectedOptionView == apnsOptionView) - TSAccountManager.sharedInstance().didRegister() + Identity.didRegister() let homeVC = HomeVC() navigationController!.setViewControllers([ homeVC ], animated: true) diff --git a/Session/Utilities/AccountManager.swift b/Session/Utilities/AccountManager.swift deleted file mode 100644 index 3f08a5da0..000000000 --- a/Session/Utilities/AccountManager.swift +++ /dev/null @@ -1,130 +0,0 @@ -// -// Copyright (c) 2019 Open Whisper Systems. All rights reserved. -// - -import Foundation -import PromiseKit -import SignalUtilitiesKit - -/** - * Signal is actually two services - textSecure for messages and red phone (for calls). - * AccountManager delegates to both. - */ -@objc -public class AccountManager: NSObject { - - // MARK: - Dependencies - - private var preferences: OWSPreferences { - return Environment.shared.preferences - } - - private var tsAccountManager: TSAccountManager { - return TSAccountManager.sharedInstance() - } - - // MARK: - - - @objc - public override init() { - super.init() - - SwiftSingletons.register(self) - } - - // MARK: registration - - @objc func registerObjc(verificationCode: String, - pin: String?) -> AnyPromise { - return AnyPromise(register(verificationCode: verificationCode, pin: pin)) - } - - func register(verificationCode: String, - pin: String?) -> Promise { - guard verificationCode.count > 0 else { - let error = OWSErrorWithCodeDescription(.userError, - NSLocalizedString("REGISTRATION_ERROR_BLANK_VERIFICATION_CODE", - comment: "alert body during registration")) - return Promise(error: error) - } - - Logger.debug("registering with signal server") - let registrationPromise: Promise = firstly { - return self.registerForTextSecure(verificationCode: verificationCode, pin: pin) - }.then { _ -> Promise in - return self.syncPushTokens().recover { (error) -> Promise in - switch error { - case PushRegistrationError.pushNotSupported(let description): - // This can happen with: - // - simulators, none of which support receiving push notifications - // - on iOS11 devices which have disabled "Allow Notifications" and disabled "Enable Background Refresh" in the system settings. - Logger.info("Recovered push registration error. Registering for manual message fetcher because push not supported: \(description)") - return self.enableManualMessageFetching() - default: - throw error - } - } - }.done { (_) -> Void in - self.completeRegistration() - } - - registrationPromise.retainUntilComplete() - - return registrationPromise - } - - private func registerForTextSecure(verificationCode: String, - pin: String?) -> Promise { - return Promise { resolver in - tsAccountManager.verifyAccount(withCode: verificationCode, - pin: pin, - success: { resolver.fulfill(()) }, - failure: resolver.reject) - } - } - - private func syncPushTokens() -> Promise { - Logger.info("") - - guard let job: Job = Job( - variant: .syncPushTokens, - details: SyncPushTokensJob.Details( - uploadOnlyIfStale: false - ) - ) - else { return Promise(error: GRDBStorageError.decodingFailed) } - - let (promise, seal) = Promise.pending() - - SyncPushTokensJob.run( - job, - success: { _, _ in seal.fulfill(()) }, - failure: { _, error, _ in seal.reject(error ?? GRDBStorageError.generic) }, - deferred: { _ in seal.reject(GRDBStorageError.generic) } - ) - - return promise - } - - private func completeRegistration() { - Logger.info("") - tsAccountManager.didRegister() - } - - // MARK: Message Delivery - - func updatePushTokens(pushToken: String, voipToken: String, isForcedUpdate: Bool) -> Promise { - return Promise { resolver in - tsAccountManager.registerForPushNotifications(pushToken: pushToken, - voipToken: voipToken, - isForcedUpdate: isForcedUpdate, - success: { resolver.fulfill(()) }, - failure: resolver.reject) - } - } - - func enableManualMessageFetching() -> Promise { - let anyPromise = tsAccountManager.setIsManualMessageFetchEnabled(true) - return Promise(anyPromise).asVoid() - } -} diff --git a/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift b/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift index b809c947d..042b6190f 100644 --- a/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift +++ b/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift @@ -64,7 +64,7 @@ public extension DisappearingMessagesConfiguration { var previewText: String { guard let senderName: String = senderName else { - // Changed by localNumber on this device or via synced transcript + // Changed by this device or via synced transcript guard isEnabled, durationSeconds > 0 else { return "YOU_DISABLED_DISAPPEARING_MESSAGES_CONFIGURATION".localized() } return String( diff --git a/SessionMessagingKit/Database/OWSPrimaryStorage.m b/SessionMessagingKit/Database/OWSPrimaryStorage.m index df54ae71e..fd1cc007e 100644 --- a/SessionMessagingKit/Database/OWSPrimaryStorage.m +++ b/SessionMessagingKit/Database/OWSPrimaryStorage.m @@ -5,11 +5,9 @@ #import "OWSPrimaryStorage.h" #import "AppContext.h" #import "OWSFileSystem.h" -#import "OWSIncomingMessageFinder.h" #import #import "OWSStorage.h" #import "OWSStorage+Subclass.h" -#import "SSKEnvironment.h" #import "TSDatabaseSecondaryIndexes.h" #import "TSDatabaseView.h" #import @@ -173,8 +171,6 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage) [TSDatabaseView asyncRegisterThreadOutgoingMessagesDatabaseView:self]; [FullTextSearchFinder asyncRegisterDatabaseExtensionWithStorage:self]; - [OWSIncomingMessageFinder asyncRegisterExtensionWithPrimaryStorage:self]; - [OWSDisappearingMessagesFinder asyncRegisterDatabaseExtensions:self]; [TSDatabaseView asyncRegisterLazyRestoreAttachmentsDatabaseView:self]; [self.database diff --git a/SessionMessagingKit/Meta/SessionMessagingKit.h b/SessionMessagingKit/Meta/SessionMessagingKit.h index 12dc61212..262399fb4 100644 --- a/SessionMessagingKit/Meta/SessionMessagingKit.h +++ b/SessionMessagingKit/Meta/SessionMessagingKit.h @@ -9,14 +9,11 @@ FOUNDATION_EXPORT const unsigned char SessionMessagingKitVersionString[]; #import #import #import -#import #import #import #import #import #import -#import -#import #import #import #import diff --git a/SessionMessagingKit/To Do/TSAccountManager.h b/SessionMessagingKit/To Do/TSAccountManager.h deleted file mode 100644 index 9c6013bf9..000000000 --- a/SessionMessagingKit/To Do/TSAccountManager.h +++ /dev/null @@ -1,167 +0,0 @@ -// -// Copyright (c) 2019 Open Whisper Systems. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -extern NSString *const TSRegistrationErrorDomain; -extern NSString *const TSRegistrationErrorUserInfoHTTPStatus; -extern NSString *const RegistrationStateDidChangeNotification; -extern NSString *const kNSNotificationName_LocalNumberDidChange; - -@class AnyPromise; -@class OWSPrimaryStorage; -@class TSNetworkManager; -@class YapDatabaseReadTransaction; -@class YapDatabaseReadWriteTransaction; - -typedef NS_ENUM(NSUInteger, OWSRegistrationState) { - OWSRegistrationState_Unregistered, - OWSRegistrationState_PendingBackupRestore, - OWSRegistrationState_Registered, - OWSRegistrationState_Deregistered, - OWSRegistrationState_Reregistering, -}; - -@interface TSAccountManager : NSObject - -@property (nonatomic, nullable) NSString *phoneNumberAwaitingVerification; - -#pragma mark - Initializers - -- (instancetype)init NS_UNAVAILABLE; - -- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER; - -+ (instancetype)sharedInstance; - -- (OWSRegistrationState)registrationState; - -/** - * Returns if a user is registered or not - * - * @return registered or not - */ -- (BOOL)isRegistered; -- (BOOL)isRegisteredAndReady; - -/** - * Returns current phone number for this device, which may not yet have been registered. - * - * @return E164 formatted phone number - */ -+ (nullable NSString *)localNumber; -- (nullable NSString *)localNumber; - -// A variant of localNumber that never opens a "sneaky" transaction. -- (nullable NSString *)storedOrCachedLocalNumber:(YapDatabaseReadTransaction *)transaction; - -/** - * Symmetric key that's used to encrypt message payloads from the server, - * - * @return signaling key - */ -+ (nullable NSString *)signalingKey; -- (nullable NSString *)signalingKey; - -/** - * The server auth token allows the Signal client to connect to the Signal server - * - * @return server authentication token - */ -+ (nullable NSString *)serverAuthToken; -- (nullable NSString *)serverAuthToken; - -/** - * The registration ID is unique to an installation of TextSecure, it allows to know if the app was reinstalled - * - * @return registrationID; - */ - -+ (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction; -- (uint32_t)getOrGenerateRegistrationId; -- (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction; - -#pragma mark - Register with phone number - -- (void)registerWithPhoneNumber:(NSString *)phoneNumber - captchaToken:(nullable NSString *)captchaToken - success:(void (^)(void))successBlock - failure:(void (^)(NSError *error))failureBlock - smsVerification:(BOOL)isSMS; - -- (void)rerequestSMSWithCaptchaToken:(nullable NSString *)captchaToken - success:(void (^)(void))successBlock - failure:(void (^)(NSError *error))failureBlock; - -- (void)rerequestVoiceWithCaptchaToken:(nullable NSString *)captchaToken - success:(void (^)(void))successBlock - failure:(void (^)(NSError *error))failureBlock; - -- (void)verifyAccountWithCode:(NSString *)verificationCode - pin:(nullable NSString *)pin - success:(void (^)(void))successBlock - failure:(void (^)(NSError *error))failureBlock; - -// Called once registration is complete - meaning the following have succeeded: -// - obtained signal server credentials -// - uploaded pre-keys -// - uploaded push tokens -- (void)didRegister; - -#if TARGET_OS_IPHONE - -/** - * Register's the device's push notification token with the server - * - * @param pushToken Apple's Push Token - */ -- (void)registerForPushNotificationsWithPushToken:(NSString *)pushToken - voipToken:(NSString *)voipToken - isForcedUpdate:(BOOL)isForcedUpdate - success:(void (^)(void))successHandler - failure:(void (^)(NSError *error))failureHandler - NS_SWIFT_NAME(registerForPushNotifications(pushToken:voipToken:isForcedUpdate:success:failure:)); - -#endif - -+ (void)unregisterTextSecureWithSuccess:(void (^)(void))success failure:(void (^)(NSError *error))failureBlock; - -#pragma mark - De-Registration - -// De-registration reflects whether or not the "last known contact" -// with the service was: -// -// * A 403 from the service, indicating de-registration. -// * A successful auth'd request _or_ websocket connection indicating -// valid registration. -- (BOOL)isDeregistered; -- (void)setIsDeregistered:(BOOL)isDeregistered; - -#pragma mark - Re-registration - -// Re-registration is the process of re-registering _with the same phone number_. - -// Returns YES on success. -- (nullable NSString *)reregisterationPhoneNumber; -- (BOOL)isReregistering; - -#pragma mark - Manual Message Fetch - -- (BOOL)isManualMessageFetchEnabled; -- (AnyPromise *)setIsManualMessageFetchEnabled:(BOOL)value __attribute__((warn_unused_result)); - -#ifdef DEBUG -- (void)registerForTestsWithLocalNumber:(NSString *)localNumber; -#endif - -- (AnyPromise *)updateAccountAttributes __attribute__((warn_unused_result)); - -// This should only be used during the registration process. -- (AnyPromise *)performUpdateAccountAttributes __attribute__((warn_unused_result)); - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/To Do/TSAccountManager.m b/SessionMessagingKit/To Do/TSAccountManager.m deleted file mode 100644 index c74e356c0..000000000 --- a/SessionMessagingKit/To Do/TSAccountManager.m +++ /dev/null @@ -1,499 +0,0 @@ -// -// Copyright (c) 2019 Open Whisper Systems. All rights reserved. -// - -#import "TSAccountManager.h" -#import "AppContext.h" -#import "AppReadiness.h" -#import "NSNotificationCenter+OWS.h" -#import "SSKEnvironment.h" -#import "YapDatabaseConnection+OWS.h" -#import "YapDatabaseTransaction+OWS.h" -#import -#import -#import -#import -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -NSString *const TSRegistrationErrorDomain = @"TSRegistrationErrorDomain"; -NSString *const TSRegistrationErrorUserInfoHTTPStatus = @"TSHTTPStatus"; -NSString *const RegistrationStateDidChangeNotification = @"RegistrationStateDidChangeNotification"; -NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName_LocalNumberDidChange"; - -NSString *const TSAccountManager_RegisteredNumberKey = @"TSStorageRegisteredNumberKey"; -NSString *const TSAccountManager_IsDeregisteredKey = @"TSAccountManager_IsDeregisteredKey"; -NSString *const TSAccountManager_ReregisteringPhoneNumberKey = @"TSAccountManager_ReregisteringPhoneNumberKey"; -NSString *const TSAccountManager_LocalRegistrationIdKey = @"TSStorageLocalRegistrationId"; -NSString *const TSAccountManager_HasPendingRestoreDecisionKey = @"TSAccountManager_HasPendingRestoreDecisionKey"; - -NSString *const TSAccountManager_UserAccountCollection = @"TSStorageUserAccountCollection"; -NSString *const TSAccountManager_ServerAuthToken = @"TSStorageServerAuthToken"; -NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignalingKey"; -NSString *const TSAccountManager_ManualMessageFetchKey = @"TSAccountManager_ManualMessageFetchKey"; -NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountManager_NeedsAccountAttributesUpdateKey"; - -@interface TSAccountManager () - -@property (atomic, readonly) BOOL isRegistered; - -@property (nonatomic, nullable) NSString *cachedLocalNumber; -@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; - -@property (nonatomic, nullable) NSNumber *cachedIsDeregistered; - -@property (nonatomic) Reachability *reachability; - -@end - -#pragma mark - - -@implementation TSAccountManager - -@synthesize isRegistered = _isRegistered; - -- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage -{ - self = [super init]; - if (!self) { - return self; - } - - _dbConnection = [primaryStorage newDatabaseConnection]; - self.reachability = [Reachability reachabilityForInternetConnection]; - - if (!CurrentAppContext().isMainApp) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(yapDatabaseModifiedExternally:) - name:YapDatabaseModifiedExternallyNotification - object:nil]; - } - - [AppReadiness runNowOrWhenAppDidBecomeReady:^{ - [[self updateAccountAttributesIfNecessary] retainUntilComplete]; - }]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(reachabilityChanged) - name:kReachabilityChangedNotification - object:nil]; - - return self; -} - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -+ (instancetype)sharedInstance -{ - return SSKEnvironment.shared.tsAccountManager; -} - -#pragma mark - Dependencies - -- (id)profileManager { - return SSKEnvironment.shared.profileManager; -} - -#pragma mark - - -- (void)setPhoneNumberAwaitingVerification:(NSString *_Nullable)phoneNumberAwaitingVerification -{ - _phoneNumberAwaitingVerification = phoneNumberAwaitingVerification; - - [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_LocalNumberDidChange - object:nil - userInfo:nil]; -} - -- (OWSRegistrationState)registrationState -{ - if (!self.isRegistered) { - return OWSRegistrationState_Unregistered; - } else if (self.isDeregistered) { - if (self.isReregistering) { - return OWSRegistrationState_Reregistering; - } else { - return OWSRegistrationState_Deregistered; - } - } else if (self.isDeregistered) { - return OWSRegistrationState_PendingBackupRestore; - } else { - return OWSRegistrationState_Registered; - } -} - -- (BOOL)isRegistered -{ - @synchronized (self) { - if (_isRegistered) { - return YES; - } else { - // Cache this once it's true since it's called alot, involves a dbLookup, and once set - it doesn't change. - _isRegistered = [self storedLocalNumber] != nil; - } - return _isRegistered; - } -} - -- (BOOL)isRegisteredAndReady -{ - return self.registrationState == OWSRegistrationState_Registered; -} - -- (void)didRegister -{ - NSString *phoneNumber = self.phoneNumberAwaitingVerification; - - [self storeLocalNumber:phoneNumber]; - - // Warm these cached values. - [self isRegistered]; - [self localNumber]; - [self isDeregistered]; - - [self postRegistrationStateDidChangeNotification]; -} - -+ (nullable NSString *)localNumber -{ - return [[self sharedInstance] localNumber]; -} - -- (nullable NSString *)localNumber -{ - NSString *awaitingVerif = self.phoneNumberAwaitingVerification; - if (awaitingVerif) { - return awaitingVerif; - } - - // Cache this since we access this a lot, and once set it will not change. - @synchronized(self) - { - if (self.cachedLocalNumber == nil) { - self.cachedLocalNumber = self.storedLocalNumber; - } - } - - return self.cachedLocalNumber; -} - -- (nullable NSString *)storedLocalNumber -{ - @synchronized (self) { - return [self.dbConnection stringForKey:TSAccountManager_RegisteredNumberKey - inCollection:TSAccountManager_UserAccountCollection]; - } -} - -- (nullable NSString *)storedOrCachedLocalNumber:(YapDatabaseReadTransaction *)transaction -{ - @synchronized(self) { - if (self.cachedLocalNumber) { - return self.cachedLocalNumber; - } - } - - return [transaction stringForKey:TSAccountManager_RegisteredNumberKey - inCollection:TSAccountManager_UserAccountCollection]; -} - -- (void)storeLocalNumber:(NSString *)localNumber -{ - @synchronized (self) { - [self.dbConnection setObject:localNumber - forKey:TSAccountManager_RegisteredNumberKey - inCollection:TSAccountManager_UserAccountCollection]; - - [self.dbConnection removeObjectForKey:TSAccountManager_ReregisteringPhoneNumberKey - inCollection:TSAccountManager_UserAccountCollection]; - - self.phoneNumberAwaitingVerification = nil; - - self.cachedLocalNumber = localNumber; - } -} - -+ (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction -{ - return [[self sharedInstance] getOrGenerateRegistrationId:transaction]; -} - -- (uint32_t)getOrGenerateRegistrationId -{ - __block uint32_t result; - [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { - result = [self getOrGenerateRegistrationId:transaction]; - }]; - return result; -} - -- (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction -{ - // Unlike other methods in this class, there's no need for a `@synchronized` block - // here, since we're already in a write transaction, and all writes occur on a serial queue. - // - // Since other code in this class which uses @synchronized(self) also needs to open write - // transaction, using @synchronized(self) here, inside of a WriteTransaction risks deadlock. - uint32_t registrationID = [[transaction objectForKey:TSAccountManager_LocalRegistrationIdKey - inCollection:TSAccountManager_UserAccountCollection] unsignedIntValue]; - - if (registrationID == 0) { - registrationID = (uint32_t)arc4random_uniform(16380) + 1; - - [transaction setObject:[NSNumber numberWithUnsignedInteger:registrationID] - forKey:TSAccountManager_LocalRegistrationIdKey - inCollection:TSAccountManager_UserAccountCollection]; - } - return registrationID; -} - -- (void)registerForPushNotificationsWithPushToken:(NSString *)pushToken - voipToken:(NSString *)voipToken - isForcedUpdate:(BOOL)isForcedUpdate - success:(void (^)(void))successHandler - failure:(void (^)(NSError *))failureHandler -{ - [self registerForPushNotificationsWithPushToken:pushToken - voipToken:voipToken - isForcedUpdate:isForcedUpdate - success:successHandler - failure:failureHandler - remainingRetries:3]; -} - -- (void)registerForPushNotificationsWithPushToken:(NSString *)pushToken - voipToken:(NSString *)voipToken - isForcedUpdate:(BOOL)isForcedUpdate - success:(void (^)(void))successHandler - failure:(void (^)(NSError *))failureHandler - remainingRetries:(int)remainingRetries -{ - BOOL isUsingFullAPNs = [NSUserDefaults.standardUserDefaults boolForKey:@"isUsingFullAPNs"]; - NSData *pushTokenAsData = [NSData dataFromHexString:pushToken]; - AnyPromise *promise = isUsingFullAPNs ? [LKPushNotificationAPI registerWithToken:pushTokenAsData hexEncodedPublicKey:self.localNumber isForcedUpdate:isForcedUpdate] - : [LKPushNotificationAPI unregisterToken:pushTokenAsData]; - promise - .then(^() { - successHandler(); - }) - .catch(^(NSError *error) { - if (remainingRetries > 0) { - [self registerForPushNotificationsWithPushToken:pushToken voipToken:voipToken isForcedUpdate:isForcedUpdate success:successHandler failure:failureHandler - remainingRetries:remainingRetries - 1]; - } else { - failureHandler(error); - } - }); -} - -- (void)rerequestSMSWithCaptchaToken:(nullable NSString *)captchaToken - success:(void (^)(void))successBlock - failure:(void (^)(NSError *error))failureBlock -{ - // TODO: Can we remove phoneNumberAwaitingVerification? - NSString *number = self.phoneNumberAwaitingVerification; - - [self registerWithPhoneNumber:number - captchaToken:captchaToken - success:successBlock - failure:failureBlock - smsVerification:YES]; -} - -- (void)rerequestVoiceWithCaptchaToken:(nullable NSString *)captchaToken - success:(void (^)(void))successBlock - failure:(void (^)(NSError *error))failureBlock -{ - NSString *number = self.phoneNumberAwaitingVerification; - - [self registerWithPhoneNumber:number - captchaToken:captchaToken - success:successBlock - failure:failureBlock - smsVerification:NO]; -} - -#pragma mark Server keying material - -+ (NSString *)generateNewAccountAuthenticationToken { - NSData *authToken = [Randomness generateRandomBytes:16]; - NSString *authTokenPrint = [[NSData dataWithData:authToken] hexadecimalString]; - return authTokenPrint; -} - -+ (nullable NSString *)signalingKey -{ - return [[self sharedInstance] signalingKey]; -} - -- (nullable NSString *)signalingKey -{ - return [self.dbConnection stringForKey:TSAccountManager_ServerSignalingKey - inCollection:TSAccountManager_UserAccountCollection]; -} - -+ (nullable NSString *)serverAuthToken -{ - return [[self sharedInstance] serverAuthToken]; -} - -- (nullable NSString *)serverAuthToken -{ - return [self.dbConnection stringForKey:TSAccountManager_ServerAuthToken - inCollection:TSAccountManager_UserAccountCollection]; -} - -- (void)storeServerAuthToken:(NSString *)authToken -{ - [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [transaction setObject:authToken - forKey:TSAccountManager_ServerAuthToken - inCollection:TSAccountManager_UserAccountCollection]; - }]; -} - -- (void)yapDatabaseModifiedExternally:(NSNotification *)notification -{ - // Any database write by the main app might reflect a deregistration, - // so clear the cached "is registered" state. This will significantly - // erode the value of this cache in the SAE. - @synchronized(self) - { - _isRegistered = NO; - } -} - -#pragma mark - De-Registration - -- (BOOL)isDeregistered -{ - // Cache this since we access this a lot, and once set it will not change. - @synchronized(self) { - if (self.cachedIsDeregistered == nil) { - self.cachedIsDeregistered = @([self.dbConnection boolForKey:TSAccountManager_IsDeregisteredKey - inCollection:TSAccountManager_UserAccountCollection - defaultValue:NO]); - } - - return self.cachedIsDeregistered.boolValue; - } -} - -- (void)setIsDeregistered:(BOOL)isDeregistered -{ - @synchronized(self) { - if (self.cachedIsDeregistered && self.cachedIsDeregistered.boolValue == isDeregistered) { - return; - } - - self.cachedIsDeregistered = @(isDeregistered); - } - - [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [transaction setObject:@(isDeregistered) - forKey:TSAccountManager_IsDeregisteredKey - inCollection:TSAccountManager_UserAccountCollection]; - }]; - - [self postRegistrationStateDidChangeNotification]; -} - -- (nullable NSString *)reregisterationPhoneNumber -{ - NSString *_Nullable result = [self.dbConnection stringForKey:TSAccountManager_ReregisteringPhoneNumberKey - inCollection:TSAccountManager_UserAccountCollection]; - return result; -} - -- (BOOL)isReregistering -{ - return nil != - [self.dbConnection stringForKey:TSAccountManager_ReregisteringPhoneNumberKey - inCollection:TSAccountManager_UserAccountCollection]; -} - -- (BOOL)isManualMessageFetchEnabled -{ - return [self.dbConnection boolForKey:TSAccountManager_ManualMessageFetchKey - inCollection:TSAccountManager_UserAccountCollection - defaultValue:NO]; -} - -- (AnyPromise *)setIsManualMessageFetchEnabled:(BOOL)value { - [self.dbConnection setBool:value - forKey:TSAccountManager_ManualMessageFetchKey - inCollection:TSAccountManager_UserAccountCollection]; - - // Try to update the account attributes to reflect this change. - return [self updateAccountAttributes]; -} - -- (void)registerForTestsWithLocalNumber:(NSString *)localNumber -{ - [self storeLocalNumber:localNumber]; -} - -#pragma mark - Account Attributes - -- (AnyPromise *)updateAccountAttributes { - // Enqueue a "account attribute update", recording the "request time". - [self.dbConnection setObject:[NSDate new] - forKey:TSAccountManager_NeedsAccountAttributesUpdateKey - inCollection:TSAccountManager_UserAccountCollection]; - - return [self updateAccountAttributesIfNecessary]; -} - -- (AnyPromise *)updateAccountAttributesIfNecessary { - if (!self.isRegistered) { - return [AnyPromise promiseWithValue:@(1)]; - } - - return [AnyPromise promiseWithValue:@(1)]; - - NSDate *_Nullable updateRequestDate = - [self.dbConnection objectForKey:TSAccountManager_NeedsAccountAttributesUpdateKey - inCollection:TSAccountManager_UserAccountCollection]; - if (!updateRequestDate) { - return [AnyPromise promiseWithValue:@(1)]; - } - AnyPromise *promise = [self performUpdateAccountAttributes]; - promise = promise.then(^(id value) { - [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - // Clear the update request unless a new update has been requested - // while this update was in flight. - NSDate *_Nullable latestUpdateRequestDate = - [transaction objectForKey:TSAccountManager_NeedsAccountAttributesUpdateKey - inCollection:TSAccountManager_UserAccountCollection]; - if (latestUpdateRequestDate && [latestUpdateRequestDate isEqual:updateRequestDate]) { - [transaction removeObjectForKey:TSAccountManager_NeedsAccountAttributesUpdateKey - inCollection:TSAccountManager_UserAccountCollection]; - } - }]; - }); - return promise; -} - -- (void)reachabilityChanged { - [AppReadiness runNowOrWhenAppDidBecomeReady:^{ - [[self updateAccountAttributesIfNecessary] retainUntilComplete]; - }]; -} - -#pragma mark - Notifications - -- (void)postRegistrationStateDidChangeNotification -{ - [[NSNotificationCenter defaultCenter] postNotificationNameAsync:RegistrationStateDidChangeNotification - object:nil - userInfo:nil]; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/OWSDisappearingMessagesFinder.h b/SessionMessagingKit/Utilities/OWSDisappearingMessagesFinder.h deleted file mode 100644 index 5ba154856..000000000 --- a/SessionMessagingKit/Utilities/OWSDisappearingMessagesFinder.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class OWSPrimaryStorage; -@class OWSStorage; -@class TSMessage; -@class TSThread; -@class YapDatabaseReadTransaction; - -@interface OWSDisappearingMessagesFinder : NSObject - -- (void)enumerateExpiredMessagesWithBlock:(void (^_Nonnull)(TSMessage *message))block - transaction:(YapDatabaseReadTransaction *)transaction; - -- (void)enumerateUnstartedExpiringMessagesInThread:(TSThread *)thread - block:(void (^_Nonnull)(TSMessage *message))block - transaction:(YapDatabaseReadTransaction *)transaction; - -- (void)enumerateMessagesWhichFailedToStartExpiringWithBlock:(void (^_Nonnull)(TSMessage *message))block - transaction:(YapDatabaseReadTransaction *)transaction; - -/** - * @return - * uint64_t millisecond timestamp wrapped in a number. Retrieve with `unsignedLongLongvalue`. - * or nil if there are no upcoming expired messages - */ -- (nullable NSNumber *)nextExpirationTimestampWithTransaction:(YapDatabaseReadTransaction *_Nonnull)transaction; - -+ (NSString *)databaseExtensionName; - -+ (void)asyncRegisterDatabaseExtensions:(OWSStorage *)storage; - -#ifdef DEBUG -/** - * Only use the sync version for testing, generally we'll want to register extensions async - */ -+ (void)blockingRegisterDatabaseExtensions:(OWSStorage *)storage; -#endif - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/OWSDisappearingMessagesFinder.m b/SessionMessagingKit/Utilities/OWSDisappearingMessagesFinder.m deleted file mode 100644 index bd58d4abc..000000000 --- a/SessionMessagingKit/Utilities/OWSDisappearingMessagesFinder.m +++ /dev/null @@ -1,241 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import "OWSDisappearingMessagesFinder.h" -#import "OWSPrimaryStorage.h" -#import "TSIncomingMessage.h" -#import "TSMessage.h" -#import "TSOutgoingMessage.h" -#import "TSThread.h" -#import -#import -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -static NSString *const OWSDisappearingMessageFinderThreadIdColumn = @"thread_id"; -static NSString *const OWSDisappearingMessageFinderExpiresAtColumn = @"expires_at"; -static NSString *const OWSDisappearingMessageFinderExpiresAtIndex = @"index_messages_on_expires_at_and_thread_id_v2"; - -@implementation OWSDisappearingMessagesFinder - -- (NSArray *)fetchUnstartedExpiringMessageIdsInThread:(TSThread *)thread - transaction:(YapDatabaseReadTransaction *_Nonnull)transaction -{ - NSMutableArray *messageIds = [NSMutableArray new]; - NSString *formattedString = [NSString stringWithFormat:@"WHERE %@ = 0 AND %@ = \"%@\"", - OWSDisappearingMessageFinderExpiresAtColumn, - OWSDisappearingMessageFinderThreadIdColumn, - thread.uniqueId]; - - YapDatabaseQuery *query = [YapDatabaseQuery queryWithFormat:formattedString]; - [[transaction ext:OWSDisappearingMessageFinderExpiresAtIndex] - enumerateKeysMatchingQuery:query - usingBlock:^void(NSString *collection, NSString *key, BOOL *stop) { - [messageIds addObject:key]; - }]; - - return [messageIds copy]; -} - -- (NSArray *)fetchMessageIdsWhichFailedToStartExpiring:(YapDatabaseReadTransaction *_Nonnull)transaction -{ - NSMutableArray *messageIds = [NSMutableArray new]; - NSString *formattedString = - [NSString stringWithFormat:@"WHERE %@ = 0", OWSDisappearingMessageFinderExpiresAtColumn]; - - YapDatabaseQuery *query = [YapDatabaseQuery queryWithFormat:formattedString]; - [[transaction ext:OWSDisappearingMessageFinderExpiresAtIndex] - enumerateKeysAndObjectsMatchingQuery:query - usingBlock:^void(NSString *collection, NSString *key, id object, BOOL *stop) { - if (![object isKindOfClass:[TSMessage class]]) { - return; - } - - TSMessage *message = (TSMessage *)object; - if ([message shouldStartExpireTimerWithTransaction:transaction]) { - if ([message isKindOfClass:[TSIncomingMessage class]]) { - TSIncomingMessage *incomingMessage = (TSIncomingMessage *)message; - if (!incomingMessage.wasRead) { - return; - } - } - [messageIds addObject:key]; - } - }]; - - return [messageIds copy]; -} - -- (NSArray *)fetchExpiredMessageIdsWithTransaction:(YapDatabaseReadTransaction *_Nonnull)transaction -{ - NSMutableArray *messageIds = [NSMutableArray new]; - - uint64_t now = [NSDate ows_millisecondTimeStamp]; - // When (expiresAt == 0) the message SHOULD NOT expire. Careful ;) - NSString *formattedString = [NSString stringWithFormat:@"WHERE %@ > 0 AND %@ <= %lld", - OWSDisappearingMessageFinderExpiresAtColumn, - OWSDisappearingMessageFinderExpiresAtColumn, - now]; - YapDatabaseQuery *query = [YapDatabaseQuery queryWithFormat:formattedString]; - [[transaction ext:OWSDisappearingMessageFinderExpiresAtIndex] - enumerateKeysMatchingQuery:query - usingBlock:^void(NSString *collection, NSString *key, BOOL *stop) { - [messageIds addObject:key]; - }]; - - return [messageIds copy]; -} - -- (nullable NSNumber *)nextExpirationTimestampWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - NSString *formattedString = [NSString stringWithFormat:@"WHERE %@ > 0 ORDER BY %@ ASC", - OWSDisappearingMessageFinderExpiresAtColumn, - OWSDisappearingMessageFinderExpiresAtColumn]; - YapDatabaseQuery *query = [YapDatabaseQuery queryWithFormat:formattedString]; - - __block TSMessage *firstMessage; - [[transaction ext:OWSDisappearingMessageFinderExpiresAtIndex] - enumerateKeysAndObjectsMatchingQuery:query - usingBlock:^void(NSString *collection, NSString *key, id object, BOOL *stop) { - firstMessage = (TSMessage *)object; - *stop = YES; - }]; - - if (firstMessage && firstMessage.expiresAt > 0) { - return [NSNumber numberWithUnsignedLongLong:firstMessage.expiresAt]; - } - - return nil; -} - -- (void)enumerateUnstartedExpiringMessagesInThread:(TSThread *)thread - block:(void (^_Nonnull)(TSMessage *message))block - transaction:(YapDatabaseReadTransaction *)transaction -{ - for (NSString *expiringMessageId in - [self fetchUnstartedExpiringMessageIdsInThread:thread transaction:transaction]) { - TSMessage *_Nullable message = [TSMessage fetchObjectWithUniqueID:expiringMessageId transaction:transaction]; - if ([message isKindOfClass:[TSMessage class]]) { - block(message); - } - } -} - -- (void)enumerateMessagesWhichFailedToStartExpiringWithBlock:(void (^_Nonnull)(TSMessage *message))block - transaction:(YapDatabaseReadTransaction *)transaction -{ - for (NSString *expiringMessageId in [self fetchMessageIdsWhichFailedToStartExpiring:transaction]) { - - TSMessage *_Nullable message = [TSMessage fetchObjectWithUniqueID:expiringMessageId transaction:transaction]; - if (![message isKindOfClass:[TSMessage class]]) { - continue; - } - - if (![message shouldStartExpireTimerWithTransaction:transaction]) { - continue; - } - - block(message); - } -} - -/** - * Don't use this in production. Useful for testing. - * We don't want to instantiate potentially many messages at once. - */ -- (NSArray *)fetchUnstartedExpiringMessagesInThread:(TSThread *)thread - transaction:(YapDatabaseReadTransaction *)transaction -{ - NSMutableArray *messages = [NSMutableArray new]; - [self enumerateUnstartedExpiringMessagesInThread:thread - block:^(TSMessage *message) { - [messages addObject:message]; - } - transaction:transaction]; - - return [messages copy]; -} - - -- (void)enumerateExpiredMessagesWithBlock:(void (^_Nonnull)(TSMessage *message))block - transaction:(YapDatabaseReadTransaction *)transaction -{ - // Since we can't directly mutate the enumerated expired messages, we store only their ids in hopes of saving a - // little memory and then enumerate the (larger) TSMessage objects one at a time. - for (NSString *expiredMessageId in [self fetchExpiredMessageIdsWithTransaction:transaction]) { - TSMessage *_Nullable message = [TSMessage fetchObjectWithUniqueID:expiredMessageId transaction:transaction]; - if ([message isKindOfClass:[TSMessage class]]) { - block(message); - } - } -} - -/** - * Don't use this in production. Useful for testing. - * We don't want to instantiate potentially many messages at once. - */ -- (NSArray *)fetchExpiredMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - NSMutableArray *messages = [NSMutableArray new]; - [self enumerateExpiredMessagesWithBlock:^(TSMessage *message) { - [messages addObject:message]; - } - transaction:transaction]; - - return [messages copy]; -} - -#pragma mark - YapDatabaseExtension - -+ (YapDatabaseSecondaryIndex *)indexDatabaseExtension -{ - YapDatabaseSecondaryIndexSetup *setup = [YapDatabaseSecondaryIndexSetup new]; - [setup addColumn:OWSDisappearingMessageFinderExpiresAtColumn withType:YapDatabaseSecondaryIndexTypeInteger]; - [setup addColumn:OWSDisappearingMessageFinderThreadIdColumn withType:YapDatabaseSecondaryIndexTypeText]; - - YapDatabaseSecondaryIndexHandler *handler = - [YapDatabaseSecondaryIndexHandler withObjectBlock:^(YapDatabaseReadTransaction *transaction, - NSMutableDictionary *dict, - NSString *collection, - NSString *key, - id object) { - if (![object isKindOfClass:[TSMessage class]]) { - return; - } - TSMessage *message = (TSMessage *)object; - - if (![message shouldStartExpireTimerWithTransaction:transaction]) { - return; - } - - dict[OWSDisappearingMessageFinderExpiresAtColumn] = @(message.expiresAt); - dict[OWSDisappearingMessageFinderThreadIdColumn] = message.uniqueThreadId; - }]; - - return [[YapDatabaseSecondaryIndex alloc] initWithSetup:setup handler:handler versionTag:@"1"]; -} - -#ifdef DEBUG -// Useful for tests, don't use in app startup path because it's slow. -+ (void)blockingRegisterDatabaseExtensions:(OWSStorage *)storage -{ - [storage registerExtension:[self indexDatabaseExtension] withName:OWSDisappearingMessageFinderExpiresAtIndex]; -} -#endif - -+ (NSString *)databaseExtensionName -{ - return OWSDisappearingMessageFinderExpiresAtIndex; -} - -+ (void)asyncRegisterDatabaseExtensions:(OWSStorage *)storage -{ - [storage asyncRegisterExtension:[self indexDatabaseExtension] withName:OWSDisappearingMessageFinderExpiresAtIndex]; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/OWSIncomingMessageFinder.h b/SessionMessagingKit/Utilities/OWSIncomingMessageFinder.h deleted file mode 100644 index 4a1fe8e41..000000000 --- a/SessionMessagingKit/Utilities/OWSIncomingMessageFinder.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class OWSPrimaryStorage; -@class OWSStorage; -@class YapDatabaseReadTransaction; - -@interface OWSIncomingMessageFinder : NSObject - -- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER; - -+ (NSString *)databaseExtensionName; -+ (void)asyncRegisterExtensionWithPrimaryStorage:(OWSStorage *)storage; - -/** - * Detects existance of a duplicate incoming message. - */ -- (BOOL)existsMessageWithTimestamp:(uint64_t)timestamp - sourceId:(NSString *)sourceId - sourceDeviceId:(uint32_t)sourceDeviceId - transaction:(YapDatabaseReadTransaction *)transaction; - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/OWSIncomingMessageFinder.m b/SessionMessagingKit/Utilities/OWSIncomingMessageFinder.m deleted file mode 100644 index f51d944a8..000000000 --- a/SessionMessagingKit/Utilities/OWSIncomingMessageFinder.m +++ /dev/null @@ -1,144 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import "OWSIncomingMessageFinder.h" -#import "OWSPrimaryStorage.h" -#import "TSIncomingMessage.h" -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -NSString *const OWSIncomingMessageFinderExtensionName = @"OWSIncomingMessageFinderExtensionName"; - -NSString *const OWSIncomingMessageFinderColumnTimestamp = @"OWSIncomingMessageFinderColumnTimestamp"; -NSString *const OWSIncomingMessageFinderColumnSourceId = @"OWSIncomingMessageFinderColumnSourceId"; -NSString *const OWSIncomingMessageFinderColumnSourceDeviceId = @"OWSIncomingMessageFinderColumnSourceDeviceId"; - -@interface OWSIncomingMessageFinder () - -@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage; -@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; - -@end - -@implementation OWSIncomingMessageFinder - -@synthesize dbConnection = _dbConnection; - -#pragma mark - init - -- (instancetype)init -{ - return [self initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]]; -} - -- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage -{ - self = [super init]; - if (!self) { - return self; - } - - _primaryStorage = primaryStorage; - - return self; -} - -#pragma mark - properties - -- (YapDatabaseConnection *)dbConnection -{ - @synchronized(self) { - if (!_dbConnection) { - _dbConnection = [self.primaryStorage newDatabaseConnection]; - } - } - return _dbConnection; -} - -#pragma mark - YAP integration - -+ (YapDatabaseSecondaryIndex *)indexExtension -{ - YapDatabaseSecondaryIndexSetup *setup = [YapDatabaseSecondaryIndexSetup new]; - - [setup addColumn:OWSIncomingMessageFinderColumnTimestamp withType:YapDatabaseSecondaryIndexTypeInteger]; - [setup addColumn:OWSIncomingMessageFinderColumnSourceId withType:YapDatabaseSecondaryIndexTypeText]; - [setup addColumn:OWSIncomingMessageFinderColumnSourceDeviceId withType:YapDatabaseSecondaryIndexTypeInteger]; - - YapDatabaseSecondaryIndexWithObjectBlock block = ^(YapDatabaseReadTransaction *transaction, - NSMutableDictionary *dict, - NSString *collection, - NSString *key, - id object) { - if ([object isKindOfClass:[TSIncomingMessage class]]) { - TSIncomingMessage *incomingMessage = (TSIncomingMessage *)object; - - // On new messages authorId should be set on all incoming messages, but there was a time when authorId was - // only set on incoming group messages. - NSObject *authorIdOrNull = incomingMessage.authorId ? incomingMessage.authorId : [NSNull null]; - [dict setObject:@(incomingMessage.timestamp) forKey:OWSIncomingMessageFinderColumnTimestamp]; - [dict setObject:authorIdOrNull forKey:OWSIncomingMessageFinderColumnSourceId]; - [dict setObject:@(incomingMessage.sourceDeviceId) forKey:OWSIncomingMessageFinderColumnSourceDeviceId]; - } - }; - - YapDatabaseSecondaryIndexHandler *handler = [YapDatabaseSecondaryIndexHandler withObjectBlock:block]; - - return [[YapDatabaseSecondaryIndex alloc] initWithSetup:setup handler:handler versionTag:nil]; -} - -+ (NSString *)databaseExtensionName -{ - return OWSIncomingMessageFinderExtensionName; -} - -+ (void)asyncRegisterExtensionWithPrimaryStorage:(OWSStorage *)storage -{ - [storage asyncRegisterExtension:self.indexExtension withName:OWSIncomingMessageFinderExtensionName]; -} - -#ifdef DEBUG -// We should not normally hit this, as we should have prefer registering async, but it is useful for testing. -- (void)registerExtension -{ - [self.primaryStorage registerExtension:self.class.indexExtension withName:OWSIncomingMessageFinderExtensionName]; -} -#endif - -#pragma mark - instance methods - -- (BOOL)existsMessageWithTimestamp:(uint64_t)timestamp - sourceId:(NSString *)sourceId - sourceDeviceId:(uint32_t)sourceDeviceId - transaction:(YapDatabaseReadTransaction *)transaction -{ -#ifdef DEBUG - if (![self.primaryStorage registeredExtension:OWSIncomingMessageFinderExtensionName]) { - - // we should be initializing this at startup rather than have an unexpectedly slow lazy setup at random. - [self registerExtension]; - } -#endif - - NSString *queryFormat = [NSString stringWithFormat:@"WHERE %@ = ? AND %@ = ? AND %@ = ?", - OWSIncomingMessageFinderColumnTimestamp, - OWSIncomingMessageFinderColumnSourceId, - OWSIncomingMessageFinderColumnSourceDeviceId]; - // YapDatabaseQuery params must be objects - YapDatabaseQuery *query = [YapDatabaseQuery queryWithFormat:queryFormat, @(timestamp), sourceId, @(sourceDeviceId)]; - - NSUInteger count; - BOOL success = [[transaction ext:OWSIncomingMessageFinderExtensionName] getNumberOfRows:&count matchingQuery:query]; - if (!success) { - return NO; - } - - return count > 0; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/OWSPreferences.h b/SessionMessagingKit/Utilities/OWSPreferences.h index 48a95067b..895d13d75 100644 --- a/SessionMessagingKit/Utilities/OWSPreferences.h +++ b/SessionMessagingKit/Utilities/OWSPreferences.h @@ -3,7 +3,6 @@ // #import -#import #import #import #import diff --git a/SessionMessagingKit/Utilities/SSKEnvironment.h b/SessionMessagingKit/Utilities/SSKEnvironment.h deleted file mode 100644 index 63751c3d5..000000000 --- a/SessionMessagingKit/Utilities/SSKEnvironment.h +++ /dev/null @@ -1,80 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class ContactDiscoveryService; -@class ContactsUpdater; -@class OWS2FAManager; -@class OWSAttachmentDownloads; -@class OWSBatchMessageProcessor; -@class OWSDisappearingMessagesJob; -@class OWSIdentityManager; -@class OWSMessageDecrypter; -@class OWSMessageManager; -@class OWSMessageReceiver; -@class OWSMessageSender; -@class OWSOutgoingReceiptManager; -@class OWSPrimaryStorage; -@class OWSReadReceiptManager; -@class SSKMessageSenderJobQueue; -@class TSAccountManager; -@class TSSocketManager; -@class YapDatabaseConnection; - -@protocol ContactsManagerProtocol; -@protocol NotificationsProtocol; -@protocol OWSCallMessageHandler; -@protocol ProfileManagerProtocol; -@protocol OWSUDManager; -@protocol SSKReachabilityManager; -@protocol OWSSyncManagerProtocol; -@protocol OWSTypingIndicators; - -@interface SSKEnvironment : NSObject - -- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage - tsAccountManager:(TSAccountManager *)tsAccountManager - disappearingMessagesJob:(OWSDisappearingMessagesJob *)disappearingMessagesJob - readReceiptManager:(OWSReadReceiptManager *)readReceiptManager - outgoingReceiptManager:(OWSOutgoingReceiptManager *)outgoingReceiptManager - reachabilityManager:(id)reachabilityManager - typingIndicators:(id)typingIndicators NS_DESIGNATED_INITIALIZER; - -- (instancetype)init NS_UNAVAILABLE; - -@property (nonatomic, readonly, class) SSKEnvironment *shared; - -+ (void)setShared:(SSKEnvironment *)env; - -#ifdef DEBUG -// Should only be called by tests. -+ (void)clearSharedForTests; -#endif - -@property (nonatomic, readonly) id profileManager; -@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage; -@property (nonatomic, readonly) OWSIdentityManager *identityManager; -@property (nonatomic, readonly) TSAccountManager *tsAccountManager; -@property (nonatomic, readonly) OWSDisappearingMessagesJob *disappearingMessagesJob; -@property (nonatomic, readonly) OWSReadReceiptManager *readReceiptManager; -@property (nonatomic, readonly) OWSOutgoingReceiptManager *outgoingReceiptManager; -@property (nonatomic, readonly) id reachabilityManager; -@property (nonatomic, readonly) id typingIndicators; - -// This property is configured after Environment is created. -@property (atomic, nullable) id notificationsManager; - -@property (atomic, readonly) YapDatabaseConnection *objectReadWriteConnection; -@property (atomic, readonly) YapDatabaseConnection *sessionStoreDBConnection; -@property (atomic, readonly) YapDatabaseConnection *migrationDBConnection; -@property (atomic, readonly) YapDatabaseConnection *analyticsDBConnection; - -- (BOOL)isComplete; - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/SSKEnvironment.m b/SessionMessagingKit/Utilities/SSKEnvironment.m deleted file mode 100644 index 75f0ead69..000000000 --- a/SessionMessagingKit/Utilities/SSKEnvironment.m +++ /dev/null @@ -1,135 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import "SSKEnvironment.h" -#import "AppContext.h" -#import "OWSPrimaryStorage.h" - -NS_ASSUME_NONNULL_BEGIN - -static SSKEnvironment *sharedSSKEnvironment; - -@interface SSKEnvironment () - -@property (nonatomic) OWSPrimaryStorage *primaryStorage; -@property (nonatomic) TSAccountManager *tsAccountManager; -@property (nonatomic) OWSDisappearingMessagesJob *disappearingMessagesJob; -@property (nonatomic) OWSReadReceiptManager *readReceiptManager; -@property (nonatomic) OWSOutgoingReceiptManager *outgoingReceiptManager; -@property (nonatomic) id reachabilityManager; -@property (nonatomic) id typingIndicators; - -@end - -#pragma mark - - -@implementation SSKEnvironment - -@synthesize notificationsManager = _notificationsManager; -@synthesize objectReadWriteConnection = _objectReadWriteConnection; -@synthesize sessionStoreDBConnection = _sessionStoreDBConnection; -@synthesize migrationDBConnection = _migrationDBConnection; -@synthesize analyticsDBConnection = _analyticsDBConnection; - -- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage - tsAccountManager:(TSAccountManager *)tsAccountManager - disappearingMessagesJob:(OWSDisappearingMessagesJob *)disappearingMessagesJob - readReceiptManager:(OWSReadReceiptManager *)readReceiptManager - outgoingReceiptManager:(OWSOutgoingReceiptManager *)outgoingReceiptManager - reachabilityManager:(id)reachabilityManager - typingIndicators:(id)typingIndicators -{ - self = [super init]; - - if (!self) { - return self; - } - - _primaryStorage = primaryStorage; - _tsAccountManager = tsAccountManager; - _disappearingMessagesJob = disappearingMessagesJob; - _readReceiptManager = readReceiptManager; - _outgoingReceiptManager = outgoingReceiptManager; - _reachabilityManager = reachabilityManager; - _typingIndicators = typingIndicators; - - return self; -} - -+ (instancetype)shared -{ - return sharedSSKEnvironment; -} - -+ (void)setShared:(SSKEnvironment *)env -{ - sharedSSKEnvironment = env; -} - -+ (void)clearSharedForTests -{ - sharedSSKEnvironment = nil; -} - -#pragma mark - Mutable Accessors - -- (nullable id)notificationsManager -{ - @synchronized(self) { - return _notificationsManager; - } -} - -- (void)setNotificationsManager:(nullable id)notificationsManager -{ - @synchronized(self) { - _notificationsManager = notificationsManager; - } -} - -- (BOOL)isComplete -{ - return self.notificationsManager != nil; -} - -- (YapDatabaseConnection *)objectReadWriteConnection -{ - @synchronized(self) { - if (!_objectReadWriteConnection) { - _objectReadWriteConnection = self.primaryStorage.newDatabaseConnection; - } - return _objectReadWriteConnection; - } -} - -- (YapDatabaseConnection *)sessionStoreDBConnection { - @synchronized(self) { - if (!_sessionStoreDBConnection) { - _sessionStoreDBConnection = self.primaryStorage.newDatabaseConnection; - } - return _sessionStoreDBConnection; - } -} - -- (YapDatabaseConnection *)migrationDBConnection { - @synchronized(self) { - if (!_migrationDBConnection) { - _migrationDBConnection = self.primaryStorage.newDatabaseConnection; - } - return _migrationDBConnection; - } -} - -- (YapDatabaseConnection *)analyticsDBConnection { - @synchronized(self) { - if (!_analyticsDBConnection) { - _analyticsDBConnection = self.primaryStorage.newDatabaseConnection; - } - return _analyticsDBConnection; - } -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Utilities/SSKEnvironment.swift b/SessionMessagingKit/Utilities/SSKEnvironment.swift index 89a0912da..9338ccab1 100644 --- a/SessionMessagingKit/Utilities/SSKEnvironment.swift +++ b/SessionMessagingKit/Utilities/SSKEnvironment.swift @@ -6,7 +6,6 @@ import SessionUtilitiesKit @objc public class SSKEnvironment: NSObject { @objc public let primaryStorage: OWSPrimaryStorage - public let tsAccountManager: TSAccountManager public let reachabilityManager: SSKReachabilityManager // Note: This property is configured after Environment is created. @@ -27,11 +26,9 @@ public class SSKEnvironment: NSObject { @objc public init( primaryStorage: OWSPrimaryStorage, - tsAccountManager: TSAccountManager, reachabilityManager: SSKReachabilityManager ) { self.primaryStorage = primaryStorage - self.tsAccountManager = tsAccountManager self.reachabilityManager = reachabilityManager self.objectReadWriteConnection = primaryStorage.newDatabaseConnection() diff --git a/SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift b/SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift deleted file mode 100644 index 3eebcbda9..000000000 --- a/SessionMessagingKit/Utilities/ThreadUpdateBatcher.swift +++ /dev/null @@ -1,31 +0,0 @@ - -final class ThreadUpdateBatcher { - private var threadIDs: Set = [] - - private lazy var timer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { [weak self] _ in self?.touch() } - - static let shared = ThreadUpdateBatcher() - - private init() { - DispatchQueue.main.async { - SessionUtilitiesKit.touch(self.timer) - } - } - - deinit { timer.invalidate() } - - func touch(_ threadID: String) { - threadIDs.insert(threadID) - } - - @objc private func touch() { - let threadIDs = self.threadIDs - self.threadIDs.removeAll() - Storage.write { transaction in - for threadID in threadIDs { - guard let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) else { return } - thread.touch(with: transaction) - } - } - } -} diff --git a/SessionShareExtension/Meta/SignalShareExtension-Bridging-Header.h b/SessionShareExtension/Meta/SignalShareExtension-Bridging-Header.h index 29c93b1b9..282ed4347 100644 --- a/SessionShareExtension/Meta/SignalShareExtension-Bridging-Header.h +++ b/SessionShareExtension/Meta/SignalShareExtension-Bridging-Header.h @@ -19,4 +19,3 @@ #import #import #import -#import diff --git a/SessionUtilitiesKit/Database/Models/Identity.swift b/SessionUtilitiesKit/Database/Models/Identity.swift index 577f55bfc..2bd3cc2ea 100644 --- a/SessionUtilitiesKit/Database/Models/Identity.swift +++ b/SessionUtilitiesKit/Database/Models/Identity.swift @@ -128,3 +128,28 @@ public extension Identity { } } } + +// MARK: - Convenience + +public extension Notification.Name { + static let registrationStateDidChange = Notification.Name("registrationStateDidChange") +} + +public extension Identity { + static func didRegister() { + NotificationCenter.default.post(name: .registrationStateDidChange, object: nil, userInfo: nil) + } +} + +// MARK: - Objective-C Support + +// TODO: Remove this when possible +@objc(SUKIdentity) +public class SUKIdentity: NSObject { + @objc(userExists) + public static func userExists() -> Bool { + return GRDBStorage.shared + .read { db in Identity.userExists(db) } + .defaulting(to: false) + } +} diff --git a/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentApprovalViewController.swift b/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentApprovalViewController.swift index 027a6f877..d478a0165 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentApprovalViewController.swift +++ b/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentApprovalViewController.swift @@ -8,8 +8,8 @@ import MediaPlayer import PromiseKit import SessionUIKit import CoreServices +import SessionMessagingKit -@objc public protocol AttachmentApprovalViewControllerDelegate: AnyObject { func attachmentApproval( _ attachmentApproval: AttachmentApprovalViewController, @@ -25,14 +25,12 @@ public protocol AttachmentApprovalViewControllerDelegate: AnyObject { didChangeMessageText newMessageText: String? ) - @objc - optional func attachmentApproval( + func attachmentApproval( _ attachmentApproval: AttachmentApprovalViewController, didRemoveAttachment attachment: SignalAttachment ) - @objc - optional func attachmentApprovalDidTapAddMore(_ attachmentApproval: AttachmentApprovalViewController) + func attachmentApprovalDidTapAddMore(_ attachmentApproval: AttachmentApprovalViewController) } // MARK: - @@ -45,9 +43,8 @@ public enum AttachmentApprovalViewControllerMode: UInt { // MARK: - -@objc public class AttachmentApprovalViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate { - @objc public enum Mode: UInt { + public enum Mode: UInt { case modal case sharedNavigation } @@ -122,7 +119,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC notImplemented() } - @objc required public init( mode: Mode, threadId: String, @@ -248,7 +244,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC // If the first item is just text, or is a URL and LinkPreviews are disabled // then just fill the 'message' box with it - if firstItem.attachment.isText || (firstItem.attachment.isUrl && OWSLinkPreview.previewURL(forRawBodyText: firstItem.attachment.text()) == nil) { + if firstItem.attachment.isText || (firstItem.attachment.isUrl && LinkPreview.previewUrl(for: firstItem.attachment.text()) == nil) { bottomToolView.attachmentTextToolbar.messageText = firstItem.attachment.text() } @@ -607,9 +603,13 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC return GalleryRailCellView() } } - + galleryRailView.configureCellViews( - itemProvider: attachmentItemCollection, + album: (attachmentItemCollection.attachmentItems as [GalleryRailItem]) + .appending(attachmentItemCollection.isAddMoreVisible ? + AddMoreRailItem() : + nil + ), focusedItem: currentItem, cellViewBuilder: cellViewBuilder ) @@ -797,17 +797,11 @@ extension SignalAttachmentItem: GalleryRailItem { return imageView } -} - -// MARK: - - -extension AttachmentItemCollection: GalleryRailItemProvider { - var railItems: [GalleryRailItem] { - if isAddMoreVisible { - return self.attachmentItems + [AddMoreRailItem()] - } else { - return self.attachmentItems - } + + func isEqual(to other: GalleryRailItem?) -> Bool { + guard let otherAttachmentItem: SignalAttachmentItem = other as? SignalAttachmentItem else { return false } + + return (self.attachment == otherAttachmentItem.attachment) } } @@ -816,7 +810,7 @@ extension AttachmentItemCollection: GalleryRailItemProvider { extension AttachmentApprovalViewController: GalleryRailViewDelegate { public func galleryRailView(_ galleryRailView: GalleryRailView, didTapItem imageRailItem: GalleryRailItem) { if imageRailItem is AddMoreRailItem { - self.approvalDelegate?.attachmentApprovalDidTapAddMore?(self) + self.approvalDelegate?.attachmentApprovalDidTapAddMore(self) return } diff --git a/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentItemCollection.swift b/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentItemCollection.swift index 3a3370820..dcb63474f 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentItemCollection.swift +++ b/SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentItemCollection.swift @@ -4,6 +4,7 @@ import Foundation import PromiseKit +import SessionMessagingKit class AddMoreRailItem: GalleryRailItem { func buildRailItemView() -> UIView { diff --git a/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m b/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m index 770342426..5df014e9b 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m +++ b/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m @@ -5,7 +5,6 @@ #import "AttachmentSharing.h" #import "UIUtil.h" #import -#import NS_ASSUME_NONNULL_BEGIN diff --git a/SignalUtilitiesKit/Utilities/AppSetup.m b/SignalUtilitiesKit/Utilities/AppSetup.m index 129400905..8c2e33da3 100644 --- a/SignalUtilitiesKit/Utilities/AppSetup.m +++ b/SignalUtilitiesKit/Utilities/AppSetup.m @@ -8,7 +8,6 @@ #import #import #import -#import #import NS_ASSUME_NONNULL_BEGIN @@ -44,7 +43,6 @@ NS_ASSUME_NONNULL_BEGIN OWSPreferences *preferences = [OWSPreferences new]; - TSAccountManager *tsAccountManager = [[TSAccountManager alloc] initWithPrimaryStorage:primaryStorage]; id reachabilityManager = [SSKReachabilityManagerImpl new]; OWSAudioSession *audioSession = [OWSAudioSession new]; @@ -59,15 +57,7 @@ NS_ASSUME_NONNULL_BEGIN // TODO: Add this back // TODO: Refactor this file to Swift [SSKEnvironment setShared:[[SSKEnvironment alloc] initWithPrimaryStorage:primaryStorage - tsAccountManager:tsAccountManager reachabilityManager:reachabilityManager]]; -// [SSKEnvironment setShared:[[SSKEnvironment alloc] initWithPrimaryStorage:primaryStorage -// tsAccountManager:tsAccountManager -// disappearingMessagesJob:disappearingMessagesJob -// readReceiptManager:readReceiptManager -// outgoingReceiptManager:outgoingReceiptManager -// reachabilityManager:reachabilityManager -// typingIndicators:typingIndicators]]; appSpecificSingletonBlock(); @@ -77,7 +67,6 @@ NS_ASSUME_NONNULL_BEGIN [SNConfiguration performMainSetup]; // Must happen before the performUpdateCheck call below // Register renamed classes. - [NSKeyedUnarchiver setClass:[OWSUserProfile class] forClassName:[OWSUserProfile collection]]; [NSKeyedUnarchiver setClass:[OWSDatabaseMigration class] forClassName:[OWSDatabaseMigration collection]]; [OWSStorage registerExtensionsWithMigrationBlock:^() { diff --git a/SignalUtilitiesKit/Utilities/Notification+Loki.swift b/SignalUtilitiesKit/Utilities/Notification+Loki.swift index 705ed8b87..6383bc077 100644 --- a/SignalUtilitiesKit/Utilities/Notification+Loki.swift +++ b/SignalUtilitiesKit/Utilities/Notification+Loki.swift @@ -1,9 +1,8 @@ -import UIKit +import Foundation public extension Notification.Name { // State changes - static let registrationStateDidChange = Notification.Name("registrationStateDidChange") static let blockedContactsUpdated = Notification.Name("blockedContactsUpdated") static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged") static let threadDeleted = Notification.Name("threadDeleted") @@ -17,7 +16,6 @@ public extension Notification.Name { @objc public extension NSNotification { // State changes - @objc static let registrationStateDidChange = Notification.Name.registrationStateDidChange.rawValue as NSString @objc static let blockedContactsUpdated = Notification.Name.blockedContactsUpdated.rawValue as NSString @objc static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString @objc static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString diff --git a/SignalUtilitiesKit/Utilities/VersionMigrations.m b/SignalUtilitiesKit/Utilities/VersionMigrations.m index 6aca6986b..f7d7c0a26 100644 --- a/SignalUtilitiesKit/Utilities/VersionMigrations.m +++ b/SignalUtilitiesKit/Utilities/VersionMigrations.m @@ -7,7 +7,6 @@ #import #import #import -#import #import #import @@ -18,15 +17,6 @@ NS_ASSUME_NONNULL_BEGIN @implementation VersionMigrations -#pragma mark - Dependencies - -+ (TSAccountManager *)tsAccountManager -{ - OWSAssertDebug(SSKEnvironment.shared.tsAccountManager); - - return SSKEnvironment.shared.tsAccountManager; -} - #pragma mark - Utility methods + (void)performUpdateCheckWithCompletion:(VersionMigrationCompletion)completion @@ -56,12 +46,12 @@ NS_ASSUME_NONNULL_BEGIN }); return; } - - if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.1.70"] && [self.tsAccountManager isRegistered]) { + + if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.1.70"] && [SUKIdentity userExists]) { [self clearVideoCache]; } - if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.3.0"] && [self.tsAccountManager isRegistered]) { + if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.3.0"] && [SUKIdentity userExists]) { [self clearBloomFilterCache]; }