@ -10,8 +10,7 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        templateName :  'contact-detail' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        initialize :  function ( options )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . errors  =  _ . reject ( options . errors ,  function ( e )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                return  ( e . name  ===  'IncomingIdentityKeyError'  || 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                        e . name  ===  'OutgoingIdentityKeyError'  || 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                return  ( e . name  ===  'OutgoingIdentityKeyError'  || 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                        e . name  ===  'OutgoingMessageError'  || 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                        e . name  ===  'SendMessageNetworkError' ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ) ; 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -36,6 +35,33 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . listenTo ( this . model ,  'change' ,  this . render ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        events :  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            'click button.retry' :  'onRetry' 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        onRetry :  function ( e )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  number  =  _ . find ( e . target . attributes ,  function ( attribute )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                return  attribute . name  ===  'data-number' ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( number )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . model . resend ( number . value ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        getContact :  function ( number )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  c  =  ConversationController . get ( number ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            return  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                number :  number , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                title :  c  ?  c . getTitle ( )  :  number 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        buildRetryTargetList :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  targets  =  _ . filter ( this . model . get ( 'errors' ) ,  function ( e )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                return  e . number  &&  e . name  ===  'OutgoingIdentityKeyError' ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            return  _ . map ( targets ,  function ( e )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                return  this . getContact ( e . number ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } . bind ( this ) ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        contacts :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( this . model . isIncoming ( ) )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                var  number  =  this . model . get ( 'source' ) ; 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -45,35 +71,36 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        renderContact :  function ( contact )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  grouped  =  _ . groupBy ( this . model . get ( 'errors' ) ,  'number' ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  view  =  new  ContactView ( { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                model :  contact , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                errors :  this . errors [ contact . id ] 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                errors :  grouped [ contact . id ] 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ) . render ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . $ ( '.contacts' ) . append ( view . el ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        render :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . errors  =  _ . groupBy ( this . model . get ( 'errors' ) ,  'number' ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  unknownErrors  =  this . errors [ 'undefined' ] ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( unknownErrors )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                unknownErrors  =  unknownErrors . filter ( function ( e )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    return  ( e . name  !==  'MessageError' ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                } ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  retryTargets  =  this . buildRetryTargetList ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  allowRetry  =  retryTargets . length  >  0 ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . $el . html ( Mustache . render ( _ . result ( this ,  'template' ,  '' ) ,  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                sent _at      :  moment ( this . model . get ( 'sent_at' ) ) . format ( 'LLLL' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                received _at  :  this . model . isIncoming ( )  ?  moment ( this . model . get ( 'received_at' ) ) . format ( 'LLLL' )  :  null , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                tofrom       :  this . model . isIncoming ( )  ?  i18n ( 'from' )  :  i18n ( 'to' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                errors       :  unknownErrors , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                title        :  i18n ( 'messageDetail' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                sent         :  i18n ( 'sent' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                received     :  i18n ( 'received' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                errorLabel   :  i18n ( 'error' ) 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                sent _at          :  moment ( this . model . get ( 'sent_at' ) ) . format ( 'LLLL' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                received _at      :  this . model . isIncoming ( )  ?  moment ( this . model . get ( 'received_at' ) ) . format ( 'LLLL' )  :  null , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                tofrom           :  this . model . isIncoming ( )  ?  i18n ( 'from' )  :  i18n ( 'to' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                errors           :  this . model . get ( 'errors' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                allowRetry       :  allowRetry , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                retryTargets     :  retryTargets , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                title            :  i18n ( 'messageDetail' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                sent             :  i18n ( 'sent' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                received         :  i18n ( 'received' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                errorLabel       :  i18n ( 'error' ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                retryDescription :  i18n ( 'retryDescription' ) 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ) ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . view . $el . prependTo ( this . $ ( '.message-container' ) ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( this . model . isOutgoing ( ) )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . conversation . contactCollection . reject ( function ( c )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    return  c . i d ===  textsecure . storage . user . getNumber  ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    return  c . i sMe ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                } ) . forEach ( this . renderContact . bind ( this ) ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            }  else  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . renderContact (