Fix oversized text messages

// FREEBIE
pull/1/head
sdkjfhsdkjhfsdlkjhfsdf 7 years ago
parent 82aeee301d
commit cf091758a5

@ -522,6 +522,9 @@ NS_ASSUME_NONNULL_BEGIN
// cell is no longer visible.
- (void)ensureViewMediaState
{
CGSize mediaSize = [self mediaBubbleSizeForContentWidth:self.contentWidth];
[self.contentConstraints addObjectsFromArray:[self.mediaMaskingView autoSetDimensionsToSize:mediaSize]];
if (!self.isCellVisible) {
// Eagerly unload.
self.stillImageView.image = nil;
@ -781,6 +784,9 @@ NS_ASSUME_NONNULL_BEGIN
self.textView.shouldIgnoreEvents = NO;
}
OWSAssert(self.contentWidth);
CGSize textBubbleSize = [self textBubbleSizeForContentWidth:self.contentWidth];
if (self.displayableText.isTextTruncated) {
self.tapForMoreLabel = [UILabel new];
self.tapForMoreLabel.text = NSLocalizedString(@"CONVERSATION_VIEW_OVERSIZE_TEXT_TAP_FOR_MORE",
@ -791,6 +797,8 @@ NS_ASSUME_NONNULL_BEGIN
[self.textBubbleImageView addSubview:self.tapForMoreLabel];
[self.contentConstraints addObjectsFromArray:@[
[self.textBubbleImageView autoSetDimension:ALDimensionWidth toSize:textBubbleSize.width],
[self.textBubbleImageView autoSetDimension:ALDimensionHeight toSize:textBubbleSize.height],
[self.textView autoPinLeadingToSuperviewWithMargin:self.textLeadingMargin],
[self.textView autoPinTrailingToSuperviewWithMargin:self.textTrailingMargin],
[self.textView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.textVMargin],
@ -802,9 +810,6 @@ NS_ASSUME_NONNULL_BEGIN
[self.tapForMoreLabel autoSetDimension:ALDimensionHeight toSize:self.tapForMoreHeight],
]];
} else {
OWSAssert(self.contentWidth);
CGSize textBubbleSize = [self textBubbleSizeForContentWidth:self.contentWidth];
[self.contentConstraints addObjectsFromArray:@[
[self.textBubbleImageView autoSetDimension:ALDimensionWidth toSize:textBubbleSize.width],
[self.textBubbleImageView autoSetDimension:ALDimensionHeight toSize:textBubbleSize.height],
@ -934,12 +939,10 @@ NS_ASSUME_NONNULL_BEGIN
view.userInteractionEnabled = NO;
[self.mediaMaskingView addSubview:view];
CGSize mediaSize = [self mediaBubbleSizeForContentWidth:self.contentWidth];
[self.contentConstraints
addObject:[self.mediaMaskingView
autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeLeading : ALEdgeTrailing)]];
[self.contentConstraints addObjectsFromArray:[self.mediaMaskingView autoSetDimensionsToSize:mediaSize]];
[self.contentConstraints addObjectsFromArray:[view autoPinEdgesToSuperviewMargins]];
[self cropMediaViewToBubbbleShape:view];

@ -377,6 +377,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
self.messageCellType = OWSMessageCellType_OversizeTextMessage;
self.displayableText =
[self displayableTextForAttachmentStream:self.attachmentStream interactionId:message.uniqueId];
self.hasText = YES;
} else if ([self.attachmentStream isAnimated] || [self.attachmentStream isImage] ||
[self.attachmentStream isVideo]) {
if ([self.attachmentStream isAnimated]) {

@ -148,9 +148,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate {
contentView.autoPinEdge(toSuperviewEdge: .bottom)
scrollView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
let hasAttachment = message.attachmentIds.count > 0
if hasAttachment {
if hasMediaAttachment {
let footer = UIToolbar()
footer.barTintColor = UIColor.ows_materialBlue()
view.addSubview(footer)
@ -325,7 +323,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate {
private func contentRows() -> [UIView] {
var rows = [UIView]()
if message.attachmentIds.count > 0 {
if hasMediaAttachment {
rows += addAttachmentRows()
}
@ -401,19 +399,27 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate {
return rows
}
private func addAttachmentRows() -> [UIView] {
var rows = [UIView]()
private func fetchAttachment(transaction: YapDatabaseReadTransaction) -> TSAttachment? {
guard let attachmentId = message.attachmentIds[0] as? String else {
owsFail("Invalid attachment")
return rows
return nil
}
guard let attachment = TSAttachment.fetch(uniqueId: attachmentId) else {
guard let attachment = TSAttachment.fetch(uniqueId: attachmentId, transaction: transaction) else {
owsFail("Missing attachment")
return nil
}
return attachment
}
private func addAttachmentRows() -> [UIView] {
var rows = [UIView]()
guard let attachment = self.attachment else {
owsFail("no attachment to add.")
return rows
}
self.attachment = attachment
guard let attachmentStream = attachment as? TSAttachmentStream else {
rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_NOT_YET_DOWNLOADED",
@ -445,7 +451,25 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate {
return rows
}
var hasMediaAttachment: Bool {
guard let attachment = self.attachment else {
return false
}
guard attachment.contentType != OWSMimeTypeOversizeTextMessage else {
// to the user, oversized text attachments should behave
// just like regular text messages.
return false
}
return true
}
private func addAttachmentMetadataRows() -> [UIView] {
guard hasMediaAttachment else {
return []
}
var rows = [UIView]()
if let attachment = self.attachment {
@ -575,6 +599,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate {
return
}
self.message = newMessage
self.attachment = self.fetchAttachment(transaction: transaction)
}
}

Loading…
Cancel
Save