1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-21 09:05:17 +00:00

Can get the list of conversations

This commit is contained in:
2019-11-23 18:41:13 +01:00
parent 6ad4375b2a
commit d6eed99a1a
4 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import { RequestHandler } from "../entities/RequestHandler";
import { ConversationsHelper } from "../helpers/ConversationsHelper";
import { Conversation } from "../entities/Conversation";
/**
* Conversations controller
*
* @author Pierre HUBERT
*/
export class ConversationsController {
/**
* Get the list of conversations of the user
*
* @param handler
*/
public static async GetList(handler: RequestHandler) {
const list = await ConversationsHelper.GetListUser(handler.getUserId());
handler.send(list.map(c => this.ConversationToAPI(c)));
}
/**
* Turn a conversation object into an API entry
*
* @param c
*/
private static ConversationToAPI(c : Conversation) : any {
return {
ID: c.id,
ID_owner: c.ownerID,
last_active: c.lastActive,
name: c.name.length > 0 ? c.name : false,
following: c.following ? 1 : 0,
saw_last_message: c.sawLastMessage ? 1 : 0,
members: c.members
};
}
}

View File

@ -2,6 +2,7 @@ import { WelcomeController } from "./WelcomeController";
import { RequestHandler } from "../entities/RequestHandler";
import { AccountController } from "./AccountController";
import { UserController } from "./UserController";
import { ConversationsController } from "./ConversationsController";
/**
* Controllers routes
@ -43,4 +44,8 @@ export const Routes : Route[] = [
{path: "/user/getInfoMultiple", cb: (h) => UserController.GetMultiple(h), needLogin: false},
{path: "/user/getInfosMultiple", cb: (h) => UserController.GetMultiple(h), needLogin: false}, // Legacy
// Conversations controller
{path: "/conversations/getList", cb: (h) => ConversationsController.GetList(h)},
]