nodebb-plugin-mentions 4.2.0 → 4.3.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/library.js CHANGED
@@ -16,6 +16,7 @@ const Topics = require.main.require('./src/topics');
16
16
  const posts = require.main.require('./src/posts');
17
17
  const User = require.main.require('./src/user');
18
18
  const Groups = require.main.require('./src/groups');
19
+ const Messaging = require.main.require('./src/messaging');
19
20
  const Notifications = require.main.require('./src/notifications');
20
21
  const Privileges = require.main.require('./src/privileges');
21
22
  const plugins = require.main.require('./src/plugins');
@@ -152,6 +153,43 @@ Mentions.notify = async function (data) {
152
153
  }
153
154
  };
154
155
 
156
+ Mentions.notifyMessage = async (hookData) => {
157
+ const cleanedContent = Mentions.clean(hookData.data.content, false, true, true);
158
+ let matches = cleanedContent.match(regex);
159
+ if (!Array.isArray(matches) || !matches.length) {
160
+ return;
161
+ }
162
+ const { message } = hookData;
163
+ const { roomId } = message;
164
+ matches = _.uniq(matches.map(slugify));
165
+ const [matchedUids, roomData] = await Promise.all([
166
+ getUidsToNotify(matches),
167
+ Messaging.getRoomData(roomId),
168
+ ]);
169
+ if (!roomData || !matchedUids.length) {
170
+ return;
171
+ }
172
+ const checks = await Promise.all(
173
+ matchedUids.map(uid => !roomData.groups.length || Groups.isMemberOfAny(uid, roomData.groups))
174
+ );
175
+ const uidsToNotify = matchedUids.filter((uid, idx) => checks[idx]);
176
+ if (!uidsToNotify.length) {
177
+ return;
178
+ }
179
+ const roomName = validator.escape(String(roomData.roomName || `Room ${roomId}`));
180
+ const notifObj = await Notifications.create({
181
+ type: 'mention',
182
+ bodyShort: `[[notifications:user_mentioned_you_in, ${message.fromUser.displayname}, ${roomName}]]`,
183
+ bodyLong: message.content,
184
+ nid: `chat:room:${roomId}:mid:${message.messageId}:uid:${message.fromuid}`,
185
+ mid: message.messageId,
186
+ from: message.fromuid,
187
+ path: `/chats/${roomId}`,
188
+ importance: 6,
189
+ });
190
+ await Notifications.push(notifObj, uidsToNotify);
191
+ };
192
+
155
193
  async function getUidsToNotify(matches) {
156
194
  const uids = await db.sortedSetScores('userslug:uid', matches);
157
195
  return _.uniq(uids.filter(Boolean).map(String));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-mentions",
3
- "version": "4.2.0",
3
+ "version": "4.3.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
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/julianlam/nodebb-plugin-mentions/issues"
23
23
  },
24
24
  "nbbpm": {
25
- "compatibility": "^3.0.0"
25
+ "compatibility": "^3.3.0"
26
26
  },
27
27
  "dependencies": {
28
28
  "html-entities": "^2.3.2",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "mocha": "10.2.0",
35
- "eslint": "8.42.0",
35
+ "eslint": "8.45.0",
36
36
  "eslint-config-nodebb": "0.2.1",
37
37
  "eslint-plugin-import": "2.27.5"
38
38
  }
package/plugin.json CHANGED
@@ -15,6 +15,7 @@
15
15
  { "hook": "action:post.save", "method": "notify" },
16
16
  { "hook": "action:post.edit", "method": "notify" },
17
17
  { "hook": "action:posts.purge", "method": "actionPostsPurge" },
18
+ { "hook": "action:messaging.save", "method": "notifyMessage" },
18
19
  { "hook": "filter:notifications.addFilters", "method": "addFilters" },
19
20
  { "hook": "filter:user.notificationTypes", "method": "notificationTypes" },
20
21
  { "hook": "filter:users.addFields", "method": "addFields" }
@@ -4,7 +4,7 @@
4
4
  <div class="row m-0">
5
5
  <div id="spy-container" class="col-12 col-md-8 px-0 mb-4" tabindex="0">
6
6
  <form role="form" class="mentions-settings">
7
- <div class="mb-4">
7
+ <div id="general" class="mb-4">
8
8
  <h5 class="fw-bold tracking-tight settings-header">General</h5>
9
9
 
10
10
  <div class="mb-3 form-check">
@@ -38,7 +38,7 @@
38
38
 
39
39
  </div>
40
40
 
41
- <div class="mb-4">
41
+ <div id="restrictions" class="mb-4">
42
42
  <h5 class="fw-bold tracking-tight settings-header">Restrictions</h5>
43
43
 
44
44
  <div class="mb-3">