Unified get user infos methods

This commit is contained in:
Pierre 2017-05-27 15:25:26 +02:00
parent a8e05437ca
commit 822fa8663b

View File

@ -20,46 +20,22 @@ ComunicWeb.user.userInfos = {
*/ */
getUserInfos: function(userID, afterGetUserInfos){ getUserInfos: function(userID, afterGetUserInfos){
//If requested user is the current user, replace "current" with userID //Check if current user infos were required
if(userID === "current") if(userID == "current")
userID = ComunicWeb.user.userLogin.__userID; userID = ComunicWeb.user.userLogin.getUserID();
//First, check if informations are already available in the cache //getMultipleUsersInfos mirror
if(this.usersInfos["user-"+userID]){ var usersID = [userID];
afterGetUserInfos(this.usersInfos["user-"+userID]); //Then return these informations now
return true;
}
//Else we have to perform an API request return this.getMultipleUsersInfos(usersID, function(result){
var apiURI = "user/getInfos"; //We check if an error occured
var params = { if(result.error)
userID: userID
};
//Specify what to do next
var onceGetUserInfos = function(result){
if(result.error){
ComunicWeb.debug.logMessage("ERROR : couldn't get infos about user ID : "+userID+" !");
//Returns the error to the next function
afterGetUserInfos(result); afterGetUserInfos(result);
return false; //Return a simple array
} else
else { afterGetUserInfos(result[userID]);
//Save result });
ComunicWeb.user.userInfos.usersInfos["user-"+userID] = result[0];
//Return result
afterGetUserInfos(result[0]);
}
}
//Perform request
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, onceGetUserInfos);
//Everything is OK
return true;
}, },