[lib.content-controller] message management + watcher chain

This commit is contained in:
xdrm-brackets 2018-03-22 15:28:34 +01:00
parent 2d6b5c7378
commit 67faf26824
4 changed files with 44 additions and 11 deletions

View File

@ -14,6 +14,9 @@ export class ChannelController{
{ id: -2, link: null, label: 'add', sub: null, icon: 'add', room: [], add: 1 }
];
/* (3) Initialize channel data buffer */
this.buffer = {};
}
@ -170,8 +173,7 @@ export class ChannelController{
/* (2) Call API to get data */
setTimeout(() => {
let fetched = require('../mockup/api-channel-init.json');
gs.get.main = fetched;
this.buffer = require('../mockup/api-channel-init.json');
}, 500);

View File

@ -3,20 +3,47 @@ export class ContentController{
/* (1) Construct default attributes
*
---------------------------------------------------------*/
constructor(){
/* (1) Initialize content data */
this.messages = [];
this.users = [];
constructor(){}
}
/* (2) Getters
/* (2) Channel bindings
*
---------------------------------------------------------*/
get cid(){ return gs.get.channel.current; }
get cbuf(){ return gs.get.channel.buffer; }
/* (3) Room ID binding
*
---------------------------------------------------------*/
get cid(){ return gs.get.channel.current; }
get rid(){ return gs.get.room.text.current; }
/* (4) Room buffer binding
*
---------------------------------------------------------*/
get rbuf(){
/* (1) Ignore: if no rooms empty */
if( this.cbuf.room == null || this.cbuf.room.length === 0 )
return {};
/* (2) Search for current room */
for( let r of this.cbuf.room ){
// Return if room found //
if( r.rid === this.rid )
return r;
}
/* (3) If nothing found */
return {};
}
get messages(){ return this.rbuf.messages; }
get members(){ return this.rbuf.members; }
}

View File

@ -147,4 +147,5 @@ export class RoomController{
}
}

View File

@ -7,6 +7,9 @@
</div>
<div class='body'>
<div class='message' v-for='msg in gs.content.messages'>
{{ msg.msg }}
</div>
</div>
</div>