Browse Source

Restructure

pull/313/head
nielsandriesse 2 years ago
parent
commit
5dfd4b1965
  1. 6
      Podfile
  2. 2
      Podfile.lock
  3. 0
      Session/Database/Storage+VolumeSamples.swift
  4. 18
      Session/Meta/Signal-Bridging-Header.h
  5. 4
      Session/Signal/AboutTableViewController.m
  6. 4
      Session/Signal/AddToBlockListViewController.m
  7. 14
      Session/Signal/AppDelegate.m
  8. 4
      Session/Signal/AvatarViewHelper.m
  9. 14
      Session/Signal/ConversationView/ConversationViewController.m
  10. 2
      Session/Signal/ConversationView/ConversationViewItem.m
  11. 16
      Session/Signal/ConversationView/ConversationViewModel.m
  12. 2
      Session/Signal/MainAppContext.m
  13. 4
      Session/Signal/OWSBackup.m
  14. 4
      Session/Signal/OWSBackupExportJob.m
  15. 4
      Session/Signal/OWSBackupImportJob.m
  16. 10
      Session/Signal/OWSConversationSettingsViewController.m
  17. 8
      Session/Signal/OWSOrphanDataCleaner.m
  18. 2
      Session/Signal/OWSSessionResetJobRecord.h
  19. 2
      Session/Signal/OWSSessionResetJobRecord.m
  20. 2
      Session/Signal/PrivacySettingsTableViewController.m
  21. 6
      Session/Signal/SignalApp.m
  22. 19
      SessionMessagingKit/Configuration.swift
  23. 2
      SessionMessagingKit/Database/OWSPrimaryStorage.h
  24. 7
      SessionMessagingKit/Database/OWSPrimaryStorage.m
  25. 0
      SessionMessagingKit/Database/OWSStorage.h
  26. 147
      SessionMessagingKit/Database/OWSStorage.m
  27. 0
      SessionMessagingKit/Database/SSKPreferences.swift
  28. 1
      SessionMessagingKit/Database/Storage+ClosedGroups.swift
  29. 0
      SessionMessagingKit/Database/Storage+Jobs.swift
  30. 0
      SessionMessagingKit/Database/Storage+Messaging.swift
  31. 0
      SessionMessagingKit/Database/Storage+OpenGroups.swift
  32. 0
      SessionMessagingKit/Database/Storage+Shared.swift
  33. 0
      SessionMessagingKit/Database/TSDatabaseSecondaryIndexes.h
  34. 0
      SessionMessagingKit/Database/TSDatabaseSecondaryIndexes.m
  35. 2
      SessionMessagingKit/Database/TSDatabaseView.h
  36. 37
      SessionMessagingKit/Database/TSDatabaseView.m
  37. 4
      SessionMessagingKit/Jobs/NotifyPNServerJob.swift
  38. 15
      SessionMessagingKit/Messages/Message+Destination.swift
  39. 4
      SessionMessagingKit/Messages/Signal/TSErrorMessage.h
  40. 5
      SessionMessagingKit/Messages/Signal/TSErrorMessage.m
  41. 2
      SessionMessagingKit/Messages/Signal/TSErrorMessage_privateConstructor.h
  42. 0
      SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift
  43. 4
      SessionMessagingKit/Messages/Signal/TSIncomingMessage.h
  44. 17
      SessionMessagingKit/Messages/Signal/TSIncomingMessage.m
  45. 4
      SessionMessagingKit/Messages/Signal/TSInfoMessage.h
  46. 9
      SessionMessagingKit/Messages/Signal/TSInfoMessage.m
  47. 0
      SessionMessagingKit/Messages/Signal/TSInteraction.h
  48. 17
      SessionMessagingKit/Messages/Signal/TSInteraction.m
  49. 4
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyErrorMessage.h
  50. 4
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyErrorMessage.m
  51. 2
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.h
  52. 12
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m
  53. 4
      SessionMessagingKit/Messages/Signal/TSMessage.h
  54. 0
      SessionMessagingKit/Messages/Signal/TSOutgoingMessage+Conversion.swift
  55. 2
      SessionMessagingKit/Messages/Signal/TSOutgoingMessage.h
  56. 82
      SessionMessagingKit/Messages/Signal/TSOutgoingMessage.m
  57. 0
      SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Attachment.swift
  58. 41
      SessionMessagingKit/Meta/SessionMessagingKit.h
  59. 35
      SessionMessagingKit/Open Groups/OpenGroupAPI.swift
  60. 5
      SessionMessagingKit/Open Groups/OpenGroupAPIDelegate.swift
  61. 0
      SessionMessagingKit/Sending & Receiving/Attachments/OWSThumbnailService.swift
  62. 51
      SessionMessagingKit/Sending & Receiving/Attachments/SignalAttachment.swift
  63. 11
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h
  64. 15
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m
  65. 0
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer+Conversion.swift
  66. 0
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer.h
  67. 0
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer.m
  68. 0
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentStream.h
  69. 0
      SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentStream.m
  70. 0
      SessionMessagingKit/Sending & Receiving/Blocking/OWSBlockingManager.h
  71. 2
      SessionMessagingKit/Sending & Receiving/Blocking/OWSBlockingManager.m
  72. 2
      SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingConfigurationUpdateInfoMessage.h
  73. 5
      SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingConfigurationUpdateInfoMessage.m
  74. 1
      SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesConfiguration.h
  75. 6
      SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesConfiguration.m
  76. 0
      SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesJob.h
  77. 2
      SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesJob.m
  78. 71
      SessionMessagingKit/Sending & Receiving/Link Previews/OWSLinkPreview.swift
  79. 0
      SessionMessagingKit/Sending & Receiving/Mentions/Mention.swift
  80. 0
      SessionMessagingKit/Sending & Receiving/Mentions/MentionsManager.swift
  81. 141
      SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift
  82. 81
      SessionMessagingKit/Sending & Receiving/MessageReceiver.swift
  83. 17
      SessionMessagingKit/Sending & Receiving/MessageReceiverDelegate.swift
  84. 33
      SessionMessagingKit/Sending & Receiving/MessageSender.swift
  85. 6
      SessionMessagingKit/Sending & Receiving/MessageSenderDelegate.swift
  86. 0
      SessionMessagingKit/Sending & Receiving/Notifications/NotificationsProtocol.h
  87. 1
      SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift
  88. 5
      SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift
  89. 4
      SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPoller.swift
  90. 1
      SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift
  91. 13
      SessionMessagingKit/Sending & Receiving/Quotes/OWSQuotedReplyModel+Conversion.swift
  92. 3
      SessionMessagingKit/Sending & Receiving/Quotes/OWSQuotedReplyModel.h
  93. 24
      SessionMessagingKit/Sending & Receiving/Quotes/OWSQuotedReplyModel.m
  94. 13
      SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage+Conversion.swift
  95. 0
      SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage.h
  96. 40
      SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage.m
  97. 0
      SessionMessagingKit/Sending & Receiving/Read Tracking/OWSOutgoingReceiptManager.h
  98. 25
      SessionMessagingKit/Sending & Receiving/Read Tracking/OWSOutgoingReceiptManager.m
  99. 9
      SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.h
  100. 172
      SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m
  101. Some files were not shown because too many files have changed in this diff Show More

