From 36e078c9f6b74e70a4826c4e5b374ce7b0926307 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 23 Jun 2017 20:16:16 +0200 Subject: [PATCH] utils: Rename `saveWithFallback` to `safeSave` --- src/converse-chatview.js | 2 +- src/converse-minimize.js | 4 ++-- src/converse-muc.js | 16 ++++++++-------- src/utils.js | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/converse-chatview.js b/src/converse-chatview.js index c586b1fd8..ee024808b 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -839,7 +839,7 @@ scrolled = false; this.onScrolledDown(); } - utils.saveWithFallback(this.model, {'scrolled': scrolled}); + utils.safeSave(this.model, {'scrolled': scrolled}); }, 150), viewUnreadMessages: function () { diff --git a/src/converse-minimize.js b/src/converse-minimize.js index cbcca7458..f6f3b8d5d 100644 --- a/src/converse-minimize.js +++ b/src/converse-minimize.js @@ -71,14 +71,14 @@ }, maximize: function () { - utils.saveWithFallback(this, { + utils.safeSave(this, { 'minimized': false, 'time_opened': moment().valueOf() }); }, minimize: function () { - utils.saveWithFallback(this, { + utils.safeSave(this, { 'minimized': true, 'time_minimized': moment().format() }); diff --git a/src/converse-muc.js b/src/converse-muc.js index 227cec9e1..572d04794 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -137,7 +137,7 @@ _tearDown: function () { var rooms = this.chatboxes.where({'type': CHATROOMS_TYPE}); _.each(rooms, function (room) { - room.save({'connection_status': ROOMSTATUS.DISCONNECTED}); + utils.safeSave(room, {'connection_status': ROOMSTATUS.DISCONNECTED}); }); this.__super__._tearDown.call(this, arguments); }, @@ -419,7 +419,7 @@ }, clearUnreadMsgCounter: function() { - utils.saveWithFallback(this, { + utils.safeSave(this, { 'num_unread': 0, 'num_unread_general': 0 }); @@ -1259,11 +1259,10 @@ if (_converse.connection.connected) { this.sendUnavailablePresence(exit_msg); } - if (utils.isPersistableModel(this.model)) { - this.model.save('connection_status', ROOMSTATUS.DISCONNECTED); - } else { - this.model.set('connection_status', ROOMSTATUS.DISCONNECTED); - } + utils.safeSave( + this.model, + {'connection_status': ROOMSTATUS.DISCONNECTED} + ); this.removeHandlers(); _converse.ChatBoxView.prototype.close.apply(this, arguments); }, @@ -1276,7 +1275,8 @@ * either submitted the form, or canceled it. * * Parameters: - * (XMLElement) stanza: The IQ stanza containing the room config. + * (XMLElement) stanza: The IQ stanza containing the room + * config. */ var that = this, $body = this.$('.chatroom-body'); diff --git a/src/utils.js b/src/utils.js index 49b378e37..bb913167d 100755 --- a/src/utils.js +++ b/src/utils.js @@ -526,11 +526,11 @@ return model.collection && model.collection.browserStorage; } - utils.saveWithFallback = function (model, attrs) { - if (utils.isPersistableModel(this)) { - model.save(attrs); + utils.safeSave = function (model, attributes) { + if (utils.isPersistableModel(model)) { + model.save(attributes); } else { - model.set(attrs); + model.set(attributes); } } return utils;