diff --git a/SessionMessagingKit/Jobs/AttachmentUploadJob.swift b/SessionMessagingKit/Jobs/AttachmentUploadJob.swift index c42e2ba8e..f0f2f37aa 100644 --- a/SessionMessagingKit/Jobs/AttachmentUploadJob.swift +++ b/SessionMessagingKit/Jobs/AttachmentUploadJob.swift @@ -57,7 +57,6 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N // MARK: Running public func execute() { - SNLog("Attachment upload failure count: \(failureCount).") guard let stream = TSAttachmentStream.fetch(uniqueId: attachmentID) else { return handleFailure(error: Error.noAttachment) } diff --git a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Attachment.swift b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Attachment.swift index 998875a35..f1454ff35 100644 --- a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Attachment.swift +++ b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Attachment.swift @@ -17,7 +17,7 @@ public extension VisibleMessage { public var isValid: Bool { // key and digest can be nil for open group attachments - fileName != nil && contentType != nil && kind != nil && size != nil && sizeInBytes != nil && url != nil + contentType != nil && kind != nil && size != nil && sizeInBytes != nil && url != nil } public enum Kind : String { diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer+Conversion.swift b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer+Conversion.swift index c4b595f90..41fa7aa8e 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer+Conversion.swift +++ b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer+Conversion.swift @@ -7,7 +7,7 @@ extension TSAttachmentPointer { case .generic: kind = .default case .voiceMessage: kind = .voiceMessage } - return TSAttachmentPointer( + let result = TSAttachmentPointer( serverId: 0, key: attachment.key, digest: attachment.digest, @@ -18,5 +18,7 @@ extension TSAttachmentPointer { albumMessageId: nil, attachmentType: kind, mediaSize: attachment.size!) + result.downloadURL = attachment.url! + return result } } diff --git a/SessionMessagingKit/Utilities/DotNetAPI.swift b/SessionMessagingKit/Utilities/DotNetAPI.swift index 4631439bd..8199b5b81 100644 --- a/SessionMessagingKit/Utilities/DotNetAPI.swift +++ b/SessionMessagingKit/Utilities/DotNetAPI.swift @@ -16,6 +16,7 @@ public class DotNetAPI : NSObject { // MARK: Error public enum Error : LocalizedError { case generic + case invalidURL case parsingFailed case signingFailed case encryptionFailed @@ -29,6 +30,7 @@ public class DotNetAPI : NSObject { public var errorDescription: String? { switch self { case .generic: return "An error occurred." + case .invalidURL: return "Invalid URL." case .parsingFailed: return "Invalid file server response." case .signingFailed: return "Couldn't sign message." case .encryptionFailed: return "Couldn't encrypt file." @@ -105,14 +107,15 @@ public class DotNetAPI : NSObject { return AnyPromise.from(downloadAttachment(from: url)) } - public static func downloadAttachment(from url: String) -> Promise { - var host = "https://\(URL(string: url)!.host!)" + public static func downloadAttachment(from urlAsString: String) -> Promise { + guard let url = URL(string: urlAsString) else { return Promise(error: Error.invalidURL) } + var host = "https://\(url.host!)" let sanitizedURL: String if FileServerAPI.fileStorageBucketURL.contains(host) { - sanitizedURL = url.replacingOccurrences(of: FileServerAPI.fileStorageBucketURL, with: "\(FileServerAPI.server)/loki/v1") + sanitizedURL = urlAsString.replacingOccurrences(of: FileServerAPI.fileStorageBucketURL, with: "\(FileServerAPI.server)/loki/v1") host = FileServerAPI.server } else { - sanitizedURL = url.replacingOccurrences(of: host, with: "\(host)/loki/v1") + sanitizedURL = urlAsString.replacingOccurrences(of: host, with: "\(host)/loki/v1") } let request: NSMutableURLRequest do {