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 { UserMembershipType } from "../entities/UserMembershipEntry";
import { FriendsController } from "./FriendsController"; import { FriendsController } from "./FriendsController";
import { Friend } from "../entities/Friend"; 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()); const list = await WebappHelper.GetUserMemberships(h.getUserId());
h.send(list.map((l) => l.type == UserMembershipType.FRIEND ? { h.send(list.map((l) => {
// In case of friend switch(l.type) {
type: "friend",
friend: FriendsController.FriendToAPI(<Friend>l.el) case UserMembershipType.FRIEND:
} : { return {
// In case of group type: "friend",
type: "group", friend: FriendsController.FriendToAPI(<Friend>l.el)
id: l.el, };
last_activity: l.lastActivity
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 { Friend } from "./Friend";
import { Conversation } from "./Conversation";
/** /**
* Get information about a membership * Get information about a membership
@ -6,12 +7,12 @@ import { Friend } from "./Friend";
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
export enum UserMembershipType { GROUP, FRIEND } export enum UserMembershipType { GROUP, FRIEND, CONVERSATION }
export class UserMembershipEntry { export class UserMembershipEntry {
constructor( constructor(
public lastActivity: number, public lastActivity: number,
public el: Friend | number, public el: Friend | Conversation | number,
public type: UserMembershipType public type: UserMembershipType
) {} ) {}
} }

View File

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