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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-mentions",
3
- "version": "4.7.6",
3
+ "version": "4.8.1",
4
4
  "description": "NodeBB Plugin that allows users to mention other users by prepending an '@' sign to their username",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -33,6 +33,6 @@
33
33
  "eslint": "^9.25.1",
34
34
  "eslint-config-nodebb": "^1.1.4",
35
35
  "eslint-plugin-import": "^2.31.0",
36
- "mocha": "11.2.2"
36
+ "mocha": "11.7.4"
37
37
  }
38
38
  }
@@ -6,6 +6,7 @@ $(document).ready(function () {
6
6
  let categoryList;
7
7
  const categorySlugMap = new Map();
8
8
  let localUserList = [];
9
+ let helpers;
9
10
 
10
11
  $(window).on('composer:autocomplete:init chat:autocomplete:init', function (ev, data) {
11
12
  loadTopicUsers(data.element);
@@ -22,11 +23,11 @@ $(document).ready(function () {
22
23
  const strategy = {
23
24
  match: /\B@([^\s\n]*)?$/,
24
25
  search: function (term, callback) {
25
- require(['composer', 'helpers', 'slugify'], function (composer, helpers, _slugify) {
26
+ require(['composer', 'helpers', 'slugify'], function (composer, _helpers, _slugify) {
26
27
  slugify = _slugify;
27
- let mentions = [];
28
+ helpers = _helpers;
28
29
  if (!term) {
29
- mentions = entriesToMentions(sortEntries(localUserList), helpers);
30
+ const mentions = entriesToMentions(sortEntries(localUserList), helpers);
30
31
  return callback(mentions);
31
32
  }
32
33
 
@@ -56,7 +57,7 @@ $(document).ready(function () {
56
57
  // remove local matches from search results, add category matches
57
58
  users = users.filter(u => !localMatches.find(lu => lu.uid === u.uid));
58
59
  users = sortEntries(localMatches).concat(sortEntries([...users, ...categoryMatches]));
59
- mentions = entriesToMentions(users, helpers);
60
+ // mentions = entriesToMentions(users, helpers);
60
61
 
61
62
  // Add groups that start with the search term
62
63
  const groupMentions = groupList.filter(function (groupName) {
@@ -64,28 +65,22 @@ $(document).ready(function () {
64
65
  }).sort(function (a, b) {
65
66
  return a.toLocaleLowerCase() > b.toLocaleLowerCase() ? 1 : -1;
66
67
  });
68
+
67
69
  // Add group mentions at the bottom of dropdown
68
- mentions = mentions.concat(groupMentions);
70
+ // mentions = mentions.concat(groupMentions);
69
71
 
70
- callback(mentions);
72
+ callback([...users, ...groupMentions]);
71
73
  });
72
74
  });
73
75
  },
74
76
  index: 1,
77
+ template: entryToMention,
75
78
  replace: function (mention) {
76
- // Strip (fullname) part from mentions
77
- mention = mention.replace(/ \(.+\)$/, '');
78
- mention = $('<div/>').html(mention);
79
- // Strip letter avatar
80
- mention.find('span').remove();
81
-
82
- const text = mention.text().trim();
83
- const categoryHandle = categorySlugMap.get(text.toLowerCase());
84
- if (categoryHandle) {
85
- return `@${categoryHandle}`;
79
+ if (mention.uid) {
80
+ return `@${mention.userslug}`;
81
+ } else if (mention.cid) {
82
+ return `@${utils.isNumber(mention.cid) ? mention.handle : mention.slug}`;
86
83
  }
87
-
88
- return '@' + slugify(text, true) + ' ';
89
84
  },
90
85
  cache: true,
91
86
  };
@@ -106,6 +101,25 @@ $(document).ready(function () {
106
101
  });
107
102
  }
108
103
 
104
+ function entryToMention(entry) {
105
+ // Format suggestions as 'avatar username/name (fullname/slug)'
106
+ switch(true) {
107
+ case entry.hasOwnProperty('uid'): {
108
+ const avatar = helpers.buildAvatar(entry, '24px', true);
109
+ const fullname = entry.fullname ? `(${entry.fullname})` : '';
110
+ return `${avatar} ${entry.username || entry.name} ${helpers.escape(fullname)}`;
111
+ }
112
+
113
+ case entry.hasOwnProperty('cid'): {
114
+ const avatar = helpers.buildCategoryIcon(entry, '24px', 'rounded-circle');
115
+ return `${avatar} ${entry.name}${!utils.isNumber(entry.cid) ? ` (${entry.slug})` : ''}`;
116
+ }
117
+
118
+ default:
119
+ return entry.name;
120
+ }
121
+ }
122
+
109
123
  function entriesToMentions(entries, helpers) {
110
124
  return entries.reduce(function (carry, entry) {
111
125
  // Don't add current user to suggestions
@@ -113,11 +127,7 @@ $(document).ready(function () {
113
127
  return carry;
114
128
  }
115
129
 
116
- // Format suggestions as 'avatar username/name (fullname)'
117
- const avatar = entry.uid ? helpers.buildAvatar(entry, '24px', true) : '';
118
- const fullname = entry.fullname ? `(${entry.fullname})` : '';
119
- carry.push(`${avatar} ${entry.username || entry.name} ${helpers.escape(fullname)}`);
120
-
130
+ carry.push(entryToMention(entry));
121
131
  return carry;
122
132
  }, []);
123
133
  }