6
Podfile

@ -69,8 +69,11 @@ target 'SessionMessagingKit' do
pod 'AFNetworking', inhibit_warnings: true
pod 'CryptoSwift', :inhibit_warnings => true
pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit.git', :inhibit_warnings => true
pod 'HKDFKit', :inhibit_warnings => true
pod 'Mantle', git: 'https://github.com/signalapp/Mantle', branch: 'signal-master', :inhibit_warnings => true
pod 'PromiseKit', :inhibit_warnings => true
pod 'Reachability', :inhibit_warnings => true
pod 'SAMKeychain', :inhibit_warnings => true
pod 'SignalCoreKit', git: 'https://github.com/signalapp/SignalCoreKit.git', :inhibit_warnings => true
pod 'SwiftProtobuf', '~> 1.5.0', :inhibit_warnings => true
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release', :inhibit_warnings => true
@ -92,13 +95,16 @@ target 'SessionSnodeKit' do
pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit.git', :inhibit_warnings => true
pod 'PromiseKit', :inhibit_warnings => true
pod 'SignalCoreKit', git: 'https://github.com/signalapp/SignalCoreKit.git', :inhibit_warnings => true
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release', :inhibit_warnings => true
end
target 'SessionUtilitiesKit' do
pod 'AFNetworking', inhibit_warnings: true
pod 'CryptoSwift', :inhibit_warnings => true
pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit.git', :inhibit_warnings => true
pod 'Mantle', git: 'https://github.com/signalapp/Mantle', branch: 'signal-master', :inhibit_warnings => true
pod 'PromiseKit', :inhibit_warnings => true
pod 'SAMKeychain', :inhibit_warnings => true
pod 'SignalCoreKit', git: 'https://github.com/signalapp/SignalCoreKit.git', :inhibit_warnings => true
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release', :inhibit_warnings => true
end

2
Podfile.lock

@ -230,6 +230,6 @@ SPEC CHECKSUMS:
YYImage: 6db68da66f20d9f169ceb94dfb9947c3867b9665
ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb
PODFILE CHECKSUM: 62df79698293257648cb6e60724f720f8477bd0f
PODFILE CHECKSUM: b12682bc3bf974c758ec8e4b9838639f7ec51d5e
COCOAPODS: 1.10.0.rc.1

0
SignalUtilitiesKit/Database/Storage/Storage+VolumeSamples.swift → Session/Database/Storage+VolumeSamples.swift

18
Session/Meta/Signal-Bridging-Header.h

@ -66,31 +66,31 @@
#import <SessionUtilitiesKit/DataSource.h>
#import <SessionUtilitiesKit/MIMETypeUtil.h>
#import <SessionUtilitiesKit/NSData+Image.h>
#import <SignalUtilitiesKit/NSNotificationCenter+OWS.h>
#import <SessionUtilitiesKit/NSNotificationCenter+OWS.h>
#import <SignalUtilitiesKit/NSString+SSK.h>
#import <SignalUtilitiesKit/OWSBackgroundTask.h>
#import <SessionMessagingKit/OWSBackgroundTask.h>
#import <SignalUtilitiesKit/OWSContactsOutputStream.h>
#import <SignalUtilitiesKit/OWSDispatch.h>
#import <SignalUtilitiesKit/OWSError.h>
#import <SessionUtilitiesKit/OWSFileSystem.h>
#import <SignalUtilitiesKit/OWSIdentityManager.h>
#import <SessionMessagingKit/OWSIdentityManager.h>
#import <SignalUtilitiesKit/OWSMediaGalleryFinder.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalUtilitiesKit/OWSRecipientIdentity.h>
#import <SignalUtilitiesKit/SignalAccount.h>
#import <SignalUtilitiesKit/SignalRecipient.h>
#import <SignalUtilitiesKit/TSAccountManager.h>
#import <SessionMessagingKit/TSAccountManager.h>
#import <SessionMessagingKit/TSAttachment.h>
#import <SessionMessagingKit/TSAttachmentPointer.h>
#import <SessionMessagingKit/TSAttachmentStream.h>
#import <SignalUtilitiesKit/TSContactThread.h>
#import <SessionMessagingKit/TSContactThread.h>
#import <SignalUtilitiesKit/TSErrorMessage.h>
#import <SignalUtilitiesKit/TSGroupThread.h>
#import <SignalUtilitiesKit/TSIncomingMessage.h>
#import <SessionMessagingKit/TSGroupThread.h>
#import <SessionMessagingKit/TSIncomingMessage.h>
#import <SignalUtilitiesKit/TSInfoMessage.h>
#import <SignalUtilitiesKit/TSOutgoingMessage.h>
#import <SessionMessagingKit/TSOutgoingMessage.h>
#import <SignalUtilitiesKit/TSPreKeyManager.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SessionMessagingKit/TSThread.h>
#import <SignalUtilitiesKit/LKGroupUtilities.h>
#import <SessionUtilitiesKit/UIImage+OWS.h>
#import <WebRTC/RTCAudioSession.h>

4
Session/Signal/AboutTableViewController.m

@ -8,8 +8,8 @@
#import <SignalUtilitiesKit/Environment.h>
#import <SignalUtilitiesKit/OWSPreferences.h>
#import <SignalUtilitiesKit/UIUtil.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage.h>
#import <SignalUtilitiesKit/TSDatabaseView.h>
#import <SessionMessagingKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/TSDatabaseView.h>
@implementation AboutTableViewController

4
Session/Signal/AddToBlockListViewController.m

