mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'charlesmchen/conversationViewModelStartupRace'
This commit is contained in:
commit
d338e00b1a
|
@ -4346,6 +4346,11 @@ typedef enum : NSUInteger {
|
|||
|
||||
#pragma mark - ConversationViewModelDelegate
|
||||
|
||||
- (BOOL)isObservingVMUpdates
|
||||
{
|
||||
return self.shouldObserveVMUpdates;
|
||||
}
|
||||
|
||||
- (void)conversationViewModelWillUpdate
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
|
|
@ -69,8 +69,7 @@ typedef NS_ENUM(NSUInteger, ConversationUpdateItemType) {
|
|||
- (void)conversationViewModelDidLoadPrevPage;
|
||||
- (void)conversationViewModelRangeDidChange;
|
||||
|
||||
// TODO: It'd be nice to remove this.
|
||||
- (BOOL)shouldObserveDBModifications;
|
||||
- (BOOL)isObservingVMUpdates;
|
||||
|
||||
- (ConversationStyle *)conversationStyle;
|
||||
|
||||
|
|
|
@ -210,18 +210,6 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|||
|
||||
- (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
|
||||
selector:@selector(applicationDidEnterBackground:)
|
||||
name:OWSApplicationDidEnterBackgroundNotification
|
||||
|
@ -259,6 +247,19 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|||
if (![self reloadViewItems]) {
|
||||
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
|
||||
|
@ -458,19 +459,24 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|||
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
if (self.delegate.shouldObserveDBModifications) {
|
||||
// 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];
|
||||
if (!self.delegate.isObservingVMUpdates) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
if (!self.delegate.isObservingVMUpdates) {
|
||||
return;
|
||||
}
|
||||
[self.delegate conversationViewModelWillUpdate];
|
||||
}
|
||||
|
||||
|
@ -618,6 +624,13 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|||
OWSAssertDebug(oldItemIdList);
|
||||
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) {
|
||||
OWSFailDebug(@"Old view item list has duplicates.");
|
||||
[self.delegate conversationViewModelDidUpdate:ConversationUpdate.reloadUpdate];
|
||||
|
|
Loading…
Reference in a new issue