nodebb-plugin-mentions 4.7.6 → 4.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,8 +1,8 @@
1
- Copyright (c) 2013-2014, Julian Lam <julian@designcreateplay.com>
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
1
+ Copyright (c) 2013-2014, Julian Lam <julian@designcreateplay.com>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
8
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
- # Username/Group Mentions
2
-
3
- This NodeBB plugin allows posters to reference (or *mention*) other users or groups on a NodeBB by simply
4
- precluding the `@` symbol before a username.
5
-
6
- A link is automatically added to the post.
7
-
8
- ## Installation
9
-
10
- This plugin is bundled with every NodeBB install. If not, you can install it via the Plugins page of the ACP.
11
-
12
- Alternatively,
13
-
1
+ # Username/Group Mentions
2
+
3
+ This NodeBB plugin allows posters to reference (or *mention*) other users or groups on a NodeBB by simply
4
+ precluding the `@` symbol before a username.
5
+
6
+ A link is automatically added to the post.
7
+
8
+ ## Installation
9
+
10
+ This plugin is bundled with every NodeBB install. If not, you can install it via the Plugins page of the ACP.
11
+
12
+ Alternatively,
13
+
14
14
  npm install nodebb-plugin-mentions
package/library.js CHANGED
@@ -360,11 +360,17 @@ Mentions.getMatches = async (content) => {
360
360
  // Exported method only accepts markdown, also filters out dupes and matches to ensure slugs exist
361
361
  let { matches } = await getMatches(content, true);
362
362
  matches = await filterMatches(matches);
363
+ if (!matches.length) {
364
+ return new Set();
365
+ }
366
+
363
367
  const normalized = matches.map(match => match.slice(1).toLowerCase());
364
- const [uids, cids] = await Promise.all([
368
+ let [uids, localCids, remoteCids] = await Promise.all([
365
369
  User.getUidsByUserslugs(normalized),
366
370
  db.sortedSetScores('categoryhandle:cid', normalized),
371
+ db.getObjectFields('handle:cid', normalized),
367
372
  ]);
373
+ remoteCids = Object.values(remoteCids);
368
374
 
369
375
  matches = matches.map((slug, idx) => {
370
376
  if (uids[idx]) {
@@ -373,10 +379,10 @@ Mentions.getMatches = async (content) => {
373
379
  id: uids[idx],
374
380
  slug,
375
381
  };
376
- } else if (cids[idx]) {
382
+ } else if (localCids[idx] || remoteCids[idx]) {
377
383
  return {
378
384
  type: 'cid',
379
- id: cids[idx],
385
+ id: localCids[idx] || remoteCids[idx],
380
386
  slug,
381
387
  };
382
388
  }
@@ -389,9 +395,11 @@ Mentions.getMatches = async (content) => {
389
395
 
390
396
  async function filterMatches(matches) {
391
397
  matches = Array.from(new Set(matches));
392
- const exists = await meta.userOrGroupExists(matches.map(match => match.slice(1)));
398
+ const slugs = matches.map(match => match.slice(1));
399
+ const exists = await meta.slugTaken(slugs);
400
+ const remoteCidExists = await db.isObjectFields('handle:cid', slugs);
393
401
 
394
- return matches.filter((m, i) => exists[[i]]);
402
+ return matches.filter((m, i) => exists[i] || remoteCidExists[i]);
395
403
  }
396
404
 
397
405
  Mentions.parseRaw = async (content, type = 'default') => {
@@ -593,17 +601,21 @@ SocketPlugins.mentions.userSearch = async (socket, data) => {
593
601
  ).concat(fullnameUsers);
594
602
  }
595
603
 
596
- if (Mentions._settings.privilegedDirectReplies !== 'on') {
597
- return users;
598
- }
604
+ if (Mentions._settings.privilegedDirectReplies === 'on') {
605
+ if (data.composerObj) {
606
+ const cid = Topics.getTopicField(data.composerObj.tid, 'cid');
607
+ const filteredUids = await filterPrivilegedUids(users.map(userObj => userObj.uid), cid, data.composerObj.toPid);
599
608
 
600
- if (data.composerObj) {
601
- const cid = Topics.getTopicField(data.composerObj.tid, 'cid');
602
- const filteredUids = await filterPrivilegedUids(users.map(userObj => userObj.uid), cid, data.composerObj.toPid);
609
+ users = users.filter(userObj => filteredUids.includes(userObj.uid));
610
+ }
603
611
 
604
- users = users.filter(userObj => filteredUids.includes(userObj.uid));
612
+ return users;
605
613
  }
606
614
 
607
- return users;
615
+ // Remote categories
616
+ let { categories: categoriesObj } = await categories.search(data);
617
+ categoriesObj = categoriesObj.filter(category => !utils.isNumber(category.cid));
618
+
619
+ return [...users, ...categoriesObj];
608
620
  };
609
621