mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-26 07:19:23 +00:00
Get the number of unread conversations of the user
This commit is contained in:
parent
ae88b7a979
commit
94600597b4
@ -283,6 +283,17 @@ export class ConversationsController {
|
|||||||
h.send(messages.map(e => this.ConversationMessageToAPI(e)));
|
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
|
* Get and return safely a conversation ID specified in a $_POST Request
|
||||||
*
|
*
|
||||||
|
@ -67,6 +67,8 @@ export const Routes : Route[] = [
|
|||||||
|
|
||||||
{path: "/conversations/get_older_messages", cb: (h) => ConversationsController.GetOlderMessages(h)},
|
{path: "/conversations/get_older_messages", cb: (h) => ConversationsController.GetOlderMessages(h)},
|
||||||
|
|
||||||
|
{path: "/conversations/get_number_unread", cb: (h) => ConversationsController.CountUnreadForUser(h)}
|
||||||
|
|
||||||
|
|
||||||
// Search controller
|
// Search controller
|
||||||
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
|
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
|
||||||
|
@ -393,6 +393,22 @@ export class ConversationsHelper {
|
|||||||
return result.map(r => r.conv_id);
|
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
|
* Get the list of members of a conversation
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user