Merge remote-tracking branch 'origin/develop' into negue/flagpm

This commit is contained in:
negue
2018-11-29 19:02:01 +01:00
316 changed files with 18625 additions and 17558 deletions

View File

@@ -88,6 +88,8 @@ function getBannedWordsFromText (message) {
return getMatchesByWordArray(message, bannedWords);
}
const mentionRegex = new RegExp('\\B@[-\\w]+', 'g');
/**
* @api {post} /api/v3/groups/:groupId/chat Post chat message to a group
* @apiName PostChat
@@ -180,7 +182,11 @@ api.postChat = {
throw new NotAuthorized(res.t('messageGroupChatSpam'));
}
const newChatMessage = group.sendChat(req.body.message, user);
let client = req.headers['x-client'] || '3rd Party';
if (client) {
client = client.replace('habitica-', '');
}
const newChatMessage = group.sendChat(req.body.message, user, null, client);
let toSave = [newChatMessage.save()];
if (group.type === 'party') {
@@ -190,6 +196,27 @@ api.postChat = {
await Promise.all(toSave);
let analyticsObject = {
uuid: user._id,
hitType: 'event',
category: 'behavior',
groupType: group.type,
privacy: group.privacy,
headers: req.headers,
};
const mentions = req.body.message.match(mentionRegex);
if (mentions) {
analyticsObject.mentionsCount = mentions.length;
} else {
analyticsObject.mentionsCount = 0;
}
if (group.privacy === 'public') {
analyticsObject.groupName = group.name;
}
res.analytics.track('group chat', analyticsObject);
if (chatUpdated) {
res.respond(200, {chat: chatRes.chat});
} else {