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
*/
getUserInfos: function(userID, afterGetUserInfos){},
getUserInfos: function(userID, afterGetUserInfos, forceRequest){},
/**
* Get multiple users informations
*/
getMultipleUsersInfos: function(usersID, afterGetUserInfos){},
getMultipleUsersInfos: function(usersID, afterGetUserInfos, forceRequest){},
/**
* Empty user informations cache

View File

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

View File

@ -81,7 +81,7 @@ ComunicWeb.components.searchForm = {
return false;
//Preload users informations
ComunicWeb.user.userInfos.getMultipleUsersInfos(response, function(userInfos){
ComunicWeb.user.userInfos.getMultipleUsersInfos(response, function(usersInfos){
//Remove any remainging element in searchResultBox
emptyElem(searchBoxContainer);
@ -96,8 +96,10 @@ ComunicWeb.components.searchForm = {
//Retrieve userID
var userID = response[i];
//Display user informations
ComunicWeb.components.searchForm.displayUser(userID, menuList);
//We show user only if we have informations about him
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
*
* @param {Integer} userID The ID of the user to display
* @param {Integer} userInfos Informations about the user
* @param {HTMLElement} menuList The target list menu
* @return {Boolean} True for a success
*/
displayUser: function(userID, menuList){
displayUser: function(userInfos, menuList){
//Create user element
var userListElement = createElem("li", menuList);
var userLinkElement = createElem("a", userListElement);
@ -135,13 +137,8 @@ ComunicWeb.components.searchForm = {
var usernameElem = createElem("h4", userLinkElement);
usernameElem.innerHTML = "Loading...";
//Get informations about user
ComunicWeb.user.userInfos.getUserInfos(userID, function(userInfos){
//Apply informations
userImage.src = userInfos.accountImage;
usernameElem.innerHTML = userInfos.firstName + " " + userInfos.lastName;
});
//Apply user 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 {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
*/
getUserInfos: function(userID, afterGetUserInfos){
getUserInfos: function(userID, afterGetUserInfos, forceRequest){
//Check if current user infos were required
if(userID == "current")
@ -35,7 +36,7 @@ ComunicWeb.user.userInfos = {
//Return a simple array
else
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 {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
*/
getMultipleUsersInfos: function(usersID, afterGetUserInfos){
getMultipleUsersInfos: function(usersID, afterGetUserInfos, forceRequest){
//First, check if informations are already available in the cache for some users
var cachedInformations = {};
@ -57,14 +59,14 @@ ComunicWeb.user.userInfos = {
var processUserID = usersID[i];
//Check the local cache
if(this.usersInfos["user-"+processUserID]){
if(this.usersInfos["user-"+processUserID] && !forceRequest){
//Add user information to cached informations
cachedInformations[processUserID] = this.usersInfos["user-"+processUserID];
}
else {
//Else we'll have to get data
needRequest = true;
usersToGetList += usersID+",";
usersToGetList += processUserID + ",";
}
}