nodebb-plugin-mention fix allowing Redactor to send notifications to mentioned groups
-
Hi Devs,
EDIT: THE BELOW ISSUE WAS RESOLVED -> SEE MY 3rd POST.
I found a weird problem:
Steps to reproduce:
- Post a new topic and mention a group.
- Create a callback and wait for action:notification.pushed
- Print the uids.
The first callback will send a message to all followers.
There used to be a second callback sending the same to the groups. I don't see that anymore.My code is synced to master as of today's AM.
Any idea?
JJ. -
Looks like the issue stems from the Mention plugin.
Mentions.notify returns early since the regex was not successful identifying a match. See below failed code.
@julian and @baris this might be a bug.Mentions.notify = function(data) { var postData = data.post; var cleanedContent = Mentions.clean(postData.content, true, true, true); var matches = cleanedContent.match(rawRegex); if (!matches) { return; }
-
Took some time to review the plugin code and twitter's @Mention code. Originally I thought the issue was due to non-unicode regex, but it turns out your search string was perfect.
I should have mentioned that I am using nodebb-plugin-composer-redactor (and yeah, I am dying to replace it with nodebb-plugin-composer-quill once the plugin is completed - its almost showtime: see: https://community.nodebb.org/topic/12856/nodebb-plugin-composer-quill-wysiwyg-alternative-to-redactor).
Well, it turns out that redactor inserts html tags into the post content, and while the mention plugin was 99.9999(+Ɛ)% redactor proof, it was missing a tiny piece of code that gets rid of the tags.
To that end, kindly consider the following very minor changes to the mention plugin:
- In package.json add the lib:
"striptags": "^3.1.1"
- In library.js add striptags:
Line 20:
var striptags = require('striptags');
Line: 80:
var cleanedContent = Mentions.clean(striptags(postData.content, [], '\n'), true, true, true);
That's it. Once done, Redactor will work with Mentions and RTL languages will be supported as a bonus.
You may want to close the below issue in github once said changes are committed: https://github.com/julianlam/nodebb-plugin-mentions/issues/60
I got to learn Regex today and went to sleep dreaming of solving the mysteries of the universe with unicode search strings.
Have fun
JJ.