mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 13:47:33 +01:00
* feat(messages): big PMs refactor * add private messages route * move to page * WIP - header + begin with the sidebar * extract userLabel + style sidebar + extract converstation item * correct conversation item style * toggle switch style * add contributor / backer to conversation user-label * fix shadows * fix the conversations list (ignoring own sent) * selected conversation label * faceAvatar component * fix message / avatar height * fix message list / empty messages height * new message padding/styles/functionality - finished sidebar conversation styling - * fix loading messages + perfect-scrollbar * fix load more line * fix loading label * open new conversation from outside * if the user doesn't have avatar-data inside the conversation and does not exist anymore, just load/set the user name * search bar new icon / style * block using from conversation context-menu * fix lint * fix merge / lint * fix merge * first separate page * fix tooltips + full width private message + card max width + more responsive * separate conversations methods, to prevent circular deps * update eslint config * fix open new private message * remove unneeded close icon + fix toggle-switch layout * same content height on empty conversations - remove border / box-shadow * canLoadMore = false * remove inbox conditions on chat components * hide footer / fix empty sidebar * floating shadow * remove tooltip on selected conversation user + pm always full-size * show avatar on empty conversation * disable face-avatar * fix faceAvatar + story * fix loading conversation messages while switching the conversation * refresh private-messages page when you are already on it * add countbadge knob to change the example * fix lint * fix hide tooltip + align header correctly * disable perfect scroll * load messages on refresh event * fix header label + conversation actions not breaking layout on hover * add gifting banner to the max height calculation * correct chunk name Co-authored-by: negue <negue@users.noreply.github.com> Co-authored-by: Matteo Pagliazzi <matteopagliazzi@gmail.com>
141 lines
3.6 KiB
JavaScript
141 lines
3.6 KiB
JavaScript
import { authWithHeaders } from '../../middlewares/auth';
|
|
import apiError from '../../libs/apiError';
|
|
import {
|
|
NotFound,
|
|
} from '../../libs/errors';
|
|
import { listConversations } from '../../libs/inbox/conversation.methods';
|
|
import { clearPMs, deleteMessage, getUserInbox } from '../../libs/inbox';
|
|
|
|
const api = {};
|
|
|
|
/* NOTE most inbox routes are either in the user or members controller */
|
|
|
|
/* NOTE the getInboxMessages route is implemented in v3 only */
|
|
|
|
/* NOTE this route has also an API v3 version */
|
|
|
|
/**
|
|
* @api {delete} /api/v4/inbox/messages/:messageId Delete a message
|
|
* @apiName deleteMessage
|
|
* @apiGroup User
|
|
*
|
|
* @apiParam (Path) {UUID} messageId The id of the message to delete
|
|
*
|
|
* @apiSuccess {Object} data Empty object
|
|
* @apiSuccessExample {json}
|
|
* {
|
|
* "success": true,
|
|
* "data": {}
|
|
* }
|
|
*/
|
|
api.deleteMessage = {
|
|
method: 'DELETE',
|
|
middlewares: [authWithHeaders()],
|
|
url: '/inbox/messages/:messageId',
|
|
async handler (req, res) {
|
|
req.checkParams('messageId', apiError('messageIdRequired')).notEmpty().isUUID();
|
|
|
|
const validationErrors = req.validationErrors();
|
|
if (validationErrors) throw validationErrors;
|
|
|
|
const { messageId } = req.params;
|
|
const { user } = res.locals;
|
|
|
|
const deleted = await deleteMessage(user, messageId);
|
|
if (!deleted) throw new NotFound(res.t('messageGroupChatNotFound'));
|
|
|
|
res.respond(200);
|
|
},
|
|
};
|
|
|
|
/* NOTE this route has also an API v3 version */
|
|
|
|
/**
|
|
* @api {delete} /api/v4/inbox/clear Delete all messages
|
|
* @apiName clearMessages
|
|
* @apiGroup User
|
|
*
|
|
* @apiSuccess {Object} data Empty object
|
|
*
|
|
* @apiSuccessExample {json}
|
|
* {"success":true,"data":{},"notifications":[]}
|
|
*/
|
|
api.clearMessages = {
|
|
method: 'DELETE',
|
|
middlewares: [authWithHeaders()],
|
|
url: '/inbox/clear',
|
|
async handler (req, res) {
|
|
const { user } = res.locals;
|
|
|
|
await clearPMs(user);
|
|
|
|
res.respond(200, {});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @api {get} /api/v4/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
|
|
*
|
|
* @apiSuccessExample {json} Success-Response:
|
|
* {"success":true,"data":[
|
|
* {
|
|
* "_id":"8a9d461b-f5eb-4a16-97d3-c03380c422a3",
|
|
* "user":"user display name",
|
|
* "username":"some_user_name",
|
|
* "timestamp":"12315123123",
|
|
* "text":"last message of conversation",
|
|
* "userStyles": {},
|
|
* "contributor": {},
|
|
* "count":1
|
|
* }
|
|
* }
|
|
*/
|
|
api.conversations = {
|
|
method: 'GET',
|
|
middlewares: [authWithHeaders()],
|
|
url: '/inbox/conversations',
|
|
async handler (req, res) {
|
|
const { user } = res.locals;
|
|
|
|
const result = await listConversations(user);
|
|
|
|
res.respond(200, result);
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @api {get} /api/v4/inbox/paged-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/paged-messages',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
const { user } = res.locals;
|
|
const { page } = req.query;
|
|
const { conversation } = req.query;
|
|
|
|
const userInbox = await getUserInbox(user, {
|
|
page, conversation, mapProps: true,
|
|
});
|
|
|
|
res.respond(200, userInbox);
|
|
},
|
|
};
|
|
|
|
export default api;
|