|
|
|
@ -4,7 +4,6 @@
|
|
|
|
|
|
|
|
|
|
#import "TSAttachment.h"
|
|
|
|
|
#import "MIMETypeUtil.h"
|
|
|
|
|
#import "TSAttachmentPointer.h"
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
@ -54,7 +53,7 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
|
|
|
|
|
|
// This constructor is used for new instances of TSAttachmentStream
|
|
|
|
|
// that represent downloaded incoming attachments.
|
|
|
|
|
- (instancetype)initWithPointer:(TSAttachmentPointer *)pointer
|
|
|
|
|
- (instancetype)initWithPointer:(TSAttachment *)pointer
|
|
|
|
|
{
|
|
|
|
|
// Once saved, this AttachmentStream will replace the AttachmentPointer in the attachments collection.
|
|
|
|
|
self = [super initWithUniqueId:pointer.uniqueId];
|
|
|
|
@ -70,11 +69,6 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)isDecimalNumberText:(NSString *)text
|
|
|
|
|
{
|
|
|
|
|
return [text componentsSeparatedByCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]].count == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable instancetype)initWithCoder:(NSCoder *)coder
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithCoder:coder];
|
|
|
|
@ -92,25 +86,8 @@ NSUInteger const TSAttachmentSchemaVersion = 3;
|
|
|
|
|
|
|
|
|
|
- (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion
|
|
|
|
|
{
|
|
|
|
|
// TSAttachment is a base class for TSAttachmentPointer (a yet-to-be-downloaded
|
|
|
|
|
// incoming attachment) and TSAttachmentStream (an outgoing or already-downloaded
|
|
|
|
|
// incoming attachment).
|
|
|
|
|
//
|
|
|
|
|
// The attachmentSchemaVersion and serverId properties only apply to
|
|
|
|
|
// TSAttachmentPointer, which can be distinguished by the isDownloaded
|
|
|
|
|
// property.
|
|
|
|
|
if (!_isDownloaded && _attachmentSchemaVersion < 2) {
|
|
|
|
|
if (!_serverId) {
|
|
|
|
|
OWSAssert([self isDecimalNumberText:self.uniqueId]);
|
|
|
|
|
if (![self isDecimalNumberText:self.uniqueId]) {
|
|
|
|
|
DDLogError(@"%@ invalid legacy attachment uniqueId: %@.", self.tag, self.uniqueId);
|
|
|
|
|
}
|
|
|
|
|
_serverId = [self.uniqueId integerValue];
|
|
|
|
|
if (!_serverId) {
|
|
|
|
|
DDLogError(@"%@ failed to parse legacy attachment uniqueId: %@.", self.tag, self.uniqueId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// This method is overridden by the base classes TSAttachmentPointer and
|
|
|
|
|
// TSAttachmentStream.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSString *)collection {
|
|
|
|
|