Pārlūkot izejas kodu

utils: Rename `saveWithFallback` to `safeSave`

JC Brand 8 gadi atpakaļ
vecāks
revīzija
36e078c9f6
4 mainītis faili ar 15 papildinājumiem un 15 dzēšanām
  1. 1 1
      src/converse-chatview.js
  2. 2 2
      src/converse-minimize.js
  3. 8 8
      src/converse-muc.js
  4. 4 4
      src/utils.js

+ 1 - 1
src/converse-chatview.js

@@ -839,7 +839,7 @@
                         scrolled = false;
                         scrolled = false;
                         this.onScrolledDown();
                         this.onScrolledDown();
                     }
                     }
-                    utils.saveWithFallback(this.model, {'scrolled': scrolled});
+                    utils.safeSave(this.model, {'scrolled': scrolled});
                 }, 150),
                 }, 150),
 
 
                 viewUnreadMessages: function () {
                 viewUnreadMessages: function () {

+ 2 - 2
src/converse-minimize.js

@@ -71,14 +71,14 @@
                 },
                 },
 
 
                 maximize: function () {
                 maximize: function () {
-                    utils.saveWithFallback(this,  {
+                    utils.safeSave(this, {
                         'minimized': false,
                         'minimized': false,
                         'time_opened': moment().valueOf()
                         'time_opened': moment().valueOf()
                     });
                     });
                 },
                 },
 
 
                 minimize: function () {
                 minimize: function () {
-                    utils.saveWithFallback(this,  {
+                    utils.safeSave(this, {
                         'minimized': true,
                         'minimized': true,
                         'time_minimized': moment().format()
                         'time_minimized': moment().format()
                     });
                     });

+ 8 - 8
src/converse-muc.js

@@ -137,7 +137,7 @@
             _tearDown: function () {
             _tearDown: function () {
                 var rooms = this.chatboxes.where({'type': CHATROOMS_TYPE});
                 var rooms = this.chatboxes.where({'type': CHATROOMS_TYPE});
                 _.each(rooms, function (room) {
                 _.each(rooms, function (room) {
-                    room.save({'connection_status': ROOMSTATUS.DISCONNECTED});
+                    utils.safeSave(room, {'connection_status': ROOMSTATUS.DISCONNECTED});
                 });
                 });
                 this.__super__._tearDown.call(this, arguments);
                 this.__super__._tearDown.call(this, arguments);
             },
             },
@@ -419,7 +419,7 @@
                 },
                 },
 
 
                 clearUnreadMsgCounter: function() {
                 clearUnreadMsgCounter: function() {
-                    utils.saveWithFallback(this,  {
+                    utils.safeSave(this, {
                         'num_unread': 0,
                         'num_unread': 0,
                         'num_unread_general': 0
                         'num_unread_general': 0
                     });
                     });
@@ -1259,11 +1259,10 @@
                     if (_converse.connection.connected) {
                     if (_converse.connection.connected) {
                         this.sendUnavailablePresence(exit_msg);
                         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();
                     this.removeHandlers();
                     _converse.ChatBoxView.prototype.close.apply(this, arguments);
                     _converse.ChatBoxView.prototype.close.apply(this, arguments);
                 },
                 },
@@ -1276,7 +1275,8 @@
                      * either submitted the form, or canceled it.
                      * either submitted the form, or canceled it.
                      *
                      *
                      * Parameters:
                      * Parameters:
-                     *  (XMLElement) stanza: The IQ stanza containing the room config.
+                     *  (XMLElement) stanza: The IQ stanza containing the room
+                     *      config.
                      */
                      */
                     var that = this,
                     var that = this,
                         $body = this.$('.chatroom-body');
                         $body = this.$('.chatroom-body');

+ 4 - 4
src/utils.js

@@ -526,11 +526,11 @@
         return model.collection && model.collection.browserStorage;
         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 {
         } else {
-            model.set(attrs);
+            model.set(attributes);
         }
         }
     }
     }
     return utils;
     return utils;