Merge branch 'charlesmchen/yapDatabaseCrash1'

pull/1/head
Matthew Chen 7 years ago
commit bdb9eed88e

@ -21,7 +21,7 @@ def shared_pods
#pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'signal-master', :inhibit_warnings => true
#pod 'JSQMessagesViewController', path: '../JSQMessagesViewController'
pod 'Mantle', :inhibit_warnings => true
pod 'YapDatabase/SQLCipher', '~> 2.9.3', :inhibit_warnings => true
pod 'YapDatabase/SQLCipher', :inhibit_warnings => true
pod 'PureLayout', :inhibit_warnings => true
pod 'Reachability', :inhibit_warnings => true
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git', :inhibit_warnings => true

@ -20,13 +20,11 @@ PODS:
- Curve25519Kit (~> 2.1.0)
- HKDFKit (~> 0.0.3)
- ProtocolBuffers (~> 1.9.8)
- CocoaLumberjack (2.4.0):
- CocoaLumberjack/Default (= 2.4.0)
- CocoaLumberjack/Extensions (= 2.4.0)
- CocoaLumberjack/Core (2.4.0)
- CocoaLumberjack/Default (2.4.0):
- CocoaLumberjack/Core
- CocoaLumberjack/Extensions (2.4.0):
- CocoaLumberjack (3.3.0):
- CocoaLumberjack/Default (= 3.3.0)
- CocoaLumberjack/Extensions (= 3.3.0)
- CocoaLumberjack/Default (3.3.0)
- CocoaLumberjack/Extensions (3.3.0):
- CocoaLumberjack/Default
- Curve25519Kit (2.1.0)
- GRKOpenSSLFramework (1.0.2.11.2)
@ -34,7 +32,7 @@ PODS:
- JSQMessagesViewController (7.3.4):
- JSQSystemSoundPlayer (~> 2.0.1)
- JSQSystemSoundPlayer (2.0.1)
- libPhoneNumber-iOS (0.9.10)
- libPhoneNumber-iOS (0.9.12)
- Mantle (2.1.0):
- Mantle/extobjc (= 2.1.0)
- Mantle/extobjc (2.1.0)
@ -54,61 +52,74 @@ PODS:
- SAMKeychain
- SocketRocket
- TwistedOakCollapsingFutures
- YapDatabase/SQLCipher (~> 2.9.3)
- YapDatabase/SQLCipher
- SocketRocket (0.5.1)
- SQLCipher (3.4.1):
- SQLCipher/standard (= 3.4.1)
- SQLCipher/common (3.4.1)
- SQLCipher/fts (3.4.1):
- SQLCipher/standard (3.4.1):
- SQLCipher/common
- TwistedOakCollapsingFutures (1.0.0):
- UnionFind (~> 1.0)
- UnionFind (1.0.1)
- YapDatabase/SQLCipher (2.9.3):
- YapDatabase/SQLCipher/Core (= 2.9.3)
- YapDatabase/SQLCipher/Extensions (= 2.9.3)
- YapDatabase/SQLCipher/Core (2.9.3):
- CocoaLumberjack (~> 2)
- SQLCipher/fts
- YapDatabase/SQLCipher/Extensions (2.9.3):
- YapDatabase/SQLCipher (3.0.2):
- YapDatabase/SQLCipher/Core (= 3.0.2)
- YapDatabase/SQLCipher/Extensions (= 3.0.2)
- YapDatabase/SQLCipher/Core (3.0.2):
- CocoaLumberjack
- SQLCipher (>= 3.4.0)
- YapDatabase/SQLCipher/Extensions (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/ActionManager (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/AutoView (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/CloudCore (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/CloudKit (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/FilteredView (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/FullTextSearch (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/Hooks (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/ManualView (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/Relationships (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/RTreeIndex (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/SearchResultsView (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/View (= 3.0.2)
- YapDatabase/SQLCipher/Extensions/ActionManager (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/AutoView
- YapDatabase/SQLCipher/Extensions/AutoView (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/View
- YapDatabase/SQLCipher/Extensions/CloudCore (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/ActionManager (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/CloudKit (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/FilteredViews (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/FullTextSearch (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/Hooks (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/Relationships (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/RTreeIndex (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/SearchResults (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/Views (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/ActionManager (2.9.3):
- YapDatabase/SQLCipher/Extensions/CloudKit (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Views
- YapDatabase/SQLCipher/Extensions/CloudKit (2.9.3):
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (2.9.3):
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (2.9.3):
- YapDatabase/SQLCipher/Extensions/FilteredView (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/FilteredViews (2.9.3):
- YapDatabase/SQLCipher/Extensions/View
- YapDatabase/SQLCipher/Extensions/FullTextSearch (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Views
- YapDatabase/SQLCipher/Extensions/FullTextSearch (2.9.3):
- YapDatabase/SQLCipher/Extensions/Hooks (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Hooks (2.9.3):
- YapDatabase/SQLCipher/Extensions/ManualView (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Relationships (2.9.3):
- YapDatabase/SQLCipher/Extensions/View
- YapDatabase/SQLCipher/Extensions/Relationships (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/RTreeIndex (2.9.3):
- YapDatabase/SQLCipher/Extensions/RTreeIndex (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/SearchResults (2.9.3):
- YapDatabase/SQLCipher/Extensions/SearchResultsView (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/AutoView
- YapDatabase/SQLCipher/Extensions/FullTextSearch
- YapDatabase/SQLCipher/Extensions/Views
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (2.9.3):
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (3.0.2):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Views (2.9.3):
- YapDatabase/SQLCipher/Extensions/View (3.0.2):
- YapDatabase/SQLCipher/Core
- YYImage (1.0.4):
- YYImage/Core (= 1.0.4)
@ -127,7 +138,7 @@ DEPENDENCIES:
- Reachability
- SignalServiceKit (from `.`)
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
- YapDatabase/SQLCipher (~> 2.9.3)
- YapDatabase/SQLCipher
- YYImage
EXTERNAL SOURCES:
@ -174,26 +185,26 @@ SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
ATAppUpdater: a9f7027060959d47e58733d3b48f6b9a28cb8de1
AxolotlKit: 7cfd2e71329b8dc398734e95b936450a2081fd60
CocoaLumberjack: aa9dcab71bdf9eaf2a63bbd9ddc87863efe45457
CocoaLumberjack: 3c8c74683302f9012bb168e1c4b7ae3c0b558431
Curve25519Kit: 76d0859ecb34704f7732847812363f83b23a6a59
GRKOpenSSLFramework: 39829d7b30f95133301f44514d4d7c070961e9f8
HKDFKit: 3fb424060aaf69795bc8ab34c4c233b98dc6303b
JSQMessagesViewController: 39fed975e3c9f8eba7292071e29eeb541d105e66
JSQSystemSoundPlayer: c5850e77a4363ffd374cd851154b9af93264ed8d
libPhoneNumber-iOS: f721ae4d5854bce60934f9fb9b0b28e8e68913cb
libPhoneNumber-iOS: b8a1038a101c78616c4df87815ac1556349faf98
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
ProtocolBuffers: d509225eb2ea43d9582a59e94348fcf86e2abd65
PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
SignalServiceKit: eacb357b55f76e5475662c801038371f37d7b02d
SignalServiceKit: 8f9038e584080bee8c367268067e6e0ec0feefcf
SocketRocket: dbb1554b8fc288ef8ef370d6285aeca7361be31e
SQLCipher: 43d12c0eb9c57fb438749618fc3ce0065509a559
TwistedOakCollapsingFutures: f359b90f203e9ab13dfb92c9ff41842a7fe1cd0c
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
YapDatabase: 299a32de9d350d37a9ac5b0532609d87d5d2a5de
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
PODFILE CHECKSUM: 95e805068c7c37952aa91bb1cf4334a87030aa45
PODFILE CHECKSUM: bbc38aeceb39482a3cc46f0de44c6aef671e3e9f
COCOAPODS: 1.3.1

@ -251,8 +251,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// Every time we change or add a database view in such a way that
// might cause a delay on launch, we need to bump this constant.
//
// We added a number of database views in v2.13.0.
NSString *kLastVersionWithDatabaseViewChange = @"2.13.0";
// We upgraded YapDatabase in v2.20.0 and need to regenerate all database views.
NSString *kLastVersionWithDatabaseViewChange = @"2.20.0";
BOOL mayNeedUpgrade = ([TSAccountManager isRegistered] && lastLaunchedAppVersion
&& (!lastCompletedLaunchAppVersion ||
[VersionMigrations isVersion:lastCompletedLaunchAppVersion

@ -89,7 +89,8 @@
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <SignalServiceKit/Threading.h>
#import <YapDatabase/YapDatabaseView.h>
#import <YapDatabase/YapDatabaseViewChange.h>
#import <YapDatabase/YapDatabaseViewConnection.h>
@import Photos;
@ -295,7 +296,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
name:YapDatabaseModifiedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
@ -2782,6 +2783,18 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return _editingDatabaseConnection;
}
- (void)yapDatabaseModifiedExternally:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
// External database modifications can't be converted into incremental updates,
// so rebuild everything. This is expensive and usually isn't necessary, but
// there's no alternative.
[self resetMappings];
}
- (void)yapDatabaseModified:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
@ -2794,6 +2807,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return;
}
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
// HACK to work around radar #28167779
// "UICollectionView performBatchUpdates can trigger a crash if the collection view is flagged for layout"
// more: https://github.com/PSPDFKit-labs/radar.apple.com/tree/master/28167779%20-%20CollectionViewBatchingIssue

@ -111,7 +111,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
_blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]];
// Ensure ExperienceUpgradeFinder has been initialized.
ExperienceUpgradeFinder.sharedManager;
[ExperienceUpgradeFinder sharedManager];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockedPhoneNumbersDidChange:)
@ -138,7 +138,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
name:YapDatabaseModifiedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
object:nil];
}
@ -923,12 +923,28 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
return _uiDatabaseConnection;
}
- (void)yapDatabaseModifiedExternally:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
// External database modifications can't be converted into incremental updates,
// so rebuild everything. This is expensive and usually isn't necessary, but
// there's no alternative.
[self resetMappings];
}
- (void)yapDatabaseModified:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
if (!self.shouldObserveDBModifications) {
return;
}
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
if (![[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] hasChangesForGroup:self.currentGrouping

@ -65,11 +65,11 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:self.dbConnection.database];
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
object:self.dbConnection.database];
object:nil];
self.refreshControl = [UIRefreshControl new];
[self.refreshControl addTarget:self action:@selector(refreshDevices) forControlEvents:UIControlEventValueChanged];
@ -200,8 +200,29 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
#pragma mark - Table view data source
- (void)yapDatabaseModifiedExternally:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
// External database modifications can't be converted into incremental updates,
// so rebuild everything. This is expensive and usually isn't necessary, but
// there's no alternative.
[self.dbConnection beginLongLivedReadTransaction];
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.deviceMappings updateWithTransaction:transaction];
}];
[self.tableView reloadData];
}
- (void)yapDatabaseModified:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
NSArray *notifications = [self.dbConnection beginLongLivedReadTransaction];
[self setupEditButton];

@ -12,6 +12,75 @@ NS_ASSUME_NONNULL_BEGIN
@implementation MainAppContext
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:nil];
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Notifications
- (void)applicationWillEnterForeground:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
}
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
}
- (void)applicationWillResignActive:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
}
#pragma mark -
- (BOOL)isMainApp
{
return YES;

@ -58,6 +58,14 @@
handler:^(UIAlertAction *_Nonnull action) {
[Pastelog.sharedManager sendToSelf:urlString];
}]];
[alert addAction:[UIAlertAction
actionWithTitle:
NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD",
@"Label for the 'send to last thread' option of the the debug log alert.")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
[Pastelog.sharedManager sendToMostRecentThread:urlString];
}]];
#endif
[alert addAction:
[UIAlertAction
@ -261,6 +269,29 @@
}];
[ThreadUtil sendMessageWithText:url inThread:thread messageSender:messageSender];
});
// Also copy to pasteboard.
[[UIPasteboard generalPasteboard] setString:url];
}
- (void)sendToMostRecentThread:(NSString *)url
{
if (![TSAccountManager isRegistered]) {
return;
}
OWSMessageSender *messageSender = Environment.current.messageSender;
DispatchMainThreadSafe(^{
__block TSThread *thread = nil;
[[TSStorageManager sharedManager].dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [[transaction ext:TSThreadDatabaseViewExtensionName] firstObjectInGroup:[TSThread collection]];
}];
[ThreadUtil sendMessageWithText:url inThread:thread messageSender:messageSender];
});
// Also copy to pasteboard.
[[UIPasteboard generalPasteboard] setString:url];
}
@end

@ -442,6 +442,9 @@
/* Label for the 'email debug log' option of the the debug log alert. */
"DEBUG_LOG_ALERT_OPTION_EMAIL" = "Email Support";
/* Label for the 'send to last thread' option of the the debug log alert. */
"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD" = "Send to Last Thread";
/* Label for the 'send to self' option of the the debug log alert. */
"DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF" = "Send to Self";
@ -637,21 +640,6 @@
/* No comment provided by engineer. */
"ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY" = "Safety number changed. Tap to verify.";
/* Message for the alert indicating the 'export with signal' file had an invalid filename. */
"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_INVALID_FILENAME" = "Invalid filename.";
/* Message for the alert indicating the 'export with signal' attachment couldn't be loaded. */
"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_ATTACHMENT" = "Couldn't load file.";
/* Message for the alert indicating the 'export with signal' data couldn't be loaded. */
"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA" = "Couldn't load file.";
/* Message for the alert indicating the 'export with signal' file had unknown type. */
"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE" = "Unknown file type.";
/* Title for the alert indicating the 'export with signal' attachment had an error. */
"EXPORT_WITH_SIGNAL_ERROR_TITLE" = "Error";
/* action sheet header when re-sending message which failed because of too many attempts */
"FAILED_SENDING_BECAUSE_RATE_LIMIT" = "Too many failures with this contact. Please try again shortly.";
@ -1384,9 +1372,6 @@
/* Label for the send button in the conversation view. */
"SEND_BUTTON_TITLE" = "Send";
/* Header title for the 'send external file' view. */
"SEND_EXTERNAL_FILE_HEADER_TITLE" = "Select a Recipient for:";
/* Title for the 'send external file' view. */
"SEND_EXTERNAL_FILE_VIEW_TITLE" = "Send File";

@ -3,6 +3,7 @@
//
#import "ThreadViewHelper.h"
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
@ -16,9 +17,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) YapDatabaseConnection *uiDatabaseConnection;
@property (nonatomic) YapDatabaseViewMappings *threadMappings;
@property (nonatomic) BOOL shouldObserveDBModifications;
@end
#pragma mark -
@implementation ThreadViewHelper
- (instancetype)init
@ -48,49 +52,117 @@ NS_ASSUME_NONNULL_BEGIN
[[YapDatabaseViewMappings alloc] initWithGroups:@[ grouping ] view:TSThreadDatabaseViewExtensionName];
[self.threadMappings setIsReversed:YES forGroup:grouping];
__weak ThreadViewHelper *weakSelf = self;
[self.uiDatabaseConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
self.uiDatabaseConnection = [TSStorageManager.sharedManager newDatabaseConnection];
[self.uiDatabaseConnection beginLongLivedReadTransaction];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf updateThreads];
[weakSelf.delegate threadListDidChange];
});
}];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
self.shouldObserveDBModifications
= !(CurrentAppContext().isMainApp && CurrentAppContext().mainApplicationState == UIApplicationStateBackground);
}
#pragma mark - Database
- (void)applicationWillEnterForeground:(NSNotification *)notification
{
self.shouldObserveDBModifications = YES;
}
- (YapDatabaseConnection *)uiDatabaseConnection
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
self.shouldObserveDBModifications = NO;
}
// Don't observe database change notifications when the app is in the background.
//
// Instead, rebuild model state when app enters foreground.
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
{
NSAssert([NSThread isMainThread], @"Must access uiDatabaseConnection on main thread!");
if (!_uiDatabaseConnection) {
YapDatabase *database = TSStorageManager.sharedManager.database;
_uiDatabaseConnection = [database newConnection];
[_uiDatabaseConnection beginLongLivedReadTransaction];
if (_shouldObserveDBModifications == shouldObserveDBModifications) {
return;
}
_shouldObserveDBModifications = shouldObserveDBModifications;
if (shouldObserveDBModifications) {
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
}];
[self updateThreads];
[self.delegate threadListDidChange];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:database];
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
object:database];
object:nil];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:YapDatabaseModifiedExternallyNotification
object:nil];
}
}
#pragma mark - Database
- (YapDatabaseConnection *)uiDatabaseConnection
{
OWSAssert([NSThread isMainThread]);
return _uiDatabaseConnection;
}
- (void)yapDatabaseModifiedExternally:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
// External database modifications can't be converted into incremental updates,
// so rebuild everything. This is expensive and usually isn't necessary, but
// there's no alternative.
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
}];
[self updateThreads];
[self.delegate threadListDidChange];
}
- (void)yapDatabaseModified:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
if (!
[[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] hasChangesForNotifications:notifications]) {
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.threadMappings updateWithTransaction:transaction];
}];
return;
}
NSArray *sectionChanges = nil;
NSArray *rowChanges = nil;
[[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:&sectionChanges
rowChanges:&rowChanges
forNotifications:notifications
withMappings:self.threadMappings];
if (sectionChanges.count == 0 && rowChanges.count == 0) {
// Ignore irrelevant modifications.
return;

@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSScrubbingLogFormatter
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
- (NSString *__nullable)formatLogMessage:(DDLogMessage *)logMessage
{
NSString *logString = [super formatLogMessage:logMessage];
NSRegularExpression *phoneRegex =

@ -43,7 +43,7 @@ An Objective-C library for communicating with the Signal messaging service.
s.dependency 'AFNetworking'
s.dependency 'AxolotlKit'
s.dependency 'Mantle'
s.dependency 'YapDatabase/SQLCipher', '~> 2.9.3'
s.dependency 'YapDatabase/SQLCipher'
s.dependency 'SocketRocket'
s.dependency 'libPhoneNumber-iOS'
s.dependency 'GRKOpenSSLFramework'

@ -14,7 +14,6 @@
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/PreKeyWhisperMessage.h>
#import <YapDatabase/YapDatabaseTransaction.h>
#import <YapDatabase/YapDatabaseView.h>
NS_ASSUME_NONNULL_BEGIN

@ -12,9 +12,10 @@
#import "TSStorageManager.h"
#import "TSYapDatabaseObject.h"
#import "Threading.h"
#import <YapDatabase/YapDatabaseAutoView.h>
#import <YapDatabase/YapDatabaseConnection.h>
#import <YapDatabase/YapDatabaseTransaction.h>
#import <YapDatabase/YapDatabaseView.h>
#import <YapDatabase/YapDatabaseViewTypes.h>
NS_ASSUME_NONNULL_BEGIN
@ -193,7 +194,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
options.allowedCollections =
[[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[OWSMessageContentJob collection]]];
return [[YapDatabaseView alloc] initWithGrouping:grouping sorting:sorting versionTag:@"1" options:options];
return [[YapDatabaseAutoView alloc] initWithGrouping:grouping sorting:sorting versionTag:@"1" options:options];
}

@ -13,9 +13,10 @@
#import "TSStorageManager.h"
#import "TSYapDatabaseObject.h"
#import "Threading.h"
#import <YapDatabase/YapDatabaseAutoView.h>
#import <YapDatabase/YapDatabaseConnection.h>
#import <YapDatabase/YapDatabaseTransaction.h>
#import <YapDatabase/YapDatabaseView.h>
#import <YapDatabase/YapDatabaseViewTypes.h>
NS_ASSUME_NONNULL_BEGIN
@ -175,7 +176,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
options.allowedCollections =
[[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[OWSMessageDecryptJob collection]]];
return [[YapDatabaseView alloc] initWithGrouping:grouping sorting:sorting versionTag:@"1" options:options];
return [[YapDatabaseAutoView alloc] initWithGrouping:grouping sorting:sorting versionTag:@"1" options:options];
}
+ (void)registerLegacyClasses

@ -11,8 +11,9 @@
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import "TSThread.h"
#import <YapDatabase/YapDatabaseAutoView.h>
#import <YapDatabase/YapDatabaseCrossProcessNotification.h>
#import <YapDatabase/YapDatabaseView.h>
#import <YapDatabase/YapDatabaseViewTypes.h>
NSString *const DatabaseViewRegistrationCompleteNotification = @"DatabaseViewRegistrationCompleteNotification";
@ -119,8 +120,10 @@ NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevic
options.allowedCollections =
[[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[TSInteraction collection]]];
YapDatabaseView *view =
[[YapDatabaseView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:version options:options];
YapDatabaseView *view = [[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping
sorting:viewSorting
versionTag:version
options:options];
if (async) {
[[TSStorageManager sharedManager].database
@ -280,7 +283,7 @@ NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevic
[[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[TSThread collection]]];
YapDatabaseView *databaseView =
[[YapDatabaseView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"3" options:options];
[[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"3" options:options];
[[TSStorageManager sharedManager].database registerExtension:databaseView
withName:TSThreadDatabaseViewExtensionName];
@ -394,7 +397,7 @@ NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevic
options.allowedCollections = [[YapWhitelistBlacklist alloc] initWithWhitelist:deviceCollection];
YapDatabaseView *view =
[[YapDatabaseView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"3" options:options];
[[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"3" options:options];
[[TSStorageManager sharedManager].database
asyncRegisterExtension:view

@ -56,7 +56,11 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault
DDLogInfo(@"%@ firstAppVersion: %@", self.logTag, self.firstAppVersion);
DDLogInfo(@"%@ lastAppVersion: %@", self.logTag, self.lastAppVersion);
DDLogInfo(@"%@ currentAppVersion: %@", self.logTag, self.currentAppVersion);
DDLogInfo(@"%@ currentAppVersion: %@ (%@)",
self.logTag,
self.currentAppVersion,
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]);
DDLogInfo(@"%@ lastCompletedLaunchAppVersion: %@", self.logTag, self.lastCompletedLaunchAppVersion);
}

@ -345,18 +345,24 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
// MARK: ShareViewDelegate, SAEFailedViewDelegate
public func shareViewWasCompleted() {
Logger.info("\(self.logTag) \(#function)")
self.dismiss(animated: true) {
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}
}
public func shareViewWasCancelled() {
Logger.info("\(self.logTag) \(#function)")
self.dismiss(animated: true) {
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}
}
public func shareViewFailed(error: Error) {
Logger.info("\(self.logTag) \(#function)")
self.dismiss(animated: true) {
self.extensionContext!.cancelRequest(withError: error)
}

@ -29,9 +29,57 @@ NS_ASSUME_NONNULL_BEGIN
_rootViewController = rootViewController;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(extensionHostDidBecomeActive:)
name:NSExtensionHostDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(extensionHostWillResignActive:)
name:NSExtensionHostWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(extensionHostDidEnterBackground:)
name:NSExtensionHostDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(extensionHostWillEnterForeground:)
name:NSExtensionHostWillEnterForegroundNotification
object:nil];
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Notifications
- (void)extensionHostDidBecomeActive:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
}
- (void)extensionHostWillResignActive:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
}
- (void)extensionHostDidEnterBackground:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
}
- (void)extensionHostWillEnterForeground:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
}
#pragma mark -
- (BOOL)isMainApp
{
return NO;

Loading…
Cancel
Save