@nodebb/nodebb-plugin-reactions 2.1.12 → 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.
@@ -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,9 +3,12 @@
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');
@@ -316,13 +319,14 @@ SocketPlugins.reactions = {
316
319
  throw new Error('[[error:post-reactions-disabled]]');
317
320
  }
318
321
  const maximumReactions = settings.maximumReactions || DEFAULT_MAX_EMOTES;
319
- const [tid, totalReactions, emojiIsAlreadyExist, alreadyReacted, reactionReputation] = await Promise.all([
320
- posts.getPostField(data.pid, 'tid'),
322
+ const [postData, totalReactions, emojiIsAlreadyExist, alreadyReacted, reactionReputation] = await Promise.all([
323
+ posts.getPostFields(data.pid, ['tid', 'uid']),
321
324
  db.setCount(`pid:${data.pid}:reactions`),
322
325
  db.isSetMember(`pid:${data.pid}:reactions`, data.reaction),
323
326
  db.isSetMember(`pid:${data.pid}:reaction:${data.reaction}`, socket.uid),
324
327
  getReactionReputation(data.reaction),
325
328
  ]);
329
+ const { tid } = postData;
326
330
  if (!tid) {
327
331
  throw new Error('[[error:no-post]]');
328
332
  }
@@ -354,6 +358,28 @@ SocketPlugins.reactions = {
354
358
  await giveOwnerReactionReputation(reactionReputation, data.pid);
355
359
  }
356
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
+
357
383
  await sendPostEvent(data, 'event:reactions.addPostReaction');
358
384
  },
359
385
  removePostReaction: async function (socket, data) {
@@ -408,12 +434,12 @@ SocketPlugins.reactions = {
408
434
  throw new Error('[[error:post-reactions-disabled]]');
409
435
  }
410
436
  const maximumReactionsPerMessage = settings.maximumReactionsPerMessage || DEFAULT_MAX_EMOTES;
411
- const [roomId, totalReactions, emojiIsAlreadyExist] = await Promise.all([
412
- messaging.getMessageField(data.mid, 'roomId'),
437
+ const [msgData, totalReactions, emojiIsAlreadyExist] = await Promise.all([
438
+ messaging.getMessageFields(data.mid, ['roomId', 'fromuid']),
413
439
  db.setCount(`mid:${data.mid}:reactions`),
414
440
  db.isSetMember(`mid:${data.mid}:reactions`, data.reaction),
415
441
  ]);
416
-
442
+ const { roomId } = msgData;
417
443
  if (!roomId) {
418
444
  throw new Error('[[error:no-message]]');
419
445
  }
@@ -443,6 +469,33 @@ SocketPlugins.reactions = {
443
469
  db.setAdd(`mid:${data.mid}:reaction:${data.reaction}`, socket.uid),
444
470
  ]);
445
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
+
446
499
  await sendMessageEvent(data, 'event:reactions.addMessageReaction');
447
500
  },
448
501
  removeMessageReaction: async function (socket, data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodebb/nodebb-plugin-reactions",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "nbbpm": {
5
5
  "compatibility": "^3.3.0"
6
6
  },
package/lib/.eslintrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "nodebb/public"
3
- }