mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-14 11:46:23 +00:00
* split component prepare new views / states * extract empty and disabled state as components * fix empty state mail icon * first logic switching between modes, move page to /private-messages/index.vue * extract autoCompleteHelper.js * style header + start new message input * style plus button + focus input * state logic, types for sanity * WIP PM new Message started * add /members/username test * first design changes to messageCard * delete private message or chat - based on the mode * copy as todo * mention links to modal * report chat or private message * WIP likeButton * likeButton styling * hide like on private message cards * fix unit test * replace copy as todo - to just a copy to clipboard * style changes * menu position + like button width * dropdown items background + like font * fix like button padding * move api endpoints and tests around to group inbox methods + like for inbox private messages * restyle system messages * Dropdown Radius and Padding * WIP system messages * fix lint * copy delta commit of allowing liking own private messages * enable liking private messages * fix menu non hovered item icon color * fix import path * ignore background on system messages * requested changes + migration * update migration to update the unique id to some messages and delete the duplicates * migration based on users pagination * fix(migration): use Promise.all * change to bulkWrites per User, and all messages in one run (of a user) * check for array * use rest operator ... * skip sorting to get the users * remove migration, disable like for private messages without uniqueMessageId * lean+bulkWrite for likes, add time checks for like and auth for further debugging * add a limit 2 get the messages by uniqueId * Adding a simple server start script * remove pinned nodemon dep * fix inbox controller/tests * fix / requested style changes * fix empty state padding / * hide avatar weapons on messages - fix avatar spacing on messages * Hourglass Simplification (#15323) * begin removing obsolete tests * begin refactoring * update cron tests * cleanup * finish basic implementation of new logic * add more subscription tests * subscription test improvements * return nextHourglassDate again * fix gem limit * fix(test): short circuit this. * fix(admin): correct logic and style for shrimple subs * WIP(frontend): draft of main subs page view * fix hourglass count * Fix hourglass logic for upgrades * fix admin panel display * WIP(subs): extant Stripe state * fix admin panel strings * fix missing transaction type * add new field for cumulative subscription count * show date for hourglass bonus if it was received * fix test * feat(subscription): max Gems progress readout * fix(css): correct and refactor heights and selection states * fix(subs): correct border-radius and redirect * fix(stripe): correct redirect after success * Admin panel display fixes * don’t give additional HG for new sub if they already got one this month * fix issue with promo hourglasses * fix(subscription): update layout when gifting * fix(subscriptions): more gift layout revisions * fix(subscriptions): minor visual updates * fix(subs): pass autoRenews through Stripe * fix(subs): gifts DON't renew * fix(lint): unnecessary ternary * fix(lint): do negate object ig * fix(subs): try again on gifts * fix(subs): unhovery and un-12-monthy * fix bug with incorrectly giving HG bonus * remove only * fix test * fix test * fix(subs): also redirect to subs after gift sub * fix(subs): fix typeError * fix(g1g1): don't try to find Gems promo during bogo --------- Co-authored-by: Phillip Thelen <phillip@habitica.com> Co-authored-by: Kalista Payne <sabe@habitica.com> * chore(sprites): update subproject * fix(layout): tighten cancellation note * fix(subs): Google wording and HG escape * chore(testing): fake g1g1 dates * fix(subs): don't hide HG preview entirely * fix(subs): center next hourglass message * working validatedTextInput.vue within start-new-conversation-input-header.vue 🎉 * fix(git): remove changes from old develop * Revert "fix(git): remove changes from old develop" This reverts commit 0e30f7df004bc363f2868d4b59de01862dec610f. * fix(git): no actually just this file i guesss * adding an empty loading state, hiding * fought the avatar arch nemesis again * fix chatMessages (party chat) message spacing * move disabled text back to above the input area - re-enable input area * show disabled private messages top panel * fix font color * fixing uiStates - removing disabled - moving the own user check to the last * fix(lint): add missing prop defaults * fix(lint): object default should be fn * fix(chat): correct grammar in error * remove weapon position relative * revert most of avatar.vue changes, add back weapons in chat message UI * show date tooltip above system / skill messages * fix toggle disable icon position * trivial CSS cleanup * fix(typo): English syntax in test * chore(test): small style cleanup * chore(logging): revert debug function * chore(debug): remove timers from inbox like --------- Co-authored-by: SabreCat <sabe@habitica.com> Co-authored-by: Kalista Payne <sabrecat@gmail.com> Co-authored-by: Phillip Thelen <phillip@habitica.com>
245 lines
7.8 KiB
JavaScript
245 lines
7.8 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 {
|
|
applyLikeToMessages,
|
|
clearPMs, deleteMessage, getUserInbox,
|
|
} from '../../libs/inbox';
|
|
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
|
import * as inboxLib from '../../libs/inbox';
|
|
import logger from '../../libs/logger';
|
|
|
|
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 */
|
|
|
|
/**
|
|
* @apiIgnore
|
|
* @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 */
|
|
|
|
/**
|
|
* @apiIgnore
|
|
* @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, {});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @apiIgnore
|
|
* @api {get} /api/v4/inbox/conversations Get the conversations for a user
|
|
* @apiName conversations
|
|
* @apiGroup Inbox
|
|
* @apiDescription Get the conversations for a user.
|
|
* This is for API v4 which must not be used in third-party tools.
|
|
* For API v3, use "Get inbox messages for a user".
|
|
*
|
|
* @apiParam (Query) {Number} page (optional) Load the conversations of the selected Page
|
|
* - 10 conversations per Page
|
|
*
|
|
* @apiSuccess {Array} data An array of inbox conversations
|
|
*
|
|
* @apiSuccessExample {json} Success-Response:
|
|
* {"success":true,"data":[
|
|
* {
|
|
* "_id":"8a9d461b-f5eb-4a16-97d3-c03380c422a3",
|
|
* "uuid":"8a9d461b-f5eb-4a16-97d3-c03380c422a3",
|
|
* "user":"user display name",
|
|
* "username":"some_user_name",
|
|
* "timestamp":"12315123123",
|
|
* "text":"last message of conversation",
|
|
* "userStyles": {},
|
|
* "contributor": {},
|
|
* "canReceive": true,
|
|
* "count":1
|
|
* }
|
|
* }
|
|
*/
|
|
api.conversations = {
|
|
method: 'GET',
|
|
middlewares: [authWithHeaders({ userFieldsToInclude: ['profile', 'contributor', 'backer', 'inbox'] })],
|
|
url: '/inbox/conversations',
|
|
async handler (req, res) {
|
|
const { user } = res.locals;
|
|
const { page } = req.query;
|
|
|
|
const result = await listConversations(user, page);
|
|
|
|
res.respond(200, result);
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @apiIgnore
|
|
* @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({ userFieldsToInclude: ['profile', 'contributor', 'backer', 'inbox'] })],
|
|
async handler (req, res) {
|
|
const { user } = res.locals;
|
|
const { page, conversation } = req.query;
|
|
|
|
const userInbox = await getUserInbox(user, {
|
|
page, conversation, mapProps: true,
|
|
});
|
|
|
|
res.respond(200, userInbox);
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @apiIgnore
|
|
* @api {post} /api/v4/members/flag-private-message/:messageId Flag a private message
|
|
* @apiDescription Moderators are notified about every flagged message,
|
|
* including the sender, recipient, and full content of the message.
|
|
* This is for API v4 which must not be used in third-party tools as it can change without notice.
|
|
* There is no equivalent route in API v3.
|
|
* @apiName FlagPrivateMessage
|
|
* @apiGroup Member
|
|
*
|
|
* @apiParam (Path) {UUID} messageId The private message id
|
|
*
|
|
* @apiSuccess {Object} data The flagged private message
|
|
* @apiSuccess {UUID} data.id The id of the message
|
|
* @apiSuccess {String} data.text The text of the message
|
|
* @apiSuccess {Number} data.timestamp The timestamp of the message in milliseconds
|
|
* @apiSuccess {Object} data.likes The likes of the message (always an empty object)
|
|
* @apiSuccess {Object} data.flags The flags of the message
|
|
* @apiSuccess {Number} data.flagCount The number of flags the message has
|
|
* @apiSuccess {UUID} data.uuid The User ID of the author of the message,
|
|
* or of the recipient if `sent` is true
|
|
* @apiSuccess {String} data.user The Display Name of the author of the message,
|
|
* or of the recipient if `sent` is true
|
|
* @apiSuccess {String} data.username The Username of the author of the message,
|
|
* or of the recipient if `sent` is true
|
|
*
|
|
* @apiUse MessageNotFound
|
|
* @apiUse MessageIdRequired
|
|
* @apiError (400) {BadRequest} messageGroupChatFlagAlreadyReported You have already
|
|
* reported this message
|
|
*/
|
|
api.flagPrivateMessage = {
|
|
method: 'POST',
|
|
url: '/members/flag-private-message/:messageId',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
const chatReporter = chatReporterFactory('Inbox', req, res);
|
|
const message = await chatReporter.flag();
|
|
res.respond(200, {
|
|
ok: true,
|
|
message,
|
|
});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @api {post} /api/v4//inbox/like-private-message/:uniqueMessageId Like a private message
|
|
* @apiName LikePrivateMessage
|
|
* @apiGroup Inbox
|
|
* @apiDescription Likes a private message, this uses the uniqueMessageId which is a shared ID
|
|
* between message copies of both chat participants
|
|
*
|
|
* @apiParam (Path) {UUID} uniqueMessageId This is NOT private message.id,
|
|
* but rather message.uniqueMessageId
|
|
*
|
|
* @apiSuccess {Object} data The liked <a href='https://github.com/HabitRPG/habitica/blob/develop/website/server/models/message.js#L42' target='_blank'>private message</a>
|
|
*
|
|
* @apiUse MessageNotFound
|
|
*/
|
|
api.likePrivateMessage = {
|
|
method: 'POST',
|
|
url: '/inbox/like-private-message/:uniqueMessageId',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
req.checkParams('uniqueMessageId', apiError('messageIdRequired')).notEmpty();
|
|
|
|
const validationErrors = req.validationErrors();
|
|
if (validationErrors) throw validationErrors;
|
|
|
|
const { user } = res.locals;
|
|
const { uniqueMessageId } = req.params;
|
|
|
|
const messages = await inboxLib.getInboxMessagesByUniqueId(uniqueMessageId);
|
|
|
|
if (messages.length === 0) {
|
|
throw new NotFound(res.t('messageGroupChatNotFound'));
|
|
}
|
|
|
|
if (messages.length > 2) {
|
|
logger.error(`More than 2 Messages exist with this uniqueMessageId: ${uniqueMessageId} check in Database!`);
|
|
}
|
|
|
|
await applyLikeToMessages(user, messages);
|
|
|
|
const messageToReturn = messages.find(m => m.uuid === user._id);
|
|
|
|
res.respond(200, messageToReturn);
|
|
},
|
|
};
|
|
|
|
export default api;
|