1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-09-19 13:48:47 +00:00

Can get all the membership of a user

This commit is contained in:
2019-12-28 16:52:52 +01:00
parent fe11162953
commit 65d07f0f4a
6 changed files with 133 additions and 0 deletions

View File

@@ -454,6 +454,16 @@ export class GroupsHelper {
});
}
/**
* Get the last activity time of a group
*
* @param groupID Target group ID
*/
public static async GetLastActivity(groupID: number) : Promise<number> {
// TODO : implement
return groupID;
}
/**
* Turn a database row into a {GroupInfo} object
*

View File

@@ -0,0 +1,40 @@
import { UserMembershipEntry, UserMembershipType } from "../entities/UserMembershipEntry";
import { FriendsHelper } from "./FriendsHelper";
import { GroupsHelper } from "./GroupsHelper";
/**
* Web applications helper
*
* @author Pierre HUBERT
*/
export class WebappHelper {
/**
* Get all the membership of a user
*
* @param userID Target user ID
*/
public static async GetUserMemberships(userID: number) : Promise<Array<UserMembershipEntry>> {
// Get the list of friends of the user
const friendsList = await FriendsHelper.GetList(userID);
const groupsList = await GroupsHelper.GetListUser(userID);
const list : Array<UserMembershipEntry> = [];
// Add friends to the list
friendsList.forEach((f) => list.push(new UserMembershipEntry(
f.lastActivityTime, f, UserMembershipType.FRIEND)));
// Add groups to the list
for(const g of groupsList) list.push(new UserMembershipEntry(
await GroupsHelper.GetLastActivity(g), g, UserMembershipType.GROUP));
// Sort entries by latest activities
list.sort((a, b) => b.lastActivity - a.lastActivity);
return list;
}
}