1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 06:49:23 +00:00

Returns the list of conversations with the memberships

This commit is contained in:
Pierre HUBERT 2020-04-09 08:22:21 +02:00
parent 85e05ccb91
commit 0988d2ac4a
3 changed files with 41 additions and 11 deletions

View File

@ -3,6 +3,8 @@ import { WebappHelper } from "../helpers/WebappHelper";
import { UserMembershipType } from "../entities/UserMembershipEntry";
import { FriendsController } from "./FriendsController";
import { Friend } from "../entities/Friend";
import { ConversationsController } from "./ConversationsController";
import { Conversation } from "../entities/Conversation";
/**
@ -21,15 +23,33 @@ export class WebAppControllers {
const list = await WebappHelper.GetUserMemberships(h.getUserId());
h.send(list.map((l) => l.type == UserMembershipType.FRIEND ? {
// In case of friend
h.send(list.map((l) => {
switch(l.type) {
case UserMembershipType.FRIEND:
return {
type: "friend",
friend: FriendsController.FriendToAPI(<Friend>l.el)
} : {
// In case of group
};
case UserMembershipType.GROUP:
return {
type: "group",
id: l.el,
last_activity: l.lastActivity
}
case UserMembershipType.CONVERSATION:
return {
type: "conversation",
conv: ConversationsController.ConversationToAPI(<Conversation>l.el)
}
default:
h.error(500, "Unsupported membership type detected!");
}
}));
}

View File

@ -1,4 +1,5 @@
import { Friend } from "./Friend";
import { Conversation } from "./Conversation";
/**
* Get information about a membership
@ -6,12 +7,12 @@ import { Friend } from "./Friend";
* @author Pierre HUBERT
*/
export enum UserMembershipType { GROUP, FRIEND }
export enum UserMembershipType { GROUP, FRIEND, CONVERSATION }
export class UserMembershipEntry {
constructor(
public lastActivity: number,
public el: Friend | number,
public el: Friend | Conversation | number,
public type: UserMembershipType
) {}
}

View File

@ -1,6 +1,7 @@
import { UserMembershipEntry, UserMembershipType } from "../entities/UserMembershipEntry";
import { FriendsHelper } from "./FriendsHelper";
import { GroupsHelper } from "./GroupsHelper";
import { ConversationsHelper } from "./ConversationsHelper";
/**
* Web applications helper
@ -20,6 +21,7 @@ export class WebappHelper {
// Get the list of friends of the user
const friendsList = await FriendsHelper.GetList(userID);
const groupsList = await GroupsHelper.GetListUser(userID);
const conversationsList = await ConversationsHelper.GetListUser(userID);
const list : Array<UserMembershipEntry> = [];
@ -31,6 +33,13 @@ export class WebappHelper {
for(const g of groupsList) list.push(new UserMembershipEntry(
await GroupsHelper.GetLastActivity(userID, g), g, UserMembershipType.GROUP));
// Add conversations to the list
conversationsList.forEach(c => list.push(new UserMembershipEntry(
c.lastActive,
c,
UserMembershipType.CONVERSATION
)))
// Sort entries by latest activities
list.sort((a, b) => b.lastActivity - a.lastActivity);