From f52814bb705a7e4d9fc1bb747ce402a24be810f1 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 13:34:24 -0400 Subject: [PATCH] =?UTF-8?q?Add=20possible=20fixes=20for=20the=20=E2=80=98e?= =?UTF-8?q?mpty=20home=20view=E2=80=99=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../ViewControllers/SignalsViewController.m | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index a8cf33d44..e35be38d9 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -415,29 +415,35 @@ - (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications { - if (!_shouldObserveDBModifications && shouldObserveDBModifications && self.threadMappings != nil) { - // Before we begin observing database modifications, make sure - // our mapping and table state is up-to-date. - // - // We need to `beginLongLivedReadTransaction` before we update our - // mapping in order to jump to the most recent commit. - [self.uiDatabaseConnection beginLongLivedReadTransaction]; - [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - [self.threadMappings updateWithTransaction:transaction]; - }]; + _shouldObserveDBModifications = shouldObserveDBModifications; + + [self ensureObserveDBModifications]; +} + +- (void)ensureObserveDBModifications +{ + if (self.shouldObserveDBModifications) { + if (self.threadMappings != nil) { + // Before we begin observing database modifications, make sure + // our mapping and table state is up-to-date. + // + // We need to `beginLongLivedReadTransaction` before we update our + // mapping in order to jump to the most recent commit. + [self.uiDatabaseConnection beginLongLivedReadTransaction]; + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [self.threadMappings updateWithTransaction:transaction]; + }]; + } [[self tableView] reloadData]; } - _shouldObserveDBModifications = shouldObserveDBModifications; - - if (shouldObserveDBModifications) { + [[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; + if (self.shouldObserveDBModifications) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yapDatabaseModified:) name:YapDatabaseModifiedNotification object:nil]; - } else { - [[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; } [self checkIfEmptyView];