Update records list in BBLocalStorage on fetch

Previously, would only update the known messages.
This commit is contained in:
lilia 2014-10-09 20:08:21 -07:00
parent 2288f8adc1
commit 0f4b53c176
3 changed files with 12 additions and 0 deletions

View file

@ -99,11 +99,15 @@ extend(Backbone.LocalStorage.prototype, {
// Retrieve a model from `this.data` by id.
find: function(model) {
var store = this.localStorage().getItem(this.name);
this.records = (store && store.split(",")) || [];
return this.serializer.deserialize(this.localStorage().getItem(this.name+"-"+model.id));
},
// Return the array of all models currently in storage.
findAll: function() {
var store = this.localStorage().getItem(this.name);
this.records = (store && store.split(",")) || [];
var result = [];
for (var i = 0, id, data; i < this.records.length; i++) {
id = this.records[i];

View file

@ -22,6 +22,7 @@ Whisper.Layout = new (Backbone.View.extend({
new Whisper.ConversationListView({el: $('#contacts')});
window.addEventListener('resize', this.resize.bind(this));
window.addEventListener('storage', function(){Whisper.Threads.fetch();});
Whisper.Threads.fetch({reset: true});
},
events: {

View file

@ -14,12 +14,19 @@ var Whisper = Whisper || {};
this.view = new Whisper.MessageListView({collection: this.model.messages()});
this.model.messages().fetch({reset: true});
this.$el.find('.discussion-container').append(this.view.el);
window.addEventListener('storage', (function(){
this.fetch();
}).bind(this));
},
events: {
'submit .send': 'sendMessage',
'close': 'remove'
},
fetch: function() {
this.model.messages().fetch({reset: true});
},
sendMessage: function(e) {
e.preventDefault();
var input = this.$el.find('.send input');