Users infos request can be forced

This commit is contained in:
Pierre 2017-05-27 15:35:10 +02:00
parent 822fa8663b
commit 09e34a8969
4 changed files with 21 additions and 22 deletions

View File

@ -333,12 +333,12 @@ var ComunicWeb = {
/** /**
* Get user informations * Get user informations
*/ */
getUserInfos: function(userID, afterGetUserInfos){}, getUserInfos: function(userID, afterGetUserInfos, forceRequest){},
/** /**
* Get multiple users informations * Get multiple users informations
*/ */
getMultipleUsersInfos: function(usersID, afterGetUserInfos){}, getMultipleUsersInfos: function(usersID, afterGetUserInfos, forceRequest){},
/** /**
* Empty user informations cache * Empty user informations cache

View File

@ -112,7 +112,7 @@ ComunicWeb.components.menuBar.authenticated = {
//Change avatar url //Change avatar url
userimage.src = userInfos.accountImage; userimage.src = userInfos.accountImage;
})); }), true);
}, },
/** /**

View File

@ -81,7 +81,7 @@ ComunicWeb.components.searchForm = {
return false; return false;
//Preload users informations //Preload users informations
ComunicWeb.user.userInfos.getMultipleUsersInfos(response, function(userInfos){ ComunicWeb.user.userInfos.getMultipleUsersInfos(response, function(usersInfos){
//Remove any remainging element in searchResultBox //Remove any remainging element in searchResultBox
emptyElem(searchBoxContainer); emptyElem(searchBoxContainer);
@ -96,8 +96,10 @@ ComunicWeb.components.searchForm = {
//Retrieve userID //Retrieve userID
var userID = response[i]; var userID = response[i];
//Display user informations //We show user only if we have informations about him
ComunicWeb.components.searchForm.displayUser(userID, menuList); if(usersInfos[userID])
//Display user informations
ComunicWeb.components.searchForm.displayUser(usersInfos[userID], menuList);
} }
@ -113,11 +115,11 @@ ComunicWeb.components.searchForm = {
/** /**
* Display a user on the result list * Display a user on the result list
* *
* @param {Integer} userID The ID of the user to display * @param {Integer} userInfos Informations about the user
* @param {HTMLElement} menuList The target list menu * @param {HTMLElement} menuList The target list menu
* @return {Boolean} True for a success * @return {Boolean} True for a success
*/ */
displayUser: function(userID, menuList){ displayUser: function(userInfos, menuList){
//Create user element //Create user element
var userListElement = createElem("li", menuList); var userListElement = createElem("li", menuList);
var userLinkElement = createElem("a", userListElement); var userLinkElement = createElem("a", userListElement);
@ -135,13 +137,8 @@ ComunicWeb.components.searchForm = {
var usernameElem = createElem("h4", userLinkElement); var usernameElem = createElem("h4", userLinkElement);
usernameElem.innerHTML = "Loading..."; usernameElem.innerHTML = "Loading...";
//Get informations about user //Apply user informations
ComunicWeb.user.userInfos.getUserInfos(userID, function(userInfos){ userImage.src = userInfos.accountImage;
usernameElem.innerHTML = userInfos.firstName + " " + userInfos.lastName;
//Apply informations
userImage.src = userInfos.accountImage;
usernameElem.innerHTML = userInfos.firstName + " " + userInfos.lastName;
});
}, },
} }

View File

@ -16,9 +16,10 @@ 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
* @param {Boolean} forceRequest Force the request to be made
* @return {Boolean} True for a success * @return {Boolean} True for a success
*/ */
getUserInfos: function(userID, afterGetUserInfos){ getUserInfos: function(userID, afterGetUserInfos, forceRequest){
//Check if current user infos were required //Check if current user infos were required
if(userID == "current") if(userID == "current")
@ -35,7 +36,7 @@ ComunicWeb.user.userInfos = {
//Return a simple array //Return a simple array
else else
afterGetUserInfos(result[userID]); afterGetUserInfos(result[userID]);
}); }, forceRequest);
}, },
@ -44,9 +45,10 @@ ComunicWeb.user.userInfos = {
* *
* @param {String} usersID User on which to make request (current to get connected user) * @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 * @param {function} afterGetUserInfos What to do once users informations are available
* @param {Boolean} forceRequest Force the request to be made
* @return {Boolean} True for a success * @return {Boolean} True for a success
*/ */
getMultipleUsersInfos: function(usersID, afterGetUserInfos){ getMultipleUsersInfos: function(usersID, afterGetUserInfos, forceRequest){
//First, check if informations are already available in the cache for some users //First, check if informations are already available in the cache for some users
var cachedInformations = {}; var cachedInformations = {};
@ -57,14 +59,14 @@ ComunicWeb.user.userInfos = {
var processUserID = usersID[i]; var processUserID = usersID[i];
//Check the local cache //Check the local cache
if(this.usersInfos["user-"+processUserID]){ if(this.usersInfos["user-"+processUserID] && !forceRequest){
//Add user information to cached informations //Add user information to cached informations
cachedInformations[processUserID] = this.usersInfos["user-"+processUserID]; cachedInformations[processUserID] = this.usersInfos["user-"+processUserID];
} }
else { else {
//Else we'll have to get data //Else we'll have to get data
needRequest = true; needRequest = true;
usersToGetList += usersID+","; usersToGetList += processUserID + ",";
} }
} }