[vue.auth.menu][lib.channel-controller] removed FIRST and LAST false channels replaced with HARD-CODED elements with associated links (/me channel no more accessible) + [lib.content-controller] eased rbuf() with creating buffer copy in {lib.room-controller}.buffer and {lib.channel-controller}.buffer

This commit is contained in:
xdrm-brackets 2018-03-28 21:04:49 +02:00
parent f4be2b1bad
commit e3fd7e147d
4 changed files with 83 additions and 63 deletions

View File

@ -9,10 +9,11 @@ export default class ChannelController{
this.current = null; this.current = null;
/* (2) Initialize channel list */ /* (2) Initialize channel list */
this.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 } /* (3) Current channel buffer */
]; this.buffer = {};
} }
@ -26,9 +27,6 @@ export default class ChannelController{
---------------------------------------------------------*/ ---------------------------------------------------------*/
nav(channel_id=null){ nav(channel_id=null){
if( channel_id == -2 )
return gs.get.popup.show('channel.create');
console.log(`channel.nav(${channel_id})`); console.log(`channel.nav(${channel_id})`);
/* (1) Get channel data */ /* (1) Get channel data */
@ -37,13 +35,19 @@ export default class ChannelController{
/* (2) Navigate vue-router */ /* (2) Navigate vue-router */
gs.get.router.push(`/channel/${channel.link}`); gs.get.router.push(`/channel/${channel.link}`);
/* (3) Update active element */ /* (3) Update current id */
this.current = channel.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(); gs.get.room.fetch();
/* (5) Log channel */ /* (6) Log channel */
console.log(`[channel.current] ${channel.link} (${channel.label})`); console.log(`[channel.current] ${channel.link} (${channel.label})`);
return true; return true;
@ -64,19 +68,18 @@ export default class ChannelController{
if( !(channels instanceof Array) ) if( !(channels instanceof Array) )
return false; return false;
/* (2) Store LAST item */ /* (2) Clear list () */
let last_item = this.list.pop(); this.list.splice();
/* (3) Clear list (except FIRST) */ /* (3) Apply new channels */
this.list.splice(1); 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); this.list.push(c);
/* (5) Restore LAST */ }
this.list.push(last_item);
return true; return true;

View File

@ -11,57 +11,22 @@ export default class ContentController{
---------------------------------------------------------*/ ---------------------------------------------------------*/
get cid(){ return gs.get.channel.current; } get cid(){ return gs.get.channel.current; }
get cbuf(){ get cbuf(){ return gs.get.channel.buffer; }
/* (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 {};
}
/* (3) Room ID binding /* (3) Room ID binding
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
get rid(){ return gs.get.room.text.current; } get rid(){ return gs.get.room.text.current; }
get rbuf(){ return gs.get.room.buffer.text; }
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 messages(){ return this.rbuf.messages; } get messages(){ return this.rbuf.messages; }
get members(){ return this.rbuf.members; } 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 /* (5) User getter
* *
@ -105,5 +70,44 @@ export default class ContentController{
} }
/* (7) Change username
*
* @username<String> 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;
}
} }

View File

@ -10,6 +10,13 @@ export default class RoomController{
this.text = { list: [], current: 0, visible: true }; this.text = { list: [], current: 0, visible: true };
this.voice = { list: [], current: null, 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 */ /* (5) Update @active room */
this[type].current = room.id; 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); console.log(`[room.${type}.opened] ${room.name} (${room.id})`, room.id);
return true; return true;

View File

@ -5,19 +5,18 @@
<div class='menu'> <div class='menu'>
<!-- First elements --> <!-- First elements -->
<span class='channel' data-special='1' data-icon='group' :data-sub='gs.channel.buffer.users != null ? `${gs.channel.buffer.users.length} online`:`0 online`'></span>
<!-- Channel List --> <!-- Channel List -->
<span v-for='c in gs.channel.list' <span v-for='c in gs.channel.list'
@click='gs.channel.nav(c.id);' @click='gs.channel.nav(c.id);'
:class='c.id == gs.channel.current ? `channel active` : `channel`' :class='c.id == gs.channel.current ? `channel active` : `channel`'
:data-sub='c.sub'
:data-special='c.id == -1?1:0'
:data-add='c.add'
:data-icon='c.icon' :data-icon='c.icon'
:title='c.label' :title='c.label'
></span> ></span>
<!-- Last elements --> <!-- Last elements -->
<span class='channel' data-special='1' data-icon='add' data-add='1' @click='gs.popup.show(`channel.create`)'></span>
</div> </div>