diff --git a/webpack/lib/channel-controller.js b/webpack/lib/channel-controller.js index 4c8171b..e166690 100644 --- a/webpack/lib/channel-controller.js +++ b/webpack/lib/channel-controller.js @@ -9,10 +9,11 @@ export default class ChannelController{ this.current = null; /* (2) Initialize channel list */ - this.list = [ - { id: -1, link: 'me', label: 'My data', sub: '0 online', icon: 'group', room: [] }, - { id: -2, link: null, label: 'add', sub: null, icon: 'add', room: [], add: 1 } - ]; + this.list = []; + + /* (3) Current channel buffer */ + this.buffer = {}; + } @@ -26,9 +27,6 @@ export default class ChannelController{ ---------------------------------------------------------*/ nav(channel_id=null){ - if( channel_id == -2 ) - return gs.get.popup.show('channel.create'); - console.log(`channel.nav(${channel_id})`); /* (1) Get channel data */ @@ -37,13 +35,19 @@ export default class ChannelController{ /* (2) Navigate vue-router */ gs.get.router.push(`/channel/${channel.link}`); - /* (3) Update active element */ + /* (3) Update current id */ this.current = channel.id; - /* (4) Load rooms */ + /* (4) Update buffer */ + this.buffer = {}; + for( let c in this.list ) + if( c.id === this.current ) + this.buffer = c; + + /* (5) Load rooms */ gs.get.room.fetch(); - /* (5) Log channel */ + /* (6) Log channel */ console.log(`[channel.current] ${channel.link} (${channel.label})`); return true; @@ -64,19 +68,18 @@ export default class ChannelController{ if( !(channels instanceof Array) ) return false; - /* (2) Store LAST item */ - let last_item = this.list.pop(); + /* (2) Clear list () */ + this.list.splice(); - /* (3) Clear list (except FIRST) */ - this.list.splice(1); + /* (3) Apply new channels */ + for(let c of channels){ + + // add 'users' field (will be filled by GET channel/cid) + c.users = []; - /* (4) Apply new channels */ - for(let c of channels) this.list.push(c); - /* (5) Restore LAST */ - this.list.push(last_item); - + } return true; diff --git a/webpack/lib/content-controller.js b/webpack/lib/content-controller.js index 8b6e3fd..d064b10 100644 --- a/webpack/lib/content-controller.js +++ b/webpack/lib/content-controller.js @@ -11,57 +11,22 @@ export default class ContentController{ ---------------------------------------------------------*/ get cid(){ return gs.get.channel.current; } - get cbuf(){ - - /* (1) Ignore: if no channel */ - if( gs.get.channel.list == null || gs.get.channel.list.length === 0 ) - return {}; - - /* (2) Search for current channel */ - for( let c of gs.get.channel.list ){ - - // Return if channel found // - if( c.id === this.cid ) - return c; - - } - - - /* (3) If nothing found */ - return {}; - - } + get cbuf(){ return gs.get.channel.buffer; } /* (3) Room ID binding * ---------------------------------------------------------*/ get rid(){ return gs.get.room.text.current; } - - get rbuf(){ - - /* (1) Ignore: if no rooms empty */ - if( gs.get.room.text.list == null || gs.get.room.text.list.length === 0 ) - return {}; - - /* (2) Search for current room */ - for( let r of gs.get.room.text.list ){ - - // Return if room found // - if( r.id === this.rid ) - return r; - - } - - - /* (3) If nothing found */ - return {}; - - } + get rbuf(){ return gs.get.room.buffer.text; } get messages(){ return this.rbuf.messages; } get members(){ return this.rbuf.members; } + // current user data + get uid(){ return gs.get.auth.user.uid; } + get ubuf(){ return gs.get.auth.user; } + /* (5) User getter * @@ -105,5 +70,44 @@ export default class ContentController{ } + /* (7) Change username + * + * @username New username + ---------------------------------------------------------*/ + change_username(username=null){ + + /* (1) Error: if invalid user_id */ + if( typeof username !== 'string' || username.length < 3 ) + return false; + + /* (2) Error: unknown user */ + if( this.uid == null ) + return false; + + /* (3) Call api UPDATE */ + api.call(`PUT /user/${this.uid}`, { username: username, password: null }, function(rs){ + + // manage error + if( rs.error !== 0 ) + return; + + // update global username + let tmp_user = auth.user; + tmp_user.username = username; + auth.user = tmp_user; + + // update username in channel + for( let u in this.cbuf.users ) + if( this.cbuf.users[u].uid == this.uid ) + this.cbuf.users[u].username = username; + + }.bind(this), auth.token); + + /* (4) Error */ + return true; + + } + + } \ No newline at end of file diff --git a/webpack/lib/room-controller.js b/webpack/lib/room-controller.js index 1ed7e0c..de7faca 100644 --- a/webpack/lib/room-controller.js +++ b/webpack/lib/room-controller.js @@ -10,6 +10,13 @@ export default class RoomController{ this.text = { list: [], current: 0, visible: true }; this.voice = { list: [], current: null, visible: true }; + /* (2) Current room buffer */ + this.buffer = { + text: {}, + voice: {} + }; + + } @@ -38,6 +45,13 @@ export default class RoomController{ /* (5) Update @active room */ this[type].current = room.id; + /* (6) Update buffer */ + this.buffer[type] = {}; + for( let r of this[type].list ) + if( r.id === this[type].current ) + this.buffer[type] = r; + + console.log(`[room.${type}.opened] ${room.name} (${room.id})`, room.id); return true; diff --git a/webpack/vue/auth/menu.vue b/webpack/vue/auth/menu.vue index 4fafa23..7a2cc7b 100644 --- a/webpack/vue/auth/menu.vue +++ b/webpack/vue/auth/menu.vue @@ -5,19 +5,18 @@