Bubble collapse.

pull/1/head
Matthew Chen 7 years ago
parent c8012d3891
commit 578f40d791

@ -155,7 +155,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
OWSAssert(DisplayableText.kMaxJumbomojiCount == 5); OWSAssert(DisplayableText.kMaxJumbomojiCount == 5);
CGFloat basePointSize = [UIFont ows_dynamicTypeBodyFont].pointSize; CGFloat basePointSize = [UIFont ows_dynamicTypeBodyFont].pointSize;
switch (self.displayableText.jumbomojiCount) { switch (self.displayableBodyText.jumbomojiCount) {
case 0: case 0:
break; break;
case 1: case 1:
@ -167,7 +167,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
case 5: case 5:
return [UIFont ows_regularFontWithSize:basePointSize + 6.f]; return [UIFont ows_regularFontWithSize:basePointSize + 6.f];
default: default:
OWSFail(@"%@ Unexpected jumbomoji count: %zd", self.logTag, self.displayableText.jumbomojiCount); OWSFail(@"%@ Unexpected jumbomoji count: %zd", self.logTag, self.displayableBodyText.jumbomojiCount);
break; break;
} }
@ -211,20 +211,20 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
return self.viewItem.messageCellType; return self.viewItem.messageCellType;
} }
- (BOOL)hasText - (BOOL)hasBodyText
{ {
// This should always be valid for the appropriate cell types. // This should always be valid for the appropriate cell types.
OWSAssert(self.viewItem); OWSAssert(self.viewItem);
return self.viewItem.hasText; return self.viewItem.hasBodyText;
} }
- (nullable DisplayableText *)displayableText - (nullable DisplayableText *)displayableBodyText
{ {
// This should always be valid for the appropriate cell types. // This should always be valid for the appropriate cell types.
OWSAssert(self.viewItem.displayableText); OWSAssert(self.viewItem.displayableBodyText);
return self.viewItem.displayableText; return self.viewItem.displayableBodyText;
} }
- (nullable TSAttachmentStream *)attachmentStream - (nullable TSAttachmentStream *)attachmentStream
@ -271,7 +271,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
case OWSMessageCellType_AnimatedImage: case OWSMessageCellType_AnimatedImage:
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
case OWSMessageCellType_Video: case OWSMessageCellType_Video:
return self.hasText; return self.hasBodyText;
} }
} }
@ -289,7 +289,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
case OWSMessageCellType_Video: case OWSMessageCellType_Video:
// Is there a caption? // Is there a caption?
return self.hasText; return self.hasBodyText;
} }
} }
@ -448,7 +448,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
OWSMessageTextView *_Nullable bodyTextView = nil; OWSMessageTextView *_Nullable bodyTextView = nil;
// We render malformed messages as "empty text" messages, // We render malformed messages as "empty text" messages,
// so create a text view if there is no body media view. // so create a text view if there is no body media view.
if (self.hasText || !bodyMediaView) { if (self.hasBodyText || !bodyMediaView) {
bodyTextView = [self createBodyTextViewIfNecessary]; bodyTextView = [self createBodyTextViewIfNecessary];
} }
if (bodyTextView) { if (bodyTextView) {
@ -754,7 +754,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
shouldIgnoreEvents = outgoingMessage.messageState != TSOutgoingMessageStateSentToService; shouldIgnoreEvents = outgoingMessage.messageState != TSOutgoingMessageStateSentToService;
} }
[self.class loadForTextDisplay:self.bodyTextViewCached [self.class loadForTextDisplay:self.bodyTextViewCached
text:self.displayableText.displayText text:self.displayableBodyText.displayText
textColor:self.textColor textColor:self.textColor
font:self.textMessageFont font:self.textMessageFont
shouldIgnoreEvents:shouldIgnoreEvents]; shouldIgnoreEvents:shouldIgnoreEvents];
@ -783,10 +783,10 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
- (nullable UIView *)createTapForMoreLabelIfNecessary - (nullable UIView *)createTapForMoreLabelIfNecessary
{ {
if (!self.hasText) { if (!self.hasBodyText) {
return nil; return nil;
} }
if (!self.displayableText.isTextTruncated) { if (!self.displayableBodyText.isTextTruncated) {
return nil; return nil;
} }
@ -1050,7 +1050,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
// Size of "message body" text, not quoted reply text. // Size of "message body" text, not quoted reply text.
- (CGSize)bodyTextSizeForContentWidth:(int)contentWidth includeMargins:(BOOL)includeMargins - (CGSize)bodyTextSizeForContentWidth:(int)contentWidth includeMargins:(BOOL)includeMargins
{ {
if (!self.hasText) { if (!self.hasBodyText) {
return CGSizeZero; return CGSizeZero;
} }
@ -1061,7 +1061,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
const int maxMessageWidth = [self maxMessageWidthForContentWidth:contentWidth]; const int maxMessageWidth = [self maxMessageWidthForContentWidth:contentWidth];
const int maxTextWidth = (int)floor(maxMessageWidth - (leftMargin + rightMargin)); const int maxTextWidth = (int)floor(maxMessageWidth - (leftMargin + rightMargin));
self.bodyTextViewCached.text = self.displayableText.displayText; self.bodyTextViewCached.text = self.displayableBodyText.displayText;
// Honor dynamic type in the message bodies. // Honor dynamic type in the message bodies.
self.bodyTextViewCached.font = [self textMessageFont]; self.bodyTextViewCached.font = [self textMessageFont];
CGSize textSize = CGSizeCeil([self.bodyTextViewCached sizeThatFits:CGSizeMake(maxTextWidth, CGFLOAT_MAX)]); CGSize textSize = CGSizeCeil([self.bodyTextViewCached sizeThatFits:CGSizeMake(maxTextWidth, CGFLOAT_MAX)]);
@ -1142,7 +1142,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
cellSize.height += self.dateHeaderHeight; cellSize.height += self.dateHeaderHeight;
cellSize.height += self.footerHeight; cellSize.height += self.footerHeight;
if (self.hasText && self.displayableText.isTextTruncated) { if (self.hasBodyText && self.displayableBodyText.isTextTruncated) {
cellSize.height += self.tapForMoreHeight; cellSize.height += self.tapForMoreHeight;
} }
@ -1344,7 +1344,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
} }
} }
if (self.hasText && self.displayableText.isTextTruncated) { if (self.hasBodyText && self.displayableBodyText.isTextTruncated) {
[self.delegate didTapTruncatedTextMessage:self.viewItem]; [self.delegate didTapTruncatedTextMessage:self.viewItem];
return; return;
} }
@ -1375,7 +1375,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
break; break;
case OWSMessageCellType_TextMessage: case OWSMessageCellType_TextMessage:
case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_OversizeTextMessage:
if (self.displayableText.isTextTruncated) { if (self.displayableBodyText.isTextTruncated) {
[self.delegate didTapTruncatedTextMessage:self.viewItem]; [self.delegate didTapTruncatedTextMessage:self.viewItem];
return; return;
} }

