mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Performance: Inbox Paging / loading (#11157)
* load messages per conversation * only sort ones in ui * add contributor to message * fix correct message layout/message * mugenScroll on chatMessages * fix lint, no mugen-scroll, use own scroll handler * fix height / margin of modal + use button to load more * fix tests * user data from inbox * style "load earlier messages" * move mapMessage to the inbox api result / extract sentMessage of members-api-controller * fix test back * fix test * keep last scroll position * just set the Id of the returned message instead of all other properties * fix add new messages (buttons were hidden) + load more * item-mounted debounce to trigger the re-scrolling
This commit is contained in:
@@ -73,7 +73,7 @@ api.clearMessages = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {get} /inbox/conversations Get the conversations for a user
|
||||
* @api {get} /api/v4/inbox/conversations Get the conversations for a user
|
||||
* @apiName conversations
|
||||
* @apiGroup Inbox
|
||||
* @apiDescription Get the conversations for a user
|
||||
@@ -93,4 +93,49 @@ api.conversations = {
|
||||
},
|
||||
};
|
||||
|
||||
function mapMessage (newChat, user) {
|
||||
if (newChat.sent) {
|
||||
newChat.toUUID = newChat.uuid;
|
||||
newChat.toUser = newChat.user;
|
||||
newChat.toUserName = newChat.username;
|
||||
newChat.toUserContributor = newChat.contributor;
|
||||
newChat.toUserBacker = newChat.backer;
|
||||
newChat.uuid = user._id;
|
||||
newChat.user = user.profile.name;
|
||||
newChat.username = user.auth.local.username;
|
||||
newChat.contributor = user.contributor;
|
||||
newChat.backer = user.backer;
|
||||
}
|
||||
|
||||
return newChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v4/inbox/messages Get inbox messages for a user
|
||||
* @apiName GetInboxMessages
|
||||
* @apiGroup Inbox
|
||||
* @apiDescription Get inbox messages for a user. Entries already populated with the correct `sent` - information
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
api.getInboxMessages = {
|
||||
method: 'GET',
|
||||
url: '/inbox/messages',
|
||||
middlewares: [authWithHeaders()],
|
||||
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, conversation,
|
||||
})).map(newChat => mapMessage(newChat, user));
|
||||
|
||||
res.respond(200, userInbox);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
|
||||
Reference in New Issue
Block a user