@ -4,8 +4,8 @@
#import "AddToBlockListViewController.h"
#import "BlockListUIUtils.h"
#import <SignalUtilitiesKit/SSKEnvironment.h>
#import <SignalUtilitiesKit/OWSBlockingManager.h>
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SessionMessagingKit/OWSBlockingManager.h>
#import <SignalUtilitiesKit/SignalAccount.h>
NS_ASSUME_NONNULL_BEGIN

14
Session/Signal/AppDelegate.m

@ -18,17 +18,17 @@
#import <SignalUtilitiesKit/OWSPreferences.h>
#import <SignalUtilitiesKit/OWSProfileManager.h>
#import <SignalUtilitiesKit/VersionMigrations.h>
#import <SignalUtilitiesKit/AppReadiness.h>
#import <SignalUtilitiesKit/NSUserDefaults+OWS.h>
#import <SignalUtilitiesKit/OWSDisappearingMessagesJob.h>
#import <SessionMessagingKit/AppReadiness.h>
#import <SessionUtilitiesKit/NSUserDefaults+OWS.h>
#import <SessionMessagingKit/OWSDisappearingMessagesJob.h>
#import <SignalUtilitiesKit/OWSFailedAttachmentDownloadsJob.h>
#import <SignalUtilitiesKit/OWSFailedMessagesJob.h>
#import <SignalUtilitiesKit/OWSMath.h>
#import <SignalUtilitiesKit/OWSReadReceiptManager.h>
#import <SignalUtilitiesKit/SSKEnvironment.h>
#import <SessionMessagingKit/OWSReadReceiptManager.h>
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SignalUtilitiesKit/TSAccountManager.h>
#import <SignalUtilitiesKit/TSDatabaseView.h>
#import <SessionMessagingKit/TSAccountManager.h>
#import <SessionMessagingKit/TSDatabaseView.h>
#import <SignalUtilitiesKit/TSPreKeyManager.h>
#import <YapDatabase/YapDatabaseCryptoUtils.h>
#import <sys/utsname.h>

4
Session/Signal/AvatarViewHelper.m

@ -10,8 +10,8 @@
#import <SignalUtilitiesKit/UIUtil.h>
#import <SignalUtilitiesKit/TSGroupModel.h>
#import <SignalUtilitiesKit/TSGroupThread.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SessionMessagingKit/TSGroupThread.h>
#import <SessionMessagingKit/TSThread.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN

14
Session/Signal/ConversationView/ConversationViewController.m

@ -32,7 +32,7 @@
#import "TSGroupThread.h"
#import "TSIncomingMessage.h"
#import "TSInfoMessage.h"
#import <SignalUtilitiesKit/TSInvalidIdentityKeyErrorMessage.h>
#import <SessionMessagingKit/TSInvalidIdentityKeyErrorMessage.h>
#import "UIFont+OWS.h"
#import "UIViewController+Permissions.h"
#import <AVFoundation/AVFoundation.h>
@ -53,15 +53,15 @@
#import <SessionUtilitiesKit/MIMETypeUtil.h>
#import <SignalUtilitiesKit/NSString+SSK.h>
#import <SignalUtilitiesKit/OWSAttachmentDownloads.h>
#import <SignalUtilitiesKit/OWSBlockingManager.h>
#import <SignalUtilitiesKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalUtilitiesKit/OWSIdentityManager.h>
#import <SessionMessagingKit/OWSBlockingManager.h>
#import <SessionMessagingKit/OWSDisappearingMessagesConfiguration.h>
#import <SessionMessagingKit/OWSIdentityManager.h>
#import <SignalUtilitiesKit/OWSMessageUtils.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/OWSPrimaryStorage.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage+Loki.h>
#import <SignalUtilitiesKit/OWSReadReceiptManager.h>
#import <SessionMessagingKit/OWSReadReceiptManager.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SignalUtilitiesKit/TSAccountManager.h>
#import <SessionMessagingKit/TSAccountManager.h>
#import <SignalUtilitiesKit/TSGroupModel.h>
#import <SignalUtilitiesKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalUtilitiesKit/TSQuotedMessage.h>

2
Session/Signal/ConversationView/ConversationViewItem.m

@ -15,7 +15,7 @@
#import <SignalUtilitiesKit/NSString+SSK.h>
#import <SignalUtilitiesKit/TSInteraction.h>
#import <SignalUtilitiesKit/SSKEnvironment.h>
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN

16
Session/Signal/ConversationView/ConversationViewModel.m

@ -11,14 +11,14 @@
#import <SignalCoreKit/NSDate+OWS.h>
#import <SignalUtilitiesKit/OWSUnreadIndicator.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SignalUtilitiesKit/OWSBlockingManager.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage.h>
#import <SignalUtilitiesKit/SSKEnvironment.h>
#import <SignalUtilitiesKit/TSDatabaseView.h>
#import <SignalUtilitiesKit/TSIncomingMessage.h>
#import <SignalUtilitiesKit/TSOutgoingMessage.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SignalUtilitiesKit/TSGroupThread.h>
#import <SessionMessagingKit/OWSBlockingManager.h>
#import <SessionMessagingKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SessionMessagingKit/TSDatabaseView.h>
#import <SessionMessagingKit/TSIncomingMessage.h>
#import <SessionMessagingKit/TSOutgoingMessage.h>
#import <SessionMessagingKit/TSThread.h>
#import <SessionMessagingKit/TSGroupThread.h>
#import <SignalUtilitiesKit/TSGroupModel.h>
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseAutoView.h>

2
Session/Signal/MainAppContext.m

@ -8,7 +8,7 @@
#import <SignalUtilitiesKit/Environment.h>
#import <SignalUtilitiesKit/OWSProfileManager.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SignalUtilitiesKit/OWSIdentityManager.h>
#import <SessionMessagingKit/OWSIdentityManager.h>
NS_ASSUME_NONNULL_BEGIN

4
Session/Signal/OWSBackup.m

@ -9,8 +9,8 @@
#import "Session-Swift.h"
#import <PromiseKit/AnyPromise.h>
#import <SignalCoreKit/Randomness.h>
#import <SignalUtilitiesKit/OWSIdentityManager.h>
#import <SignalUtilitiesKit/YapDatabaseConnection+OWS.h>
#import <SessionMessagingKit/OWSIdentityManager.h>
#import <SessionMessagingKit/YapDatabaseConnection+OWS.h>
@import CloudKit;