@ -43,7 +43,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@property (nonatomic, readonly) TSInteraction *interaction; @property (nonatomic, readonly) TSInteraction *interaction;
@property (nonatomic, readonly) BOOL isGroupThread; @property (nonatomic, readonly) BOOL isGroupThread;
@property (nonatomic, readonly) BOOL hasText; @property (nonatomic, readonly) BOOL hasBodyText;
@property (nonatomic) BOOL shouldShowDate; @property (nonatomic) BOOL shouldShowDate;
@property (nonatomic) BOOL shouldHideRecipientStatus; @property (nonatomic) BOOL shouldHideRecipientStatus;
@ -79,7 +79,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
// These methods only apply to text & attachment messages. // These methods only apply to text & attachment messages.
- (OWSMessageCellType)messageCellType; - (OWSMessageCellType)messageCellType;
- (nullable DisplayableText *)displayableText; - (nullable DisplayableText *)displayableBodyText;
- (nullable TSAttachmentStream *)attachmentStream; - (nullable TSAttachmentStream *)attachmentStream;
- (nullable TSAttachmentPointer *)attachmentPointer; - (nullable TSAttachmentPointer *)attachmentPointer;
- (CGSize)mediaSize; - (CGSize)mediaSize;

@ -56,12 +56,12 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
@property (nonatomic) BOOL hasViewState; @property (nonatomic) BOOL hasViewState;
@property (nonatomic) OWSMessageCellType messageCellType; @property (nonatomic) OWSMessageCellType messageCellType;
// TODO: Rename to displayableBodyText. // TODO: Rename to displayableBodyText.
@property (nonatomic, nullable) DisplayableText *displayableText; @property (nonatomic, nullable) DisplayableText *displayableBodyText;
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream; @property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
@property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer; @property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer;
@property (nonatomic) CGSize mediaSize; @property (nonatomic) CGSize mediaSize;
// TODO: Remove in favor of displayableBodyText nil test. // TODO: Remove in favor of displayableBodyText nil test.
//@property (nonatomic) BOOL hasText; //@property (nonatomic) BOOL hasBodyText;
@end @end
@ -97,7 +97,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
self.hasViewState = NO; self.hasViewState = NO;
self.messageCellType = OWSMessageCellType_Unknown; self.messageCellType = OWSMessageCellType_Unknown;
self.displayableText = nil; self.displayableBodyText = nil;
self.attachmentStream = nil; self.attachmentStream = nil;
self.attachmentPointer = nil; self.attachmentPointer = nil;
self.mediaSize = CGSizeZero; self.mediaSize = CGSizeZero;
@ -107,9 +107,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
[self ensureViewState:transaction]; [self ensureViewState:transaction];
} }
- (BOOL)hasText - (BOOL)hasBodyText
{ {
return _displayableText != nil; return _displayableBodyText != nil;
} }
- (void)setShouldShowDate:(BOOL)shouldShowDate - (void)setShouldShowDate:(BOOL)shouldShowDate
@ -271,7 +271,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
// TODO: Now that we're caching the displayable text on the view items, // TODO: Now that we're caching the displayable text on the view items,
// I don't think we need this cache any more. // I don't think we need this cache any more.
- (NSCache *)displayableTextCache - (NSCache *)displayableBodyTextCache
{ {
static NSCache *cache = nil; static NSCache *cache = nil;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
@ -283,44 +283,45 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
return cache; return cache;
} }
- (DisplayableText *)displayableTextForText:(NSString *)text interactionId:(NSString *)interactionId - (DisplayableText *)displayableBodyTextForText:(NSString *)text interactionId:(NSString *)interactionId
{ {
OWSAssert(text); OWSAssert(text);
OWSAssert(interactionId.length > 0); OWSAssert(interactionId.length > 0);
return [self displayableTextForInteractionId:interactionId return [self displayableBodyTextForInteractionId:interactionId
textBlock:^{ textBlock:^{
return text; return text;
}]; }];
} }
- (DisplayableText *)displayableTextForOversizeTextAttachment:(TSAttachmentStream *)attachmentStream - (DisplayableText *)displayableBodyTextForOversizeTextAttachment:(TSAttachmentStream *)attachmentStream
interactionId:(NSString *)interactionId interactionId:(NSString *)interactionId
{ {
OWSAssert(attachmentStream); OWSAssert(attachmentStream);
OWSAssert(interactionId.length > 0); OWSAssert(interactionId.length > 0);
return [self displayableTextForInteractionId:interactionId return
textBlock:^{ [self displayableBodyTextForInteractionId:interactionId
NSData *textData = [NSData dataWithContentsOfURL:attachmentStream.mediaURL]; textBlock:^{
NSString *text = NSData *textData = [NSData dataWithContentsOfURL:attachmentStream.mediaURL];
[[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding]; NSString *text =
return text; [[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];
}]; return text;
}];
} }
- (DisplayableText *)displayableTextForInteractionId:(NSString *)interactionId - (DisplayableText *)displayableBodyTextForInteractionId:(NSString *)interactionId
textBlock:(NSString * (^_Nonnull)(void))textBlock textBlock:(NSString * (^_Nonnull)(void))textBlock
{ {
OWSAssert(interactionId.length > 0); OWSAssert(interactionId.length > 0);
DisplayableText *_Nullable displayableText = [[self displayableTextCache] objectForKey:interactionId]; DisplayableText *_Nullable displayableBodyText = [[self displayableBodyTextCache] objectForKey:interactionId];
if (!displayableText) { if (!displayableBodyText) {
NSString *text = textBlock(); NSString *text = textBlock();
displayableText = [DisplayableText displayableText:text]; displayableBodyText = [DisplayableText displayableText:text];
[[self displayableTextCache] setObject:displayableText forKey:interactionId]; [[self displayableBodyTextCache] setObject:displayableBodyText forKey:interactionId];
} }
return displayableText; return displayableBodyText;
} }
- (nullable TSAttachment *)firstAttachmentIfAnyOfMessage:(TSMessage *)message - (nullable TSAttachment *)firstAttachmentIfAnyOfMessage:(TSMessage *)message
@ -360,9 +361,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) { if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) {
self.messageCellType = OWSMessageCellType_OversizeTextMessage; self.messageCellType = OWSMessageCellType_OversizeTextMessage;
self.displayableText = [self displayableTextForOversizeTextAttachment:self.attachmentStream self.displayableBodyText = [self displayableBodyTextForOversizeTextAttachment:self.attachmentStream
interactionId:message.uniqueId]; interactionId:message.uniqueId];
// self.hasText = YES; // self.hasBodyText = YES;
} else if ([self.attachmentStream isAnimated] || [self.attachmentStream isImage] || } else if ([self.attachmentStream isAnimated] || [self.attachmentStream isImage] ||
[self.attachmentStream isVideo]) { [self.attachmentStream isVideo]) {
if ([self.attachmentStream isAnimated]) { if ([self.attachmentStream isAnimated]) {
@ -407,19 +408,19 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
// Ignore message body for oversize text attachments. // Ignore message body for oversize text attachments.
if (message.body.length > 0) { if (message.body.length > 0) {
if (self.hasText) { if (self.hasBodyText) {
OWSFail(@"%@ oversize text message has unexpected caption.", self.logTag); OWSFail(@"%@ oversize text message has unexpected caption.", self.logTag);
} }
// self.hasText = YES; // self.hasBodyText = YES;
// If we haven't already assigned an attachment type at this point, message.body isn't a caption, // If we haven't already assigned an attachment type at this point, message.body isn't a caption,
// it's a stand-alone text message. // it's a stand-alone text message.
if (self.messageCellType == OWSMessageCellType_Unknown) { if (self.messageCellType == OWSMessageCellType_Unknown) {
OWSAssert(message.attachmentIds.count == 0); OWSAssert(message.attachmentIds.count == 0);
self.messageCellType = OWSMessageCellType_TextMessage; self.messageCellType = OWSMessageCellType_TextMessage;
} }
self.displayableText = [self displayableTextForText:message.body interactionId:message.uniqueId]; self.displayableBodyText = [self displayableBodyTextForText:message.body interactionId:message.uniqueId];
OWSAssert(self.displayableText); OWSAssert(self.displayableBodyText);
} }
if (self.messageCellType == OWSMessageCellType_Unknown) { if (self.messageCellType == OWSMessageCellType_Unknown) {
@ -427,8 +428,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
// are rendered like empty text messages, but without any interactivity. // are rendered like empty text messages, but without any interactivity.
DDLogWarn(@"%@ Treating unknown message as empty text message: %@", self.logTag, message.description); DDLogWarn(@"%@ Treating unknown message as empty text message: %@", self.logTag, message.description);
self.messageCellType = OWSMessageCellType_TextMessage; self.messageCellType = OWSMessageCellType_TextMessage;
// self.hasText = YES; // self.hasBodyText = YES;
self.displayableText = [[DisplayableText alloc] initWithFullText:@"" displayText:@"" isTextTruncated:NO]; self.displayableBodyText = [[DisplayableText alloc] initWithFullText:@"" displayText:@"" isTextTruncated:NO];
} }
} }
@ -439,16 +440,16 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
return _messageCellType; return _messageCellType;
} }
- (nullable DisplayableText *)displayableText - (nullable DisplayableText *)displayableBodyText
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSAssert(self.hasViewState); OWSAssert(self.hasViewState);
OWSAssert(_displayableText); OWSAssert(_displayableBodyText);
OWSAssert(_displayableText.displayText); OWSAssert(_displayableBodyText.displayText);
OWSAssert(_displayableText.fullText); OWSAssert(_displayableBodyText.fullText);
return _displayableText; return _displayableBodyText;
} }
- (nullable TSAttachmentStream *)attachmentStream - (nullable TSAttachmentStream *)attachmentStream
@ -551,13 +552,13 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
- (BOOL)canPerformAction:(SEL)action - (BOOL)canPerformAction:(SEL)action
{ {
if (action == self.copyTextActionSelector) { if (action == self.copyTextActionSelector) {
return [self hasTextActionContent]; return [self hasBodyTextActionContent];
} else if (action == self.copyMediaActionSelector) { } else if (action == self.copyMediaActionSelector) {
return [self hasMediaActionContent]; return [self hasMediaActionContent];
} else if (action == self.saveMediaActionSelector) { } else if (action == self.saveMediaActionSelector) {
return [self canSaveMedia]; return [self canSaveMedia];
} else if (action == self.shareTextActionSelector) { } else if (action == self.shareTextActionSelector) {
return [self hasTextActionContent]; return [self hasBodyTextActionContent];
} else if (action == self.shareMediaActionSelector) { } else if (action == self.shareMediaActionSelector) {
return [self hasMediaActionContent]; return [self hasMediaActionContent];
} else if (action == self.deleteActionSelector) { } else if (action == self.deleteActionSelector) {
@ -579,8 +580,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
case OWSMessageCellType_Video: case OWSMessageCellType_Video:
case OWSMessageCellType_GenericAttachment: { case OWSMessageCellType_GenericAttachment: {
OWSAssert(self.displayableText); OWSAssert(self.displayableBodyText);
[UIPasteboard.generalPasteboard setString:self.displayableText.fullText]; [UIPasteboard.generalPasteboard setString:self.displayableBodyText.fullText];
break; break;
} }
case OWSMessageCellType_DownloadingAttachment: { case OWSMessageCellType_DownloadingAttachment: {
@ -638,8 +639,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
case OWSMessageCellType_Video: case OWSMessageCellType_Video:
case OWSMessageCellType_GenericAttachment: { case OWSMessageCellType_GenericAttachment: {
OWSAssert(self.displayableText); OWSAssert(self.displayableBodyText);
[AttachmentSharing showShareUIForText:self.displayableText.fullText]; [AttachmentSharing showShareUIForText:self.displayableBodyText.fullText];
break; break;
} }
case OWSMessageCellType_DownloadingAttachment: { case OWSMessageCellType_DownloadingAttachment: {
@ -746,9 +747,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
[self.interaction remove]; [self.interaction remove];
} }
- (BOOL)hasTextActionContent - (BOOL)hasBodyTextActionContent
{ {
return self.hasText && self.displayableText.fullText.length > 0; return self.hasBodyText && self.displayableBodyText.fullText.length > 0;
} }
- (BOOL)hasMediaActionContent - (BOOL)hasMediaActionContent

@ -307,10 +307,10 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
} }
private func displayableTextIfText() -> String? { private func displayableTextIfText() -> String? {
guard viewItem.hasText else { guard viewItem.hasBodyText else {
return nil return nil
} }
guard let displayableText = viewItem.displayableText() else { guard let displayableText = viewItem.displayableBodyText() else {
return nil return nil
} }
let messageBody = displayableText.fullText let messageBody = displayableText.fullText

Loading…
Cancel
Save