Conversation: Start w/DEFAULT verified state, avoid null timestamp
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
This commit is contained in:
parent
bd0050b6c6
commit
1eb450ca35
1 changed files with 18 additions and 12 deletions
|
@ -29,7 +29,10 @@
|
||||||
database: Whisper.Database,
|
database: Whisper.Database,
|
||||||
storeName: 'conversations',
|
storeName: 'conversations',
|
||||||
defaults: function() {
|
defaults: function() {
|
||||||
return { unreadCount : 0 };
|
return {
|
||||||
|
unreadCount: 0,
|
||||||
|
verified: textsecure.storage.protocol.VerifiedStatus.DEFAULT
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
handleMessageError: function(message, errors) {
|
handleMessageError: function(message, errors) {
|
||||||
|
@ -63,8 +66,7 @@
|
||||||
if (this.isPrivate()) {
|
if (this.isPrivate()) {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
textsecure.storage.protocol.getVerified(this.id),
|
textsecure.storage.protocol.getVerified(this.id),
|
||||||
// new Promise necessary because a fetch will fail if convo not in db yet
|
this.safeFetch()
|
||||||
new Promise(function(resolve) { this.fetch().always(resolve); }.bind(this))
|
|
||||||
]).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
|
||||||
|
@ -80,22 +82,26 @@
|
||||||
}.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() {
|
||||||
return this._setVerified(DEFAULT, options);
|
return this.safeFetch().then(this._setVerified.bind(this, DEFAULT, options));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
setVerified: function(options) {
|
setVerified: function(options) {
|
||||||
var VERIFIED = this.verifiedEnum.VERIFIED;
|
var VERIFIED = this.verifiedEnum.VERIFIED;
|
||||||
return this.queueJob(function() {
|
return this.queueJob(function() {
|
||||||
return this._setVerified(VERIFIED, options);
|
return this.safeFetch().then(this._setVerified.bind(this, VERIFIED, options));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
setUnverified: function(options) {
|
setUnverified: function(options) {
|
||||||
var UNVERIFIED = this.verifiedEnum.UNVERIFIED;
|
var UNVERIFIED = this.verifiedEnum.UNVERIFIED;
|
||||||
return this.queueJob(function() {
|
return this.queueJob(function() {
|
||||||
return this._setVerified(UNVERIFIED, options);
|
return this.safeFetch().then(this._setVerified.bind(this, UNVERIFIED, options));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
_setVerified: function(verified, options) {
|
_setVerified: function(verified, options) {
|
||||||
|
@ -294,12 +300,15 @@
|
||||||
options = options || {};
|
options = options || {};
|
||||||
_.defaults(options, {local: true});
|
_.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 timestamp = Date.now();
|
||||||
var message = new Whisper.Message({
|
var message = new Whisper.Message({
|
||||||
conversationId : this.id,
|
conversationId : this.id,
|
||||||
type : 'verified-change',
|
type : 'verified-change',
|
||||||
sent_at : this.get('timestamp'),
|
sent_at : lastMessage,
|
||||||
received_at : timestamp,
|
received_at : timestamp,
|
||||||
verifiedChanged : id,
|
verifiedChanged : id,
|
||||||
verified : verified,
|
verified : verified,
|
||||||
|
@ -661,10 +670,7 @@
|
||||||
type : 'private'
|
type : 'private'
|
||||||
});
|
});
|
||||||
this.listenTo(c, 'change:verified', this.onMemberVerifiedChange);
|
this.listenTo(c, 'change:verified', this.onMemberVerifiedChange);
|
||||||
// new Promise necessary because a fetch will fail if convo not in db yet
|
promises.push(c.safeFetch());
|
||||||
promises.push(new Promise(function(resolve) {
|
|
||||||
c.fetch().always(resolve);
|
|
||||||
}));
|
|
||||||
return c;
|
return c;
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue