Skip to content

Commit

Permalink
Conversation: Start w/DEFAULT verified state, avoid null timestamp
Browse files Browse the repository at this point in the history
Fix too-aggressive verification notifications on startup by starting a
conversation with the right initial verified state, and then making sure
to fetch() before setting a new verified state.

FREEBIE
  • Loading branch information
scottnonnenberg committed Aug 4, 2017
1 parent bd0050b commit 1eb450c
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions js/models/conversations.js
Expand Up @@ -29,7 +29,10 @@
database: Whisper.Database,
storeName: 'conversations',
defaults: function() {
return { unreadCount : 0 };
return {
unreadCount: 0,
verified: textsecure.storage.protocol.VerifiedStatus.DEFAULT
};
},

handleMessageError: function(message, errors) {
Expand Down Expand Up @@ -63,8 +66,7 @@
if (this.isPrivate()) {
return Promise.all([
textsecure.storage.protocol.getVerified(this.id),
// new Promise necessary because a fetch will fail if convo not in db yet
new Promise(function(resolve) { this.fetch().always(resolve); }.bind(this))
this.safeFetch()
]).then(function(results) {
var trust = results[0];
// we don't return here because we don't need to wait for this to finish
Expand All @@ -80,22 +82,26 @@
}.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) {
var DEFAULT = this.verifiedEnum.DEFAULT;
return this.queueJob(function() {
return this._setVerified(DEFAULT, options);
return this.safeFetch().then(this._setVerified.bind(this, DEFAULT, options));
}.bind(this));
},
setVerified: function(options) {
var VERIFIED = this.verifiedEnum.VERIFIED;
return this.queueJob(function() {
return this._setVerified(VERIFIED, options);
return this.safeFetch().then(this._setVerified.bind(this, VERIFIED, options));
}.bind(this));
},
setUnverified: function(options) {
var UNVERIFIED = this.verifiedEnum.UNVERIFIED;
return this.queueJob(function() {
return this._setVerified(UNVERIFIED, options);
return this.safeFetch().then(this._setVerified.bind(this, UNVERIFIED, options));
}.bind(this));
},
_setVerified: function(verified, options) {
Expand Down Expand Up @@ -294,12 +300,15 @@
options = options || {};
_.defaults(options, {local: true});

console.log('adding verified change advisory for', this.id, id, this.get('timestamp'));
var lastMessage = this.get('timestamp') || Date.now();

console.log('adding verified change advisory for', this.id, id, lastMessage);

var timestamp = Date.now();
var message = new Whisper.Message({
conversationId : this.id,
type : 'verified-change',
sent_at : this.get('timestamp'),
sent_at : lastMessage,
received_at : timestamp,
verifiedChanged : id,
verified : verified,
Expand Down Expand Up @@ -661,10 +670,7 @@
type : 'private'
});
this.listenTo(c, 'change:verified', this.onMemberVerifiedChange);
// new Promise necessary because a fetch will fail if convo not in db yet
promises.push(new Promise(function(resolve) {
c.fetch().always(resolve);
}));
promises.push(c.safeFetch());
return c;
}.bind(this))
);
Expand Down

0 comments on commit 1eb450c

Please sign in to comment.