Use UI database connection throughout the conversation cells.

pull/1/head
Matthew Chen 7 years ago
parent d40f74dd0b
commit fc299b8700

@ -74,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction;
- (CGSize)cellSize;
- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction;
@end

@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
OWS_ABSTRACT_METHOD();
}
- (CGSize)cellSize
- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWS_ABSTRACT_METHOD();

@ -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);

@ -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);

@ -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));

@ -104,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN
.uppercaseString;
}
- (CGSize)cellSize
- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(self.layoutInfo);
OWSAssert(self.viewItem);

@ -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;

@ -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];
}

@ -14,10 +14,12 @@ typedef NS_ENUM(NSInteger, ConversationViewLayoutAlignment) {
};
@class ConversationLayoutInfo;
@class YapDatabaseConnection;
@class YapDatabaseReadTransaction;
@protocol ConversationViewLayoutItem <NSObject>
- (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

@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface ConversationViewLayout ()
@property (nonatomic, readonly) YapDatabaseConnection *uiDatabaseConnection;
@property (nonatomic) CGSize contentSize;
@property (nonatomic, readonly) NSMutableDictionary<NSNumber *, UICollectionViewLayoutAttributes *> *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<id<ConversationViewLayoutItem>> *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);

@ -20,8 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
createdByRemoteName:(nullable NSString *)remoteName
createdInExistingGroup:(BOOL)createdInExistingGroup;
- (NSString *)previewText;
@end
NS_ASSUME_NONNULL_END

@ -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);

@ -27,9 +27,6 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
@interface TSErrorMessage : TSMessage <OWSReadTracking>
@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

@ -104,11 +104,6 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
}
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{
return [self previewText];
}
- (NSString *)previewText
{
switch (_errorType) {
case TSErrorMessageNoSession:

@ -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

@ -112,11 +112,6 @@ NSUInteger TSInfoMessageSchemaVersion = 1;
}
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{
return [self previewText];
}
- (NSString *)previewText
{
switch (_messageType) {
case TSInfoMessageTypeSessionDidEnd:

@ -35,8 +35,6 @@ typedef enum {
- (void)updateCallType:(RPRecentCallType)callType;
- (NSString *)previewText;
@end
NS_ASSUME_NONNULL_END

@ -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) {

Loading…
Cancel
Save