53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
class User {
|
|
constructor(info){
|
|
if(!info || !info.userid) throw "Can not construct empty profile";
|
|
this.userid = info.userid;
|
|
this.profile = {
|
|
firstName: info.profile && info.profile.firstName || '',
|
|
lastName: info.profile && info.profile.lastName || '',
|
|
photo: info.profile && info.profile.photo || '',
|
|
location: info.profile && info.profile.location || 'USA',
|
|
language: info.profile && info.profile.language || 'en',
|
|
status: info.profile && info.profile.status || '',
|
|
description: info.profile && info.profile.description || '',
|
|
};
|
|
this.data = info.data || {};
|
|
this.username = info.username || '';
|
|
this.following = info.following || [];
|
|
this.lastUpdate = info.lastUpdate || new Date();
|
|
this.newsFeedCache = info.newsFeedCache || [];
|
|
this.notifications = info.notifications || [];
|
|
|
|
//groupRelated
|
|
this.isGroup = info.isGroup || false;
|
|
this.isCourse = info.isCourse || false;
|
|
this.isPrivate = info.isPrivate || false;
|
|
this.isChat = info.isChat || false;
|
|
this.subscribed = info.subscribed || {}; //Subscribed user to groups
|
|
this.pending = info.pending || {}; //Private groups require authorization
|
|
}
|
|
|
|
toObj(){
|
|
let r = {};
|
|
r.userid = this.userid
|
|
r.username = this.username;
|
|
r.profile = this.profile;
|
|
r.data = this.data;
|
|
r.username = this.username;
|
|
r.following = this.following;
|
|
r.lastUpdate = this.lastUpdate;
|
|
r.newsFeedCache = this.newsFeedCache;
|
|
r.notifications = this.notifications;
|
|
|
|
r.isGroup = this.isGroup;
|
|
r.isCourse = this.isCourse;
|
|
r.isPrivate = this.isPrivate;
|
|
r.isChat = this.isChat;
|
|
r.subscribed = this.subscribed;
|
|
r.pending = this.pending;
|
|
return r;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = User; |