@ -305,42 +305,38 @@
options = options || { } ;
options = options || { } ;
_ . defaults ( options , { sendReadReceipts : true } ) ;
_ . defaults ( options , { sendReadReceipts : true } ) ;
if ( this . get ( 'unreadCount' ) > 0 ) {
var conversationId = this . id ;
var conversationId = this . id ;
Whisper . Notifications . remove ( Whisper . Notifications . where ( {
Whisper . Notifications . remove ( Whisper . Notifications . where ( {
conversationId : conversationId
conversationId : conversationId
} ) ) ;
} ) ) ;
this . getUnread ( ) . then ( function ( unreadMessages ) {
var oldUnread = unreadMessages . filter ( function ( message ) {
return message . get ( 'received_at' ) <= newestUnreadDate ;
} ) ;
var read = _ . map ( oldUnread , function ( m ) {
if ( this . messageCollection . get ( m . id ) ) {
m = this . messageCollection . get ( m . id ) ;
} else {
console . log ( 'Marked a message as read in the database, but ' +
'it was not in messageCollection.' ) ;
}
m . markRead ( ) ;
return {
sender : m . get ( 'source' ) ,
timestamp : m . get ( 'sent_at' )
} ;
} . bind ( this ) ) ;
if ( read . length > 0 ) {
this . getUnread ( ) . then ( function ( unreadMessages ) {
var unreadCount = unreadMessages . length - read . length ;
var oldUnread = unreadMessages . filter ( function ( message ) {
this . save ( { unreadCount : unreadCount } ) ;
return message . get ( 'received_at' ) <= newestUnreadDate ;
} ) ;
if ( options . sendReadReceipts ) {
var read = _ . map ( oldUnread , function ( m ) {
console . log ( 'Sending' , read . length , 'read receipts' ) ;
if ( this . messageCollection . get ( m . id ) ) {
textsecure . messaging . syncReadMessages ( read ) ;
m = this . messageCollection . get ( m . id ) ;
}
} else {
console . log ( 'Marked a message as read in the database, but ' +
'it was not in messageCollection.' ) ;
}
}
m . markRead ( ) ;
return {
sender : m . get ( 'source' ) ,
timestamp : m . get ( 'sent_at' )
} ;
} . bind ( this ) ) ;
} . bind ( this ) ) ;
}
var unreadCount = unreadMessages . length - read . length ;
this . save ( { unreadCount : unreadCount } ) ;
if ( read . length && options . sendReadReceipts ) {
console . log ( 'Sending' , read . length , 'read receipts' ) ;
textsecure . messaging . syncReadMessages ( read ) ;
}
} . bind ( this ) ) ;
} ,
} ,
fetchMessages : function ( ) {
fetchMessages : function ( ) {