4
Session/Signal/OWSBackupExportJob.m

@ -10,13 +10,13 @@
#import <SignalCoreKit/NSData+OWS.h>
#import <SignalCoreKit/NSDate+OWS.h>
#import <SignalCoreKit/Threading.h>
#import <SignalUtilitiesKit/OWSBackgroundTask.h>
#import <SessionMessagingKit/OWSBackgroundTask.h>
#import <SignalUtilitiesKit/OWSError.h>
#import <SessionUtilitiesKit/OWSFileSystem.h>
#import <SessionMessagingKit/TSAttachment.h>
#import <SessionMessagingKit/TSAttachmentStream.h>
#import <SignalUtilitiesKit/TSMessage.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SessionMessagingKit/TSThread.h>
@import CloudKit;

4
Session/Signal/OWSBackupImportJob.m

@ -9,11 +9,11 @@
#import "Session-Swift.h"
#import <PromiseKit/AnyPromise.h>
#import <SignalCoreKit/NSData+OWS.h>
#import <SignalUtilitiesKit/OWSBackgroundTask.h>
#import <SessionMessagingKit/OWSBackgroundTask.h>
#import <SessionUtilitiesKit/OWSFileSystem.h>
#import <SessionMessagingKit/TSAttachment.h>
#import <SignalUtilitiesKit/TSMessage.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SessionMessagingKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN

10
Session/Signal/OWSConversationSettingsViewController.m

@ -23,12 +23,12 @@
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SignalUtilitiesKit/UIUtil.h>
#import <SignalUtilitiesKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalUtilitiesKit/OWSDisappearingMessagesConfiguration.h>
#import <SessionMessagingKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage.h>
#import <SignalUtilitiesKit/TSGroupThread.h>
#import <SignalUtilitiesKit/TSOutgoingMessage.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SessionMessagingKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/TSGroupThread.h>
#import <SessionMessagingKit/TSOutgoingMessage.h>
#import <SessionMessagingKit/TSThread.h>
@import ContactsUI;
@import PromiseKit;

8
Session/Signal/OWSOrphanDataCleaner.m

@ -7,17 +7,17 @@
#import <SignalCoreKit/NSDate+OWS.h>
#import <SignalUtilitiesKit/OWSProfileManager.h>
#import <SignalUtilitiesKit/OWSUserProfile.h>
#import <SignalUtilitiesKit/AppReadiness.h>
#import <SessionMessagingKit/AppReadiness.h>
#import <SignalUtilitiesKit/AppVersion.h>
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
#import <SessionUtilitiesKit/OWSFileSystem.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/TSAttachmentStream.h>
#import <SignalUtilitiesKit/TSInteraction.h>
#import <SignalUtilitiesKit/TSMessage.h>
#import <SignalUtilitiesKit/TSQuotedMessage.h>
#import <SignalUtilitiesKit/TSThread.h>
#import <SignalUtilitiesKit/YapDatabaseTransaction+OWS.h>
#import <SessionMessagingKit/TSThread.h>
#import <SessionMessagingKit/YapDatabaseTransaction+OWS.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <YapDatabase/YapDatabase.h>

2
Session/Signal/OWSSessionResetJobRecord.h

@ -2,7 +2,7 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <SignalUtilitiesKit/SSKJobRecord.h>
#import <SessionMessagingKit/SSKJobRecord.h>
@class TSContactThread;

2
Session/Signal/OWSSessionResetJobRecord.m

@ -3,7 +3,7 @@
//
#import "OWSSessionResetJobRecord.h"
#import <SignalUtilitiesKit/TSContactThread.h>
#import <SessionMessagingKit/TSContactThread.h>
NS_ASSUME_NONNULL_BEGIN

2
Session/Signal/PrivacySettingsTableViewController.m

@ -13,7 +13,7 @@
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SignalUtilitiesKit/NSString+SSK.h>
#import <SignalUtilitiesKit/ThreadUtil.h>
#import <SignalUtilitiesKit/OWSReadReceiptManager.h>
#import <SessionMessagingKit/OWSReadReceiptManager.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN

6
Session/Signal/SignalApp.m

@ -9,9 +9,9 @@
#import <SignalCoreKit/Threading.h>
#import <SignalUtilitiesKit/DebugLogger.h>
#import <SignalUtilitiesKit/Environment.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage.h>
#import <SignalUtilitiesKit/TSContactThread.h>
#import <SignalUtilitiesKit/TSGroupThread.h>
#import <SessionMessagingKit/OWSPrimaryStorage.h>
#import <SessionMessagingKit/TSContactThread.h>
#import <SessionMessagingKit/TSGroupThread.h>
NS_ASSUME_NONNULL_BEGIN

19
SessionMessagingKit/Configuration.swift

@ -2,15 +2,10 @@ import SessionProtocolKit
public struct Configuration {
public let storage: SessionMessagingKitStorageProtocol
public let messageSenderDelegate: MessageSenderDelegate
public let messageReceiverDelegate: MessageReceiverDelegate
public let signalStorage: SessionStore & PreKeyStore & SignedPreKeyStore
public let identityKeyStore: IdentityKeyStore
public let sessionRestorationImplementation: SessionRestorationProtocol
public let certificateValidator: SMKCertificateValidator
public let openGroupAPIDelegate: OpenGroupAPIDelegate
public let pnServerURL: String
public let pnServerPublicKey: String
internal static var shared: Configuration!
}
@ -19,27 +14,17 @@ public enum SNMessagingKit { // Just to make the external API nice
public static func configure(
storage: SessionMessagingKitStorageProtocol,
messageSenderDelegate: MessageSenderDelegate,
messageReceiverDelegate: MessageReceiverDelegate,
signalStorage: SessionStore & PreKeyStore & SignedPreKeyStore,
identityKeyStore: IdentityKeyStore,
sessionRestorationImplementation: SessionRestorationProtocol,
certificateValidator: SMKCertificateValidator,
openGroupAPIDelegate: OpenGroupAPIDelegate,
pnServerURL: String,
pnServerPublicKey: String
certificateValidator: SMKCertificateValidator
) {
Configuration.shared = Configuration(
storage: storage,
messageSenderDelegate: messageSenderDelegate,
messageReceiverDelegate: messageReceiverDelegate,
signalStorage: signalStorage,
identityKeyStore: identityKeyStore,
sessionRestorationImplementation: sessionRestorationImplementation,
certificateValidator: certificateValidator,
openGroupAPIDelegate: openGroupAPIDelegate,
pnServerURL: pnServerURL,
pnServerPublicKey: pnServerPublicKey
certificateValidator: certificateValidator
)
}
}

