Fixup e61c81 by migrating old schema
// FREEBIE
This commit is contained in:
parent
c14e4bb7b3
commit
baf564db2e
@ -5,6 +5,31 @@
|
||||
#import "TSAttachment.h"
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
|
||||
static const NSUInteger OWSMessageSchemaVersion = 2;
|
||||
|
||||
@interface TSMessage ()
|
||||
|
||||
/**
|
||||
* The version of the model class's schema last used to serialize this model. Use this to manage data migrations during
|
||||
* object de/serialization.
|
||||
*
|
||||
* e.g.
|
||||
*
|
||||
* - (id)initWithCoder:(NSCoder *)coder
|
||||
* {
|
||||
* self = [super initWithCoder:coder];
|
||||
* if (!self) { return self; }
|
||||
* if (_schemaVersion < 2) {
|
||||
* _newName = [coder decodeObjectForKey:@"oldName"]
|
||||
* }
|
||||
* ...
|
||||
* _schemaVersion = 2;
|
||||
* }
|
||||
*/
|
||||
@property (nonatomic, readonly) NSUInteger schemaVersion;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TSMessage
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
@ -24,6 +49,24 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
self = [super initWithCoder:coder];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
if (_schemaVersion < 2) {
|
||||
if (!_attachmentIds) {
|
||||
_attachmentIds = [coder decodeObjectForKey:@"attachments"];
|
||||
}
|
||||
}
|
||||
|
||||
_schemaVersion = OWSMessageSchemaVersion;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)hasAttachments
|
||||
{
|
||||
return self.attachmentIds ? (self.attachmentIds.count > 0) : false;
|
||||
|
||||
@ -77,7 +77,6 @@
|
||||
}
|
||||
}];
|
||||
|
||||
// TODO Make sure we're not deleting group update avatars
|
||||
NSArray<NSString *> *filenamesToDelete = [attachmentIdFilenames allValues];
|
||||
NSMutableArray<NSString *> *absolutePathsToDelete = [NSMutableArray arrayWithCapacity:[filenamesToDelete count]];
|
||||
for (NSString *filename in filenamesToDelete) {
|
||||
|
||||
@ -54,7 +54,6 @@
|
||||
+ (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction
|
||||
usingBlock:(void (^)(id object, BOOL *stop))block;
|
||||
|
||||
|
||||
/**
|
||||
* @return A shared database connection.
|
||||
*/
|
||||
@ -69,15 +68,12 @@
|
||||
*
|
||||
* @return Instance of the object or nil if non-existent
|
||||
*/
|
||||
|
||||
+ (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction;
|
||||
|
||||
+ (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID;
|
||||
|
||||
/**
|
||||
* Saves the object with a new YapDatabaseConnection
|
||||
*/
|
||||
|
||||
- (void)save;
|
||||
|
||||
/**
|
||||
@ -85,18 +81,13 @@
|
||||
*
|
||||
* @param transaction Database transaction
|
||||
*/
|
||||
|
||||
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
|
||||
/**
|
||||
* The unique identifier of the stored object
|
||||
*/
|
||||
|
||||
|
||||
@property (nonatomic) NSString *uniqueId;
|
||||
|
||||
|
||||
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
- (void)remove;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user