Skip to content

Commit

Permalink
Merge tag 'v3.1.2'
Browse files Browse the repository at this point in the history
Version 3.1.2
  • Loading branch information
chrisballinger committed Aug 5, 2015
2 parents da7ca23 + c83a794 commit e4f4deb
Show file tree
Hide file tree
Showing 33 changed files with 272 additions and 295 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
url = [email protected]:chrisballinger/ProxyKit.git
[submodule "Submodules/CPAProxy"]
path = Submodules/CPAProxy
url = [email protected]:ChatSecure/CPAProxy.git
url = [email protected]:ursachec/CPAProxy.git
[submodule "Submodules/YapDatabase"]
path = Submodules/YapDatabase
url = [email protected]:chrisballinger/YapDatabase.git
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: objective-c
osx_image: xcode6.4

# Handle git submodules yourself
# http://stackoverflow.com/a/24600210/805882
Expand All @@ -20,6 +21,7 @@ install:

before_script:
- gem install cocoapods --no-rdoc --no-ri # Need Cocoapods >= 0.34.1
- export COCOAPODS_DISABLE_DETERMINISTIC_UUIDS=1 # Fix XMPPFramework podspec error w/ Cocoapods 0.38
- pod install
script:
- xctool -workspace ChatSecure.xcworkspace -scheme ChatSecure -sdk iphonesimulator -arch i386 build
6 changes: 6 additions & 0 deletions ChatSecure.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
633AF2FA1A7C3DBC0030A3FF /* OTRAudioSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 633AF2F91A7C3DBC0030A3FF /* OTRAudioSessionManager.m */; };
6353AC2D1AD5E32000753B83 /* OTRAudioTrashView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6353AC2C1AD5E32000753B83 /* OTRAudioTrashView.m */; };
6354BBE41A96C67400E8EBAC /* OTRMediaFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6354BBE31A96C67400E8EBAC /* OTRMediaFileManager.m */; };
638FC09D1B0BE46100B37454 /* NSFileManager+ChatSecure.m in Sources */ = {isa = PBXBuildFile; fileRef = 638FC09C1B0BE46100B37454 /* NSFileManager+ChatSecure.m */; };
6396AFA01A169D54009F3E6C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6396AF9F1A169D54009F3E6C /* main.m */; };
6396AFBA1A169D54009F3E6C /* ChatSecureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6396AFB91A169D54009F3E6C /* ChatSecureTests.m */; };
639CDD8E1AD71BC4009BAABC /* OTRCircleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 639CDD8D1AD71BC4009BAABC /* OTRCircleView.m */; };
Expand Down Expand Up @@ -470,6 +471,8 @@
6353AC2C1AD5E32000753B83 /* OTRAudioTrashView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRAudioTrashView.m; sourceTree = "<group>"; };
6354BBE21A96C67400E8EBAC /* OTRMediaFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRMediaFileManager.h; sourceTree = "<group>"; };
6354BBE31A96C67400E8EBAC /* OTRMediaFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRMediaFileManager.m; sourceTree = "<group>"; };
638FC09B1B0BE46100B37454 /* NSFileManager+ChatSecure.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+ChatSecure.h"; sourceTree = "<group>"; };
638FC09C1B0BE46100B37454 /* NSFileManager+ChatSecure.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+ChatSecure.m"; sourceTree = "<group>"; };
6396AF9A1A169D54009F3E6C /* ChatSecure.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ChatSecure.app; sourceTree = BUILT_PRODUCTS_DIR; };
6396AF9E1A169D54009F3E6C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6396AF9F1A169D54009F3E6C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -666,6 +669,8 @@
63FABC8D1A410EBF009BF681 /* JSQMessagesCollectionViewCell+ChatSecure.m */,
63FABC8F1A41218E009BF681 /* NSString+ChatSecure.h */,
63FABC901A41218E009BF681 /* NSString+ChatSecure.m */,
638FC09B1B0BE46100B37454 /* NSFileManager+ChatSecure.h */,
638FC09C1B0BE46100B37454 /* NSFileManager+ChatSecure.m */,
);
path = Categories;
sourceTree = "<group>";
Expand Down Expand Up @@ -1589,6 +1594,7 @@
633620991A76E87B006E8739 /* OTRImageItem.m in Sources */,
633107081A16D1A300C17BAE /* OTRNewAccountViewController.m in Sources */,
6336209C1A76E88C006E8739 /* OTRVideoItem.m in Sources */,
638FC09D1B0BE46100B37454 /* NSFileManager+ChatSecure.m in Sources */,
633106F01A16D1A300C17BAE /* OTRLoginViewController.m in Sources */,
633106C81A16D1A300C17BAE /* OTRSettingsGroup.m in Sources */,
633107271A16D1A400C17BAE /* OTRSocialButtonsView.m in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions ChatSecure/Classes/Categories/NSFileManager+ChatSecure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NSFileManager+ChatSecure.h
// ChatSecure
//
// Created by David Chiles on 5/19/15.
// Copyright (c) 2015 Chris Ballinger. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSFileManager (ChatSecure)


- (void)otr_enumerateFilesInDirectory:(NSString *)directory block:(void (^)(NSString *fullPath,BOOL *stop))enumerateBlock;
- (BOOL)otr_setFileProtection:(NSString *)fileProtection forFilesInDirectory:(NSString *)directory;
- (BOOL)otr_excudeFromBackUpFilesInDirectory:(NSString *)directory;

@end
49 changes: 49 additions & 0 deletions ChatSecure/Classes/Categories/NSFileManager+ChatSecure.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// NSFileManager+ChatSecure.m
// ChatSecure
//
// Created by David Chiles on 5/19/15.
// Copyright (c) 2015 Chris Ballinger. All rights reserved.
//

#import "NSFileManager+ChatSecure.h"

@implementation NSFileManager (ChatSecure)

- (void)otr_enumerateFilesInDirectory:(NSString *)directory block:(void (^)(NSString *fullPath,BOOL *stop))enumerateBlock
{
BOOL isDirecotry = NO;
BOOL exists = [self fileExistsAtPath:directory isDirectory:&isDirecotry];
if (enumerateBlock && isDirecotry && exists) {
NSDirectoryEnumerator *directoryEnumerator = [self enumeratorAtPath:directory];
NSString *file = nil;
BOOL stop = NO;
while ((file = [directoryEnumerator nextObject]) && !stop) {
NSString *path = [NSString pathWithComponents:@[directory,file]];
enumerateBlock(path,&stop);
}
}
}

- (BOOL)otr_setFileProtection:(NSString *)fileProtection forFilesInDirectory:(NSString *)directory
{
__block BOOL success = YES;
[self otr_enumerateFilesInDirectory:directory block:^(NSString *fullPath, BOOL *stop) {
success = [self setAttributes:@{NSFileProtectionKey:fileProtection}
ofItemAtPath:fullPath error:nil];
*stop = !success;
}];
return success;
}

- (BOOL)otr_excudeFromBackUpFilesInDirectory:(NSString *)directory
{
__block BOOL success = YES;
[self otr_enumerateFilesInDirectory:directory block:^(NSString *fullPath, BOOL *stop) {
success = [self setAttributes:@{NSURLIsExcludedFromBackupKey:@(YES)} ofItemAtPath:fullPath error:nil];
*stop = !success;
}];
return success;
}

@end
34 changes: 15 additions & 19 deletions ChatSecure/Classes/Controllers/OTRAudioSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "OTRAudioSessionManager.h"
#import <KVOController/FBKVOController.h>

@import AVFoundation;

Expand All @@ -25,7 +26,6 @@ @implementation OTRAudioSessionManager
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_currentPlayer removeObserver:self forKeyPath:NSStringFromSelector(@selector(rate))];
}

- (instancetype)init
Expand Down Expand Up @@ -92,7 +92,7 @@ - (void)stopPlaying
{
[self.currentPlayer pause];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.currentPlayer removeObserver:self forKeyPath:NSStringFromSelector(@selector(rate))];
[self.KVOController unobserve:self.currentPlayer];
self.currentPlayer = nil;
[self deactivateSession:nil];

Expand Down Expand Up @@ -200,7 +200,18 @@ - (AVPlayer *)audioPlayerWithURL:(NSURL *)url error:(NSError **)error
name:AVPlayerItemFailedToPlayToEndTimeNotification
object:playerItem];

[audioPlayer addObserver:self forKeyPath:NSStringFromSelector(@selector(rate)) options:NSKeyValueObservingOptionNew context:NULL];
__weak typeof(self)weakSelf = self;
[self.KVOController observe:audioPlayer keyPath:NSStringFromSelector(@selector(rate)) options:NSKeyValueObservingOptionNew block:^(id observer, id object, NSDictionary *change) {
__strong typeof(weakSelf)strongSelf = weakSelf;
if ([object isEqual:strongSelf.currentPlayer]) {
if (strongSelf.currentPlayer.rate && [strongSelf.delegate respondsToSelector:@selector(audioSessionDidStartPlaying:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf.delegate audioSessionDidStartPlaying:strongSelf];
});
}
}

}];

return audioPlayer;
}
Expand All @@ -213,21 +224,6 @@ - (AVAudioRecorder *)audioRecorderWithURL:(NSURL *)url error:(NSError **)error
return recorder;
}

#pragma - mark KVO Methods

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:NSStringFromSelector(@selector(rate))]) {
if ([object isEqual:self.currentPlayer]) {
if (self.currentPlayer.rate && [self.delegate respondsToSelector:@selector(audioSessionDidStartPlaying:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate audioSessionDidStartPlaying:self];
});
}
}
}
}

#pragma - mark AVAudioRecorderDelegate Methods

#pragma - mark AVAudioPlayerDelegate Notifcation
Expand Down Expand Up @@ -262,7 +258,7 @@ - (void)playerItem:(AVPlayerItem *)playerItem finishedPlayingWithError:(NSError
}

[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.currentPlayer removeObserver:self forKeyPath:NSStringFromSelector(@selector(rate))];
[self.KVOController unobserve:self.currentPlayer];
self.currentPlayer = nil;
[self deactivateSession:nil];
}
Expand Down
86 changes: 9 additions & 77 deletions ChatSecure/Classes/Controllers/OTRDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#import "OTRManagedFacebookAccount.h"
#import "OTRGoogleOAuthXMPPAccount.h"
#import "OTRAccount.h"
#import "CoreData+MagicalRecord.h"
#import "OTRMessage.h"
#import "OTRMediaFileManager.h"
#import "IOCipher.h"
#import "NSFileManager+ChatSecure.h"

NSString *const OTRYapDatabaseRelationshipName = @"OTRYapDatabaseRelationshipName";
NSString *const OTRYapDatabseMessageIdSecondaryIndex = @"OTRYapDatabseMessageIdSecondaryIndex";
Expand All @@ -50,10 +50,15 @@ - (BOOL) setupDatabaseWithName:(NSString*)databaseName {
BOOL success = NO;
if ([self setupYapDatabaseWithName:databaseName] )
{
[self migrateCoreDataToYapDatabase];
success = YES;
}
success = [self setupSecureMediaStorage];
if (success) success = [self setupSecureMediaStorage];

NSString *databaseDirectory = [OTRDatabaseManager yapDatabaseDirectory];
//Enumerate all files in yap database directory and exclude from backup
if (success) success = [[NSFileManager defaultManager] otr_excudeFromBackUpFilesInDirectory:databaseDirectory];
//fix file protection on existing files
if (success) success = [[NSFileManager defaultManager] otr_setFileProtection:NSFileProtectionCompleteUntilFirstUserAuthentication forFilesInDirectory:databaseDirectory];
return success;
}

Expand All @@ -73,64 +78,6 @@ - (BOOL)setupSecureMediaStorage
return success;
}

- (void)migrateCoreDataToYapDatabase
{
NSString *legacyDatabaseName = @"db.sqlite";
NSURL * legacyDatabaseURL = [NSPersistentStore MR_urlForStoreName:legacyDatabaseName];

NSURL * databaseURL = [NSPersistentStore MR_urlForStoreName:@"ChatSecure.sqlite"];

NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:legacyDatabaseURL.path]) {
// migrate store
if([OTRDatabaseManager migrateLegacyStore:legacyDatabaseURL destinationStore:databaseURL]) {
[fileManager removeItemAtURL:legacyDatabaseURL error:nil];
}
}


if ([fileManager fileExistsAtPath:databaseURL.path])
{
NSURL *mom2 = [[NSBundle mainBundle] URLForResource:@"ChatSecure 2" withExtension:@"mom" subdirectory:@"ChatSecure.momd"];
NSURL *mom3 = [[NSBundle mainBundle] URLForResource:@"ChatSecure 3" withExtension:@"mom" subdirectory:@"ChatSecure.momd"];
NSManagedObjectModel *version2Model = [[NSManagedObjectModel alloc] initWithContentsOfURL:mom2];
NSManagedObjectModel *version3Model = [[NSManagedObjectModel alloc] initWithContentsOfURL:mom3];

if ([OTRDatabaseManager isManagedObjectModel:version2Model compatibleWithStoreAtUrl:databaseURL]) {
[OTRDatabaseManager migrateLegacyStore:databaseURL destinationStore:databaseURL sourceModel:version2Model destinationModel:version3Model error:nil];
}


[MagicalRecord setShouldAutoCreateManagedObjectModel:NO];
[MagicalRecord setDefaultModelNamed:@"ChatSecure.momd"];
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"ChatSecure.sqlite"];

////// Migrate core data to yapdatabase //////

NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];

NSArray *coreDataAccounts = [OTRManagedAccount MR_findAllInContext:context];

NSMutableArray *accounts = [NSMutableArray array];
[coreDataAccounts enumerateObjectsUsingBlock:^(OTRManagedAccount *account, NSUInteger idx, BOOL *stop) {
OTRAccount *newAccount = [self accountWithCoreDataAccount:account];
if (newAccount) {
[accounts addObject:newAccount];
}
}];

[[OTRDatabaseManager sharedInstance].readWriteDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[accounts enumerateObjectsUsingBlock:^(OTRAccount *account, NSUInteger idx, BOOL *stop) {
[account saveWithTransaction:transaction];
}];
}];

[[NSFileManager defaultManager] removeItemAtURL:databaseURL error:nil];
}

[OTRDatabaseManager deleteLegacyXMPPFiles];
}

- (OTRAccount *)accountWithCoreDataAccount:(OTRManagedAccount *)managedAccount
{
NSDictionary *accountDictionary = [managedAccount propertiesDictionary];
Expand Down Expand Up @@ -200,6 +147,7 @@ - (BOOL)setupYapDatabaseWithName:(NSString *)name
}
NSString *databasePath = [[self class] yapDatabasePathWithName:name];


self.database = [[YapDatabase alloc] initWithPath:databasePath
serializer:nil
deserializer:nil
Expand Down Expand Up @@ -227,22 +175,6 @@ - (BOOL)setupYapDatabaseWithName:(NSString *)name
if (success) success = [OTRDatabaseView registerUnreadMessagesView];
if (success) success = [self setupSecondaryIndexes];



//Enumerate all files in yap database directory and exclude from backup
if (success) {
NSError *error = nil;
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:databaseDirectory];
id file;
while ((file = [directoryEnumerator nextObject]) && success && !error) {
if([file isKindOfClass:[NSString class]]) {
NSString *fileName = file;
NSURL *url = [NSURL fileURLWithPath:[databaseDirectory stringByAppendingPathComponent:fileName]];
success = [url setResourceValue: @(YES) forKey: NSURLIsExcludedFromBackupKey error: &error];
}
}
}

if (self.database && success) {
return YES;
}
Expand Down
Loading

0 comments on commit e4f4deb

Please sign in to comment.