mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Send push notifications on mentions
This commit is contained in:
@@ -4,13 +4,14 @@ const mentionRegex = new RegExp('\\B@[-\\w]+', 'g');
|
||||
|
||||
export async function highlightMentions (text) {
|
||||
const mentions = text.match(mentionRegex);
|
||||
let members = [];
|
||||
if (mentions !== null && mentions.length <= 5) {
|
||||
const usernames = mentions.map((mention) => {
|
||||
return mention.substr(1);
|
||||
});
|
||||
let members = await User
|
||||
members = await User
|
||||
.find({'auth.local.username': {$in: usernames}, 'flags.verifiedUsername': true})
|
||||
.select(['auth.local.username', '_id'])
|
||||
.select(['auth.local.username', '_id', 'preferences.pushNotifications', 'pushDevices'])
|
||||
.lean()
|
||||
.exec();
|
||||
members.forEach((member) => {
|
||||
@@ -18,5 +19,5 @@ export async function highlightMentions (text) {
|
||||
text = text.replace(new RegExp(`@${username}(?![\\-\\w])`, 'g'), `[@${username}](/profile/${member._id})`);
|
||||
});
|
||||
}
|
||||
return [text, mentions];
|
||||
return [text, mentions, members];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user