mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 13:59:23 +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
|
||||||
@ -129,3 +129,18 @@ ComunicWeb.components.conversations.utils = {
|
|||||||
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
|
// Get the list of memberships
|
||||||
if(memberships.error)
|
const memberships = await api("webApp/getMemberships", {}, true);
|
||||||
return err(memberships.error);
|
|
||||||
|
|
||||||
// Get users & groups ID in case of success
|
// Get users & groups ID in case of success
|
||||||
let usersID = [];
|
const usersID = [];
|
||||||
let groupsID = [];
|
const groupsID = [];
|
||||||
|
|
||||||
memberships.forEach(el => {
|
memberships.forEach(el => {
|
||||||
if(el.type == "friend")
|
if(el.type == "friend")
|
||||||
usersID.push(el.friend.ID_friend);
|
usersID.push(el.friend.ID_friend);
|
||||||
else
|
else if(el.type == "group")
|
||||||
groupsID.push(el.id);
|
groupsID.push(el.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
getMultipleUsersInfo(usersID, users => {
|
const usersInfo = await getUsers(usersID);
|
||||||
if(users.error)
|
const groupsInfo = await getGroups(groupsID);
|
||||||
return err(memberships.error);
|
|
||||||
|
|
||||||
getInfoMultipleGroups(groupsID, groupsInfo => {
|
// Get conversations name
|
||||||
if(groupsInfo.error)
|
const convNames = new Map()
|
||||||
return err(groupsInfo.error);
|
for(const el of memberships.filter(el => el.type == "conversation"))
|
||||||
|
convNames.set(el.conv.ID, await getConvName(el.conv))
|
||||||
|
|
||||||
success(memberships, users, groupsInfo);
|
success(memberships, usersInfo, groupsInfo, convNames);
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
console.error("Get memberships error", e)
|
||||||
|
err();
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user