diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.h b/SignalServiceKit/src/Messages/Attachments/TSAttachment.h index be2a6849e5..978e3bae5f 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.h @@ -29,7 +29,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) { @property (atomic) NSString *cdnKey; @property (atomic) UInt32 cdnNumber; @property (atomic, readwrite, nullable) NSData *encryptionKey; -@property (nonatomic) NSString *contentType; +@property (nonatomic, readonly) NSString *contentType; @property (nonatomic) TSAttachmentType attachmentType; // Though now required, may incorrectly be 0 on legacy attachments. @@ -141,6 +141,10 @@ NS_DESIGNATED_INITIALIZER NS_SWIFT_NAME(init(grdbId:uniqueId:albumMessageId:atta + (NSString *)emojiForMimeType:(NSString *)contentType; +// This should only ever be used before the attachment is saved, +// after that point the content type will be already set. +- (void)setDefaultContentType:(NSString *)contentType; + #pragma mark - Update With... - (void)updateWithBlurHash:(NSString *)blurHash transaction:(SDSAnyWriteTransaction *)transaction; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m index 6a45301aa5..0575aae073 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m @@ -456,6 +456,13 @@ NSUInteger const TSAttachmentSchemaVersion = 5; [self.attachmentReadCache didRemoveAttachment:self transaction:transaction]; } +- (void)setDefaultContentType:(NSString *)contentType +{ + if ([self.contentType isEqualToString:OWSMimeTypeApplicationOctetStream]) { + _contentType = contentType; + } +} + #pragma mark - Update With... - (void)updateWithBlurHash:(NSString *)blurHash transaction:(SDSAnyWriteTransaction *)transaction diff --git a/SignalServiceKit/src/Messages/Stickers/MessageSticker.swift b/SignalServiceKit/src/Messages/Stickers/MessageSticker.swift index fd628fc124..d143576ec7 100644 --- a/SignalServiceKit/src/Messages/Stickers/MessageSticker.swift +++ b/SignalServiceKit/src/Messages/Stickers/MessageSticker.swift @@ -154,10 +154,7 @@ public class MessageSticker: MTLModel { throw StickerError.invalidInput } - if dataProto.contentType?.isEmpty != false && attachmentPointer.contentType == OWSMimeTypeApplicationOctetStream { - Logger.warn("Assuming sticker is webp, received with unspecified content-type") - attachmentPointer.contentType = OWSMimeTypeImageWebp - } + attachmentPointer.setDefaultContentType(OWSMimeTypeImageWebp) attachmentPointer.anyInsert(transaction: transaction) return attachmentPointer