mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 18:08:50 +00:00
Start to upgrade memberships sidebar
This commit is contained in:
parent
c5965b5a79
commit
b07ae2ee39
@ -4,7 +4,7 @@
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.components.conversations.utils = {
|
||||
const ConversationsUtils = {
|
||||
|
||||
/**
|
||||
* Given conversation informations, returns its name
|
||||
@ -128,4 +128,19 @@ ComunicWeb.components.conversations.utils = {
|
||||
//Return result
|
||||
return form;
|
||||
},
|
||||
}
|
||||
|
||||
ComunicWeb.components.conversations.utils = ConversationsUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Get information about a conversation
|
||||
*
|
||||
* @param {Conversation} conv Information about the
|
||||
* target conversation
|
||||
*/
|
||||
async function getConvName(conv) {
|
||||
return new Promise((res, rej) => {
|
||||
ConversationsUtils.getName(conv, (name) => res(name));
|
||||
})
|
||||
}
|
@ -311,7 +311,7 @@ ComunicWeb.components.sideBar.main = {
|
||||
refreshMemberships: function(target){
|
||||
ComunicWeb.components.webApp.interface.getMemberships(
|
||||
() => notify("Could not refresh your memberships!", "error"),
|
||||
(m, u, g) => this.applyMemberships(target, m, u, g)
|
||||
(m, u, g, c) => this.applyMemberships(target, m, u, g, c)
|
||||
);
|
||||
},
|
||||
|
||||
@ -322,8 +322,9 @@ ComunicWeb.components.sideBar.main = {
|
||||
* @param {*} memberships
|
||||
* @param {*} users
|
||||
* @param {*} groups
|
||||
* @param {*} convs
|
||||
*/
|
||||
applyMemberships: function(target, memberships, users, groups) {
|
||||
applyMemberships: function(target, memberships, users, groups, convs) {
|
||||
|
||||
// Empty liste
|
||||
target.innerHTML = "";
|
||||
@ -337,10 +338,10 @@ ComunicWeb.components.sideBar.main = {
|
||||
memberships.forEach(e => {
|
||||
|
||||
if(e.type == "friend")
|
||||
this.applyFriend(friendsTarget, e.friend, users["user-"+e.friend.ID_friend]);
|
||||
this.applyFriend(friendsTarget, e.friend, users.get(e.friend.ID_friend));
|
||||
|
||||
if(e.type == "group")
|
||||
this.applyGroup(friendsTarget, groups[e.id], e.last_activity);
|
||||
this.applyGroup(friendsTarget, groups.get(e.id), e.last_activity);
|
||||
});
|
||||
|
||||
createElem2({
|
||||
@ -381,7 +382,7 @@ ComunicWeb.components.sideBar.main = {
|
||||
appendTo: a,
|
||||
type: "img",
|
||||
class: "img-circle",
|
||||
src: user.accountImage
|
||||
src: user.image
|
||||
});
|
||||
|
||||
// User name
|
||||
|
@ -10,46 +10,41 @@ ComunicWeb.components.webApp.interface = {
|
||||
* Get all the membership of the user
|
||||
*
|
||||
* @param {Function} err Function called in case of errors
|
||||
* @param {Function(memberships, usersInfo, groupsInfo) : void} success Function called in case of success
|
||||
* @param {Function(memberships, usersInfo, groupsInfo, convNames) : void} success Function called in case of success
|
||||
*/
|
||||
getMemberships: function(err, success) {
|
||||
getMemberships: async function(err, success) {
|
||||
|
||||
// Peform the request on the server
|
||||
ComunicWeb.common.api.makeAPIrequest(
|
||||
"webApp/getMemberships",
|
||||
{},
|
||||
true,
|
||||
memberships => {
|
||||
|
||||
// Check for error
|
||||
if(memberships.error)
|
||||
return err(memberships.error);
|
||||
|
||||
// Get users & groups ID in case of success
|
||||
let usersID = [];
|
||||
let groupsID = [];
|
||||
try {
|
||||
|
||||
memberships.forEach(el => {
|
||||
if(el.type == "friend")
|
||||
usersID.push(el.friend.ID_friend);
|
||||
else
|
||||
groupsID.push(el.id);
|
||||
});
|
||||
// Get the list of memberships
|
||||
const memberships = await api("webApp/getMemberships", {}, true);
|
||||
|
||||
getMultipleUsersInfo(usersID, users => {
|
||||
if(users.error)
|
||||
return err(memberships.error);
|
||||
|
||||
getInfoMultipleGroups(groupsID, groupsInfo => {
|
||||
if(groupsInfo.error)
|
||||
return err(groupsInfo.error);
|
||||
|
||||
success(memberships, users, groupsInfo);
|
||||
});
|
||||
});
|
||||
// Get users & groups ID in case of success
|
||||
const usersID = [];
|
||||
const groupsID = [];
|
||||
|
||||
memberships.forEach(el => {
|
||||
if(el.type == "friend")
|
||||
usersID.push(el.friend.ID_friend);
|
||||
else if(el.type == "group")
|
||||
groupsID.push(el.id);
|
||||
});
|
||||
|
||||
const usersInfo = await getUsers(usersID);
|
||||
const groupsInfo = await getGroups(groupsID);
|
||||
|
||||
// Get conversations name
|
||||
const convNames = new Map()
|
||||
for(const el of memberships.filter(el => el.type == "conversation"))
|
||||
convNames.set(el.conv.ID, await getConvName(el.conv))
|
||||
|
||||
success(memberships, usersInfo, groupsInfo, convNames);
|
||||
|
||||
} catch(e) {
|
||||
console.error("Get memberships error", e)
|
||||
err();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user