Revision ce32510a
| ChatSecure/Classes/Controllers/OTRMediaFileManager.h | ||
|---|---|---|
| 30 | 30 |
completion:(void (^)(NSInteger bytesWritten, NSError * _Nullable error))completion |
| 31 | 31 |
completionQueue:(nullable dispatch_queue_t)completionQueue; |
| 32 | 32 |
|
| 33 |
//#865 |
|
| 34 |
- (void)deleteDataForItem:(OTRMediaItem *)mediaItem |
|
| 35 |
buddyUniqueId:(NSString *)buddyUniqueId |
|
| 36 |
completion:(void (^)(BOOL success, NSError * _Nullable error))completion |
|
| 37 |
completionQueue:(nullable dispatch_queue_t)completionQueue; |
|
| 38 |
|
|
| 33 | 39 |
- (nullable NSData*)dataForItem:(OTRMediaItem *)mediaItem |
| 34 | 40 |
buddyUniqueId:(NSString *)buddyUniqueId |
| 35 | 41 |
error:(NSError* __autoreleasing *)error; |
| ChatSecure/Classes/Controllers/OTRMediaFileManager.m | ||
|---|---|---|
| 128 | 128 |
}]; |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 |
//#865 |
|
| 132 |
- (void)deleteDataForItem:(OTRMediaItem *)mediaItem |
|
| 133 |
buddyUniqueId:(NSString *)buddyUniqueId |
|
| 134 |
completion:(void (^)(BOOL success, NSError * _Nullable error))completion |
|
| 135 |
completionQueue:(nullable dispatch_queue_t)completionQueue {
|
|
| 136 |
if (!completionQueue) {
|
|
| 137 |
completionQueue = dispatch_get_main_queue(); |
|
| 138 |
} |
|
| 139 |
[self performAsyncWrite:^{
|
|
| 140 |
NSString *path = [[self class] pathForMediaItem:mediaItem buddyUniqueId:buddyUniqueId]; |
|
| 141 |
if (![path length]) {
|
|
| 142 |
NSError *error = [NSError errorWithDomain:kOTRErrorDomain code:150 userInfo:@{NSLocalizedDescriptionKey:@"Unable to create file path"}];
|
|
| 143 |
if (completion) {
|
|
| 144 |
dispatch_async(completionQueue, ^{
|
|
| 145 |
completion(NO, error); |
|
| 146 |
}); |
|
| 147 |
} |
|
| 148 |
return; |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
BOOL fileExists = [self.ioCipher fileExistsAtPath:path isDirectory:NULL]; |
|
| 152 |
|
|
| 153 |
if (fileExists) {
|
|
| 154 |
NSError *error = nil; |
|
| 155 |
[self.ioCipher removeItemAtPath:path error:&error]; |
|
| 156 |
if (error) {
|
|
| 157 |
NSError *error = [NSError errorWithDomain:kOTRErrorDomain code:151 userInfo:@{NSLocalizedDescriptionKey:@"Unable to remove existing file"}];
|
|
| 158 |
if (completion) {
|
|
| 159 |
dispatch_async(completionQueue, ^{
|
|
| 160 |
completion(NO, error); |
|
| 161 |
}); |
|
| 162 |
} |
|
| 163 |
return; |
|
| 164 |
} |
|
| 165 |
} |
|
| 166 |
|
|
| 167 |
if (completion) {
|
|
| 168 |
dispatch_async(completionQueue, ^{
|
|
| 169 |
completion(YES, nil); |
|
| 170 |
}); |
|
| 171 |
} |
|
| 172 |
}]; |
|
| 173 |
} |
|
| 174 |
|
|
| 131 | 175 |
/* Internal. If "length" is set, only return the length of the data, otherwise the data ifself */ |
| 132 | 176 |
- (nullable NSData*)dataForItem:(OTRMediaItem *)mediaItem |
| 133 | 177 |
buddyUniqueId:(NSString *)buddyUniqueId |
| ChatSecure/Classes/Model/Yap Storage/OTRMediaItem.m | ||
|---|---|---|
| 329 | 329 |
|
| 330 | 330 |
- (id)yapDatabaseRelationshipEdgeDeleted:(YapDatabaseRelationshipEdge *)edge withReason:(YDB_NotifyReason)reason |
| 331 | 331 |
{
|
| 332 |
//TODO:Delete File because the parent OTRMessage was deleted |
|
| 332 |
//#865 Delete File because the parent OTRMessage was deleted |
|
| 333 |
__block id<OTRThreadOwner> thread = nil; |
|
| 334 |
__block id<OTRMessageProtocol> message = nil; |
|
| 335 |
[OTRDatabaseManager.shared.readOnlyDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
| 336 |
message = [self parentMessageWithTransaction:transaction]; |
|
| 337 |
thread = [message threadOwnerWithTransaction:transaction]; |
|
| 338 |
}]; |
|
| 339 |
if (!message || !thread) {
|
|
| 340 |
DDLogError(@"Missing parent message or thread for media message!"); |
|
| 341 |
return nil; |
|
| 342 |
} |
|
| 343 |
|
|
| 344 |
NSString *buddyUniqueId = [thread threadIdentifier]; |
|
| 345 |
if (!buddyUniqueId) {
|
|
| 346 |
return nil; |
|
| 347 |
} |
|
| 348 |
|
|
| 349 |
[[OTRMediaFileManager sharedInstance] deleteDataForItem:self buddyUniqueId:buddyUniqueId completion:^(BOOL success, NSError *error) {
|
|
| 350 |
if (error) {
|
|
| 351 |
DDLogError(@"ERROR in deleting data for media item"); |
|
| 352 |
} |
|
| 353 |
} completionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; |
|
| 354 |
|
|
| 333 | 355 |
return nil; |
| 334 | 356 |
} |
| 335 | 357 |
|
| Podfile | ||
|---|---|---|
| 59 | 59 |
pod 'gtm-oauth2', :podspec => 'Podspecs/gtm-oauth2.podspec' |
| 60 | 60 |
|
| 61 | 61 |
# Storage |
| 62 |
pod 'YapDatabase/SQLCipher', '~> 3.0.2' |
|
| 63 |
# pod 'YapDatabase/SQLCipher', :git => 'https://github.com/yapstudios/YapDatabase.git', :commit => 'd632658'
|
|
| 62 |
# pod 'YapDatabase/SQLCipher', '~> 3.0.2'
|
|
| 63 |
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/yapstudios/YapDatabase.git', :commit => 'ce9c8db' # 865 fix
|
|
| 64 | 64 |
pod 'libsqlfs/SQLCipher', :git => 'https://github.com/ChatSecure/libsqlfs.git', :branch => 'podspec-fix' |
| 65 | 65 |
pod 'IOCipher/GCDWebServer', :path => 'Submodules/IOCipher/IOCipher.podspec' |
| 66 | 66 |
pod 'YapTaskQueue/SQLCipher', :git => 'https://github.com/ChatSecure/YapTaskQueue.git', :branch => 'swift4' |
Also available in: Unified diff