|
|
@ -21,9 +21,18 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
// i.e. undownloaded incoming attachments.
|
|
|
|
// i.e. undownloaded incoming attachments.
|
|
|
|
- (instancetype)initWithServerId:(UInt64)serverId
|
|
|
|
- (instancetype)initWithServerId:(UInt64)serverId
|
|
|
|
encryptionKey:(NSData *)encryptionKey
|
|
|
|
encryptionKey:(NSData *)encryptionKey
|
|
|
|
|
|
|
|
byteCount:(UInt32)byteCount
|
|
|
|
contentType:(NSString *)contentType
|
|
|
|
contentType:(NSString *)contentType
|
|
|
|
sourceFilename:(nullable NSString *)sourceFilename
|
|
|
|
sourceFilename:(nullable NSString *)sourceFilename
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
OWSAssert(serverId > 0);
|
|
|
|
|
|
|
|
OWSAssert(encryptionKey.length > 0);
|
|
|
|
|
|
|
|
if (byteCount <= 0) {
|
|
|
|
|
|
|
|
// This will fail with legacy iOS clients which don't upload attachment size.
|
|
|
|
|
|
|
|
DDLogWarn(@"%@ Missing byteCount for attachment with serverId: %lld", self.tag, serverId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OWSAssert(contentType.length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
self = [super init];
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
@ -31,26 +40,35 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
|
|
|
|
|
|
|
|
_serverId = serverId;
|
|
|
|
_serverId = serverId;
|
|
|
|
_encryptionKey = encryptionKey;
|
|
|
|
_encryptionKey = encryptionKey;
|
|
|
|
|
|
|
|
_byteCount = byteCount;
|
|
|
|
_contentType = contentType;
|
|
|
|
_contentType = contentType;
|
|
|
|
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
|
|
|
|
|
|
|
_sourceFilename = sourceFilename;
|
|
|
|
_sourceFilename = sourceFilename;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
|
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This constructor is used for new instances of TSAttachmentStream
|
|
|
|
// This constructor is used for new instances of TSAttachmentStream
|
|
|
|
// that represent new, un-uploaded outgoing attachments.
|
|
|
|
// that represent new, un-uploaded outgoing attachments.
|
|
|
|
- (instancetype)initWithContentType:(NSString *)contentType sourceFilename:(nullable NSString *)sourceFilename
|
|
|
|
- (instancetype)initWithContentType:(NSString *)contentType
|
|
|
|
|
|
|
|
byteCount:(UInt32)byteCount
|
|
|
|
|
|
|
|
sourceFilename:(nullable NSString *)sourceFilename
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
OWSAssert(contentType.length > 0);
|
|
|
|
|
|
|
|
OWSAssert(byteCount > 0);
|
|
|
|
|
|
|
|
|
|
|
|
self = [super init];
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_contentType = contentType;
|
|
|
|
_contentType = contentType;
|
|
|
|
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
|
|
|
_byteCount = byteCount;
|
|
|
|
_sourceFilename = sourceFilename;
|
|
|
|
_sourceFilename = sourceFilename;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
|
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -58,6 +76,14 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
// that represent downloaded incoming attachments.
|
|
|
|
// that represent downloaded incoming attachments.
|
|
|
|
- (instancetype)initWithPointer:(TSAttachment *)pointer
|
|
|
|
- (instancetype)initWithPointer:(TSAttachment *)pointer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
OWSAssert(pointer.serverId > 0);
|
|
|
|
|
|
|
|
OWSAssert(pointer.encryptionKey.length > 0);
|
|
|
|
|
|
|
|
if (pointer.byteCount <= 0) {
|
|
|
|
|
|
|
|
// This will fail with legacy iOS clients which don't upload attachment size.
|
|
|
|
|
|
|
|
DDLogWarn(@"%@ Missing pointer.byteCount for attachment with serverId: %lld", self.tag, pointer.serverId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OWSAssert(pointer.contentType.length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Once saved, this AttachmentStream will replace the AttachmentPointer in the attachments collection.
|
|
|
|
// Once saved, this AttachmentStream will replace the AttachmentPointer in the attachments collection.
|
|
|
|
self = [super initWithUniqueId:pointer.uniqueId];
|
|
|
|
self = [super initWithUniqueId:pointer.uniqueId];
|
|
|
|
if (!self) {
|
|
|
|
if (!self) {
|
|
|
@ -66,8 +92,10 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
|
|
|
|
|
|
|
|
_serverId = pointer.serverId;
|
|
|
|
_serverId = pointer.serverId;
|
|
|
|
_encryptionKey = pointer.encryptionKey;
|
|
|
|
_encryptionKey = pointer.encryptionKey;
|
|
|
|
|
|
|
|
_byteCount = pointer.byteCount;
|
|
|
|
_contentType = pointer.contentType;
|
|
|
|
_contentType = pointer.contentType;
|
|
|
|
_sourceFilename = pointer.sourceFilename;
|
|
|
|
_sourceFilename = pointer.sourceFilename;
|
|
|
|
|
|
|
|
|
|
|
|
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
|
|
|
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
|
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
|