Skip to content

Commit

Permalink
Conversation.markRead: Remove checks for unread
Browse files Browse the repository at this point in the history
We will now always attempt to mark things unread if this method. If the
conversation's unreadCount gets out of date, set to zero, we will still
do it. If we go through the motions, and nothing is newly marked read,
we will still set the unreadCount to zero.
  • Loading branch information
scottnonnenberg committed Jun 7, 2017
1 parent 6fbdd63 commit aeefc53
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions js/models/conversations.js
Expand Up @@ -305,42 +305,38 @@
options = options || {};
_.defaults(options, {sendReadReceipts: true});

if (this.get('unreadCount') > 0) {
var conversationId = this.id;
Whisper.Notifications.remove(Whisper.Notifications.where({
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));
var conversationId = this.id;
Whisper.Notifications.remove(Whisper.Notifications.where({
conversationId: conversationId
}));

if (read.length > 0) {
var unreadCount = unreadMessages.length - read.length;
this.save({ unreadCount: unreadCount });
this.getUnread().then(function(unreadMessages) {
var oldUnread = unreadMessages.filter(function(message) {
return message.get('received_at') <= newestUnreadDate;
});

if (options.sendReadReceipts) {
console.log('Sending', read.length, 'read receipts');
textsecure.messaging.syncReadMessages(read);
}
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));
}

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() {
Expand Down

1 comment on commit aeefc53

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $146.00USD for this commit.

Please sign in to comment.