I got a simple mentioning script, it adds a link to the users profile if that user exists.
content = content.replace(/@(\w+)?/g, function(match, contents, offset, content) {
contents = contents.replace(/\s/g, ''); // remove spaces from the mention
if(Meteor.users.find({username: contents}).count() > 0) {
return "<a href=''>@"+Meteor.users.findOne({username: contents}).username+"</a>";
} else {
return contents;
}
});
The problem with this though is that I don’t know how to make mongo search for the string with the removed spaces. If I use a “like” query, then it will find multiple results. I was thinking of maybe storing the original string in another variable and search with that, but that just brings me back to square one: mongo would have to search for all possible results which is very bad.
Any ideas?