1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-26 07:19:23 +00:00
comunicapiv2/src/helpers/WebappHelper.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-12-28 15:52:52 +00:00
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(
2020-03-21 15:43:53 +00:00
await GroupsHelper.GetLastActivity(userID, g), g, UserMembershipType.GROUP));
2019-12-28 15:52:52 +00:00
// Sort entries by latest activities
list.sort((a, b) => b.lastActivity - a.lastActivity);
return list;
}
}