@nodebb/nodebb-plugin-reactions 2.1.11 → 2.1.13
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/languages/en-GB/reactions.json +3 -1
- package/library.js +78 -13
- package/package.json +1 -1
- package/lib/.eslintrc +0 -3
|
@@ -19,5 +19,7 @@
|
|
|
19
19
|
"settings.reaction-reputations.reaction": "Reaction",
|
|
20
20
|
"settings.reaction-reputations.reputation": "Reputation",
|
|
21
21
|
"settings.reaction-reputations.remove": "Delete",
|
|
22
|
-
"settings.reaction-reputations.edit": "Edit"
|
|
22
|
+
"settings.reaction-reputations.edit": "Edit",
|
|
23
|
+
"notification.user-has-reacted-with-to-your-post-in-topic": "<strong>%1</strong> has reacted with %2 to your post in <strong>%3</strong>",
|
|
24
|
+
"notification.user-has-reacted-with-to-your-message-in-room": "<strong>%1</strong> has reacted with %2 to your message in <strong class=\"text-nowrap\"><i class=\"fa %3\"></i>%4</strong>"
|
|
23
25
|
}
|
package/library.js
CHANGED
|
@@ -3,21 +3,36 @@
|
|
|
3
3
|
const meta = require.main.require('./src/meta');
|
|
4
4
|
const user = require.main.require('./src/user');
|
|
5
5
|
const posts = require.main.require('./src/posts');
|
|
6
|
+
const topics = require.main.require('./src/topics');
|
|
6
7
|
const messaging = require.main.require('./src/messaging');
|
|
7
8
|
const privileges = require.main.require('./src/privileges');
|
|
8
9
|
const db = require.main.require('./src/database');
|
|
10
|
+
const translator = require.main.require('./src/translator');
|
|
11
|
+
const notifications = require.main.require('./src/notifications');
|
|
9
12
|
const routesHelpers = require.main.require('./src/routes/helpers');
|
|
10
13
|
const websockets = require.main.require('./src/socket.io/index');
|
|
11
14
|
const SocketPlugins = require.main.require('./src/socket.io/plugins');
|
|
12
15
|
|
|
13
16
|
const emojiParser = require.main.require('nodebb-plugin-emoji/build/lib/parse.js');
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
let emojiTable = null;
|
|
19
|
+
let emojiAliases = null;
|
|
16
20
|
|
|
17
21
|
const DEFAULT_MAX_EMOTES = 4;
|
|
18
22
|
|
|
23
|
+
function nameToEmoji(name) {
|
|
24
|
+
if (!emojiTable) {
|
|
25
|
+
emojiTable = require.main.require('nodebb-plugin-emoji/build/emoji/table.json');
|
|
26
|
+
}
|
|
27
|
+
return emojiTable[name];
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
function parse(name) {
|
|
20
|
-
|
|
31
|
+
if (!emojiAliases) {
|
|
32
|
+
emojiAliases = require.main.require('nodebb-plugin-emoji/build/emoji/aliases.json');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return emojiParser.buildEmoji(nameToEmoji(name) || emojiTable[emojiAliases[name]], '');
|
|
21
36
|
}
|
|
22
37
|
|
|
23
38
|
const ReactionsPlugin = module.exports;
|
|
@@ -295,7 +310,7 @@ SocketPlugins.reactions = {
|
|
|
295
310
|
throw new Error('[[error:not-logged-in]]');
|
|
296
311
|
}
|
|
297
312
|
|
|
298
|
-
if (!
|
|
313
|
+
if (!nameToEmoji(data.reaction)) {
|
|
299
314
|
throw new Error('[[reactions:error.invalid-reaction]]');
|
|
300
315
|
}
|
|
301
316
|
|
|
@@ -304,13 +319,14 @@ SocketPlugins.reactions = {
|
|
|
304
319
|
throw new Error('[[error:post-reactions-disabled]]');
|
|
305
320
|
}
|
|
306
321
|
const maximumReactions = settings.maximumReactions || DEFAULT_MAX_EMOTES;
|
|
307
|
-
const [
|
|
308
|
-
posts.
|
|
322
|
+
const [postData, totalReactions, emojiIsAlreadyExist, alreadyReacted, reactionReputation] = await Promise.all([
|
|
323
|
+
posts.getPostFields(data.pid, ['tid', 'uid']),
|
|
309
324
|
db.setCount(`pid:${data.pid}:reactions`),
|
|
310
325
|
db.isSetMember(`pid:${data.pid}:reactions`, data.reaction),
|
|
311
326
|
db.isSetMember(`pid:${data.pid}:reaction:${data.reaction}`, socket.uid),
|
|
312
327
|
getReactionReputation(data.reaction),
|
|
313
328
|
]);
|
|
329
|
+
const { tid } = postData;
|
|
314
330
|
if (!tid) {
|
|
315
331
|
throw new Error('[[error:no-post]]');
|
|
316
332
|
}
|
|
@@ -342,6 +358,28 @@ SocketPlugins.reactions = {
|
|
|
342
358
|
await giveOwnerReactionReputation(reactionReputation, data.pid);
|
|
343
359
|
}
|
|
344
360
|
|
|
361
|
+
if (postData.uid && postData.uid !== socket.uid) {
|
|
362
|
+
const [userData, topicData] = await Promise.all([
|
|
363
|
+
user.getUserFields(socket.uid, ['username', 'fullname']),
|
|
364
|
+
topics.getTopicFields(data.tid, ['title']),
|
|
365
|
+
]);
|
|
366
|
+
const notifObj = await notifications.create({
|
|
367
|
+
bodyShort: translator.compile(
|
|
368
|
+
'reactions:notification.user-has-reacted-with-to-your-post-in-topic',
|
|
369
|
+
userData.displayname,
|
|
370
|
+
`:${data.reaction}:`,
|
|
371
|
+
topicData.title
|
|
372
|
+
),
|
|
373
|
+
nid: `uid:${socket.uid}:pid:${data.pid}:reaction:${data.reaction}`,
|
|
374
|
+
pid: data.pid,
|
|
375
|
+
tid: data.tid,
|
|
376
|
+
from: socket.uid,
|
|
377
|
+
path: `/post/${data.pid}`,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
await notifications.push(notifObj, [postData.uid]);
|
|
381
|
+
}
|
|
382
|
+
|
|
345
383
|
await sendPostEvent(data, 'event:reactions.addPostReaction');
|
|
346
384
|
},
|
|
347
385
|
removePostReaction: async function (socket, data) {
|
|
@@ -349,7 +387,7 @@ SocketPlugins.reactions = {
|
|
|
349
387
|
throw new Error('[[error:not-logged-in]]');
|
|
350
388
|
}
|
|
351
389
|
|
|
352
|
-
if (!
|
|
390
|
+
if (!nameToEmoji(data.reaction)) {
|
|
353
391
|
throw new Error('[[reactions:error.invalid-reaction]]');
|
|
354
392
|
}
|
|
355
393
|
|
|
@@ -387,7 +425,7 @@ SocketPlugins.reactions = {
|
|
|
387
425
|
throw new Error('[[error:not-logged-in]]');
|
|
388
426
|
}
|
|
389
427
|
|
|
390
|
-
if (!
|
|
428
|
+
if (!nameToEmoji(data.reaction)) {
|
|
391
429
|
throw new Error('[[reactions:error.invalid-reaction]]');
|
|
392
430
|
}
|
|
393
431
|
|
|
@@ -396,12 +434,12 @@ SocketPlugins.reactions = {
|
|
|
396
434
|
throw new Error('[[error:post-reactions-disabled]]');
|
|
397
435
|
}
|
|
398
436
|
const maximumReactionsPerMessage = settings.maximumReactionsPerMessage || DEFAULT_MAX_EMOTES;
|
|
399
|
-
const [
|
|
400
|
-
messaging.
|
|
437
|
+
const [msgData, totalReactions, emojiIsAlreadyExist] = await Promise.all([
|
|
438
|
+
messaging.getMessageFields(data.mid, ['roomId', 'fromuid']),
|
|
401
439
|
db.setCount(`mid:${data.mid}:reactions`),
|
|
402
440
|
db.isSetMember(`mid:${data.mid}:reactions`, data.reaction),
|
|
403
441
|
]);
|
|
404
|
-
|
|
442
|
+
const { roomId } = msgData;
|
|
405
443
|
if (!roomId) {
|
|
406
444
|
throw new Error('[[error:no-message]]');
|
|
407
445
|
}
|
|
@@ -431,6 +469,33 @@ SocketPlugins.reactions = {
|
|
|
431
469
|
db.setAdd(`mid:${data.mid}:reaction:${data.reaction}`, socket.uid),
|
|
432
470
|
]);
|
|
433
471
|
|
|
472
|
+
if (msgData.fromuid && msgData.fromuid !== socket.uid) {
|
|
473
|
+
const [userData, roomData] = await Promise.all([
|
|
474
|
+
user.getUserFields(socket.uid, ['username', 'userslug', 'fullname']),
|
|
475
|
+
messaging.getRoomData(roomId),
|
|
476
|
+
]);
|
|
477
|
+
const roomName = roomData.roomName || `[[modules:chat.room-id, ${roomId}]]`;
|
|
478
|
+
const icon = messaging.getRoomIcon(roomData);
|
|
479
|
+
|
|
480
|
+
const notifObj = await notifications.create({
|
|
481
|
+
bodyShort: translator.compile(
|
|
482
|
+
'reactions:notification.user-has-reacted-with-to-your-message-in-room',
|
|
483
|
+
userData.displayname,
|
|
484
|
+
`:${data.reaction}:`,
|
|
485
|
+
icon,
|
|
486
|
+
roomName
|
|
487
|
+
),
|
|
488
|
+
roomIcon: icon,
|
|
489
|
+
nid: `uid:${socket.uid}:mid:${data.mid}:reaction:${data.reaction}`,
|
|
490
|
+
mid: data.mid,
|
|
491
|
+
roomId: roomId,
|
|
492
|
+
from: socket.uid,
|
|
493
|
+
path: `/chats/${roomId}`,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
await notifications.push(notifObj, [msgData.fromuid]);
|
|
497
|
+
}
|
|
498
|
+
|
|
434
499
|
await sendMessageEvent(data, 'event:reactions.addMessageReaction');
|
|
435
500
|
},
|
|
436
501
|
removeMessageReaction: async function (socket, data) {
|
|
@@ -438,7 +503,7 @@ SocketPlugins.reactions = {
|
|
|
438
503
|
throw new Error('[[error:not-logged-in]]');
|
|
439
504
|
}
|
|
440
505
|
|
|
441
|
-
if (!
|
|
506
|
+
if (!nameToEmoji(data.reaction)) {
|
|
442
507
|
throw new Error('[[reactions:error.invalid-reaction]]');
|
|
443
508
|
}
|
|
444
509
|
|
|
@@ -470,7 +535,7 @@ SocketPlugins.reactions = {
|
|
|
470
535
|
if (!socket.uid) {
|
|
471
536
|
throw new Error('[[error:not-logged-in]]');
|
|
472
537
|
}
|
|
473
|
-
if (!
|
|
538
|
+
if (!nameToEmoji(data.reaction)) {
|
|
474
539
|
throw new Error('[[reactions:error.invalid-reaction]]');
|
|
475
540
|
}
|
|
476
541
|
let set = '';
|
package/package.json
CHANGED
package/lib/.eslintrc
DELETED