diff --git a/js/models/room.js b/js/models/room.js index 601434c25..10167056a 100644 --- a/js/models/room.js +++ b/js/models/room.js @@ -75,7 +75,27 @@ } return Backbone.Model.prototype.sync.call(this, method, model, options); - } + }, + join: function() { + OCA.SpreedMe.app.connection.joinRoom(this.get('token')); + }, + leave: function() { + if (!this.get('active')) { + return; + } + + OCA.SpreedMe.app.connection.leaveCurrentRoom(true); + }, + removeSelf: function() { + this.destroy({ + url: this.url() + '/participants/self' + }); + }, + destroy: function(options) { + this.leave(); + + return Backbone.Model.prototype.destroy.call(this, options); + }, }); OCA.SpreedMe.Models.Room = Room; diff --git a/js/views/roomlistview.js b/js/views/roomlistview.js index bccb8f014..d226662b8 100644 --- a/js/views/roomlistview.js +++ b/js/views/roomlistview.js @@ -235,13 +235,9 @@ } }, removeRoom: function() { - this.cleanupIfActiveRoom(); this.$el.slideUp(); - $.ajax({ - url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + this.model.get('token') + '/participants/self', - type: 'DELETE' - }); + this.model.removeSelf(); }, deleteRoom: function() { if (this.model.get('participantType') !== 1 && @@ -249,13 +245,9 @@ return; } - this.cleanupIfActiveRoom(); this.$el.slideUp(); - $.ajax({ - url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + this.model.get('token'), - type: 'DELETE' - }); + this.model.destroy(); }, addRoomToFavorites: function() { if (this.model.get('participantType') === 5) { @@ -311,17 +303,10 @@ } }); }, - cleanupIfActiveRoom: function() { - if (!this.model.get('active')) { - return; - } - - OCA.SpreedMe.app.connection.leaveCurrentRoom(true); - }, joinRoom: function(e) { e.preventDefault(); - var token = this.ui.room.attr('data-token'); - OCA.SpreedMe.app.connection.joinRoom(token); + + this.model.join(); }, });