mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			48 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			48 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Matlab
		
	
| 
											8 years ago
										 | // | ||
|  | //  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; | ||
| 
											8 years ago
										 |                                               [attachmentStreams addObject:attachmentStream]; | ||
| 
											8 years ago
										 |                                           }]; | ||
|  | 
 | ||
|  |     DDLogInfo(@"Saving %zd attachment streams.", attachmentStreams.count); | ||
|  | 
 | ||
| 
											8 years ago
										 |     // Persist the new localRelativeFilePath property of TSAttachmentStream. | ||
|  |     // For performance, we want to upgrade all existing attachment streams in | ||
|  |     // a single transaction. | ||
| 
											8 years ago
										 |     for (TSAttachmentStream *attachmentStream in attachmentStreams) { | ||
|  |         [attachmentStream saveWithTransaction:transaction]; | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | @end | ||
|  | 
 | ||
|  | NS_ASSUME_NONNULL_END |