mirror of
https://github.com/signalapp/Signal-iOS.git
synced 2025-12-05 01:10:41 +00:00
Remove DataSource.isValidImage
This commit is contained in:
@@ -712,7 +712,7 @@ private struct ForwardMessageContent {
|
||||
var canSendToStories: Bool {
|
||||
return allItems.allSatisfy { item in
|
||||
if !item.attachments.isEmpty {
|
||||
return item.attachments.allSatisfy({ $0.dataSource.isValidImage || $0.isVideo })
|
||||
return item.attachments.allSatisfy({ $0.isImage || $0.isVideo })
|
||||
} else if item.textAttachment != nil {
|
||||
return true
|
||||
} else if item.messageBody != nil {
|
||||
|
||||
@@ -693,8 +693,10 @@ public class SignalAttachment: CustomDebugStringConvertible {
|
||||
throw .invalidData
|
||||
}
|
||||
|
||||
let imageMetadata = dataSource.imageMetadata
|
||||
let isAnimated = imageMetadata?.isAnimated ?? false
|
||||
guard let imageMetadata = dataSource.imageMetadata else {
|
||||
throw .invalidData
|
||||
}
|
||||
let isAnimated = imageMetadata.isAnimated
|
||||
if isAnimated {
|
||||
guard dataSource.dataLength <= OWSMediaUtils.kMaxFileSizeAnimatedImage else {
|
||||
throw .fileSizeTooLarge
|
||||
@@ -1176,6 +1178,7 @@ public class SignalAttachment: CustomDebugStringConvertible {
|
||||
public class func genericAttachment(dataSource: DataSource, dataUTI: String) throws(SignalAttachmentError) -> SignalAttachment {
|
||||
// [15M] TODO: Enforce this at compile-time rather than runtime.
|
||||
owsPrecondition(!videoUTISet.contains(dataUTI))
|
||||
owsPrecondition(!inputImageUTISet.contains(dataUTI))
|
||||
return try newAttachment(
|
||||
dataSource: dataSource,
|
||||
dataUTI: dataUTI,
|
||||
|
||||
@@ -26,7 +26,6 @@ public protocol DataSource: AnyObject {
|
||||
|
||||
/// Will return zero in the error case.
|
||||
var dataLength: UInt { get }
|
||||
var isValidImage: Bool { get }
|
||||
var hasStickerLikeProperties: Bool { get }
|
||||
var imageMetadata: ImageMetadata? { get }
|
||||
|
||||
@@ -160,11 +159,6 @@ public class DataSourceValue: DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
public var isValidImage: Bool {
|
||||
owsAssertDebug(!isConsumed)
|
||||
return DataImageSource(data).ows_isValidImage
|
||||
}
|
||||
|
||||
public var hasStickerLikeProperties: Bool {
|
||||
owsAssertDebug(!isConsumed)
|
||||
return imageMetadata?.hasStickerLikeProperties ?? false
|
||||
@@ -270,11 +264,6 @@ public class DataSourcePath: DataSource {
|
||||
return fileUrl
|
||||
}
|
||||
|
||||
public var isValidImage: Bool {
|
||||
owsAssertDebug(!isConsumed)
|
||||
return (try? DataImageSource.forPath(fileUrl.path))?.ows_isValidImage ?? false
|
||||
}
|
||||
|
||||
public var hasStickerLikeProperties: Bool {
|
||||
owsAssertDebug(!isConsumed)
|
||||
return imageMetadata?.hasStickerLikeProperties ?? false
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
|
||||
if
|
||||
attachmentApprovalItemCollection.attachmentApprovalItems.count == 1,
|
||||
let firstItem = attachmentApprovalItemCollection.attachmentApprovalItems.first,
|
||||
firstItem.attachment.dataSource.isValidImage || firstItem.attachment.isVideo,
|
||||
firstItem.attachment.isImage || firstItem.attachment.isVideo,
|
||||
!receivedOptions.contains(.disallowViewOnce)
|
||||
{
|
||||
options.insert(.canToggleViewOnce)
|
||||
@@ -109,7 +109,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
|
||||
|
||||
if
|
||||
ImageQualityLevel.maximumForCurrentAppContext == .high,
|
||||
attachmentApprovalItemCollection.attachmentApprovalItems.contains(where: { $0.attachment.dataSource.isValidImage }) {
|
||||
attachmentApprovalItemCollection.attachmentApprovalItems.contains(where: { $0.attachment.isImage }) {
|
||||
options.insert(.canChangeQualityLevel)
|
||||
}
|
||||
|
||||
@@ -1448,7 +1448,7 @@ private extension SaveableAsset {
|
||||
}
|
||||
|
||||
private init(attachment: SignalAttachment) throws {
|
||||
if attachment.dataSource.isValidImage {
|
||||
if attachment.isImage {
|
||||
guard let imageUrl = attachment.dataSource.dataUrl else {
|
||||
throw OWSAssertionError("imageUrl was unexpectedly nil")
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AttachmentApprovalItem {
|
||||
}
|
||||
|
||||
private static func imageEditorModel(for attachment: SignalAttachment) -> ImageEditorModel? {
|
||||
guard attachment.dataSource.isValidImage, !attachment.isAnimatedImage else {
|
||||
guard attachment.isImage, !attachment.isAnimatedImage else {
|
||||
return nil
|
||||
}
|
||||
guard let dataUrl: URL = attachment.dataSource.dataUrl, dataUrl.isFileURL else {
|
||||
|
||||
@@ -53,7 +53,7 @@ public enum TypedItem {
|
||||
case .contact: return false
|
||||
case .other(let attachment):
|
||||
// TODO: Consolidate with isVisualMedia after fixing validity checks.
|
||||
return attachment.dataSource.isValidImage || attachment.isVideo
|
||||
return attachment.isImage || attachment.isVideo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class MediaMessageView: UIView, AudioPlayerDelegate {
|
||||
|
||||
private func createAnimatedPreview() {
|
||||
guard
|
||||
attachment.dataSource.isValidImage,
|
||||
attachment.isImage,
|
||||
let dataUrl = attachment.dataSource.dataUrl,
|
||||
let image = SDAnimatedImage(contentsOfFile: dataUrl.path),
|
||||
image.size.width > 0 && image.size.height > 0
|
||||
@@ -182,7 +182,7 @@ class MediaMessageView: UIView, AudioPlayerDelegate {
|
||||
|
||||
private func createImagePreview() {
|
||||
guard
|
||||
attachment.dataSource.isValidImage,
|
||||
attachment.isImage,
|
||||
let image = attachment.image(),
|
||||
image.size.width > 0 && image.size.height > 0
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user