@ -59,6 +59,10 @@
this . ourNumber = textsecure . storage . user . getNumber ( ) ;
this . ourNumber = textsecure . storage . user . getNumber ( ) ;
this . verifiedEnum = textsecure . storage . protocol . VerifiedStatus ;
this . verifiedEnum = textsecure . storage . protocol . VerifiedStatus ;
// This may be overridden by ConversationController.getOrCreate, and signify
// our first save to the database. Or first fetch from the database.
this . initialPromise = Promise . resolve ( ) ;
this . contactCollection = new Backbone . Collection ( ) ;
this . contactCollection = new Backbone . Collection ( ) ;
this . messageCollection = new Whisper . MessageCollection ( [ ] , {
this . messageCollection = new Whisper . MessageCollection ( [ ] , {
conversation : this
conversation : this
@ -87,7 +91,7 @@
if ( this . isPrivate ( ) ) {
if ( this . isPrivate ( ) ) {
return Promise . all ( [
return Promise . all ( [
this . safeGetVerified ( ) ,
this . safeGetVerified ( ) ,
this . safeFetch( )
this . initialPromise,
] ) . then ( function ( results ) {
] ) . then ( function ( results ) {
var trust = results [ 0 ] ;
var trust = results [ 0 ] ;
// we don't return here because we don't need to wait for this to finish
// we don't return here because we don't need to wait for this to finish
@ -103,12 +107,6 @@
} . bind ( this ) ) . then ( this . onMemberVerifiedChange . bind ( this ) ) ;
} . bind ( this ) ) . then ( this . onMemberVerifiedChange . bind ( this ) ) ;
}
}
} ,
} ,
safeFetch : function ( ) {
// new Promise necessary because a fetch will fail if convo not in db yet
return new Promise ( function ( resolve ) {
this . fetch ( ) . always ( resolve ) ;
} . bind ( this ) ) ;
} ,
setVerifiedDefault : function ( options ) {
setVerifiedDefault : function ( options ) {
var DEFAULT = this . verifiedEnum . DEFAULT ;
var DEFAULT = this . verifiedEnum . DEFAULT ;
return this . queueJob ( function ( ) {
return this . queueJob ( function ( ) {
@ -801,28 +799,23 @@
return _ . contains ( this . get ( 'members' ) , number ) ;
return _ . contains ( this . get ( 'members' ) , number ) ;
} ,
} ,
fetchContacts : function ( options ) {
fetchContacts : function ( options ) {
return new Promise ( function ( resolve ) {
if ( this . isPrivate ( ) ) {
if ( this . isPrivate ( ) ) {
this . contactCollection . reset ( [ this ] ) ;
this . contactCollection . reset ( [ this ] ) ;
resolve ( ) ;
return Promise . resolve ( ) ;
} else {
} else {
var promises = [ ] ;
var members = this . get ( 'members' ) || [ ] ;
var members = this . get ( 'members' ) || [ ] ;
var promises = members . map ( function ( number ) {
this . contactCollection . reset (
return ConversationController . getOrCreateAndWait ( number , 'private' ) ;
members . map ( function ( number ) {
var c = ConversationController . create ( {
id : number ,
type : 'private'
} ) ;
} ) ;
this . listenTo ( c , 'change:verified' , this . onMemberVerifiedChange ) ;
promises . push ( c . safeFetch ( ) ) ;
return Promise . all ( promises ) . then ( function ( contacts ) {
return c ;
_ . forEach ( contacts , function ( contact ) {
} . bind ( this ) )
this . listenTo ( contact , 'change:verified' , this . onMemberVerifiedChange ) ;
) ;
resolve ( Promise . all ( promises ) ) ;
}
} . bind ( this ) ) ;
} . bind ( this ) ) ;
this . contactCollection . reset ( contacts ) ;
} . bind ( this ) ) ;
}
} ,
} ,
destroyMessages : function ( ) {
destroyMessages : function ( ) {
@ -956,14 +949,11 @@
}
}
window . drawAttention ( ) ;
window . drawAttention ( ) ;
var sender = ConversationController . create ( {
id : message . get ( 'source' ) , type : 'private'
} ) ;
var conversationId = this . id ;
var conversationId = this . id ;
return new Promise ( function ( resolve , reject ) {
ConversationController . getOrCreateAndWait ( message . get ( 'source' ) , 'private' )
sender . fetch ( ) . then ( function ( ) {
. then ( function ( sender ) {
sender . getNotificationIcon ( ) . then ( function ( iconUrl ) {
return sender . getNotificationIcon ( ) . then ( function ( iconUrl ) {
console . log ( 'adding notification' ) ;
console . log ( 'adding notification' ) ;
Whisper . Notifications . add ( {
Whisper . Notifications . add ( {
title : sender . getTitle ( ) ,
title : sender . getTitle ( ) ,
@ -973,10 +963,7 @@
conversationId : conversationId ,
conversationId : conversationId ,
messageId : message . id
messageId : message . id
} ) ;
} ) ;
} ) ;
return resolve ( ) ;
} , reject ) ;
} , reject ) ;
} ) ;
} ) ;
} ,
} ,
hashCode : function ( ) {
hashCode : function ( ) {
@ -1054,20 +1041,6 @@
}
}
} ) . always ( resolve ) ;
} ) . always ( resolve ) ;
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} ,
fetchActive : function ( ) {
// Ensures all active conversations are included in this collection,
// and updates their attributes, but removes nothing.
return this . fetch ( {
index : {
name : 'inbox' , // 'inbox' index on active_at
order : 'desc' // ORDER timestamp DESC
// TODO pagination/infinite scroll
// limit: 10, offset: page*10,
} ,
remove : false
} ) ;
}
}
} ) ;
} ) ;