[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 } { 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 */ /* (2) Call API to get data */
setTimeout(() => { setTimeout(() => {
let fetched = require('../mockup/api-channel-init.json'); this.buffer = require('../mockup/api-channel-init.json');
gs.get.main = fetched;
}, 500); }, 500);

View File

@ -3,20 +3,47 @@ export class ContentController{
/* (1) Construct default attributes /* (1) Construct default attributes
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
constructor(){
/* (1) Initialize content data */ constructor(){}
this.messages = [];
this.users = [];
} /* (2) Channel bindings
*
---------------------------------------------------------*/
/* (2) Getters 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; } 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>
<div class='body'> <div class='body'>
<div class='message' v-for='msg in gs.content.messages'>
{{ msg.msg }}
</div>
</div> </div>
</div> </div>