From 84264de4423b23321c3fe5b2258738467c00c6c2 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 24 Feb 2018 14:24:33 +0100 Subject: [PATCH] Display the account image of the users who created new messages. --- .../js/components/conversations/interface.js | 15 +++ .../conversations/unreadDropdown.js | 99 ++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 961ad47c..dba6cda8 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -288,6 +288,21 @@ ComunicWeb.components.conversations.interface = { return true; }, + /** + * Get the list of unread conversations + * + * @param {function} callback + */ + getUnreadConversations: function(callback){ + + //Perform a request on the API + var apiURI = "conversations/get_list_unread"; + var params = {}; + + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + + }, + /** * Empty conversations cache * diff --git a/assets/js/components/conversations/unreadDropdown.js b/assets/js/components/conversations/unreadDropdown.js index 0135b760..29f156cf 100644 --- a/assets/js/components/conversations/unreadDropdown.js +++ b/assets/js/components/conversations/unreadDropdown.js @@ -87,11 +87,108 @@ ComunicWeb.components.conversations.unreadDropdown = { //Refresh the unread conversations list if the user click the dropdown button dropdownToggle.onclick = function(){ - ComunicWeb.components.conversations.dropdown.refresh_list_conversations(conversationsList); + ComunicWeb.components.conversations.unreadDropdown.refresh_list_conversations(conversationsList); } //Return the number of conversations target return conversationsNumber; }, + /** + * Refresh the list of conversations + * + * @param {HTMLElement} target The target to display the conversations + */ + refresh_list_conversations: function(target){ + + //Perform a request through the interface + ComunicWeb.components.conversations.interface.getUnreadConversations(function(conversations){ + + //Check for errors + if(conversations.error){ + //Display an error + ComunicWeb.common.notificationSystem.showNotification("Could not retrieve the list of unread conversations !", "danger"); + return; + } + + //Get the list of users ID + var usersID = []; + + //Process the list of conversations + for (let index = 0; index < conversations.length; index++) { + const entry = conversations[index]; + + var userID = entry.userID; + if(!usersID.includes(userID)) + usersID.push(userID); + } + + //Get informations about the users + ComunicWeb.user.userInfos.getMultipleUsersInfos(usersID, function(usersInfos){ + + //Check for errors + if(usersInfos.error){ + //Display an error + ComunicWeb.common.notificationSystem.showNotification("Could not get informations about some users !", "danger"); + return; + } + + //Display the list of conversations + ComunicWeb.components.conversations.unreadDropdown._display_list(target, conversations, usersInfos); + }); + }); + + }, + + /** + * Display the list of conversations + * + * @param {HTMLElement} target The target for the fields + * @param {array} conversations The list of conversations + * @param {object} usersInfos Informations about related users + */ + _display_list: function(target, conversations, usersInfos){ + + //Empty the target + target.innerHTML = ""; + + //Process each conversation + for (let index = 0; index < conversations.length; index++) { + + //Get the conversation + const conversation = conversations[index]; + + //Get informations about the user + const userInfos = usersInfos["user-" + conversation.userID]; + + //Create list element + var convLi = createElem2({ + appendTo: target, + type: "li" + }); + + //Create the conversation link element + var convLink = createElem2({ + appendTo: convLi, + type: "a", + href: "#" + }); + + //Add left elements + var leftElems = createElem2({ + appendTo: convLink, + type: "div", + class: "pull-left" + }); + + //Add user account image on the left + var userAccountImage = createElem2({ + appendTo: leftElems, + type: "img", + class: "img-circle", + src: userInfos.accountImage + }); + } + + }, } \ No newline at end of file