Inbox: Add API to list conversations (#11110)
* Add API to list inbox conversations * fix test + add api doc * use `.lean()` * orderBy after the the grouped conversations are loaded * fix ordering
This commit is contained in:
@@ -12,6 +12,7 @@ let api = {};
|
||||
* @apiDescription Get inbox messages for a user
|
||||
*
|
||||
* @apiParam (Query) {Number} page Load the messages of the selected Page - 10 Messages per Page
|
||||
* @apiParam (Query) {GUID} conversation Loads only the messages of a conversation
|
||||
*
|
||||
* @apiSuccess {Array} data An array of inbox messages
|
||||
*/
|
||||
@@ -22,9 +23,10 @@ api.getInboxMessages = {
|
||||
async handler (req, res) {
|
||||
const user = res.locals.user;
|
||||
const page = req.query.page;
|
||||
const conversation = req.query.conversation;
|
||||
|
||||
const userInbox = await inboxLib.getUserInbox(user, {
|
||||
page,
|
||||
page, conversation,
|
||||
});
|
||||
|
||||
res.respond(200, userInbox);
|
||||
|
||||
@@ -72,4 +72,25 @@ api.clearMessages = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {get} /inbox/conversations Get the conversations for a user
|
||||
* @apiName conversations
|
||||
* @apiGroup Inbox
|
||||
* @apiDescription Get the conversations for a user
|
||||
*
|
||||
* @apiSuccess {Array} data An array of inbox conversations
|
||||
*/
|
||||
api.conversations = {
|
||||
method: 'GET',
|
||||
middlewares: [authWithHeaders()],
|
||||
url: '/inbox/conversations',
|
||||
async handler (req, res) {
|
||||
const user = res.locals.user;
|
||||
|
||||
const result = await inboxLib.listConversations(user);
|
||||
|
||||
res.respond(200, result);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
|
||||
Reference in New Issue
Block a user