From 5710fe18fb5a15ed8d719145dd8351260c7a50c6 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Mon, 21 Mar 2022 11:08:21 +1100 Subject: [PATCH] Reverted a change to the type for the serverId of a TSAttachment (change didn't match the protobuf) --- SessionMessagingKit/Jobs/AttachmentUploadJob.swift | 9 +++++++-- .../Sending & Receiving/Attachments/TSAttachment.h | 2 +- .../Sending & Receiving/Attachments/TSAttachment.m | 2 +- .../Attachments/TSAttachmentPointer.m | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SessionMessagingKit/Jobs/AttachmentUploadJob.swift b/SessionMessagingKit/Jobs/AttachmentUploadJob.swift index 21f33d160..7688a65c6 100644 --- a/SessionMessagingKit/Jobs/AttachmentUploadJob.swift +++ b/SessionMessagingKit/Jobs/AttachmentUploadJob.swift @@ -66,7 +66,7 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N guard let stream = TSAttachment.fetch(uniqueId: attachmentID) as? TSAttachmentStream else { return handleFailure(error: Error.noAttachment) } - guard !stream.isUploaded else { return handleSuccess(stream.serverId) } // Should never occur + guard !stream.isUploaded else { return handleSuccess("\(stream.serverId)") } // Should never occur let storage = SNMessagingKitConfiguration.shared.storage if let openGroup = storage.getOpenGroup(for: threadID) { @@ -124,8 +124,13 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N stream.isUploaded = false stream.save() upload(data).done(on: DispatchQueue.global(qos: .userInitiated)) { fileId in + guard let intFileId: UInt64 = UInt64(fileId) else { + onFailure?(HTTP.Error.parsingFailed) + return + } + let downloadURL = "\(FileServerAPI.server)/files/\(fileId)" - stream.serverId = fileId + stream.serverId = intFileId stream.isUploaded = true stream.downloadURL = downloadURL stream.save() diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h index b6334028b..d8f0d8936 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h +++ b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h @@ -23,7 +23,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) { // The attachmentSchemaVersion and serverId properties only apply to // TSAttachmentPointer, which can be distinguished by the isDownloaded // property. -@property (atomic, readwrite) NSString *serverId; +@property (atomic, readwrite) UInt64 serverId; @property (atomic, readwrite, nullable) NSData *encryptionKey; @property (nonatomic, readonly) NSString *contentType; @property (atomic, readwrite) BOOL isDownloaded; diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m index 6fd590954..3d92cdca8 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m +++ b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m @@ -27,7 +27,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4; // This constructor is used for new instances of TSAttachmentPointer, // i.e. undownloaded incoming attachments. -- (instancetype)initWithServerId:(NSString *)serverId +- (instancetype)initWithServerId:(UInt64)serverId encryptionKey:(nullable NSData *)encryptionKey byteCount:(UInt32)byteCount contentType:(NSString *)contentType diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer.m b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer.m index c5aa6fcf2..e27bccab2 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer.m +++ b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachmentPointer.m @@ -170,7 +170,7 @@ NS_ASSUME_NONNULL_BEGIN // uniqueId. if (attachmentSchemaVersion < 2 && self.serverId == 0) { // For legacy instances, try to parse the serverId from the uniqueId. - self.serverId = self.uniqueId; + self.serverId = (UInt64)[self.uniqueId integerValue]; } }