Merge branch 'charlesmchen/conversationViewModelStartupRace'

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

@ -4346,6 +4346,11 @@ typedef enum : NSUInteger {
#pragma mark - ConversationViewModelDelegate #pragma mark - ConversationViewModelDelegate
- (BOOL)isObservingVMUpdates
{
return self.shouldObserveVMUpdates;
}
- (void)conversationViewModelWillUpdate - (void)conversationViewModelWillUpdate
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();

@ -69,8 +69,7 @@ typedef NS_ENUM(NSUInteger, ConversationUpdateItemType) {
- (void)conversationViewModelDidLoadPrevPage; - (void)conversationViewModelDidLoadPrevPage;
- (void)conversationViewModelRangeDidChange; - (void)conversationViewModelRangeDidChange;
// TODO: It'd be nice to remove this. - (BOOL)isObservingVMUpdates;
- (BOOL)shouldObserveDBModifications;
- (ConversationStyle *)conversationStyle; - (ConversationStyle *)conversationStyle;

@ -210,18 +210,6 @@ static const int kYapDatabaseRangeMinLength = 0;
- (void)addNotificationListeners - (void)addNotificationListeners
{ {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(uiDatabaseDidUpdateExternally:)
name:OWSUIDatabaseConnectionDidUpdateExternallyNotification
object:self.primaryStorage.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(uiDatabaseWillUpdate:)
name:OWSUIDatabaseConnectionWillUpdateNotification
object:self.primaryStorage.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(uiDatabaseDidUpdate:)
name:OWSUIDatabaseConnectionDidUpdateNotification
object:self.primaryStorage.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:) selector:@selector(applicationDidEnterBackground:)
name:OWSApplicationDidEnterBackgroundNotification name:OWSApplicationDidEnterBackgroundNotification
@ -259,6 +247,19 @@ static const int kYapDatabaseRangeMinLength = 0;
if (![self reloadViewItems]) { if (![self reloadViewItems]) {
OWSFailDebug(@"failed to reload view items in configureForThread."); OWSFailDebug(@"failed to reload view items in configureForThread.");
} }
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(uiDatabaseDidUpdateExternally:)
name:OWSUIDatabaseConnectionDidUpdateExternallyNotification
object:self.primaryStorage.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(uiDatabaseWillUpdate:)
name:OWSUIDatabaseConnectionWillUpdateNotification
object:self.primaryStorage.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(uiDatabaseDidUpdate:)
name:OWSUIDatabaseConnectionDidUpdateNotification
object:self.primaryStorage.dbNotificationObject];
} }
- (void)viewDidLoad - (void)viewDidLoad
@ -458,19 +459,24 @@ static const int kYapDatabaseRangeMinLength = 0;
OWSLogVerbose(@""); OWSLogVerbose(@"");
if (self.delegate.shouldObserveDBModifications) { if (!self.delegate.isObservingVMUpdates) {
// External database modifications can't be converted into incremental updates, return;
// so rebuild everything. This is expensive and usually isn't necessary, but
// there's no alternative.
//
// We don't need to do this if we're not observing db modifications since we'll
// do it when we resume.
[self resetMappings];
} }
// 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.
//
// We don't need to do this if we're not observing db modifications since we'll
// do it when we resume.
[self resetMappings];
} }
- (void)uiDatabaseWillUpdate:(NSNotification *)notification - (void)uiDatabaseWillUpdate:(NSNotification *)notification
{ {
if (!self.delegate.isObservingVMUpdates) {
return;
}
[self.delegate conversationViewModelWillUpdate]; [self.delegate conversationViewModelWillUpdate];
} }
@ -618,6 +624,13 @@ static const int kYapDatabaseRangeMinLength = 0;
OWSAssertDebug(oldItemIdList); OWSAssertDebug(oldItemIdList);
OWSAssertDebug(updatedItemSet); OWSAssertDebug(updatedItemSet);
if (!self.delegate.isObservingVMUpdates) {
OWSFailDebug(@"Skipping VM update.");
// We fire this event, but it will be ignored.
[self.delegate conversationViewModelDidUpdate:ConversationUpdate.minorUpdate];
return;
}
if (oldItemIdList.count != [NSSet setWithArray:oldItemIdList].count) { if (oldItemIdList.count != [NSSet setWithArray:oldItemIdList].count) {
OWSFailDebug(@"Old view item list has duplicates."); OWSFailDebug(@"Old view item list has duplicates.");
[self.delegate conversationViewModelDidUpdate:ConversationUpdate.reloadUpdate]; [self.delegate conversationViewModelDidUpdate:ConversationUpdate.reloadUpdate];

Loading…
Cancel
Save