mirror of https://github.com/oxen-io/session-ios
				
				
				
			
							parent
							
								
									f6f5d3d455
								
							
						
					
					
						commit
						6a5fe94d59
					
				@ -0,0 +1,13 @@
 | 
			
		||||
//
 | 
			
		||||
//  Copyright (c) 2017 Open Whisper Systems. All rights reserved.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#import "OWSDatabaseMigration.h"
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_BEGIN
 | 
			
		||||
 | 
			
		||||
@interface OWS105AttachmentFilePaths : OWSDatabaseMigration
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_END
 | 
			
		||||
@ -0,0 +1,58 @@
 | 
			
		||||
//
 | 
			
		||||
//  Copyright (c) 2017 Open Whisper Systems. All rights reserved.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#import "OWS105AttachmentFilePaths.h"
 | 
			
		||||
#import <SignalServiceKit/TSAttachmentStream.h>
 | 
			
		||||
#import <YapDatabase/YapDatabaseTransaction.h>
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_BEGIN
 | 
			
		||||
 | 
			
		||||
// Increment a similar constant for every future DBMigration
 | 
			
		||||
static NSString *const OWS105AttachmentFilePathsMigrationId = @"105";
 | 
			
		||||
 | 
			
		||||
@implementation OWS105AttachmentFilePaths
 | 
			
		||||
 | 
			
		||||
+ (NSString *)migrationId
 | 
			
		||||
{
 | 
			
		||||
    return OWS105AttachmentFilePathsMigrationId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
 | 
			
		||||
{
 | 
			
		||||
    OWSAssert(transaction);
 | 
			
		||||
 | 
			
		||||
    NSMutableArray<TSAttachmentStream *> *attachmentStreams = [NSMutableArray new];
 | 
			
		||||
    [transaction enumerateKeysAndObjectsInCollection:TSAttachmentStream.collection
 | 
			
		||||
                                          usingBlock:^(NSString *key, TSAttachment *attachment, BOOL *stop) {
 | 
			
		||||
                                              if (![attachment isKindOfClass:[TSAttachmentStream class]]) {
 | 
			
		||||
                                                  return;
 | 
			
		||||
                                              }
 | 
			
		||||
                                              TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
 | 
			
		||||
                                              if (attachmentStream.hasUnsavedFilePath) {
 | 
			
		||||
                                                  [attachmentStreams addObject:attachmentStream];
 | 
			
		||||
                                              }
 | 
			
		||||
                                          }];
 | 
			
		||||
 | 
			
		||||
    DDLogInfo(@"Saving %zd attachment streams.", attachmentStreams.count);
 | 
			
		||||
 | 
			
		||||
    for (TSAttachmentStream *attachmentStream in attachmentStreams) {
 | 
			
		||||
        [attachmentStream saveWithTransaction:transaction];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#pragma mark - Logging
 | 
			
		||||
 | 
			
		||||
+ (NSString *)tag
 | 
			
		||||
{
 | 
			
		||||
    return [NSString stringWithFormat:@"[%@]", self.class];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (NSString *)tag
 | 
			
		||||
{
 | 
			
		||||
    return self.class.tag;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_END
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue