2019-05-16 13:48:50 +00:00
|
|
|
/**
|
|
|
|
* Web application interface
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
2021-03-05 14:26:45 +00:00
|
|
|
const WebAppInterface = {
|
2019-05-16 13:48:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the membership of the user
|
|
|
|
*
|
|
|
|
* @param {Function} err Function called in case of errors
|
2021-03-05 14:26:45 +00:00
|
|
|
* @param {(UserMembership[], UsersList, groupsInfo, convNames) => void} success Function called in case of success
|
2019-05-16 13:48:50 +00:00
|
|
|
*/
|
2020-04-09 06:45:03 +00:00
|
|
|
getMemberships: async function(err, success) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// Get the list of memberships
|
|
|
|
const memberships = await api("webApp/getMemberships", {}, true);
|
|
|
|
|
|
|
|
// 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);
|
2021-03-05 14:26:45 +00:00
|
|
|
|
2020-04-09 06:45:03 +00:00
|
|
|
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"))
|
2021-03-05 14:26:45 +00:00
|
|
|
convNames.set(el.conv.id, await getConvName(el.conv))
|
2020-04-09 06:45:03 +00:00
|
|
|
|
|
|
|
success(memberships, usersInfo, groupsInfo, convNames);
|
|
|
|
|
|
|
|
} catch(e) {
|
|
|
|
console.error("Get memberships error", e)
|
|
|
|
err();
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:48:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|