Create a new way to retrieve multiple groups information

This commit is contained in:
Pierre HUBERT 2019-05-19 16:43:54 +02:00
parent d1c339c414
commit dacab00ae4
3 changed files with 70 additions and 2 deletions

View File

@ -138,7 +138,7 @@ function getMultipleUsersInfo(usersID, afterGetUserInfos, forceRequest){
*
* @param {Array~Object} users The list of users to get
* @param {Boolean} force
* @returns {Promise}
* @returns {Promise<UsersList>}
*/
function getUsers(users, force) {
return new Promise((resolve, error) => {
@ -224,6 +224,22 @@ function getInfoMultipleGroups(IDs, callback, force){
ComunicWeb.components.groups.info.getInfoMultiple(IDs, callback, force);
}
/**
* Get information about multiple groups
*
* @param {Number[]} list The ID of the groups to get
* @param {Boolean} force Specify whether to force or not the request
* @return {Promise<GroupsList>}
*/
function getGroups(list, force){
return new Promise((resolve, reject) => {
getInfoMultipleGroups(list, result => {
if(result.error) reject(result.error);
else resolve(new GroupsList(result));
}, force);
});
}
/**
* Get the difference of time from now to a specified
* timestamp and return it as a string

View File

@ -0,0 +1,51 @@
/**
* Groups list
*
* @author Pierre HUBERT
*/
class Group {
constructor(info){
this.id = info.id;
this.following = info.following;
this.icon_url = info.icon_url;
this.membership = info.membership;
this.name = info.name;
this.number_members = info.number_members;
this.posts_level = info.posts_level;
this.registration_level = info.registration_level;
this.virtual_directory = info.virtual_directory;
this.visibility = info.visibility;
}
}
class GroupsList {
constructor(list){
/**
* @type {Group[]}
*/
this.list = [];
// Initialize the list of groups
for (const key in list) {
if (list.hasOwnProperty(key))
this.list.push(new Group(list[key]));
}
}
/**
* Get a group specified by its ID
*
* @param {Number} id The ID of the target group
* @return {Group} information about the target group
*/
get(id){
for (let index = 0; index < this.list.length; index++) {
const group = this.list[index];
if(group.id == id)
return group;
}
}
}

View File

@ -440,6 +440,7 @@ class Dev {
"js/components/groups/interface.js",
"js/components/groups/utils.js",
"js/components/groups/info.js",
"js/components/groups/GroupsList.js",
//Virtual directory component
"js/components/virtualDirectory/interface.js",