Fix receiving attachments from old clients

Protobuf's null-object pattern provides an empty NSData when no digest
is provided rather than nil.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 312f398ddd
commit d6af5028ca

@ -63,9 +63,17 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<NSString *> *supportedAttachmentIds = [NSMutableArray new];
for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) {
OWSAssert(attachmentProto.id != 0);
OWSAssert(attachmentProto.key != nil);
OWSAssert(attachmentProto.contentType != nil);
// digest will be empty for old clients.
NSData *digest = attachmentProto.hasDigest ? attachmentProto.digest : nil;
TSAttachmentPointer *pointer = [[TSAttachmentPointer alloc] initWithServerId:attachmentProto.id
key:attachmentProto.key
digest:attachmentProto.digest
digest:digest
contentType:attachmentProto.contentType
relay:relay];

@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithServerId:(UInt64)serverId
key:(NSData *)key
digest:(NSData *)digest
digest:(nullable NSData *)digest
contentType:(NSString *)contentType
relay:(NSString *)relay NS_DESIGNATED_INITIALIZER;

@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithServerId:(UInt64)serverId
key:(NSData *)key
digest:(NSData *)digest
digest:(nullable NSData *)digest
contentType:(NSString *)contentType
relay:(NSString *)relay
{
@ -19,7 +19,6 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
OWSAssert(digest != nil);
_digest = digest;
_failed = NO;
_downloading = NO;

Loading…
Cancel
Save