diff --git a/webpack/lib/channel-controller.js b/webpack/lib/channel-controller.js index 582ca2e..aef4306 100644 --- a/webpack/lib/channel-controller.js +++ b/webpack/lib/channel-controller.js @@ -215,7 +215,7 @@ export default class ChannelController{ gs.get.popup.hide(); /* (2) Manage error */ - if( rs.error !== 0 || rs.cid == null ) + if( rs.error !== 0 ) return false; /* (3) Reload channel list */ @@ -227,4 +227,73 @@ export default class ChannelController{ } + + /* (8) Removes the current channel + * + * @return removed 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 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; + + } + } \ No newline at end of file diff --git a/webpack/lib/popup-controller.js b/webpack/lib/popup-controller.js index 2cd4806..18be6c7 100644 --- a/webpack/lib/popup-controller.js +++ b/webpack/lib/popup-controller.js @@ -105,7 +105,7 @@ export default class PopupController{ /* (5) Remove channel */ this.register('channel.remove', { reset(){ }, - submit(){ this.parent.loading = gs.get.channel.remove(); } + submit(){ this.parent.loading = gs.get.channel.remove(gs.get.content.cid); } }); /* (6) Remove channel */ @@ -123,7 +123,7 @@ export default class PopupController{ /* (7) Leave channel */ this.register('channel.leave', { reset(){ }, - submit(){ this.parent.loading = gs.get.channel.remove(); } + submit(){ this.parent.loading = gs.get.channel.leave(); } }); /* (8) Change password */