2
SignalUtilitiesKit/Database/OWSStorage/OWSPrimaryStorage.h → SessionMessagingKit/Database/OWSPrimaryStorage.h

@ -2,7 +2,7 @@
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import <SignalUtilitiesKit/OWSStorage.h>
#import <SessionMessagingKit/OWSStorage.h>
NS_ASSUME_NONNULL_BEGIN

7
SignalUtilitiesKit/Database/OWSStorage/OWSPrimaryStorage.m → SessionMessagingKit/Database/OWSPrimaryStorage.m

@ -5,8 +5,6 @@
#import "OWSPrimaryStorage.h"
#import "AppContext.h"
#import "OWSDisappearingMessagesFinder.h"
#import "OWSFailedAttachmentDownloadsJob.h"
#import "OWSFailedMessagesJob.h"
#import "OWSFileSystem.h"
#import "OWSIncomingMessageFinder.h"
#import "OWSMediaGalleryFinder.h"
@ -14,7 +12,8 @@
#import "SSKEnvironment.h"
#import "TSDatabaseSecondaryIndexes.h"
#import "TSDatabaseView.h"
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
#import <YapDatabase/YapDatabaseConnectionPool.h>
#import "SSKAsserts.h"
NS_ASSUME_NONNULL_BEGIN
@ -201,8 +200,6 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
[FullTextSearchFinder asyncRegisterDatabaseExtensionWithStorage:self];
[OWSIncomingMessageFinder asyncRegisterExtensionWithPrimaryStorage:self];
[OWSDisappearingMessagesFinder asyncRegisterDatabaseExtensions:self];
[OWSFailedMessagesJob asyncRegisterDatabaseExtensionsWithPrimaryStorage:self];
[OWSFailedAttachmentDownloadsJob asyncRegisterDatabaseExtensionsWithPrimaryStorage:self];
[OWSMediaGalleryFinder asyncRegisterDatabaseExtensionsWithPrimaryStorage:self];
[TSDatabaseView asyncRegisterLazyRestoreAttachmentsDatabaseView:self];
[SSKJobRecordFinder asyncRegisterDatabaseExtensionObjCWithStorage:self];

0
SignalUtilitiesKit/Database/OWSStorage/OWSStorage.h → SessionMessagingKit/Database/OWSStorage.h

147
SignalUtilitiesKit/Database/OWSStorage/OWSStorage.m → SessionMessagingKit/Database/OWSStorage.m

