Use thumbnails dir.

pull/1/head
Matthew Chen 7 years ago
parent a9096209e9
commit 2daa66fdf6

@ -281,16 +281,20 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
return [[containingDir stringByAppendingPathComponent:newFilename] stringByAppendingPathExtension:@"jpg"]; return [[containingDir stringByAppendingPathComponent:newFilename] stringByAppendingPathExtension:@"jpg"];
} }
- (nullable NSString *)pathForThumbnail:(TSAttachmentThumbnail *)thumbnail - (NSString *)thumbnailsDirPath
{ {
NSString *filePath = self.originalFilePath; if (!self.localRelativeFilePath) {
if (!filePath) {
OWSFail(@"%@ Attachment missing local file path.", self.logTag); OWSFail(@"%@ Attachment missing local file path.", self.logTag);
return nil; return nil;
} }
NSString *containingDir = filePath.stringByDeletingLastPathComponent; NSString *dirName = [NSString stringWithFormat:@"%@-thumbnails", self.uniqueId];
return [containingDir stringByAppendingPathComponent:thumbnail.filename]; return [[[self class] attachmentsFolder] stringByAppendingPathComponent:dirName];
}
- (nullable NSString *)pathForThumbnail:(TSAttachmentThumbnail *)thumbnail
{
return [self.thumbnailsDirPath stringByAppendingPathComponent:thumbnail.filename];
} }
- (nullable NSURL *)originalMediaURL - (nullable NSURL *)originalMediaURL
@ -307,13 +311,11 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
{ {
NSError *error; NSError *error;
for (TSAttachmentThumbnail *thumbnail in self.thumbnails) { NSString *thumbnailsDirPath = self.thumbnailsDirPath;
NSString *_Nullable thumbnailPath = [self pathForThumbnail:thumbnail]; if ([[NSFileManager defaultManager] fileExistsAtPath:thumbnailsDirPath]) {
if (thumbnailPath) { BOOL success = [[NSFileManager defaultManager] removeItemAtPath:thumbnailsDirPath error:&error];
BOOL success = [[NSFileManager defaultManager] removeItemAtPath:thumbnailPath error:&error];
if (error || !success) { if (error || !success) {
DDLogError(@"%@ remove thumbnail failed with: %@", self.logTag, error); DDLogError(@"%@ remove thumbnails dir failed with: %@", self.logTag, error);
}
} }
} }

Loading…
Cancel
Save