@ -26,6 +26,29 @@ static NSString *keychainDBPassAccount    = @"TSDatabasePass";
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					@ end @ end  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					/ /  Some  lingering  TSRecipient  records  in  the  wild  causing  crashes .  
			
		
	
		
		
			
				
					
					/ /  This  is  a  stop  gap  until  a  proper  cleanup  happens .  
			
		
	
		
		
			
				
					
					@ interface  TSRecipient  :  NSObject  < NSCoding >  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					@ end  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					@ implementation  TSRecipient  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					-  ( instancetype ) initWithCoder : ( NSCoder  * ) aDecoder  
			
		
	
		
		
			
				
					
					{  
			
		
	
		
		
			
				
					
					    DDLogWarn ( @ "Ignoring  decoding  signal  recipient  with  coder . ") ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    self  =  [ super  init ] ; 
 
			
		
	
		
		
			
				
					
					    return  nil ; 
 
			
		
	
		
		
			
				
					
					}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					-  ( void ) encodeWithCoder : ( NSCoder  * ) aCoder  
			
		
	
		
		
			
				
					
					{  
			
		
	
		
		
			
				
					
					    DDLogWarn ( @ "Ignoring  encoding  signal  recipient  with  coder . ") ; 
 
			
		
	
		
		
			
				
					
					}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					@ end  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					@ implementation  TSStorageManager @ implementation  TSStorageManager  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					+  ( instancetype ) sharedManager  { +  ( instancetype ) sharedManager  {  
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -67,19 +90,21 @@ static NSString *keychainDBPassAccount    = @"TSDatabasePass";
 
			
		
	
		
		
			
				
					
					        if  ( !data  ||  data . length  < =  0 )  { 
        if  ( !data  ||  data . length  < =  0 )  { 
 
			
		
	
		
		
			
				
					
					            return  nil ; 
            return  nil ; 
 
			
		
	
		
		
			
				
					
					        } 
        } 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        @ try  { 
        @ try  { 
 
			
		
	
		
		
			
				
					
					            return  [ NSKeyedUnarchiver  unarchiveObjectWithData : data ] ; 
            return  [ NSKeyedUnarchiver  unarchiveObjectWithData : data ] ; 
 
			
		
	
		
		
			
				
					
					        }  @ catch  ( NSException  * exception )  { 
        }  @ catch  ( NSException  * exception )  { 
 
			
		
	
		
		
			
				
					
					            / /  Sync  log  in  case  we  bail . 
            / /  Sync  log  in  case  we  bail . 
 
			
		
	
		
		
			
				
					
					            NSLog ( @ "%@ Unarchiving key:%@ from collection:%@ and data %@ failed with error: %@", 
            DDLogError ( @ "%@ Unarchiving key:%@ from collection:%@ and data %@ failed with error: %@", 
 
			
				
				
			
		
	
		
		
			
				
					
					                [ self  tag ] , 
                self . tag , 
 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					                key , 
                key , 
 
			
		
	
		
		
			
				
					
					                collection , 
                collection , 
 
			
		
	
		
		
			
				
					
					                data , 
                data , 
 
			
		
	
		
		
			
				
					
					                exception . reason ) ; 
                exception . reason ) ; 
 
			
		
	
		
		
			
				
					
					            / /  Sync  log  in  case  we  bail . 
            DDLogError ( @ "%@ Raising exception.", self.tag); 
 
			
				
				
			
		
	
		
		
			
				
					
					            NSLog ( @ "%@ Raising exception since deserialization failed", [self tag]); 
            @ throw  exception ; 
 
			
				
				
			
		
	
		
		
			
				
					
					            [ exception  raise ] ; 
            / /             DDLogWarn ( @ "%@ Ignoring exception.", self.tag); 
 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            / /             return  nil ; 
 
			
		
	
		
		
			
				
					
					        } 
        } 
 
			
		
	
		
		
			
				
					
					    } ; 
    } ; 
 
			
		
	
		
		
			
				
					
					} }  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -100,13 +125,11 @@ static NSString *keychainDBPassAccount    = @"TSDatabasePass";
 
			
		
	
		
		
			
				
					
					    / /  Seeing  this  raise  an  exception - on - boot  for  some  users ,  making  it  impossible  to  get  any  good  data . 
    / /  Seeing  this  raise  an  exception - on - boot  for  some  users ,  making  it  impossible  to  get  any  good  data . 
 
			
		
	
		
		
			
				
					
					    @ try  { 
    @ try  { 
 
			
		
	
		
		
			
				
					
					        [ OWSReadReceipt  registerIndexOnSenderIdAndTimestampWithDatabase : self . database ] ; 
        [ OWSReadReceipt  registerIndexOnSenderIdAndTimestampWithDatabase : self . database ] ; 
 
			
		
	
		
		
			
				
					
					    } 
    }  @ catch  ( NSException  * exception )  { 
 
			
				
				
			
		
	
		
		
			
				
					
					    @ catch  ( NSException  * exception )  { 
 
			
		
	
		
		
	
		
		
			
				
					
					        DDLogError ( @ "%@ Failed to register read receipt index with exception: %@ with reason: %@", self.tag, exception, exception.reason); 
        DDLogError ( @ "%@ Failed to register read receipt index with exception: %@ with reason: %@", self.tag, exception, exception.reason); 
 
			
		
	
		
		
			
				
					
					    } 
    } 
 
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					-  ( void ) protectSignalFiles  { -  ( void ) protectSignalFiles  {  
			
		
	
		
		
			
				
					
					    [ self  protectFolderAtPath : [ TSAttachmentStream  attachmentsFolder ] ] ; 
    [ self  protectFolderAtPath : [ TSAttachmentStream  attachmentsFolder ] ] ; 
 
			
		
	
		
		
			
				
					
					    [ self  protectFolderAtPath : [ self  dbPath ] ] ; 
    [ self  protectFolderAtPath : [ self  dbPath ] ] ; 
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -321,6 +344,8 @@ static NSString *keychainDBPassAccount    = @"TSDatabasePass";
 
			
		
	
		
		
			
				
					
					    [ [ self  init ]  setupDatabase ] ; 
    [ [ self  init ]  setupDatabase ] ; 
 
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					#pragma  mark  -  Logging 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					+  ( NSString  * ) tag +  ( NSString  * ) tag  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    return  [ NSString  stringWithFormat : @ "[ %@]", self.class]; 
    return  [ NSString  stringWithFormat : @ "[ %@]", self.class];