mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 01:48:50 +00:00
Users infos request can be forced
This commit is contained in:
parent
822fa8663b
commit
09e34a8969
@ -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
|
||||
|
@ -112,7 +112,7 @@ ComunicWeb.components.menuBar.authenticated = {
|
||||
//Change avatar url
|
||||
userimage.src = userInfos.accountImage;
|
||||
|
||||
}));
|
||||
}), true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
@ -95,9 +95,11 @@ 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);
|
||||
@ -134,14 +136,9 @@ ComunicWeb.components.searchForm = {
|
||||
//User name
|
||||
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;
|
||||
},
|
||||
}
|
@ -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 + ",";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user