mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-21 17:15:17 +00:00
Can get the list of unread conversations
This commit is contained in:
@ -4,6 +4,7 @@ import { Conversation, BaseConversation } from "../entities/Conversation";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
import { removeHTMLNodes } from "../utils/StringUtils";
|
||||
import { ConversationMessage } from "../entities/ConversationMessage";
|
||||
import { UnreadConversation } from "../entities/UnreadConversation";
|
||||
|
||||
/**
|
||||
* Conversations controller
|
||||
@ -294,6 +295,17 @@ export class ConversationsController {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of unread conversations of the user
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async GetListUnread(h: RequestHandler) {
|
||||
const list = await ConversationsHelper.GetListUnread(h.getUserId());
|
||||
|
||||
h.send(list.map(e => this.UnreadConversationToAPI(e)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return safely a conversation ID specified in a $_POST Request
|
||||
*
|
||||
@ -341,4 +353,19 @@ export class ConversationsController {
|
||||
image_path: c.hasImage ? c.imageURL : null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an UnreadConversation object into an API entry
|
||||
*
|
||||
* @param c Target conversation
|
||||
*/
|
||||
private static UnreadConversationToAPI(c: UnreadConversation): any {
|
||||
return {
|
||||
id: c.id,
|
||||
conv_name: c.name,
|
||||
last_active: c.lastActive,
|
||||
userID: c.userID,
|
||||
message: c.message
|
||||
}
|
||||
}
|
||||
}
|
@ -67,7 +67,9 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/conversations/get_older_messages", cb: (h) => ConversationsController.GetOlderMessages(h)},
|
||||
|
||||
{path: "/conversations/get_number_unread", cb: (h) => ConversationsController.CountUnreadForUser(h)}
|
||||
{path: "/conversations/get_number_unread", cb: (h) => ConversationsController.CountUnreadForUser(h)},
|
||||
|
||||
{path: "/conversations/get_list_unread", cb: (h) => ConversationsController.GetListUnread(h)},
|
||||
|
||||
|
||||
// Search controller
|
||||
|
Reference in New Issue
Block a user