diff --git a/webpack/lib/channel-controller.js b/webpack/lib/channel-controller.js index 94e18ec..dcc2b67 100644 --- a/webpack/lib/channel-controller.js +++ b/webpack/lib/channel-controller.js @@ -71,9 +71,8 @@ export default class ChannelController{ this.list.splice(1); /* (4) Apply new channels */ - this.buffer = {}; for(let c of channels) - ( this.list.push(c) === 2 ) && ( this.buffer = c ); + this.list.push(c); /* (5) Restore LAST */ this.list.push(last_item); diff --git a/webpack/lib/content-controller.js b/webpack/lib/content-controller.js index fb204af..ebcd609 100644 --- a/webpack/lib/content-controller.js +++ b/webpack/lib/content-controller.js @@ -10,7 +10,6 @@ export default class ContentController{ * ---------------------------------------------------------*/ get cid(){ return gs.get.channel.current; } - get cbuf(){ return gs.get.channel.buffer; } /* (3) Room ID binding diff --git a/webpack/lib/room-controller.js b/webpack/lib/room-controller.js index c5d43ac..e1bbaa8 100644 --- a/webpack/lib/room-controller.js +++ b/webpack/lib/room-controller.js @@ -84,33 +84,30 @@ export default class RoomController{ continue; // {2} Ignore: if missing field // - if( isNaN(r.rid) || typeof r.type !== 'string' ) + if( isNaN(r.rid) || typeof r.type !== 'string' || typeof r.name !== 'string' ) continue; - // {3} Ignore if cannot find name in buffer // - var name = null; - gs.get.content.cbuf.room.map( (v) => { ( v.rid === r.rid ) && ( name = v.name ); }); - - if( name === null ) - continue; - - // {4} Default: missing messages // + // {3} Default: missing messages // if( !( r.messages instanceof Array) ) r.messages = []; - // {5} Default: missing members // + // {4} Default: missing members // if( !( r.members instanceof Array) ) r.members = []; - - // {6} Ignore: not available type // + // {5} Ignore: not available type // if( this[r.type] == null ) continue; - // {7} store data - this[r.type].list.push({ id: r.rid, name: name, type: r.type, messages: r.messages }); + // {6} store data + this[r.type].list.push({ + id: r.rid, + name: r.name, + type: r.type, + messages: r.messages + }); - // {8} redirect if first element + // {7} redirect if first element if( !redirected && r.type == 'text' ){ redirected = true; this.nav('text', r.rid); @@ -186,7 +183,6 @@ export default class RoomController{ return; /* (2) Dump data */ - console.log(rs.channel.room); this.dump(rs.channel.room); }.bind(this), auth.token); @@ -213,10 +209,19 @@ export default class RoomController{ return false; /* (3) Try to create room in API */ - console.log(`POST /channel/${gs.get.content.cid}/room/${type}`); + api.call(`POST /channel/room/${gs.get.content.cid}`, { type: type, name: name }, function(rs){ - /* (4) Add room -> update VueJS */ + /* (1) Manage error */ + if( rs.error !== 0 || rs.rid == null ) + return false; + /* (2) Reload room list */ + this.fetch(); + + /* (3) Hide popup */ + gs.get.popup.hide(); + + }.bind(this), auth.token); return true; diff --git a/webpack/mockup/api-channel-init.json b/webpack/mockup/api-channel-init.json index 414531d..2f40f2b 100644 --- a/webpack/mockup/api-channel-init.json +++ b/webpack/mockup/api-channel-init.json @@ -14,6 +14,7 @@ { "rid": 0, + "type": "text", "members": [1,3,5], @@ -32,6 +33,7 @@ { "rid": 1, + "type": "text", "members": [1,4],