mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Performance/inbox paging (#11258)
* merge all changes to one commit of PR #11157 / #11226 * rename the new paged messages route * rename event, move map-method to the Inbox schema, fix lint * move `mapMessage`-call to `getUserInbox` * revert schema.method back to a normal one
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
} from '../../libs/email';
|
||||
import { sendNotification as sendPushNotification } from '../../libs/pushNotifications';
|
||||
import { achievements } from '../../../../website/common/';
|
||||
import {sentMessage} from '../../libs/inbox';
|
||||
|
||||
let api = {};
|
||||
|
||||
@@ -633,6 +634,7 @@ api.sendPrivateMessage = {
|
||||
|
||||
const sender = res.locals.user;
|
||||
const message = req.body.message;
|
||||
|
||||
const receiver = await User.findById(req.body.toUserId).exec();
|
||||
if (!receiver) throw new NotFound(res.t('userNotFound'));
|
||||
if (!receiver.flags.verifiedUsername) delete receiver.auth.local.username;
|
||||
@@ -640,26 +642,7 @@ api.sendPrivateMessage = {
|
||||
const objections = sender.getObjectionsToInteraction('send-private-message', receiver);
|
||||
if (objections.length > 0 && !sender.isAdmin()) throw new NotAuthorized(res.t(objections[0]));
|
||||
|
||||
const messageSent = await sender.sendMessage(receiver, { receiverMsg: message });
|
||||
|
||||
if (receiver.preferences.emailNotifications.newPM !== false) {
|
||||
sendTxnEmail(receiver, 'new-pm', [
|
||||
{name: 'SENDER', content: getUserInfo(sender, ['name']).name},
|
||||
]);
|
||||
}
|
||||
|
||||
if (receiver.preferences.pushNotifications.newPM !== false) {
|
||||
sendPushNotification(
|
||||
receiver,
|
||||
{
|
||||
title: res.t('newPM'),
|
||||
message: res.t('newPMInfo', {name: getUserInfo(sender, ['name']).name, message}),
|
||||
identifier: 'newPM',
|
||||
category: 'newPM',
|
||||
payload: {replyTo: sender._id},
|
||||
}
|
||||
);
|
||||
}
|
||||
const messageSent = await sentMessage(sender, receiver, message, res.t);
|
||||
|
||||
res.respond(200, {message: messageSent});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user