2018-03-24 15:49:00 +00:00
|
|
|
export default class ContentController{
|
2018-03-22 13:57:03 +00:00
|
|
|
|
|
|
|
/* (1) Construct default attributes
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
2018-03-22 14:28:34 +00:00
|
|
|
constructor(){}
|
2018-03-22 13:57:03 +00:00
|
|
|
|
2018-03-22 14:28:34 +00:00
|
|
|
/* (2) Channel bindings
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
get cid(){ return gs.get.channel.current; }
|
2018-03-22 13:57:03 +00:00
|
|
|
|
2018-03-28 13:54:19 +00:00
|
|
|
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 {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-22 13:57:03 +00:00
|
|
|
|
2018-03-22 14:28:34 +00:00
|
|
|
/* (3) Room ID binding
|
2018-03-22 13:57:03 +00:00
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
get rid(){ return gs.get.room.text.current; }
|
|
|
|
|
2018-03-22 14:28:34 +00:00
|
|
|
get rbuf(){
|
|
|
|
|
|
|
|
/* (1) Ignore: if no rooms empty */
|
2018-03-27 16:21:02 +00:00
|
|
|
if( gs.get.room.text.list == null || gs.get.room.text.list.length === 0 )
|
2018-03-22 14:28:34 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
/* (2) Search for current room */
|
2018-03-27 16:21:02 +00:00
|
|
|
for( let r of gs.get.room.text.list ){
|
2018-03-22 14:28:34 +00:00
|
|
|
|
|
|
|
// Return if room found //
|
2018-03-27 16:21:02 +00:00
|
|
|
if( r.id === this.rid )
|
2018-03-22 14:28:34 +00:00
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) If nothing found */
|
|
|
|
return {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
get messages(){ return this.rbuf.messages; }
|
|
|
|
get members(){ return this.rbuf.members; }
|
|
|
|
|
2018-03-22 15:03:09 +00:00
|
|
|
|
|
|
|
/* (5) User getter
|
|
|
|
*
|
|
|
|
* @user_id<int> User id
|
|
|
|
*
|
|
|
|
* @return user<array> User data
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
user(user_id=null){
|
|
|
|
|
|
|
|
/* (1) Error: if invalid user_id */
|
|
|
|
if( isNaN(user_id) )
|
|
|
|
return {};
|
|
|
|
|
|
|
|
/* (2) Error: unknown user */
|
|
|
|
if( this.cbuf.users == null || this.cbuf.users.length < 1 )
|
|
|
|
return {};
|
|
|
|
|
|
|
|
/* (3) return user data */
|
|
|
|
for( let u of this.cbuf.users )
|
|
|
|
if( u.uid === user_id )
|
|
|
|
return u;
|
|
|
|
|
|
|
|
/* (4) Error */
|
|
|
|
return {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-23 07:41:17 +00:00
|
|
|
/* (6) Textarea auto_grow
|
|
|
|
*
|
|
|
|
* @e<Event> Textarea event
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
auto_grow(e){
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
e.target.style.height = '0';
|
|
|
|
e.target.style.height = `calc( ${e.target.scrollHeight}px )`;
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-22 13:57:03 +00:00
|
|
|
}
|