mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-29 23:36:27 +00:00
Get multiple users infos
This commit is contained in:
parent
96d86ce97a
commit
a8e05437ca
@ -335,6 +335,11 @@ var ComunicWeb = {
|
|||||||
*/
|
*/
|
||||||
getUserInfos: function(userID, afterGetUserInfos){},
|
getUserInfos: function(userID, afterGetUserInfos){},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get multiple users informations
|
||||||
|
*/
|
||||||
|
getMultipleUsersInfos: function(usersID, afterGetUserInfos){},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty user informations cache
|
* Empty user informations cache
|
||||||
* Remove all entries from user informations cache
|
* Remove all entries from user informations cache
|
||||||
|
@ -80,6 +80,9 @@ ComunicWeb.components.searchForm = {
|
|||||||
if(response.error)
|
if(response.error)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Preload users informations
|
||||||
|
ComunicWeb.user.userInfos.getMultipleUsersInfos(response, function(userInfos){
|
||||||
|
|
||||||
//Remove any remainging element in searchResultBox
|
//Remove any remainging element in searchResultBox
|
||||||
emptyElem(searchBoxContainer);
|
emptyElem(searchBoxContainer);
|
||||||
|
|
||||||
@ -103,7 +106,7 @@ ComunicWeb.components.searchForm = {
|
|||||||
height: '200px',
|
height: '200px',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -63,6 +63,89 @@ ComunicWeb.user.userInfos = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get multiple users informations
|
||||||
|
*
|
||||||
|
* @param {String} usersID User on which to make request (current to get connected user)
|
||||||
|
* @param {function} afterGetUserInfos What to do once users informations are available
|
||||||
|
* @return {Boolean} True for a success
|
||||||
|
*/
|
||||||
|
getMultipleUsersInfos: function(usersID, afterGetUserInfos){
|
||||||
|
|
||||||
|
//First, check if informations are already available in the cache for some users
|
||||||
|
var cachedInformations = {};
|
||||||
|
var needRequest = false; //By default the request isn't required
|
||||||
|
var usersToGetList = "";
|
||||||
|
for(i in usersID){
|
||||||
|
//Extract userID
|
||||||
|
var processUserID = usersID[i];
|
||||||
|
|
||||||
|
//Check the local cache
|
||||||
|
if(this.usersInfos["user-"+processUserID]){
|
||||||
|
//Add user information to cached informations
|
||||||
|
cachedInformations[processUserID] = this.usersInfos["user-"+processUserID];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Else we'll have to get data
|
||||||
|
needRequest = true;
|
||||||
|
usersToGetList += usersID+",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if an API request is not required
|
||||||
|
if(!needRequest){
|
||||||
|
//Go immediatly to the next step
|
||||||
|
afterGetUserInfos(cachedInformations);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Perform API request
|
||||||
|
var apiURI = "user/getInfosMultiple";
|
||||||
|
var params = {
|
||||||
|
usersID: usersToGetList,
|
||||||
|
}
|
||||||
|
|
||||||
|
//Specify what to do next
|
||||||
|
var onceGetUserInfos = function(result){
|
||||||
|
if(result.error){
|
||||||
|
//Log error
|
||||||
|
ComunicWeb.debug.logMessage("ERROR : couldn't get infos about users ID !");
|
||||||
|
|
||||||
|
//Returns the error to the next function
|
||||||
|
afterGetUserInfos(result);
|
||||||
|
|
||||||
|
//Something went wrong
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Prepare return
|
||||||
|
var returnInformations = cachedInformations;
|
||||||
|
|
||||||
|
//Save results and prepare return
|
||||||
|
for(i in result){
|
||||||
|
//Get user ID
|
||||||
|
var userID = result[i]['userID'];
|
||||||
|
|
||||||
|
//Store
|
||||||
|
ComunicWeb.user.userInfos.usersInfos["user-"+userID] = result[i];
|
||||||
|
|
||||||
|
returnInformations[userID] = result[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Return results
|
||||||
|
afterGetUserInfos(returnInformations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Perform request
|
||||||
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, onceGetUserInfos);
|
||||||
|
|
||||||
|
//Everything is OK
|
||||||
|
return true;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty user informations cache
|
* Empty user informations cache
|
||||||
* Remove all entries from user informations cache
|
* Remove all entries from user informations cache
|
||||||
|
Loading…
Reference in New Issue
Block a user