[lib.channel-controller] invite(username) leave() remove()

This commit is contained in:
xdrm-brackets 2018-03-29 22:59:00 +02:00
parent 0676b8d747
commit dad14da4a8
2 changed files with 72 additions and 3 deletions

View File

@ -215,7 +215,7 @@ export default class ChannelController{
gs.get.popup.hide(); gs.get.popup.hide();
/* (2) Manage error */ /* (2) Manage error */
if( rs.error !== 0 || rs.cid == null ) if( rs.error !== 0 )
return false; return false;
/* (3) Reload channel list */ /* (3) Reload channel list */
@ -227,4 +227,73 @@ export default class ChannelController{
} }
/* (8) Removes the current channel
*
* @return removed<bool> Whether the channel has been removed
*
---------------------------------------------------------*/
remove(){
/* (2) Try to remove channel in API */
api.call(`DELETE /channel/${gs.get.content.cid}`, {}, function(rs){
/* (1) Hide popup */
gs.get.popup.hide();
/* (2) Reload channel list */
this.fetch();
}.bind(this), auth.token);
return true;
}
/* (9) Invite a friend to the current channel
*
* @username<String> Username
*
---------------------------------------------------------*/
invite(username=null) {
/* (1) Manage invalid @username */
if( typeof username !== 'string' )
return false;
/* (2) Try to remove channel in API */
api.call(`POST /channel/subscribe/${gs.get.content.cid}/${username}`, {}, function(rs){
/* (1) Hide popup */
gs.get.popup.hide();
}.bind(this), auth.token);
return true;
}
/* (10) Leave the current channel
*
---------------------------------------------------------*/
leave(){
/* (1) Try to leave channel in API */
api.call(`DELETE /channel/subscribe/${gs.get.content.cid}`, {}, function(rs){
/* (1) Hide popup */
gs.get.popup.hide();
/* (2) Reload channels */
this.fetch();
}.bind(this), auth.token);
return true;
}
} }

View File

@ -105,7 +105,7 @@ export default class PopupController{
/* (5) Remove channel */ /* (5) Remove channel */
this.register('channel.remove', { this.register('channel.remove', {
reset(){ }, reset(){ },
submit(){ this.parent.loading = gs.get.channel.remove(); } submit(){ this.parent.loading = gs.get.channel.remove(gs.get.content.cid); }
}); });
/* (6) Remove channel */ /* (6) Remove channel */
@ -123,7 +123,7 @@ export default class PopupController{
/* (7) Leave channel */ /* (7) Leave channel */
this.register('channel.leave', { this.register('channel.leave', {
reset(){ }, reset(){ },
submit(){ this.parent.loading = gs.get.channel.remove(); } submit(){ this.parent.loading = gs.get.channel.leave(); }
}); });
/* (8) Change password */ /* (8) Change password */