nodebb-plugin-mentions 3.0.2 → 3.0.6

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
@@ -170,10 +170,12 @@ async function getGroupsToNotify(matches) {
170
170
  }
171
171
 
172
172
  Mentions.actionPostPurge = async (hookData) => {
173
- await db.deleteAll([
174
- `mentions:pid:${hookData.postData.pid}:uids`,
175
- `mentions:pid:${hookData.postData.pid}:groups`,
176
- ]);
173
+ if (hookData && hookData.post) {
174
+ await db.deleteAll([
175
+ `mentions:pid:${hookData.post.pid}:uids`,
176
+ `mentions:pid:${hookData.post.pid}:groups`,
177
+ ]);
178
+ }
177
179
  };
178
180
 
179
181
  async function filterUidsAlreadyMentioned(uids, pid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-mentions",
3
- "version": "3.0.2",
3
+ "version": "3.0.6",
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": "9.1.3",
35
- "eslint": "8.2.0",
36
- "eslint-config-nodebb": "0.0.3",
37
- "eslint-plugin-import": "2.25.2"
34
+ "mocha": "9.2.0",
35
+ "eslint": "8.9.0",
36
+ "eslint-config-nodebb": "0.1.1",
37
+ "eslint-plugin-import": "2.25.4"
38
38
  }
39
39
  }
package/plugin.json CHANGED
@@ -22,9 +22,9 @@
22
22
  "scripts": [
23
23
  "static/autofill.js"
24
24
  ],
25
- "acpScripts": [
26
- "static/admin.js"
27
- ],
25
+ "modules": {
26
+ "../admin/plugins/mentions.js": "./static/admin.js"
27
+ },
28
28
  "languages": "languages",
29
29
  "defaultLang": "en_GB",
