Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 301c8c51a1
commit 2d76f2beb9

@ -111,7 +111,8 @@ typedef enum : NSUInteger {
@protocol OWSMessagesCollectionViewFlowLayoutDelegate <NSObject> @protocol OWSMessagesCollectionViewFlowLayoutDelegate <NSObject>
- (BOOL)isSpecialItemAtIndexPath:(NSIndexPath *)indexPath; // Returns YES for incoming and outgoing text and attachment messages.
- (BOOL)isUserMessageAtIndexPath:(NSIndexPath *)indexPath;
@end @end
@ -130,7 +131,7 @@ typedef enum : NSUInteger {
- (CGSize)sizeForItemAtIndexPath:(NSIndexPath *)indexPath - (CGSize)sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
// The unread indicator should be sized according to its desired size. // The unread indicator should be sized according to its desired size.
if ([self.delegate isSpecialItemAtIndexPath:indexPath]) { if (![self.delegate isUserMessageAtIndexPath:indexPath]) {
CGSize messageBubbleSize = [self messageBubbleSizeForItemAtIndexPath:indexPath]; CGSize messageBubbleSize = [self messageBubbleSizeForItemAtIndexPath:indexPath];
CGFloat finalHeight = messageBubbleSize.height; CGFloat finalHeight = messageBubbleSize.height;
return CGSizeMake(CGRectGetWidth(self.collectionView.frame), ceilf((float)finalHeight)); return CGSizeMake(CGRectGetWidth(self.collectionView.frame), ceilf((float)finalHeight));
@ -1563,8 +1564,7 @@ typedef enum : NSUInteger {
OWSUnreadIndicatorCell *cell = OWSUnreadIndicatorCell *cell =
[self.collectionView dequeueReusableCellWithReuseIdentifier:[OWSUnreadIndicatorCell cellReuseIdentifier] [self.collectionView dequeueReusableCellWithReuseIdentifier:[OWSUnreadIndicatorCell cellReuseIdentifier]
forIndexPath:indexPath]; forIndexPath:indexPath];
cell.interaction = unreadIndicator; [cell configureWithInteraction:unreadIndicator];
[cell configure];
return cell; return cell;
} }
@ -1577,8 +1577,7 @@ typedef enum : NSUInteger {
OWSSystemMessageCell *cell = OWSSystemMessageCell *cell =
[self.collectionView dequeueReusableCellWithReuseIdentifier:[OWSSystemMessageCell cellReuseIdentifier] [self.collectionView dequeueReusableCellWithReuseIdentifier:[OWSSystemMessageCell cellReuseIdentifier]
forIndexPath:indexPath]; forIndexPath:indexPath];
cell.interaction = interaction; [cell configureWithInteraction:interaction];
[cell configure];
return cell; return cell;
} }
@ -3825,13 +3824,12 @@ typedef enum : NSUInteger {
#pragma mark - OWSMessagesCollectionViewFlowLayoutDelegate #pragma mark - OWSMessagesCollectionViewFlowLayoutDelegate
- (BOOL)isSpecialItemAtIndexPath:(NSIndexPath *)indexPath - (BOOL)isUserMessageAtIndexPath:(NSIndexPath *)indexPath;
{ {
// TODO: // TODO: Eventually it'd be nice to this in a more performant way.
TSInteraction *interaction = [self interactionAtIndexPath:indexPath]; TSInteraction *interaction = [self interactionAtIndexPath:indexPath];
return ([interaction isKindOfClass:[TSUnreadIndicatorInteraction class]] || return (
[interaction isKindOfClass:[TSInfoMessage class]] || [interaction isKindOfClass:[TSErrorMessage class]] || [interaction isKindOfClass:[TSIncomingMessage class]] || [interaction isKindOfClass:[TSOutgoingMessage class]]);
[interaction isKindOfClass:[TSCall class]]);
} }
#pragma mark - Class methods #pragma mark - Class methods

@ -42,15 +42,15 @@ NS_ASSUME_NONNULL_BEGIN
items:@[ items:@[
[OWSTableItem itemWithTitle:@"Send 10 messages (1/sec.)" [OWSTableItem itemWithTitle:@"Send 10 messages (1/sec.)"
actionBlock:^{ actionBlock:^{
[DebugUIMessages sendTextMessage:10 thread:thread]; [DebugUIMessages sendTextMessages:10 thread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Send 100 messages (1/sec.)" [OWSTableItem itemWithTitle:@"Send 100 messages (1/sec.)"
actionBlock:^{ actionBlock:^{
[DebugUIMessages sendTextMessage:100 thread:thread]; [DebugUIMessages sendTextMessages:100 thread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Send 1,000 messages (1/sec.)" [OWSTableItem itemWithTitle:@"Send 1,000 messages (1/sec.)"
actionBlock:^{ actionBlock:^{
[DebugUIMessages sendTextMessage:1000 thread:thread]; [DebugUIMessages sendTextMessages:1000 thread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Send text/x-signal-plain" [OWSTableItem itemWithTitle:@"Send text/x-signal-plain"
actionBlock:^{ actionBlock:^{
@ -146,22 +146,23 @@ NS_ASSUME_NONNULL_BEGIN
{ {
NSArray<NSString *> *randomTexts = @[ NSArray<NSString *> *randomTexts = @[
@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. ", @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. ",
@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. " (@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
@"Suspendisse rutrum, nulla vitae pretium hendrerit, tellus " @"Suspendisse rutrum, nulla vitae pretium hendrerit, tellus "
@"turpis pharetra libero, vitae sodales tortor ante vel sem.", @"turpis pharetra libero, vitae sodales tortor ante vel sem."),
@"In a time of universal deceit - telling the truth is a revolutionary act.", @"In a time of universal deceit - telling the truth is a revolutionary act.",
@"If you want a vision of the future, imagine a boot stamping on a human face - forever.", @"If you want a vision of the future, imagine a boot stamping on a human face - forever.",
@"Who controls the past controls the future. Who controls the present controls the past.", @"Who controls the past controls the future. Who controls the present controls the past.",
@"All animals are equal, but some animals are more equal than others.", @"All animals are equal, but some animals are more equal than others.",
@"War is peace. Freedom is slavery. Ignorance is strength.", @"War is peace. Freedom is slavery. Ignorance is strength.",
@"All the war-propaganda, all the screaming and lies and hatred, comes invariably from people who are not " (@"All the war-propaganda, all the screaming and lies and hatred, comes invariably from people who are not "
@"fighting.", @"fighting."),
@"Political language. . . is designed to make lies sound truthful and murder respectable, and to give an " (@"Political language. . . is designed to make lies sound truthful and murder respectable, and to give an "
@"appearance of solidity to pure wind.", @"appearance of solidity to pure wind."),
@"The nationalist not only does not disapprove of atrocities committed by his own side, but he has a " (@"The nationalist not only does not disapprove of atrocities committed by his own side, but he has a "
@"remarkable capacity for not even hearing about them.", @"remarkable capacity for not even hearing about them."),
@"Every generation imagines itself to be more intelligent than the one that went before it, and wiser than the " (@"Every generation imagines itself to be more intelligent than the one that went before it, and wiser than "
@"one that comes after it.", @"the "
@"one that comes after it."),
@"War against a foreign country only happens when the moneyed classes think they are going to profit from it.", @"War against a foreign country only happens when the moneyed classes think they are going to profit from it.",
]; ];
NSString *randomText = randomTexts[(NSUInteger)arc4random_uniform((uint32_t)randomTexts.count)]; NSString *randomText = randomTexts[(NSUInteger)arc4random_uniform((uint32_t)randomTexts.count)];
@ -170,14 +171,14 @@ NS_ASSUME_NONNULL_BEGIN
[ThreadUtil sendMessageWithText:text inThread:thread messageSender:messageSender]; [ThreadUtil sendMessageWithText:text inThread:thread messageSender:messageSender];
} }
+ (void)sendTextMessage:(int)counter thread:(TSThread *)thread + (void)sendTextMessages:(int)counter thread:(TSThread *)thread
{ {
if (counter < 1) { if (counter < 1) {
return; return;
} }
[self sendTextMessageInThread:thread counter:counter]; [self sendTextMessageInThread:thread counter:counter];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self sendTextMessage:counter - 1 thread:thread]; [self sendTextMessages:counter - 1 thread:thread];
}); });
} }

@ -9,9 +9,9 @@
@interface OWSSystemMessageCell : JSQMessagesCollectionViewCell @interface OWSSystemMessageCell : JSQMessagesCollectionViewCell
@property (nonatomic) TSInteraction *interaction; @property (nonatomic, nullable, readonly) TSInteraction *interaction;
- (void)configure; - (void)configureWithInteraction:(TSInteraction *)interaction;
+ (CGSize)cellSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth; + (CGSize)cellSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth;

@ -15,6 +15,8 @@
@interface OWSSystemMessageCell () @interface OWSSystemMessageCell ()
@property (nonatomic, nullable) TSInteraction *interaction;
@property (nonatomic) UIImageView *imageView; @property (nonatomic) UIImageView *imageView;
@property (nonatomic) UILabel *titleLabel; @property (nonatomic) UILabel *titleLabel;
@ -29,8 +31,12 @@
return NSStringFromClass([self class]); return NSStringFromClass([self class]);
} }
- (void)configure - (void)configureWithInteraction:(TSInteraction *)interaction;
{ {
OWSAssert(interaction);
_interaction = interaction;
self.backgroundColor = [UIColor whiteColor]; self.backgroundColor = [UIColor whiteColor];
if (!self.titleLabel) { if (!self.titleLabel) {
@ -72,12 +78,12 @@
if ([interaction isKindOfClass:[TSErrorMessage class]]) { if ([interaction isKindOfClass:[TSErrorMessage class]]) {
switch (((TSErrorMessage *)self.interaction).errorType) { switch (((TSErrorMessage *)self.interaction).errorType) {
case TSErrorMessageInvalidKeyException:
case TSErrorMessageNonBlockingIdentityChange: case TSErrorMessageNonBlockingIdentityChange:
case TSErrorMessageWrongTrustedIdentityKey: case TSErrorMessageWrongTrustedIdentityKey:
case TSErrorMessageMissingKeyId:
result = [UIImage imageNamed:@"system_message_security"]; result = [UIImage imageNamed:@"system_message_security"];
break; break;
case TSErrorMessageInvalidKeyException:
case TSErrorMessageMissingKeyId:
case TSErrorMessageNoSession: case TSErrorMessageNoSession:
case TSErrorMessageInvalidMessage: case TSErrorMessageInvalidMessage:
case TSErrorMessageDuplicateMessage: case TSErrorMessageDuplicateMessage:
@ -89,8 +95,6 @@
} else if ([interaction isKindOfClass:[TSInfoMessage class]]) { } else if ([interaction isKindOfClass:[TSInfoMessage class]]) {
switch (((TSInfoMessage *)self.interaction).messageType) { switch (((TSInfoMessage *)self.interaction).messageType) {
case TSInfoMessageUserNotRegistered: case TSInfoMessageUserNotRegistered:
result = [UIImage imageNamed:@"system_message_info"];
break;
case TSInfoMessageTypeSessionDidEnd: case TSInfoMessageTypeSessionDidEnd:
case TSInfoMessageTypeUnsupportedMessage: case TSInfoMessageTypeUnsupportedMessage:
case TSInfoMessageAddToContactsOffer: case TSInfoMessageAddToContactsOffer:
@ -202,4 +206,11 @@
return result; return result;
} }
- (void)prepareForReuse
{
[super prepareForReuse];
self.interaction = nil;
}
@end @end

@ -9,9 +9,10 @@
@interface OWSUnreadIndicatorCell : JSQMessagesCollectionViewCell @interface OWSUnreadIndicatorCell : JSQMessagesCollectionViewCell
@property (nonatomic) TSUnreadIndicatorInteraction *interaction; @property (nonatomic, nullable, readonly) TSUnreadIndicatorInteraction *interaction;
- (void)configure; - (void)configureWithInteraction:(TSUnreadIndicatorInteraction *)interaction;
;
+ (CGSize)cellSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction + (CGSize)cellSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction
collectionViewWidth:(CGFloat)collectionViewWidth; collectionViewWidth:(CGFloat)collectionViewWidth;

@ -12,6 +12,8 @@
@interface OWSUnreadIndicatorCell () @interface OWSUnreadIndicatorCell ()
@property (nonatomic, nullable) TSUnreadIndicatorInteraction *interaction;
@property (nonatomic) UIView *bannerView; @property (nonatomic) UIView *bannerView;
@property (nonatomic) UIView *bannerTopHighlightView; @property (nonatomic) UIView *bannerTopHighlightView;
@property (nonatomic) UIView *bannerBottomHighlightView1; @property (nonatomic) UIView *bannerBottomHighlightView1;
@ -30,8 +32,12 @@
return NSStringFromClass([self class]); return NSStringFromClass([self class]);
} }
- (void)configure - (void)configureWithInteraction:(TSUnreadIndicatorInteraction *)interaction;
{ {
OWSAssert(interaction);
_interaction = interaction;
self.backgroundColor = [UIColor whiteColor]; self.backgroundColor = [UIColor whiteColor];
if (!self.titleLabel) { if (!self.titleLabel) {
@ -205,4 +211,11 @@
return result; return result;
} }
- (void)prepareForReuse
{
[super prepareForReuse];
self.interaction = nil;
}
@end @end

Loading…
Cancel
Save