Skip to content

Commit

Permalink
Override Message.fetch to ensure that db data overrides local
Browse files Browse the repository at this point in the history
FREEBIE
  • Loading branch information
scottnonnenberg committed May 25, 2017
1 parent 2c81539 commit 3ceb3a0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions js/models/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@
isUnread: function() {
return !!this.get('unread');
},
// overriding this to allow for this.unset('unread'), save to db, then fetch()
// to propagate. We don't want the unset key in the db so our unread index stays
// small.
fetch: function(options) {
options = options ? _.clone(options) : {};
if (options.parse === void 0) options.parse = true;
var model = this;
var success = options.success;
options.success = function(resp) {
model.attributes = {}; // this is the only changed line
if (!model.set(model.parse(resp, options), options)) return false;
if (success) success(model, resp, options);
model.trigger('sync', model, resp, options);
};
var error = options.error;
options.error = function(resp) {
if (error) error(model, resp, options);
model.trigger('error', model, resp, options);
};
return this.sync('read', this, options);
},
getDescription: function() {
if (this.isGroupUpdate()) {
var group_update = this.get('group_update');
Expand Down

0 comments on commit 3ceb3a0

Please sign in to comment.