Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 88f343a0aa
commit c8efd83c39

@ -6,8 +6,6 @@
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentPointer;
@interface TSAttachment : TSYapDatabaseObject {
@protected
@ -24,7 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (atomic, readwrite) UInt64 serverId;
@property (atomic, readwrite) NSData *encryptionKey;
@property (nonatomic, readonly) NSString *contentType;
// This property
@property (atomic, readwrite) BOOL isDownloaded;
@ -40,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
// This constructor is used for new instances of TSAttachmentStream
// that represent downloaded incoming attachments.
- (instancetype)initWithPointer:(TSAttachmentPointer *)pointer;
- (instancetype)initWithPointer:(TSAttachment *)pointer;
- (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion;

@ -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 {

@ -28,6 +28,38 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
- (BOOL)isDecimalNumberText:(NSString *)text
{
return [text componentsSeparatedByCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]].count == 1;
}
- (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion
{
// Legacy instances of TSAttachmentPointer apparently used the serverId as their
// uniqueId.
if (attachmentSchemaVersion < 2 && self.serverId == 0) {
OWSAssert([self isDecimalNumberText:self.uniqueId]);
if ([self isDecimalNumberText:self.uniqueId]) {
// For legacy instances, try to parse the serverId from the uniqueId.
self.serverId = [self.uniqueId integerValue];
} else {
DDLogError(@"%@ invalid legacy attachment uniqueId: %@.", self.tag, self.uniqueId);
}
}
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save