mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Start to upgrade memberships sidebar
This commit is contained in:
parent
c5965b5a79
commit
b07ae2ee39
@ -4,7 +4,7 @@
|
|||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ComunicWeb.components.conversations.utils = {
|
const ConversationsUtils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given conversation informations, returns its name
|
* Given conversation informations, returns its name
|
||||||
@ -128,4 +128,19 @@ ComunicWeb.components.conversations.utils = {
|
|||||||
//Return result
|
//Return result
|
||||||
return form;
|
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){
|
refreshMemberships: function(target){
|
||||||
ComunicWeb.components.webApp.interface.getMemberships(
|
ComunicWeb.components.webApp.interface.getMemberships(
|
||||||
() => notify("Could not refresh your memberships!", "error"),
|
() => 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 {*} memberships
|
||||||
* @param {*} users
|
* @param {*} users
|
||||||
* @param {*} groups
|
* @param {*} groups
|
||||||
|
* @param {*} convs
|
||||||
*/
|
*/
|
||||||
applyMemberships: function(target, memberships, users, groups) {
|
applyMemberships: function(target, memberships, users, groups, convs) {
|
||||||
|
|
||||||
// Empty liste
|
// Empty liste
|
||||||
target.innerHTML = "";
|
target.innerHTML = "";
|
||||||
@ -337,10 +338,10 @@ ComunicWeb.components.sideBar.main = {
|
|||||||
memberships.forEach(e => {
|
memberships.forEach(e => {
|
||||||
|
|
||||||
if(e.type == "friend")
|
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")
|
if(e.type == "group")
|
||||||
this.applyGroup(friendsTarget, groups[e.id], e.last_activity);
|
this.applyGroup(friendsTarget, groups.get(e.id), e.last_activity);
|
||||||
});
|
});
|
||||||
|
|
||||||
createElem2({
|
createElem2({
|
||||||
@ -381,7 +382,7 @@ ComunicWeb.components.sideBar.main = {
|
|||||||
appendTo: a,
|
appendTo: a,
|
||||||
type: "img",
|
type: "img",
|
||||||
class: "img-circle",
|
class: "img-circle",
|
||||||
src: user.accountImage
|
src: user.image
|
||||||
});
|
});
|
||||||
|
|
||||||
// User name
|
// User name
|
||||||
|
@ -10,46 +10,41 @@ ComunicWeb.components.webApp.interface = {
|
|||||||
* Get all the membership of the user
|
* Get all the membership of the user
|
||||||
*
|
*
|
||||||
* @param {Function} err Function called in case of errors
|
* @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
|
try {
|
||||||
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 = [];
|
|
||||||
|
|
||||||
memberships.forEach(el => {
|
// Get the list of memberships
|
||||||
if(el.type == "friend")
|
const memberships = await api("webApp/getMemberships", {}, true);
|
||||||
usersID.push(el.friend.ID_friend);
|
|
||||||
else
|
|
||||||
groupsID.push(el.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMultipleUsersInfo(usersID, users => {
|
// Get users & groups ID in case of success
|
||||||
if(users.error)
|
const usersID = [];
|
||||||
return err(memberships.error);
|
const groupsID = [];
|
||||||
|
|
||||||
getInfoMultipleGroups(groupsID, groupsInfo => {
|
memberships.forEach(el => {
|
||||||
if(groupsInfo.error)
|
if(el.type == "friend")
|
||||||
return err(groupsInfo.error);
|
usersID.push(el.friend.ID_friend);
|
||||||
|
else if(el.type == "group")
|
||||||
success(memberships, users, groupsInfo);
|
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