diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h index 9438fc35e..44df14689 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h @@ -74,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction; -- (CGSize)cellSize; +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction; @end diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m index 9ff980098..df7f78a8d 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN OWS_ABSTRACT_METHOD(); } -- (CGSize)cellSize +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { OWS_ABSTRACT_METHOD(); diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m index f74fdf514..14b96d413 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSContactOffersCell.m @@ -165,7 +165,7 @@ NS_ASSUME_NONNULL_BEGIN return (self.buttonVPadding + CGSizeCeil([self.addToContactsButton sizeThatFits:CGSizeZero]).height); } -- (CGSize)cellSize +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssert(self.layoutInfo); OWSAssert(self.layoutInfo.viewWidth > 0); diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 22e7fb1dd..07a8606a1 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -384,7 +384,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Measurement -- (CGSize)cellSize +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssert(self.layoutInfo); OWSAssert(self.layoutInfo.viewWidth > 0); diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m index bc3d411d6..bcbcf2d92 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m @@ -92,6 +92,7 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(self.layoutInfo); OWSAssert(self.viewItem); + OWSAssert(transaction); TSInteraction *interaction = self.viewItem.interaction; @@ -99,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN self.imageView.image = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; self.imageView.tintColor = [self iconColorForInteraction:interaction]; self.titleLabel.textColor = [self textColor]; - [self applyTitleForInteraction:interaction label:self.titleLabel]; + [self applyTitleForInteraction:interaction label:self.titleLabel transaction:transaction]; CGSize titleSize = [self titleSize]; @@ -195,9 +196,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)applyTitleForInteraction:(TSInteraction *)interaction label:(UILabel *)label + transaction:(YapDatabaseReadTransaction *)transaction { OWSAssert(interaction); OWSAssert(label); + OWSAssert(transaction); [self configureFonts]; @@ -205,7 +208,7 @@ NS_ASSUME_NONNULL_BEGIN if ([interaction isKindOfClass:[TSErrorMessage class]]) { TSErrorMessage *errorMessage = (TSErrorMessage *)interaction; - label.text = [errorMessage previewText]; + label.text = [errorMessage previewTextWithTransaction:transaction]; } else if ([interaction isKindOfClass:[TSInfoMessage class]]) { TSInfoMessage *infoMessage = (TSInfoMessage *)interaction; if ([infoMessage isKindOfClass:[OWSVerificationStateChangeMessage class]]) { @@ -230,11 +233,11 @@ NS_ASSUME_NONNULL_BEGIN @"another device. Embeds {{user's name or phone number}}."))); label.text = [NSString stringWithFormat:titleFormat, displayName]; } else { - label.text = [infoMessage previewText]; + label.text = [infoMessage previewTextWithTransaction:transaction]; } } else if ([interaction isKindOfClass:[TSCall class]]) { TSCall *call = (TSCall *)interaction; - label.text = [call previewText]; + label.text = [call previewTextWithTransaction:transaction]; } else { OWSFail(@"Unknown interaction type: %@", [interaction class]); label.text = nil; @@ -272,7 +275,7 @@ NS_ASSUME_NONNULL_BEGIN return [self.titleLabel sizeThatFits:CGSizeMake(maxTitleWidth, CGFLOAT_MAX)]; } -- (CGSize)cellSize +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssert(self.layoutInfo); OWSAssert(self.viewItem); @@ -281,7 +284,7 @@ NS_ASSUME_NONNULL_BEGIN CGSize result = CGSizeMake(self.layoutInfo.viewWidth, 0); - [self applyTitleForInteraction:interaction label:self.titleLabel]; + [self applyTitleForInteraction:interaction label:self.titleLabel transaction:transaction]; CGSize titleSize = [self titleSize]; CGFloat contentHeight = ceil(MAX([self iconSize], titleSize.height)); diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m index 172b3a495..6dba74621 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m @@ -104,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN .uppercaseString; } -- (CGSize)cellSize +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssert(self.layoutInfo); OWSAssert(self.viewItem); diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index bbfd985e6..5f85bf309 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -535,7 +535,8 @@ typedef enum : NSUInteger { { OWSAssert(self.layoutInfo); - _layout = [[ConversationViewLayout alloc] initWithLayoutInfo:self.layoutInfo]; + _layout = [[ConversationViewLayout alloc] initWithLayoutInfo:self.layoutInfo + uiDatabaseConnection:self.uiDatabaseConnection]; self.layoutInfo.viewWidth = self.view.width; self.layout.delegate = self; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 9a1cb891f..2cb4e15eb 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -178,8 +178,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) self.cachedCellSize = nil; } -- (CGSize)cellSize +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { + OWSAssert(transaction); OWSAssertIsOnMainThread(); OWSAssert(self.layoutInfo); @@ -187,7 +188,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) ConversationViewCell *_Nullable measurementCell = [self measurementCell]; measurementCell.viewItem = self; measurementCell.layoutInfo = self.layoutInfo; - CGSize cellSize = [measurementCell cellSize]; + CGSize cellSize = [measurementCell cellSizeWithTransaction:transaction]; self.cachedCellSize = [NSValue valueWithCGSize:cellSize]; [measurementCell prepareForReuse]; } diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h index e72c9513d..5fc3b17be 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h @@ -14,10 +14,12 @@ typedef NS_ENUM(NSInteger, ConversationViewLayoutAlignment) { }; @class ConversationLayoutInfo; +@class YapDatabaseConnection; +@class YapDatabaseReadTransaction; @protocol ConversationViewLayoutItem -- (CGSize)cellSize; +- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction; - (ConversationViewLayoutAlignment)layoutAlignment; @@ -48,7 +50,8 @@ typedef NS_ENUM(NSInteger, ConversationViewLayoutAlignment) { - (instancetype)init NS_UNAVAILABLE; -- (instancetype)initWithLayoutInfo:(ConversationLayoutInfo *)layoutInfo; +- (instancetype)initWithLayoutInfo:(ConversationLayoutInfo *)layoutInfo + uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection; @end diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m index 61097b3bc..102a3213f 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m @@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @interface ConversationViewLayout () +@property (nonatomic, readonly) YapDatabaseConnection *uiDatabaseConnection; + @property (nonatomic) CGSize contentSize; @property (nonatomic, readonly) NSMutableDictionary *itemAttributesMap; @@ -29,10 +31,12 @@ NS_ASSUME_NONNULL_BEGIN @implementation ConversationViewLayout - (instancetype)initWithLayoutInfo:(ConversationLayoutInfo *)layoutInfo + uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection { if (self = [super init]) { _itemAttributesMap = [NSMutableDictionary new]; _layoutInfo = layoutInfo; + _uiDatabaseConnection = uiDatabaseConnection; } return self; @@ -94,6 +98,15 @@ NS_ASSUME_NONNULL_BEGIN // TODO: Remove this log statement after we've reduced the invalidation churn. DDLogVerbose(@"%@ prepareLayout", self.logTag); + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [self prepareLayoutWithTransaction:transaction]; + }]; +} + +- (void)prepareLayoutWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + OWSAssert(transaction); + const CGFloat viewWidth = self.layoutInfo.viewWidth; NSArray> *layoutItems = self.delegate.layoutItems; @@ -108,7 +121,7 @@ NS_ASSUME_NONNULL_BEGIN y += [layoutItem vSpacingWithPreviousLayoutItem:previousLayoutItem]; } - CGSize layoutSize = CGSizeCeil([layoutItem cellSize]); + CGSize layoutSize = CGSizeCeil([layoutItem cellSizeWithTransaction:transaction]); // Ensure cell fits within view. OWSAssert(layoutSize.width <= viewWidth); diff --git a/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.h b/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.h index d552268e6..852fa1496 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.h @@ -20,8 +20,6 @@ NS_ASSUME_NONNULL_BEGIN createdByRemoteName:(nullable NSString *)remoteName createdInExistingGroup:(BOOL)createdInExistingGroup; -- (NSString *)previewText; - @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.m b/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.m index f54d740f1..bcb58ce73 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.m @@ -50,11 +50,6 @@ NS_ASSUME_NONNULL_BEGIN } -(NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - return [self previewText]; -} - -- (NSString *)previewText { if (self.createdInExistingGroup) { OWSAssert(self.configurationIsEnabled && self.configurationDurationSeconds > 0); diff --git a/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.h b/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.h index 01a3b8946..1d2e62159 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.h @@ -27,9 +27,6 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) { @interface TSErrorMessage : TSMessage -@property (nonatomic, readonly) TSErrorMessageType errorType; -@property (nullable, nonatomic, readonly) NSString *recipientId; - - (instancetype)initMessageWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread messageBody:(nullable NSString *)body @@ -73,7 +70,8 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) { + (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId; -- (NSString *)previewText; +@property (nonatomic, readonly) TSErrorMessageType errorType; +@property (nullable, nonatomic, readonly) NSString *recipientId; @end diff --git a/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.m b/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.m index 5c736a58e..550aa1b92 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSErrorMessage.m @@ -104,11 +104,6 @@ NSUInteger TSErrorMessageSchemaVersion = 1; } - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - return [self previewText]; -} - -- (NSString *)previewText { switch (_errorType) { case TSErrorMessageNoSession: diff --git a/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.h b/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.h index d360a1d2b..03d1e7d05 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.h @@ -61,8 +61,6 @@ typedef NS_ENUM(NSInteger, TSInfoMessageType) { expiresInSeconds:(uint32_t)expiresInSeconds expireStartedAt:(uint64_t)expireStartedAt NS_UNAVAILABLE; -- (NSString *)previewText; - @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.m b/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.m index b5b63b1c6..b9a181158 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSInfoMessage.m @@ -112,11 +112,6 @@ NSUInteger TSInfoMessageSchemaVersion = 1; } - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - return [self previewText]; -} - -- (NSString *)previewText { switch (_messageType) { case TSInfoMessageTypeSessionDidEnd: diff --git a/SignalServiceKit/src/Messages/TSCall.h b/SignalServiceKit/src/Messages/TSCall.h index 207290a9a..fdca7d4d1 100644 --- a/SignalServiceKit/src/Messages/TSCall.h +++ b/SignalServiceKit/src/Messages/TSCall.h @@ -35,8 +35,6 @@ typedef enum { - (void)updateCallType:(RPRecentCallType)callType; -- (NSString *)previewText; - @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/TSCall.m b/SignalServiceKit/src/Messages/TSCall.m index 64d149c3d..20d805c09 100644 --- a/SignalServiceKit/src/Messages/TSCall.m +++ b/SignalServiceKit/src/Messages/TSCall.m @@ -68,11 +68,6 @@ NSUInteger TSCallCurrentSchemaVersion = 1; } - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - return [self previewText]; -} - -- (NSString *)previewText { // We don't actually use the `transaction` but other sibling classes do. switch (_callType) {