From fffff0413579d02df3c4ed5dfe6037214daa2a42 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 23 Apr 2019 12:46:36 -0700 Subject: [PATCH] include file size --- .../MessageDetailViewController.swift | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index 822214764a..17d49b2732 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -42,7 +42,6 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele var contentView: UIView? var attachment: TSAttachment? - var dataSource: DataSource? var attachmentStream: TSAttachmentStream? var messageBody: String? @@ -439,6 +438,8 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele return true } + private let byteCountFormatter: ByteCountFormatter = ByteCountFormatter() + private func addAttachmentMetadataRows() -> [UIView] { guard hasMediaAttachment else { return [] @@ -447,26 +448,26 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele var rows = [UIView]() if let attachment = self.attachment { - // Only show MIME types in DEBUG builds. - if _isDebugAssertConfiguration() { - let contentType = attachment.contentType - rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_MIME_TYPE", - comment: "Label for the MIME type of attachments in the 'message metadata' view."), - value: contentType)) - } - if let sourceFilename = attachment.sourceFilename { rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_SOURCE_FILENAME", comment: "Label for the original filename of any attachment in the 'message metadata' view."), value: sourceFilename)) } - } - if let dataSource = self.dataSource { - let fileSize = dataSource.dataLength() - rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_FILE_SIZE", - comment: "Label for file size of attachments in the 'message metadata' view."), - value: OWSFormat.formatFileSize(UInt(fileSize)))) + if _isDebugAssertConfiguration() { + let contentType = attachment.contentType + rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_MIME_TYPE", + comment: "Label for the MIME type of attachments in the 'message metadata' view."), + value: contentType)) + + if let formattedByteCount = byteCountFormatter.string(for: attachment.byteCount) { + rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_FILE_SIZE", + comment: "Label for file size of attachments in the 'message metadata' view."), + value: formattedByteCount)) + } else { + owsFailDebug("formattedByteCount was unexpectedly nil") + } + } } return rows