[lib.content-controller] managed user updates (DEL, ADD, UPD)

This commit is contained in:
xdrm-brackets 2018-04-04 11:59:59 +02:00
parent 1c4db78b36
commit 17a3438e5b
2 changed files with 54 additions and 12 deletions

View File

@ -224,9 +224,6 @@ export default class ChannelController{
if( rs.error !== 0 )
return false;
/* (3) Reload channel list */
// this.fetch();
}.bind(this), auth.token);
return true;
@ -247,9 +244,6 @@ export default class ChannelController{
/* (1) Hide popup */
gs.get.popup.hide();
/* (2) Reload channel list */
// this.fetch();
}.bind(this), auth.token);
return true;

View File

@ -84,11 +84,6 @@ export default class ContentController{
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 */
@ -338,7 +333,6 @@ export default class ContentController{
/* (4) Manage channels CREATE
---------------------------------------------------------*/
for( let c of _dat.channels.add ){
console.log(c);
gs.get.channel.dump([{
id: parseInt(c.id),
@ -370,6 +364,60 @@ export default class ContentController{
}
let userset = gs.get.content.cbuf.users;
/* (6) Manage users DELETE
---------------------------------------------------------*/
for( let u of _dat.users.rem ){
for( let ui in userset ){
// 1. Local copy user data
let user = userset[ui];
// 2. If id matches -> REMOVE
if( user.uid === u.id )
userset.splice(ui, 1);
}
}
/* (7) Manage users CREATE
---------------------------------------------------------*/
for( let u of _dat.users.add ){
userset.push({
uid: parseInt(u.id),
username: u.name
});
}
/* (8) Manage users UPDATE
---------------------------------------------------------*/
for( let u of _dat.users.upd ){
for( let ui in userset ){
// 1. Local copy user data
let user = userset[ui];
// 2. If id matches -> UPDATE
if( user.uid === u.id )
userset[ui].username = u.name;
}
}
}