nodebb-plugin-mentions 4.0.2 → 4.0.4

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/library.js CHANGED
@@ -96,12 +96,12 @@ Mentions.notify = async function (data) {
96
96
  return;
97
97
  }
98
98
 
99
- const [topic, author, topicFollowers] = await Promise.all([
99
+ const [topic, userData, topicFollowers] = await Promise.all([
100
100
  Topics.getTopicFields(postData.tid, ['title', 'cid']),
101
- User.getUserField(postData.uid, 'username'),
101
+ User.getUserFields(postData.uid, ['username']),
102
102
  Mentions._settings.disableFollowedTopics === 'on' ? Topics.getFollowers(postData.tid) : [],
103
103
  ]);
104
-
104
+ const { displayname } = userData;
105
105
  const title = entitiesDecode(topic.title);
106
106
  const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
107
107
 
@@ -129,7 +129,7 @@ Mentions.notify = async function (data) {
129
129
 
130
130
  const filteredUids = await filterUidsAlreadyMentioned(uids, postData.pid);
131
131
  if (filteredUids.length) {
132
- await sendNotificationToUids(postData, filteredUids, 'user', `[[notifications:user_mentioned_you_in, ${author}, ${titleEscaped}]]`);
132
+ await sendNotificationToUids(postData, filteredUids, 'user', `[[notifications:user_mentioned_you_in, ${displayname}, ${titleEscaped}]]`);
133
133
  await db.setAdd(`mentions:pid:${postData.pid}:uids`, filteredUids);
134
134
  }
135
135
 
@@ -139,7 +139,7 @@ Mentions.notify = async function (data) {
139
139
  const groupName = groupsToNotify[i].name;
140
140
  const groupMentionSent = await db.isSetMember(`mentions:pid:${postData.pid}:groups`, groupName);
141
141
  if (!groupMentionSent && memberUids.length) {
142
- await sendNotificationToUids(postData, memberUids, groupName, `[[notifications:user_mentioned_group_in, ${author} , ${groupName}, ${titleEscaped}]]`);
142
+ await sendNotificationToUids(postData, memberUids, groupName, `[[notifications:user_mentioned_group_in, ${displayname} , ${groupName}, ${titleEscaped}]]`);
143
143
  await db.setAdd(`mentions:pid:${postData.pid}:groups`, groupName);
144
144
  }
145
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-mentions",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
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
  "scripts": {
@@ -31,9 +31,9 @@
31
31
  "xregexp": "^5.1.0"
32
32
  },
33
33
  "devDependencies": {
34
- "mocha": "10.0.0",
35
- "eslint": "8.24.0",
36
- "eslint-config-nodebb": "0.1.1",
37
- "eslint-plugin-import": "2.26.0"
34
+ "mocha": "10.2.0",
35
+ "eslint": "8.34.0",
36
+ "eslint-config-nodebb": "0.2.1",
37
+ "eslint-plugin-import": "2.27.5"
38
38
  }
39
39
  }
package/static/admin.js CHANGED
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
- /* globals $, app, socket, define */
4
-
5
3
  define('admin/plugins/mentions', ['settings', 'alerts'], function (Settings, alerts) {
6
-
7
- var ACP = {};
4
+ const ACP = {};
8
5
 
9
6
  ACP.init = function () {
10
7
  Settings.load('mentions', $('.mentions-settings'));
@@ -18,9 +15,10 @@ define('admin/plugins/mentions', ['settings', 'alerts'], function (Settings, ale
18
15
  alert_id: 'mentions-saved',
19
16
  title: 'Settings Saved',
20
17
  message: 'Please reload your NodeBB to apply these settings',
18
+ timeout: 5000,
21
19
  clickfn: function () {
22
20
  socket.emit('admin.reload');
23
- }
21
+ },
24
22
  });
25
23
  });
26
24
  });
@@ -34,4 +32,4 @@ define('admin/plugins/mentions', ['settings', 'alerts'], function (Settings, ale
34
32
  }
35
33
 
36
34
  return ACP;
37
- });
35
+ });
@@ -33,12 +33,18 @@ $(document).ready(function () {
33
33
  if (err) {
34
34
  return callback([]);
35
35
  }
36
+ const termLowerCase = term.toLocaleLowerCase();
37
+ const localMatches = localUserList.filter(
38
+ u => u.username.startsWith(termLowerCase)
39
+ );
36
40
 
37
- mentions = mentions.concat(usersToMentions(sortUsers(users), helpers));
41
+ // remove local matches from search results
42
+ users = users.filter(u => !localMatches.find(lu => lu.uid === u.uid));
43
+ mentions = usersToMentions(sortUsers(localMatches).concat(sortUsers(users)), helpers);
38
44
 
39
45
  // Add groups that start with the search term
40
46
  const groupMentions = groupList.filter(function (groupName) {
41
- return groupName.toLocaleLowerCase().startsWith(term.toLocaleLowerCase());
47
+ return groupName.toLocaleLowerCase().startsWith(termLowerCase);
42
48
  }).sort(function (a, b) {
43
49
  return a.toLocaleLowerCase() > b.toLocaleLowerCase() ? 1 : -1;
44
50
  });
@@ -93,21 +99,28 @@ $(document).ready(function () {
93
99
 
94
100
  function loadTopicUsers(element) {
95
101
  require(['composer', 'alerts'], function (composer, alerts) {
96
- const composerEl = element.parents('.composer').get(0);
97
- if (!composerEl) {
98
- return;
102
+ function findTid() {
103
+ const composerEl = element.parents('.composer').get(0);
104
+ if (composerEl) {
105
+ const uuid = composerEl.getAttribute('data-uuid');
106
+ const composerObj = composer.posts[uuid];
107
+ if (composerObj && composerObj.tid) {
108
+ return composerObj.tid;
109
+ }
110
+ }
111
+ if (ajaxify.data.template.topic) {
112
+ return ajaxify.data.tid;
113
+ }
114
+ return null;
99
115
  }
100
116
 
101
- const uuid = composerEl.getAttribute('data-uuid');
102
- const composerObj = composer.posts[uuid];
103
-
104
- if (!composerObj.tid) {
117
+ const tid = findTid();
118
+ if (!tid) {
105
119
  localUserList = [];
106
120
  return;
107
121
  }
108
-
109
122
  socket.emit('plugins.mentions.getTopicUsers', {
110
- tid: composerObj.tid,
123
+ tid: tid,
111
124
  }, function (err, users) {
112
125
  if (err) {
113
126
  return alerts.error(err);
@@ -56,6 +56,4 @@
56
56
  </div>
57
57
  </form>
58
58
 
59
- <button id="save" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored">
60
- <i class="material-icons">save</i>
61
- </button>
59
+ <!-- IMPORT admin/partials/save_button.tpl -->
@@ -1,23 +1,24 @@
1
- 'use strict';
2
-
3
-
4
- const db = module.parent.require('./database');
5
- const batch = module.parent.require('./batch');
6
- module.exports = {
7
- name: 'Delete mentions:sent:<pid> sorted sets',
8
- timestamp: Date.UTC(2021, 10, 2),
9
- method: async function () {
10
- const { progress } = this;
11
- const nextPid = await db.getObjectField('global', 'nextPid');
12
- const allPids = [];
13
- for (let pid = 1; pid < nextPid; ++ pid) {
14
- allPids.push(pid);
15
- }
16
- await batch.processArray(allPids, async (pids) => {
17
- progress.incr(pids.length);
18
- await db.deleteAll(pids.map(pid => `mentions:sent:${pid}`));
19
- }, {
20
- batch: 500,
21
- });
22
- },
1
+ 'use strict';
2
+
3
+
4
+ const db = module.parent.require('./database');
5
+ const batch = module.parent.require('./batch');
6
+ module.exports = {
7
+ name: 'Delete mentions:sent:<pid> sorted sets',
8
+ timestamp: Date.UTC(2021, 10, 2),
9
+ method: async function () {
10
+ const { progress } = this;
11
+ const nextPid = await db.getObjectField('global', 'nextPid');
12
+ const allPids = [];
13
+ for (let pid = 1; pid < nextPid; ++pid) {
14
+ allPids.push(pid);
15
+ }
16
+ progress.total = allPids.length;
17
+ await batch.processArray(allPids, async (pids) => {
18
+ progress.incr(pids.length);
19
+ await db.deleteAll(pids.map(pid => `mentions:sent:${pid}`));
20
+ }, {
21
+ batch: 500,
22
+ });
23
+ },
23
24
  };