nodebb-plugin-mentions 4.1.1 → 4.3.0
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/controllers.js +4 -1
- package/library.js +38 -0
- package/package.json +3 -3
- package/plugin.json +1 -0
- package/templates/admin/plugins/mentions.tpl +61 -53
package/controllers.js
CHANGED
|
@@ -6,5 +6,8 @@ const Controllers = module.exports;
|
|
|
6
6
|
|
|
7
7
|
Controllers.renderAdminPage = async function (req, res) {
|
|
8
8
|
const groupData = await groups.getGroupsFromSet('groups:visible:createtime', 0, -1);
|
|
9
|
-
res.render('admin/plugins/mentions', {
|
|
9
|
+
res.render('admin/plugins/mentions', {
|
|
10
|
+
groups: groupData,
|
|
11
|
+
title: '[[notifications:mentions]]',
|
|
12
|
+
});
|
|
10
13
|
};
|
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.
|
|
3
|
+
"version": "4.3.0",
|
|
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.
|
|
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.
|
|
35
|
+
"eslint": "8.44.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" }
|
|
@@ -1,59 +1,67 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
<div class="acp-page-container">
|
|
2
|
+
<!-- IMPORT admin/partials/settings/header.tpl -->
|
|
3
|
+
|
|
4
|
+
<div class="row m-0">
|
|
5
|
+
<div id="spy-container" class="col-12 col-md-8 px-0 mb-4" tabindex="0">
|
|
6
|
+
<form role="form" class="mentions-settings">
|
|
7
|
+
<div class="mb-4">
|
|
8
|
+
<h5 class="fw-bold tracking-tight settings-header">General</h5>
|
|
9
|
+
|
|
10
|
+
<div class="mb-3 form-check">
|
|
11
|
+
<input type="checkbox" class="form-check-input" id="autofillGroups" name="autofillGroups" />
|
|
12
|
+
<label for="autofillGroups" class="form-check-label">
|
|
13
|
+
<span>Allow mentioning User Groups</span>
|
|
14
|
+
</label>
|
|
15
|
+
</div>
|
|
16
|
+
<div class="mb-3 form-check">
|
|
17
|
+
<input type="checkbox" class="form-check-input" id="overrideIgnores" name="overrideIgnores" />
|
|
18
|
+
<label for="overrideIgnores" class="form-check-label">
|
|
19
|
+
<span>Notify recipients of mentions even if topic is explictly ignored</span>
|
|
20
|
+
</label>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="mb-3">
|
|
23
|
+
<label class="form-label" for="disableGroupMentions">Select groups you wish to disable mentions</label>
|
|
24
|
+
<select class="form-select" id="disableGroupMentions" name="disableGroupMentions" multiple>
|
|
25
|
+
<!-- BEGIN groups -->
|
|
26
|
+
<option value="{groups.displayName}">{groups.displayName}</option>
|
|
27
|
+
<!-- END groups -->
|
|
28
|
+
</select>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="mb-3">
|
|
31
|
+
<label class="form-label" for="display">Mentions will display ...</label>
|
|
32
|
+
<select class="form-select" id="display" name="display">
|
|
33
|
+
<option value="">... as written</option>
|
|
34
|
+
<option value="fullname">... as user's full name (if set)</option>
|
|
35
|
+
<option value="username">... as user's username</option>
|
|
36
|
+
</select>
|
|
37
|
+
</div>
|
|
35
38
|
|
|
36
|
-
<div class="row">
|
|
37
|
-
<div class="col-sm-2 col-12 settings-header">Restrictions</div>
|
|
38
|
-
<div class="col-sm-10 col-12">
|
|
39
|
-
<div class="mb-3">
|
|
40
|
-
<div class="mb-3 form-check">
|
|
41
|
-
<input type="checkbox" class="form-check-input" id="disableFollowedTopics" name="disableFollowedTopics" />
|
|
42
|
-
<label for="disableFollowedTopics" class="form-check-label">
|
|
43
|
-
<span>Disable mentions for followed topics</span>
|
|
44
|
-
</label>
|
|
45
39
|
</div>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<
|
|
51
|
-
<
|
|
52
|
-
|
|
40
|
+
|
|
41
|
+
<div class="mb-4">
|
|
42
|
+
<h5 class="fw-bold tracking-tight settings-header">Restrictions</h5>
|
|
43
|
+
|
|
44
|
+
<div class="mb-3">
|
|
45
|
+
<div class="mb-3 form-check">
|
|
46
|
+
<input type="checkbox" class="form-check-input" id="disableFollowedTopics" name="disableFollowedTopics" />
|
|
47
|
+
<label for="disableFollowedTopics" class="form-check-label">
|
|
48
|
+
<span>Disable mentions for followed topics</span>
|
|
49
|
+
</label>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
<div class="mb-3">
|
|
53
|
+
<div class="mb-3 form-check">
|
|
54
|
+
<input type="checkbox" class="form-check-input" id="privilegedDirectReplies" name="privilegedDirectReplies" />
|
|
55
|
+
<label for="privilegedDirectReplies" class="form-check-label">
|
|
56
|
+
<span>Restrict mentions to privileged users (mods, global mods, administrators), unless it is a direct reply to a post</span>
|
|
57
|
+
</label>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
53
60
|
</div>
|
|
54
|
-
</
|
|
61
|
+
</form>
|
|
55
62
|
</div>
|
|
63
|
+
|
|
64
|
+
<!-- IMPORT admin/partials/settings/toc.tpl -->
|
|
56
65
|
</div>
|
|
57
|
-
</
|
|
66
|
+
</div>
|
|
58
67
|
|
|
59
|
-
<!-- IMPORT admin/partials/save_button.tpl -->
|