mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 23:09:22 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
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(userID, g), g, UserMembershipType.GROUP));
|
|
|
|
// Sort entries by latest activities
|
|
list.sort((a, b) => b.lastActivity - a.lastActivity);
|
|
|
|
return list;
|
|
}
|
|
|
|
} |