30
30
  "templates": "templates"
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "nodebb/public"
3
+ }
package/static/admin.js CHANGED
@@ -1,36 +1,37 @@
1
- 'use strict';
2
- /* globals $, app, socket */
3
-
4
- define('admin/plugins/mentions', ['settings'], function (Settings) {
5
-
6
- var ACP = {};
7
-
8
- ACP.init = function () {
9
- Settings.load('mentions', $('.mentions-settings'));
10
-
11
- $(window).on('action:admin.settingsLoaded', applyDefaults);
12
-
13
- $('#save').on('click', function () {
14
- Settings.save('mentions', $('.mentions-settings'), function () {
15
- app.alert({
16
- type: 'success',
17
- alert_id: 'mentions-saved',
18
- title: 'Settings Saved',
19
- message: 'Please reload your NodeBB to apply these settings',
20
- clickfn: function () {
21
- socket.emit('admin.reload');
22
- }
23
- });
24
- });
25
- });
26
- };
27
-
28
- function applyDefaults() {
29
- if (!ajaxify.data.settings || !ajaxify.data.settings.hasOwnProperty('autofillGroups')) {
30
- $('input#autofillGroups').parents('.mdl-switch').toggleClass('is-checked', false);
31
- $('input#autofillGroups').prop('checked', false);
32
- }
33
- }
34
-
35
- return ACP;
1
+ 'use strict';
2
+
3
+ /* globals $, app, socket, define */
4
+
5
+ define('admin/plugins/mentions', ['settings', 'alerts'], function (Settings, alerts) {
6
+
7
+ var ACP = {};
8
+
9
+ ACP.init = function () {
10
+ Settings.load('mentions', $('.mentions-settings'));
11
+
12
+ $(window).on('action:admin.settingsLoaded', applyDefaults);
13
+
14
+ $('#save').on('click', function () {
15
+ Settings.save('mentions', $('.mentions-settings'), function () {
16
+ alerts.alert({
17
+ type: 'success',
18
+ alert_id: 'mentions-saved',
19
+ title: 'Settings Saved',
20
+ message: 'Please reload your NodeBB to apply these settings',
21
+ clickfn: function () {
22
+ socket.emit('admin.reload');
23
+ }
24
+ });
25
+ });
26
+ });
27
+ };
28
+
29
+ function applyDefaults() {
30
+ if (!ajaxify.data.settings || !ajaxify.data.settings.hasOwnProperty('autofillGroups')) {
31
+ $('input#autofillGroups').parents('.mdl-switch').toggleClass('is-checked', false);
32
+ $('input#autofillGroups').prop('checked', false);
33
+ }
34
+ }
35
+
36
+ return ACP;
36
37
  });
@@ -1,12 +1,11 @@
1
- "use strict";
2
- /* globals socket, app */
3
1
 
2
+ 'use strict';
4
3
 
5
- $(document).ready(function() {
4
+ $(document).ready(function () {
6
5
  let groupList = [];
7
6
  let localUserList = [];
8
7
 
9
- $(window).on('composer:autocomplete:init chat:autocomplete:init', function(ev, data) {
8
+ $(window).on('composer:autocomplete:init chat:autocomplete:init', function (ev, data) {
10
9
  loadTopicUsers(data.element);
11
10
 
12
11
  if (!groupList.length) {
@@ -30,7 +29,7 @@ $(document).ready(function() {
30
29
  socket.emit('plugins.mentions.userSearch', {
31
30
  query: term,
32
31
  composerObj: composer.posts[uuid],
33
- }, function(err, users) {
32
+ }, function (err, users) {
34
33
  if (err) {
35
34
  return callback([]);
36
35
  }
@@ -40,7 +39,7 @@ $(document).ready(function() {
40
39
  // Add groups that start with the search term
41
40
  const groupMentions = groupList.filter(function (groupName) {
42
41
  return groupName.toLocaleLowerCase().startsWith(term.toLocaleLowerCase());
43
- }).sort(function(a, b) {
42
+ }).sort(function (a, b) {
44
43
  return a.toLocaleLowerCase() > b.toLocaleLowerCase() ? 1 : -1;
45
44
  });
46
45
  // Add group mentions at the bottom of dropdown
@@ -59,24 +58,24 @@ $(document).ready(function() {
59
58
  mention.find('span').remove();
60
59
  return '@' + slugify(mention.text(), true) + ' ';
61
60
  },
62
- cache: true
61
+ cache: true,
63
62
  };
64
63
 
65
64
  data.strategies.push(strategy);
66
65
  });
67
66
 
68
- $(window).on('action:composer.loaded', function(e, data) {
67
+ $(window).on('action:composer.loaded', function (ev, data) {
69
68
  const composer = $('#cmp-uuid-' + data.post_uuid + ' .write');
70
69
  composer.attr('data-mentions', '1');
71
70
  });
72
71
 
73
- function sortUsers (users) {
72
+ function sortUsers(users) {
74
73
  return users.sort(function (user1, user2) {
75
74
  return user1.username.toLocaleLowerCase() > user2.username.toLocaleLowerCase() ? 1 : -1;
76
75
  });
77
76
  }
78
77
 
79
- function usersToMentions (users, helpers) {
78
+ function usersToMentions(users, helpers) {
80
79
  return users.reduce(function (carry, user) {
81
80
  // Don't add current user to suggestions
82
81
  if (app.user.username && app.user.username === user.username) {
@@ -93,7 +92,7 @@ $(document).ready(function() {
93
92
  }
94
93
 
95
94
  function loadTopicUsers(element) {
96
- require(['composer'], function (composer) {
95
+ require(['composer', 'alerts'], function (composer, alerts) {
97
96
  const composerEl = element.parents('.composer').get(0);
98
97
  if (!composerEl) {
99
98
  return;
@@ -110,18 +109,23 @@ $(document).ready(function() {
110
109
  socket.emit('plugins.mentions.getTopicUsers', {
111
110
  tid: composerObj.tid,
112
111
  }, function (err, users) {
112
+ if (err) {
113
+ return alerts.error(err);
114
+ }
113
115
  localUserList = users;
114
116
  });
115
117
  });
116
118
  }
117
119
 
118
120
  function loadGroupList() {
119
- socket.emit('plugins.mentions.listGroups', function(err, groupNames) {
121
+ socket.emit('plugins.mentions.listGroups', function (err, groupNames) {
120
122
  if (err) {
121
- return app.alertError(err.message);
123
+ require(['alerts'], function (alerts) {
124
+ alerts.error(err);
125
+ });
126
+ return;
122
127
  }
123
128
  groupList = groupNames;
124
129
  });
125
130
  }
126
-
127
131
  });