Register all database views asynchronously.

This commit is contained in:
Matthew Chen 2018-01-26 16:11:05 -05:00
parent 100adae245
commit eb180ba5c4
5 changed files with 27 additions and 33 deletions

View File

@ -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<id<OWSReadTracking> > *)unreadMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction
{
NSMutableArray<id<OWSReadTracking> > *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<OWSReadTracking>)object];
}];
return [messages copy];
}
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -21,6 +21,7 @@
#import <SignalMessaging/UIView+OWS.h>
#import <SignalMessaging/VersionMigrations.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/AppReadiness.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/NSObject+OWS.h>
#import <SignalServiceKit/OWSAsserts.h>