diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index cd01ecc3f..f40e0eec8 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSThread.h" @@ -215,24 +215,6 @@ NS_ASSUME_NONNULL_BEGIN return [messages copy]; } -- (NSArray > *)unreadMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - NSMutableArray > *messages = [NSMutableArray new]; - [[transaction ext:TSUnreadDatabaseViewExtensionName] - enumerateRowsInGroup:self.uniqueId - usingBlock:^( - NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) { - - if (![object conformsToProtocol:@protocol(OWSReadTracking)]) { - OWSFail(@"%@ Unexpected object in unread messages: %@", self.logTag, object); - return; - } - [messages addObject:(id)object]; - }]; - - return [messages copy]; -} - - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { for (id message in [self unseenMessagesWithTransaction:transaction]) { diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 2e6951ab8..4835c3fe5 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -4,6 +4,7 @@ #import "OWSMessageManager.h" #import "AppContext.h" +#import "AppReadiness.h" #import "ContactsManagerProtocol.h" #import "Cryptography.h" #import "MimeTypeUtil.h" @@ -135,7 +136,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)yapDatabaseModified:(NSNotification *)notification { - [self updateApplicationBadgeCount]; + if (AppReadiness.isAppReady) { + [self updateApplicationBadgeCount]; + } } #pragma mark - Blocking diff --git a/SignalServiceKit/src/Storage/TSDatabaseView.h b/SignalServiceKit/src/Storage/TSDatabaseView.h index 27f015863..cc538222f 100644 --- a/SignalServiceKit/src/Storage/TSDatabaseView.h +++ b/SignalServiceKit/src/Storage/TSDatabaseView.h @@ -21,6 +21,20 @@ extern NSString *const TSSecondaryDevicesDatabaseViewExtensionName; - (instancetype)init NS_UNAVAILABLE; +#pragma mark - Views + +// Returns the "unseen" database view if it is ready; +// otherwise it returns the "unread" database view. ++ (id)unseenDatabaseViewExtension:(YapDatabaseReadTransaction *)transaction; + +// NOTE: It is not safe to call this method while hasPendingViewRegistrations is YES. ++ (id)threadOutgoingMessageDatabaseView:(YapDatabaseReadTransaction *)transaction; + +// NOTE: It is not safe to call this method while hasPendingViewRegistrations is YES. ++ (id)threadSpecialMessagesDatabaseView:(YapDatabaseReadTransaction *)transaction; + +#pragma mark - Registration + + (void)registerCrossProcessNotifier:(OWSStorage *)storage; // This method must be called _AFTER_ asyncRegisterThreadInteractionsDatabaseView. @@ -43,14 +57,4 @@ extern NSString *const TSSecondaryDevicesDatabaseViewExtensionName; + (void)asyncRegisterSecondaryDevicesDatabaseView:(OWSStorage *)storage; -// Returns the "unseen" database view if it is ready; -// otherwise it returns the "unread" database view. -+ (id)unseenDatabaseViewExtension:(YapDatabaseReadTransaction *)transaction; - -// NOTE: It is not safe to call this method while hasPendingViewRegistrations is YES. -+ (id)threadOutgoingMessageDatabaseView:(YapDatabaseReadTransaction *)transaction; - -// NOTE: It is not safe to call this method while hasPendingViewRegistrations is YES. -+ (id)threadSpecialMessagesDatabaseView:(YapDatabaseReadTransaction *)transaction; - @end diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 96d88887e..e1a2207b2 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -192,6 +192,8 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE Logger.debug("\(self.logTag) \(#function)") + AppReadiness.setAppIsReady() + if TSAccountManager.isRegistered() { Logger.info("\(self.logTag) localNumber: \(TSAccountManager.localNumber)") @@ -219,7 +221,6 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE // We don't need to fetch the local profile in the SAE OWSReadReceiptManager.shared().prepareCachedValues() - } @objc @@ -323,7 +324,9 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE Logger.debug("\(self.logTag) \(#function)") if isReadyForAppExtensions { - activate() + AppReadiness.runNowOr(whenAppIsReady: { + self.activate() + }) } } @@ -434,7 +437,8 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE self.showPrimaryViewController(conversationPicker) Logger.info("showing picker with attachment: \(attachment)") }.catch { error in - let alertTitle = NSLocalizedString("SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE", comment: "Shown when trying to share content to a Signal user for the share extension. Followed by failure details.") + let alertTitle = NSLocalizedString("SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE", + comment: "Shown when trying to share content to a Signal user for the share extension. Followed by failure details.") OWSAlerts.showAlert(withTitle: alertTitle, message: error.localizedDescription, buttonTitle: CommonStrings.cancelButton) { _ in diff --git a/SignalShareExtension/SignalShareExtension-Bridging-Header.h b/SignalShareExtension/SignalShareExtension-Bridging-Header.h index b8d303e4e..198d68085 100644 --- a/SignalShareExtension/SignalShareExtension-Bridging-Header.h +++ b/SignalShareExtension/SignalShareExtension-Bridging-Header.h @@ -21,6 +21,7 @@ #import #import #import +#import #import #import #import