Improve @mention handling (#10872)

* move the update username route to v3 (#10836)

* Add API Call to retrieve auto-complete options for usernames

* Create links to users profile in chat messages

* Begin adding server-side autocomplete to web client

* Add Test to opt out of username being searchable

* Fix issue with username highlighting

* Correctly update message text when using autocomplete

* remove old autocomplete component

* Improve chat input design

* rewrite mongoose migration to avoid using recursion

* fixes

* select more fields

* use lean and .update

* fix(tests): correct expects

* fix(tests): linting & more expects
Also one more tweak for invite validation responsiveness

* chore(news): Bailey

* chore(i18n): update locales

* 4.70.0

* fix(chat): less intrusive highlight and better margins

* fix(chat): more width tweakage

* feat(content): Oddballs Bundle
Also includes one more tweak to @mention text highlighting

* chore(sprites): compile

* chore(i18n): update locales

* 4.71.0

* groupChatReceived webhook fix (#10802)

* Moved sendGroupChatReceivedWebhooks to group.sendChat function.

* Added test for new functionality.

* Set width on .custom-control-label (#10840)

Set `width: 100%` on the `.custom-control-label`.

Although `overflow-wrap: break-word` is set on the parent `.checklist-item` element, it doesn't seem to take effect unless a width is set on the label.

* Very large Guild member counts overflow the badge #10753 (#10812)

* Update superagent to the latest version 🚀 (#10848)

* fix(package): update superagent to version 4.0.0

* chore(package): update lockfile package-lock.json

* fix(chat): prevent duplicate messages, closes #10823

* Fix for #10814, prevent ParallelSave errors (#10852)

* fix(group leave): prevent ParallelSave errors while leaving a group with multiple group or challenge tasks

* fix typo

* move computed-props to methods - refactor mountItem to use the states inside (#10853)

* feat(content): Frost Hatching Potions

* chore(sprites): compile

* chore(i18n): update locales

* 4.72.0

* fix(stable): remove progress number from petItem

* add two slurs - TRIGGER / CONTENT WARNING: assault, slurs, swearwords, etc

* more checks on the item.klass, also added the specialClass checks (#10859)

* feat(content): Turkey Day 2018

* chore(sprites): compile

* chore(i18n): update locales

* 4.73.0

* chore(i18n): update locales

* 4.73.1

* feat(footer): always show expanded footer (#10862)

* Fixes issue #10857 ("Tags have extra space at the bottom when they should be centered") (#10861)

* Fix for #10857 centered category tag text

* Fixes #10857 and #10856 display tag markdown.

* Attach client to chat messages (#10845)

* Attach client to chat messages

* Word

* Design tweaks

* Fix potential error

* chore(event): end Thanksgiving tweaks

* chore(i18n): update locales

* 4.73.2

* Improve chat input design

* Fix test errors

* Move tier icons import to index

* correctly name event variable

* Debounce autocomplete calls

* optimize mention highlighting

* fix failing tests

* Fix sending private messages

* Cache username autocomplete requests

* optimize autocomplete regex

* Fix lint error

* add optional parameters to limit autocompletion to specific group

* Fix non-profile urls not being usable.

* Correctly handle autocomplete for public and private guilds

* Add check to make sure users don’t search for parties/guilds they are not part of

* fix lint error

* limit autocomplete results to 5

* fix(mentioning): change default, adapt settings control to checkbox

* Improve auto completing

* improve username autocomplete

* Fix merge issue

* remove old code

* Send push notifications on mentions

* Improve handling for sending mention notifications

* Fix lint error

* Update schema.js

* Fix failing test

* Don't send push notification to users who aren't in the party

* Remove tributejs from dependencies
This commit is contained in:
Matteo Pagliazzi
2019-10-18 17:05:13 +02:00
committed by GitHub
10 changed files with 170 additions and 20 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) => {
return { email, canSend: true };
@@ -90,7 +91,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
@@ -183,6 +183,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-', '');
@@ -191,7 +192,6 @@ api.postChat = {
let flagCount = 0;
if (group.privacy === 'public' && user.flags.chatShadowMuted) {
flagCount = common.constants.CHAT_FLAG_FROM_SHADOW_MUTE;
let message = req.body.message;
// Email the mods
let authorEmail = getUserInfo(user, ['email']).email;
@@ -223,7 +223,14 @@ api.postChat = {
});
}
const newChatMessage = group.sendChat({message: req.body.message, user, flagCount, metaData: null, client, translate: res.t});
const newChatMessage = group.sendChat({message: req.body.message,
user,
flagCount,
metaData: null,
client,
translate: res.t,
mentions,
mentionedMembers});
let toSave = [newChatMessage.save()];
if (group.type === 'party') {
@@ -231,6 +238,7 @@ api.postChat = {
toSave.push(user.save());
}
await Promise.all(toSave);
let analyticsObject = {
@@ -242,7 +250,6 @@ api.postChat = {
headers: req.headers,
};
const mentions = req.body.message.match(mentionRegex);
if (mentions) {
analyticsObject.mentionsCount = mentions.length;
} else {

View File

@@ -21,6 +21,7 @@ import {
import { sendNotification as sendPushNotification } from '../../libs/pushNotifications';
import { achievements } from '../../../../website/common/';
import {sentMessage} from '../../libs/inbox';
import {highlightMentions} from '../../libs/highlightMentions';
let api = {};
@@ -633,7 +634,7 @@ api.sendPrivateMessage = {
if (validationErrors) throw validationErrors;
const sender = res.locals.user;
const message = req.body.message;
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'));