From 09e34a89693583d32e1c88ebd16a7479f0128d12 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 27 May 2017 15:35:10 +0200 Subject: [PATCH] Users infos request can be forced --- assets/js/common/functionsSchema.js | 4 +-- assets/js/components/menuBar/authenticated.js | 2 +- assets/js/components/searchForm/searchForm.js | 25 ++++++++----------- assets/js/user/userInfos.js | 12 +++++---- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 245c0816..808bc6b6 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -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 diff --git a/assets/js/components/menuBar/authenticated.js b/assets/js/components/menuBar/authenticated.js index 3f8fdf67..da0f56b6 100644 --- a/assets/js/components/menuBar/authenticated.js +++ b/assets/js/components/menuBar/authenticated.js @@ -112,7 +112,7 @@ ComunicWeb.components.menuBar.authenticated = { //Change avatar url userimage.src = userInfos.accountImage; - })); + }), true); }, /** diff --git a/assets/js/components/searchForm/searchForm.js b/assets/js/components/searchForm/searchForm.js index 41e13928..b7baa41d 100644 --- a/assets/js/components/searchForm/searchForm.js +++ b/assets/js/components/searchForm/searchForm.js @@ -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; }, } \ No newline at end of file diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index dc54a7a3..7bf5246a 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -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 + ","; } }