Merge branch 'develop' into client-monorepo

This commit is contained in:
Matteo Pagliazzi
2019-10-18 20:26:12 +02:00
17 changed files with 292 additions and 45 deletions

View File

@@ -19,6 +19,7 @@ import guildsAllowingBannedWords from '../../libs/guildsAllowingBannedWords';
import { getMatchesByWordArray } from '../../libs/stringUtils';
import bannedSlurs from '../../libs/bannedSlurs';
import apiError from '../../libs/apiError';
import { highlightMentions } from '../../libs/highlightMentions';
const FLAG_REPORT_EMAILS = nconf.get('FLAG_REPORT_EMAIL').split(',').map(email => ({ email, canSend: true }));
@@ -89,7 +90,6 @@ function getBannedWordsFromText (message) {
}
const mentionRegex = new RegExp('\\B@[-\\w]+', 'g');
/**
* @api {post} /api/v3/groups/:groupId/chat Post chat message to a group
* @apiName PostChat
@@ -187,6 +187,7 @@ api.postChat = {
throw new NotAuthorized(res.t('messageGroupChatSpam'));
}
const [message, mentions, mentionedMembers] = await highlightMentions(req.body.message);
let client = req.headers['x-client'] || '3rd Party';
if (client) {
client = client.replace('habitica-', '');
@@ -195,7 +196,6 @@ api.postChat = {
let flagCount = 0;
if (group.privacy === 'public' && user.flags.chatShadowMuted) {
flagCount = common.constants.CHAT_FLAG_FROM_SHADOW_MUTE;
const { message } = req.body;
// Email the mods
const authorEmail = getUserInfo(user, ['email']).email;
@@ -228,7 +228,14 @@ api.postChat = {
}
const newChatMessage = group.sendChat({
message: req.body.message, user, flagCount, metaData: null, client, translate: res.t,
message: req.body.message,
user,
flagCount,
metaData: null,
client,
translate: res.t,
mentions,
mentionedMembers,
});
const toSave = [newChatMessage.save()];
@@ -237,6 +244,7 @@ api.postChat = {
toSave.push(user.save());
}
await Promise.all(toSave);
const analyticsObject = {
@@ -248,7 +256,6 @@ api.postChat = {
headers: req.headers,
};
const mentions = req.body.message.match(mentionRegex);
if (mentions) {
analyticsObject.mentionsCount = mentions.length;
} else {

View File

@@ -630,16 +630,47 @@ api.joinGroup = {
if (group.type === 'party' && inviter) {
if (group.memberCount > 1) {
promises.push(User.update({
$or: [{ 'party._id': group._id }, { _id: user._id }],
'achievements.partyUp': { $ne: true },
}, { $set: { 'achievements.partyUp': true } }, { multi: true }).exec());
promises.push(User.update(
{
$or: [{ 'party._id': group._id }, { _id: user._id }],
'achievements.partyUp': { $ne: true },
},
{
$set: { 'achievements.partyUp': true },
$push: { notifications: { type: 'ACHIEVEMENT_PARTY_UP' } },
},
{ multi: true },
).exec());
if (inviter) {
if (inviter.achievements.partyUp !== true) {
// Since the notification list of the inviter is already
// updated in this save we need to add the notification here
inviter.addNotification('ACHIEVEMENT_PARTY_UP');
}
}
}
if (group.memberCount > 3) {
promises.push(User.update({
$or: [{ 'party._id': group._id }, { _id: user._id }],
'achievements.partyOn': { $ne: true },
}, { $set: { 'achievements.partyOn': true } }, { multi: true }).exec());
promises.push(User.update(
{
$or: [{ 'party._id': group._id }, { _id: user._id }],
'achievements.partyOn': { $ne: true },
},
{
$set: { 'achievements.partyOn': true },
$push: { notifications: { type: 'ACHIEVEMENT_PARTY_ON' } },
},
{ multi: true },
).exec());
if (inviter) {
if (inviter.achievements.partyOn !== true) {
// Since the notification list of the inviter is already
// updated in this save we need to add the notification here
inviter.addNotification('ACHIEVEMENT_PARTY_ON');
}
}
}
}

View File

@@ -21,6 +21,7 @@ import {
import { sendNotification as sendPushNotification } from '../../libs/pushNotifications';
import common from '../../../common';
import { sentMessage } from '../../libs/inbox';
import { highlightMentions } from '../../libs/highlightMentions';
const { achievements } = common;
@@ -676,7 +677,7 @@ api.sendPrivateMessage = {
if (validationErrors) throw validationErrors;
const sender = res.locals.user;
const { message } = req.body;
const message = (await highlightMentions(req.body.message))[0];
const receiver = await User.findById(req.body.toUserId).exec();
if (!receiver) throw new NotFound(res.t('userNotFound'));