From dad14da4a816fb2b12ec12b3952f1fc44766c225 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 29 Mar 2018 22:59:00 +0200 Subject: [PATCH] [lib.channel-controller] invite(username) leave() remove() --- webpack/lib/channel-controller.js | 71 ++++++++++++++++++++++++++++++- webpack/lib/popup-controller.js | 4 +- 2 files changed, 72 insertions(+), 3 deletions(-) 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 */