Search results are correctly shown

This commit is contained in:
Pierre 2017-05-27 12:12:39 +02:00
parent 32cf8601f7
commit 736f740d05

View File

@ -16,36 +16,44 @@ ComunicWeb.user.userInfos = {
* *
* @param {String} userID User on which to make request (current to get connected user) * @param {String} userID User on which to make request (current to get connected user)
* @param {function} afterGetUserInfos What to do once user informations are available * @param {function} afterGetUserInfos What to do once user informations are available
* @return {Boolean} False if it fails * @return {Boolean} True for a success
*/ */
getUserInfos: function(userID, afterGetUserInfos){ getUserInfos: function(userID, afterGetUserInfos){
//If requested user is the current user, replace "current" with userID
if(userID === "current")
userID = ComunicWeb.user.userLogin.__userID;
//First, check if informations are already available in the cache //First, check if informations are already available in the cache
if(this.usersInfos[userID]) if(this.usersInfos[userID]){
afterGetUserInfos(this.usersInfos[userID]); //Then return these informations now afterGetUserInfos(this.usersInfos[userID]); //Then return these informations now
return true;
}
//Else we have to perform an API request //Else we have to perform an API request
if(userID == "current" || userID == ComunicWeb.user.userLogin.__userID){ var apiURI = "user/getInfos";
var apiURI = "user/getCurrentUserInfos"; var params = {
var params = {}; userID: userID
} };
else{
ComunicWeb.debug.logMessage("ERROR : getUserInfos not implemented for other user than the current one !");
return false;
}
//Specify what to do next //Specify what to do next
var onceGetUserInfos = function(result){ var onceGetUserInfos = function(result){
if(result.error){ if(result.error){
ComunicWeb.debug.logMessage("ERROR : couldn't get infos about user ID : "+userID+" !"); ComunicWeb.debug.logMessage("ERROR : couldn't get infos about user ID : "+userID+" !");
//Returns the error to the next function
afterGetUserInfos(result);
return false; return false;
} }
else {
//Save result //Save result
ComunicWeb.user.userInfos.usersInfos[""+userID] = result[0]; ComunicWeb.user.userInfos.usersInfos[""+userID] = result[0];
//Return result //Return result
afterGetUserInfos(result[0]); afterGetUserInfos(result[0]);
} }
}
//Perform request //Perform request
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, onceGetUserInfos); ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, onceGetUserInfos);