@ -4,24 +4,24 @@
#import "OWSStorage.h"
#import "AppContext.h"
#import "NSNotificationCenter+OWS.h"
#import "NSUserDefaults+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSFileSystem.h"
#import "OWSPrimaryStorage.h"
#import "OWSStorage+Subclass.h"
#import "TSYapDatabaseObject.h"
#import "TSAttachmentStream.h"
#import <SignalCoreKit/NSData+OWS.h>
#import <SignalCoreKit/SignalCoreKit.h>
#import <SignalCoreKit/Randomness.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseAutoView.h>
#import <YapDatabase/YapDatabaseCrossProcessNotification.h>
#import <YapDatabase/YapDatabaseCryptoUtils.h>
#import <YapDatabase/YapDatabaseCrossProcessNotification.h>
#import <YapDatabase/YapDatabaseFullTextSearch.h>
#import <YapDatabase/YapDatabaseFullTextSearchPrivate.h>
#import <YapDatabase/YapDatabaseSecondaryIndex.h>
#import <YapDatabase/YapDatabaseSecondaryIndexPrivate.h>
#import <YapDatabase/YapDatabaseSecondaryIndexSetup.h>
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
#import <SessionUtilitiesKit/AppContext.h>
NS_ASSUME_NONNULL_BEGIN
@ -59,8 +59,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
return self;
}
OWSAssertDebug(delegate);
self.delegate = delegate;
return self;
@ -76,8 +74,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (void)readWriteWithBlock:(void (^)(YapDatabaseReadWriteTransaction *transaction))block
{
id<OWSDatabaseConnectionDelegate> delegate = self.delegate;
OWSAssertDebug(delegate);
OWSAssertDebug(delegate.areAllRegistrationsComplete);
OWSBackgroundTask *_Nullable backgroundTask = nil;
if (CurrentAppContext().isMainApp && !CurrentAppContext().isRunningTests) {
@ -103,8 +99,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
completionBlock:(nullable dispatch_block_t)completionBlock
{
id<OWSDatabaseConnectionDelegate> delegate = self.delegate;
OWSAssertDebug(delegate);
OWSAssertDebug(delegate.areAllRegistrationsComplete);
__block OWSBackgroundTask *_Nullable backgroundTask = nil;
if (CurrentAppContext().isMainApp) {
@ -155,8 +149,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
return self;
}
OWSAssertDebug(delegate);
self.delegate = delegate;
return self;
@ -169,7 +161,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (YapDatabaseConnection *)newConnection
{
id<OWSDatabaseConnectionDelegate> delegate = self.delegate;
OWSAssertDebug(delegate);
OWSDatabaseConnection *connection = [[OWSDatabaseConnection alloc] initWithDatabase:self delegate:delegate];
[self addConnection:connection];
@ -201,8 +192,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (void)encodeWithCoder:(NSCoder *)aCoder
{
OWSFailDebug(@"Tried to save object from unknown collection");
return [super encodeWithCoder:aCoder];
}
@ -218,22 +207,16 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSFailDebug(@"Tried to save unknown object");
// No-op.
}
- (void)touchWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSFailDebug(@"Tried to touch unknown object");
// No-op.
}
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSFailDebug(@"Tried to remove unknown object");
// No-op.
}
@ -253,11 +236,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
cannotDecodeObjectOfClassName:(NSString *)name
originalClasses:(NSArray<NSString *> *)classNames
{
if ([name isEqualToString:@"TSRecipient"]) {
OWSLogError(@"Could not decode object: %@", name);
} else {
NSLog(@"Could not decode object: %@", name);
}
return [OWSUnknownDBObject class];
}
@ -295,9 +273,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (void)dealloc
{
// Surface memory leaks by logging the deallocation of this class.
OWSLogVerbose(@"Dealloc: %@", self.class);
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@ -308,7 +283,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
//
// The best we can try to do is to discard the current database
// and behave like a clean install.
OWSFailDebug(@"Could not load database");
// Try to reset app by deleting all databases.
//
@ -316,34 +290,27 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// [OWSStorage deleteDatabaseFiles];
if (![self tryToLoadDatabase]) {
OWSFailDebug(@"Could not load database (second try)");
// Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:15.0f];
OWSFail(@"Failed to initialize database.");
NSAssert(NO, @"Couldn't load database");
}
}
}
- (nullable id)dbNotificationObject
{
OWSAssertDebug(self.database);
return self.database;
}
- (BOOL)areAsyncRegistrationsComplete
{
OWSAbstractMethod();
return NO;
}
- (BOOL)areSyncRegistrationsComplete
{
OWSAbstractMethod();
return NO;
}
@ -354,26 +321,22 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (void)runSyncRegistrations
{
OWSAbstractMethod();
}
- (void)runAsyncRegistrationsWithCompletion:(void (^_Nonnull)(void))completion
{
OWSAbstractMethod();
}
+ (void)registerExtensionsWithMigrationBlock:(OWSStorageMigrationBlock)migrationBlock
{
OWSAssertDebug(migrationBlock);
__block OWSBackgroundTask *_Nullable backgroundTask =
[OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
[OWSPrimaryStorage.sharedManager runSyncRegistrations];
[OWSPrimaryStorage.sharedManager runAsyncRegistrationsWithCompletion:^{
OWSAssertDebug(self.isStorageReady);
[self postRegistrationCompleteNotification];
migrationBlock();
@ -390,10 +353,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// Returns YES IFF all registrations are complete.
+ (void)postRegistrationCompleteNotification
{
OWSAssertDebug(self.isStorageReady);
OWSLogInfo(@"");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:StorageIsReadyNotification
@ -424,15 +383,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_migrate
options.legacyCipherCompatibilityVersion = 3;
// If any of these asserts fails, we need to verify and update
// OWSDatabaseConverter which assumes the values of these options.
OWSAssertDebug(options.cipherDefaultkdfIterNumber == 0);
OWSAssertDebug(options.kdfIterNumber == 0);
OWSAssertDebug(options.cipherPageSize == 0);
OWSAssertDebug(options.pragmaPageSize == 0);
OWSAssertDebug(options.pragmaJournalSizeLimit == 0);
OWSAssertDebug(options.pragmaMMapSize == 0);
return options;
}
@ -445,13 +395,11 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// (e.g. by using OWSAssertDebug()) or this database will contain a
// circular reference and will leak.
OWSStorage *strongSelf = weakSelf;
OWSCAssertDebug(strongSelf);
// Rather than compute this once and capture the value of the key
// in the closure, we prefer to fetch the key from the keychain multiple times
// in order to keep the key out of application memory.
NSData *databaseKeySpec = [strongSelf databaseKeySpec];
OWSCAssertDebug(databaseKeySpec.length == kSQLCipherKeySpecLength);
return databaseKeySpec;
};
@ -484,7 +432,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
return ^id(NSString __unused *collection, NSString __unused *key, NSData *data) {
if (!data || data.length <= 0) {
OWSFailDebug(@"can't deserialize null object: %@", collection);
return [OWSUnknownDBObject new];
}
@ -502,9 +449,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (YapDatabaseConnection *)newDatabaseConnection
{
YapDatabaseConnection *dbConnection = self.database.newConnection;
if (!dbConnection) {
OWSFail(@"Storage could not open new database connection.");
}
return dbConnection;
}
@ -512,8 +456,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
+ (void)incrementVersionOfDatabaseExtension:(NSString *)extensionName
{
OWSLogError(@"%@", extensionName);
// Don't increment version of a given extension more than once
// per launch.
static NSMutableSet<NSString *> *incrementedViewSet = nil;
@ -523,14 +465,12 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
});
@synchronized(incrementedViewSet) {
if ([incrementedViewSet containsObject:extensionName]) {
OWSLogInfo(@"Ignoring redundant increment: %@", extensionName);
return;
}
[incrementedViewSet addObject:extensionName];
}
NSUserDefaults *appUserDefaults = [NSUserDefaults appUserDefaults];
OWSAssertDebug(appUserDefaults);
NSMutableDictionary<NSString *, NSNumber *> *_Nullable versionMap =
[[appUserDefaults valueForKey:kNSUserDefaults_DatabaseExtensionVersionMap] mutableCopy];
if (!versionMap) {
@ -545,10 +485,7 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (nullable NSString *)appendSuffixToDatabaseExtensionVersionIfNecessary:(nullable NSString *)versionTag
extensionName:(NSString *)extensionName
{
OWSAssertIsOnMainThread();
NSUserDefaults *appUserDefaults = [NSUserDefaults appUserDefaults];
OWSAssertDebug(appUserDefaults);
NSDictionary<NSString *, NSNumber *> *_Nullable versionMap =
[appUserDefaults valueForKey:kNSUserDefaults_DatabaseExtensionVersionMap];
NSNumber *_Nullable versionSuffix = versionMap[extensionName];
@ -556,7 +493,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
if (versionSuffix) {
NSString *result =
[NSString stringWithFormat:@"%@.%@", (versionTag.length < 1 ? @"0" : versionTag), versionSuffix];
OWSLogWarn(@"database extension version: %@ + %@ -> %@", versionTag, versionSuffix, result);
return result;
}
return versionTag;
@ -564,9 +500,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (YapDatabaseExtension *)updateExtensionVersion:(YapDatabaseExtension *)extension withName:(NSString *)extensionName
{
OWSAssertDebug(extension);
OWSAssertDebug(extensionName.length > 0);
if ([extension isKindOfClass:[YapDatabaseAutoView class]]) {
YapDatabaseAutoView *databaseView = (YapDatabaseAutoView *)extension;
YapDatabaseAutoView *databaseViewCopy = [[YapDatabaseAutoView alloc]
@ -578,8 +511,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
return databaseViewCopy;
} else if ([extension isKindOfClass:[YapDatabaseSecondaryIndex class]]) {
YapDatabaseSecondaryIndex *secondaryIndex = (YapDatabaseSecondaryIndex *)extension;
OWSAssertDebug(secondaryIndex->setup);
OWSAssertDebug(secondaryIndex->handler);
YapDatabaseSecondaryIndex *secondaryIndexCopy = [[YapDatabaseSecondaryIndex alloc]
initWithSetup:secondaryIndex->setup
handler:secondaryIndex->handler
@ -606,7 +537,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// This method needs to be able to update the versionTag of all extensions.
// If we start using other extension types, we need to modify this method to
// handle them as well.
OWSFailDebug(@"Unknown extension type: %@", [extension class]);
return extension;
}
@ -616,7 +546,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
{
extension = [self updateExtensionVersion:extension withName:extensionName];
OWSAssertDebug(![self.extensionNames containsObject:extensionName]);
[self.extensionNames addObject:extensionName];
return [self.database registerExtension:extension withName:extensionName];
@ -634,18 +563,11 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
{
extension = [self updateExtensionVersion:extension withName:extensionName];
OWSAssertDebug(![self.extensionNames containsObject:extensionName]);
[self.extensionNames addObject:extensionName];
[self.database asyncRegisterExtension:extension
withName:extensionName
completionBlock:^(BOOL ready) {
if (!ready) {
OWSFailDebug(@"asyncRegisterExtension failed: %@", extensionName);
} else {
OWSLogVerbose(@"asyncRegisterExtension succeeded: %@", extensionName);
}
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
completion();
@ -710,22 +632,16 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (NSString *)databaseFilePath
{
OWSAbstractMethod();
return @"";
}
- (NSString *)databaseFilePath_SHM
{
OWSAbstractMethod();
return @"";
}
- (NSString *)databaseFilePath_WAL
{
OWSAbstractMethod();
return @"";
}
@ -740,10 +656,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
return YES;
}
if (error) {
OWSLogWarn(@"Database key couldn't be accessed: %@", error.localizedDescription);
}
return NO;
}
@ -755,29 +667,21 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
+ (nullable NSData *)tryToLoadDatabaseCipherKeySpec:(NSError **)errorHandle
{
NSData *_Nullable data = [self tryToLoadKeyChainValue:keychainDBCipherKeySpec errorHandle:errorHandle];
OWSAssertDebug(!data || data.length == kSQLCipherKeySpecLength);
return data;
}
+ (void)storeDatabaseCipherKeySpec:(NSData *)cipherKeySpecData
{
OWSAssertDebug(cipherKeySpecData.length == kSQLCipherKeySpecLength);
[self storeKeyChainValue:cipherKeySpecData keychainKey:keychainDBCipherKeySpec];
}
+ (void)removeLegacyPassphrase
{
OWSLogInfo(@"removing legacy passphrase");
NSError *_Nullable error;
BOOL result = [CurrentAppContext().keychainStorage removeWithService:keychainService
key:keychainDBLegacyPassphrase
error:&error];
if (error || !result) {
OWSFailDebug(@"could not remove legacy passphrase.");
}
}
- (void)ensureDatabaseKeySpecExists
@ -800,8 +704,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
errorDescription = [errorDescription
stringByAppendingFormat:@", ApplicationState: %@", NSStringForUIApplicationState(applicationState)];
}
OWSLogError(@"%@", errorDescription);
[DDLog flushLog];
if (CurrentAppContext().isMainApp) {
if (CurrentAppContext().isInBackground) {
@ -818,9 +720,6 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// or the keychain has become corrupt. Either way, we want to get back to a
// "known good state" and behave like a new install.
BOOL doesDBExist = [NSFileManager.defaultManager fileExistsAtPath:[self databaseFilePath]];
if (doesDBExist) {
OWSFailDebug(@"Could not load database metadata");
}
if (!CurrentAppContext().isRunningTests) {
// Try to reset app by deleting database.
@ -838,12 +737,10 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
NSData *_Nullable keySpec = [[self class] tryToLoadDatabaseCipherKeySpec:&error];
if (error) {
OWSLogError(@"failed to fetch databaseKeySpec with error: %@", error);
[self raiseKeySpecInaccessibleExceptionWithErrorDescription:@"CipherKeySpec inaccessible"];
}
if (keySpec.length != kSQLCipherKeySpecLength) {
OWSLogError(@"keyspec had length: %lu", (unsigned long)keySpec.length);
[self raiseKeySpecInaccessibleExceptionWithErrorDescription:@"CipherKeySpec invalid"];
}
@ -852,15 +749,12 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
- (void)raiseKeySpecInaccessibleExceptionWithErrorDescription:(NSString *)errorDescription
{
OWSAssertDebug(CurrentAppContext().isMainApp && CurrentAppContext().isInBackground);
// Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:5.0f];
// Presumably this happened in response to a push notification. It's possible that the keychain is corrupted
// but it could also just be that the user hasn't yet unlocked their device since our password is
// kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
OWSFail(@"%@", errorDescription);
}
+ (void)deleteDBKeys
@ -869,15 +763,9 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
BOOL result = [CurrentAppContext().keychainStorage removeWithService:keychainService
key:keychainDBLegacyPassphrase
error:&error];
if (error || !result) {
OWSFailDebug(@"could not remove legacy passphrase.");
}
result = [CurrentAppContext().keychainStorage removeWithService:keychainService
key:keychainDBCipherKeySpec
error:&error];
if (error || !result) {
OWSFailDebug(@"could not remove cipher key spec.");
}
}
- (unsigned long long)databaseFileSize
@ -897,42 +785,27 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
+ (nullable NSData *)tryToLoadKeyChainValue:(NSString *)keychainKey errorHandle:(NSError **)errorHandle
{
OWSAssertDebug(keychainKey.length > 0);
OWSAssertDebug(errorHandle);
NSData *_Nullable data =
[CurrentAppContext().keychainStorage dataForService:keychainService key:keychainKey error:errorHandle];
if (*errorHandle || !data) {
OWSLogWarn(@"could not load keychain value.");
}
return data;
}
+ (void)storeKeyChainValue:(NSData *)data keychainKey:(NSString *)keychainKey
{
OWSAssertDebug(keychainKey.length > 0);
OWSAssertDebug(data.length > 0);
NSError *error;
BOOL success =
[CurrentAppContext().keychainStorage setWithData:data service:keychainService key:keychainKey error:&error];
if (!success || error) {
OWSFailDebug(@"Could not store database metadata");
// Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:15.0f];
OWSFail(@"Setting keychain value failed with error: %@", error);
} else {
OWSLogWarn(@"Successfully set new keychain value.");
}
}
- (void)logFileSizes
{
OWSLogInfo(@"Database file size: %@", [OWSFileSystem fileSizeOfPath:self.databaseFilePath]);
OWSLogInfo(@"\t SHM file size: %@", [OWSFileSystem fileSizeOfPath:self.databaseFilePath_SHM]);
OWSLogInfo(@"\t WAL file size: %@", [OWSFileSystem fileSizeOfPath:self.databaseFilePath_WAL]);
}
@end

0
SignalUtilitiesKit/Database/Utilities/SSKPreferences.swift → SessionMessagingKit/Database/SSKPreferences.swift

1
SignalUtilitiesKit/Database/Storage/Storage+ClosedGroups.swift → SessionMessagingKit/Database/Storage+ClosedGroups.swift

@ -1,3 +1,4 @@
import SessionProtocolKit
extension Storage {

0
SignalUtilitiesKit/Database/Storage/Storage+Jobs.swift → SessionMessagingKit/Database/Storage+Jobs.swift

0
SignalUtilitiesKit/Database/Storage/Storage+Messaging.swift → SessionMessagingKit/Database/Storage+Messaging.swift

0
SignalUtilitiesKit/Database/Storage/Storage+OpenGroups.swift → SessionMessagingKit/Database/Storage+OpenGroups.swift

0
SignalUtilitiesKit/Database/Storage/Storage+Shared.swift → SessionMessagingKit/Database/Storage+Shared.swift

0
SignalUtilitiesKit/Database/Utilities/TSDatabaseSecondaryIndexes.h → SessionMessagingKit/Database/TSDatabaseSecondaryIndexes.h

0
SignalUtilitiesKit/Database/Utilities/TSDatabaseSecondaryIndexes.m → SessionMessagingKit/Database/TSDatabaseSecondaryIndexes.m

2
SignalUtilitiesKit/Database/Utilities/TSDatabaseView.h → SessionMessagingKit/Database/TSDatabaseView.h

@ -2,7 +2,7 @@
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import <SignalUtilitiesKit/OWSStorage.h>
#import <SessionMessagingKit/OWSStorage.h>
#import <YapDatabase/YapDatabaseViewTransaction.h>
NS_ASSUME_NONNULL_BEGIN

37
SignalUtilitiesKit/Database/Utilities/TSDatabaseView.m → SessionMessagingKit/Database/TSDatabaseView.m

@ -60,8 +60,6 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
+ (void)registerCrossProcessNotifier:(OWSStorage *)storage
{
OWSAssertDebug(storage);
// I don't think the identifier and name of this extension matter for our purposes,
// so long as they don't conflict with any other extension names.
YapDatabaseExtension *extension =
@ -74,14 +72,8 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
version:(NSString *)version
storage:(OWSStorage *)storage
{
OWSAssertIsOnMainThread();
OWSAssertDebug(viewName.length > 0);
OWSAssertDebug((viewGrouping));
OWSAssertDebug(storage);
YapDatabaseView *existingView = [storage registeredExtension:viewName];
if (existingView) {
OWSFailDebug(@"Registered database view twice: %@", viewName);
return;
}
@ -142,7 +134,6 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(
YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {
if (![object isKindOfClass:[TSInteraction class]]) {
OWSFailDebug(@"Unexpected entity %@ in collection: %@", [object class], collection);
return nil;
}
TSInteraction *interaction = (TSInteraction *)object;
@ -167,19 +158,14 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
+ (void)asyncRegisterLegacyThreadInteractionsDatabaseView:(OWSStorage *)storage
{
OWSAssertIsOnMainThread();
OWSAssert(storage);
YapDatabaseView *existingView = [storage registeredExtension:TSMessageDatabaseViewExtensionName_Legacy];
if (existingView) {
OWSFailDebug(@"Registered database view twice: %@", TSMessageDatabaseViewExtensionName_Legacy);
return;
}
YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(
YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {
if (![object isKindOfClass:[TSInteraction class]]) {
OWSFailDebug(@"%@ Unexpected entity %@ in collection: %@", self.logTag, [object class], collection);
return nil;
}
TSInteraction *interaction = (TSInteraction *)object;
@ -197,11 +183,9 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
NSString *key2,
id object2) {
if (![object1 isKindOfClass:[TSInteraction class]]) {
OWSFailDebug(@"%@ Unexpected entity %@ in collection: %@", self.logTag, [object1 class], collection1);
return NSOrderedSame;
}
if (![object2 isKindOfClass:[TSInteraction class]]) {
OWSFailDebug(@"%@ Unexpected entity %@ in collection: %@", self.logTag, [object2 class], collection2);
return NSOrderedSame;
}
TSInteraction *interaction1 = (TSInteraction *)object1;
@ -237,7 +221,6 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(
YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {
if (![object isKindOfClass:[TSInteraction class]]) {
OWSFailDebug(@"Unexpected entity %@ in collection: %@", [object class], collection);
return nil;
}
TSInteraction *interaction = (TSInteraction *)object;
@ -271,14 +254,12 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
{
YapDatabaseView *threadView = [storage registeredExtension:TSThreadDatabaseViewExtensionName];
if (threadView) {
OWSFailDebug(@"Registered database view twice: %@", TSThreadDatabaseViewExtensionName);
return;
}
YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(
YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {
if (![object isKindOfClass:[TSThread class]]) {
OWSFailDebug(@"Unexpected entity %@ in collection: %@", [object class], collection);
return nil;
}
TSThread *thread = (TSThread *)object;
@ -287,7 +268,6 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
// Do nothing; we never hide threads that have ever had a message.
} else {
YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSMessageDatabaseViewExtensionName];
OWSAssertDebug(viewTransaction);
NSUInteger threadMessageCount = [viewTransaction numberOfItemsInGroup:thread.uniqueId];
if (threadMessageCount < 1) {
return nil;
@ -320,11 +300,9 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
NSString *key2,
id object2) {
if (![object1 isKindOfClass:[TSThread class]]) {
OWSFailDebug(@"Unexpected entity %@ in collection: %@", [object1 class], collection1);
return NSOrderedSame;
}
if (![object2 isKindOfClass:[TSThread class]]) {
OWSFailDebug(@"Unexpected entity %@ in collection: %@", [object2 class], collection2);
return NSOrderedSame;
}
TSThread *thread1 = (TSThread *)object1;