Move some actions from RoomListView to Room

Rooms are now deleted by using the standard "destroy" method of Backbone
models instead of calling the endpoint directly from the view. In a
similar way, the current user now removes herself from the room also by
destroying the model, but with a special URL. This will make possible to
listen to and handle the "destroy" event of the model from other places.

Leaving the current room when it is destroyed or removed was also moved
to the model; for consistency, the model now provides a method to join
the room too (which, in the end, will also synchronize the model).

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2018-12-05 01:38:14 +01:00
Родитель 6ad206a38c
Коммит 9e42d26fb0
2 изменённых файлов: 25 добавлений и 20 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();
},
});