From 006021ea414a249522893cf7e0a5aadb2b2dd6fb Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 1 Oct 2018 17:01:48 -0600 Subject: [PATCH] Fix: group color change doesn't immediately apply Because we were fetching a new thread instance, instead of updating the existing thread instance, classes which were bound to the old thread instance weren't updating. This affected the HeaderView.AvatarView.thread and the ConversationStyle.thread. --- .../ConversationView/ConversationViewController.m | 12 +----------- SignalServiceKit/src/Storage/TSYapDatabaseObject.h | 1 + SignalServiceKit/src/Storage/TSYapDatabaseObject.m | 9 ++++++++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index bce53d997..bc101e9c8 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3239,17 +3239,7 @@ typedef enum : NSUInteger { if (self.isGroupConversation) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - TSGroupThread *gThread = (TSGroupThread *)self.thread; - - if (gThread.groupModel) { - TSGroupThread *_Nullable updatedThread = - [TSGroupThread threadWithGroupId:gThread.groupModel.groupId transaction:transaction]; - if (updatedThread) { - self.thread = updatedThread; - } else { - OWSFailDebug(@"Could not reload thread."); - } - } + [self.thread reloadWithTransaction:transaction]; }]; [self updateNavigationTitle]; } diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.h b/SignalServiceKit/src/Storage/TSYapDatabaseObject.h index 0958def56..2c31c81a4 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.h +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.h @@ -94,6 +94,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Assign the latest persisted values from the database. */ +- (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction; - (void)reload; /** diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m index d8a0eddbd..a3a5d9108 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m @@ -220,7 +220,14 @@ NS_ASSUME_NONNULL_BEGIN - (void)reload { - TSYapDatabaseObject *latest = [[self class] fetchObjectWithUniqueID:self.uniqueId]; + [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + [self reloadWithTransaction:transaction]; + }]; +} + +- (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + TSYapDatabaseObject *latest = [[self class] fetchObjectWithUniqueID:self.uniqueId transaction:transaction]; if (!latest) { OWSFailDebug(@"`latest` was unexpectedly nil"); return;