From 0f4b53c176fb7ce8591e83e9dab1cf2bbd9ac578 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 9 Oct 2014 20:08:21 -0700 Subject: [PATCH] Update records list in BBLocalStorage on fetch Previously, would only update the known messages. --- js-deps/backbone.localStorage.js | 4 ++++ js/popup.js | 1 + js/views/conversation_view.js | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/js-deps/backbone.localStorage.js b/js-deps/backbone.localStorage.js index e801c9655..a842cf9af 100644 --- a/js-deps/backbone.localStorage.js +++ b/js-deps/backbone.localStorage.js @@ -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]; diff --git a/js/popup.js b/js/popup.js index b8e4d7d34..ba83d5a31 100644 --- a/js/popup.js +++ b/js/popup.js @@ -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: { diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 95790af07..fc7189d52 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -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');