1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Get the number of unread conversations of the user

This commit is contained in:
Pierre HUBERT 2019-12-07 17:15:33 +01:00
parent ae88b7a979
commit 94600597b4
3 changed files with 29 additions and 0 deletions

View File

@ -283,6 +283,17 @@ export class ConversationsController {
h.send(messages.map(e => this.ConversationMessageToAPI(e)));
}
/**
* Get the number of unread conversations for the user
*
* @param h Request handler
*/
public static async CountUnreadForUser(h: RequestHandler) {
h.send({
nb_unread: await ConversationsHelper.CountUnreadForUser(h.getUserId())
})
}
/**
* Get and return safely a conversation ID specified in a $_POST Request
*

View File

@ -66,6 +66,8 @@ export const Routes : Route[] = [
{path: "/conversations/sendMessage", cb: (h) => ConversationsController.SendMessage(h)},
{path: "/conversations/get_older_messages", cb: (h) => ConversationsController.GetOlderMessages(h)},
{path: "/conversations/get_number_unread", cb: (h) => ConversationsController.CountUnreadForUser(h)}
// Search controller

View File

@ -393,6 +393,22 @@ export class ConversationsHelper {
return result.map(r => r.conv_id);
}
/**
* Count the number of unread conversations of the user
*
* @param userID Target user ID
*/
public static async CountUnreadForUser(userID: number) : Promise<number> {
return await DatabaseHelper.Count({
table: USERS_TABLE,
where: {
user_id: userID,
saw_last_message: 0,
following: 1
}
});
}
/**
* Get the list of members of a conversation
*