@nodebb/nodebb-plugin-reactions 2.0.0 → 2.0.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/README.md CHANGED
@@ -1,2 +1,12 @@
1
1
  # nodebb-plugin-reactions
2
2
  Reactions plugin for NodeBB
3
+
4
+ # Screenshots
5
+
6
+ ## Reactions:
7
+ ![CleanShot 2023-05-11 at 08 53 48@2x](https://github.com/ShlomoCode/nodebb-plugin-reactions/assets/78599753/613cb49e-994a-4869-a721-c1eeb00959ff)
8
+
9
+
10
+ ## ACP:
11
+ ![CleanShot 2023-05-11 at 04 09 11@2x](https://github.com/ShlomoCode/nodebb-plugin-reactions/assets/78599753/f4a4e5cb-f060-4415-a337-222a157a6e59)
12
+
@@ -3,8 +3,11 @@
3
3
  "add-reaction": "Add reaction",
4
4
  "error.invalid-reaction": "Invalid reaction",
5
5
  "error.maximum-reached": "Maximum reactions reached",
6
+ "error.maximum-per-user-per-post-reached": "Maximum reactions per user per post reached",
6
7
  "settings.title": "Reactions plugin settings",
7
- "settings.max-reactions-per-post": "Maximum unique reactions per post",
8
+ "settings.max-reactions-per-post": "Maximum unique reactions per post (0 for unlimited, default: 4)",
9
+ "settings.max-reactions-per-user-per-post": "Maximum reactions per user per post (0 for unlimited)",
10
+ "settings.max-reactions-per-user-per-post-help": "The limit is enforced only when adding a new reaction and not when joining an existing reaction.",
8
11
  "settings.reaction-reputations": "Reaction Reputations (Optional)",
9
12
  "settings.reaction-reputations-help": "You can assign a reputation to individual reactions. When a reaction is applied to a post, the owner of that post will get this reputation.",
10
13
  "settings.reaction-reputations.add": "Add Rule",
@@ -3,8 +3,11 @@
3
3
  "add-reaction": "הוסף תגובה",
4
4
  "error.invalid-reaction": "תגובה לא חוקית",
5
5
  "error.maximum-reached": "הגעת למספר התגובות המקסימלי לפוסט",
6
+ "error.maximum-per-user-per-post-reached": "הגעת למספר התגובות המקסימלי למשתמש לפוסט",
6
7
  "settings.title": "הגדרות תגובות",
7
- "settings.max-reactions-per-post": "מספר התגובות המקסימלי לפוסט",
8
+ "settings.max-reactions-per-post": "מספר התגובות המקסימלי לפוסט (0 = ללא הגבלה, ברירת מחדל: 4)",
9
+ "settings.max-reactions-per-user-per-post": "מספר התגובות המקסימלי למשתמש לפוסט (0 = ללא הגבלה)",
10
+ "settings.max-reactions-per-user-per-post-help": ".ההגבלה נאכפת רק בהוספת תגובה חדשה ולא בהצטרפות לתגובה קיימת",
8
11
  "settings.reaction-reputations": "מוניטין תגובה (אופציונלי)",
9
12
  "settings.reaction-reputations-help": "אתה יכול להקצות מוניטין לתגובות מסוימות. כאשר התגובה נוספת לפוסט, בעל הפוסט יקבל את המוניטין שנקבע.",
10
13
  "settings.reaction-reputations.add": "הוסף כלל",
package/library.js CHANGED
@@ -13,7 +13,7 @@ const emojiParser = require.main.require('nodebb-plugin-emoji/build/lib/parse.js
13
13
  const emojiTable = require.main.require('nodebb-plugin-emoji/build/emoji/table.json');
14
14
  const emojiAliases = require.main.require('nodebb-plugin-emoji/build/emoji/aliases.json');
15
15
 
16
- const DEFAULT_MAX_EMOTES = 5;
16
+ const DEFAULT_MAX_EMOTES = 4;
17
17
 
18
18
  function parse(name) {
19
19
  return emojiParser.buildEmoji(emojiTable[name] || emojiTable[emojiAliases[name]], '');
@@ -71,7 +71,7 @@ ReactionsPlugin.getReactions = async function (data) {
71
71
 
72
72
  if (reactionsList && reactionsList.length > 0) {
73
73
  pidToReactionsMap.set(pid, reactionsList);
74
- pidToIsMaxReactionsReachedMap.set(pid, reactionsCount >= maximumReactions);
74
+ pidToIsMaxReactionsReachedMap.set(pid, reactionsCount > maximumReactions);
75
75
  reactionSets = reactionSets.concat(reactionsList.map(reaction => `pid:${pid}:reaction:${reaction}`));
76
76
  }
77
77
  } catch (e) {
@@ -205,16 +205,29 @@ SocketPlugins.reactions = {
205
205
 
206
206
  const settings = await meta.settings.get('reactions');
207
207
  const maximumReactions = settings.maximumReactions || DEFAULT_MAX_EMOTES;
208
- const [totalReactions, isMember, alreadyReacted, reactionReputation] = await Promise.all([
208
+ const [totalReactions, emojiIsAlreadyExist, alreadyReacted, reactionReputation] = await Promise.all([
209
209
  db.setCount(`pid:${data.pid}:reactions`),
210
210
  db.isSetMember(`pid:${data.pid}:reactions`, data.reaction),
211
211
  db.isSetMember(`pid:${data.pid}:reaction:${data.reaction}`, socket.uid),
212
212
  getReactionReputation(data.reaction),
213
213
  ]);
214
214
 
215
- if (!isMember && totalReactions >= maximumReactions) {
216
- throw new Error('[[reactions:error.maximum-reached]]');
215
+ if (!emojiIsAlreadyExist) {
216
+ if (totalReactions > maximumReactions) {
217
+ throw new Error(`[[reactions:error.maximum-reached]] (${maximumReactions})`);
218
+ }
219
+
220
+ const maximumReactionsPerUserPerPost = settings.maximumReactionsPerUserPerPost ? parseInt(settings.maximumReactionsPerUserPerPost, 10) : 0;
221
+ if (maximumReactionsPerUserPerPost > 0) {
222
+ const emojiesInPost = await db.getSetMembers(`pid:${data.pid}:reactions`);
223
+ const userPostReactions = await db.isMemberOfSets(emojiesInPost.map(emojiName => `pid:${data.pid}:reaction:${emojiName}`), socket.uid);
224
+ const userPostReactionCount = userPostReactions.filter(Boolean).length;
225
+ if (userPostReactionCount > maximumReactionsPerUserPerPost) {
226
+ throw new Error(`[[reactions:error.maximum-per-user-per-post-reached]] (${maximumReactionsPerUserPerPost})`);
227
+ }
228
+ }
217
229
  }
230
+
218
231
 
219
232
  await Promise.all([
220
233
  db.setAdd(`pid:${data.pid}:reactions`, data.reaction),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodebb/nodebb-plugin-reactions",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "nbbpm": {
5
5
  "compatibility": "^3.0.0"
6
6
  },
package/public/client.js CHANGED
@@ -74,10 +74,10 @@ $(document).ready(function () {
74
74
  }
75
75
 
76
76
  function updateReactionCount(data) {
77
- var maxReactionsReached = parseInt(data.totalReactions, 10) >= config.maximumReactions;
77
+ var maxReactionsReached = parseInt(data.totalReactions, 10) > config.maximumReactions;
78
78
  $('[component="post/reaction/add"][data-pid="' + data.pid + '"]').toggleClass('max-reactions', maxReactionsReached);
79
79
 
80
- var reactionEl = $('[component="post/reaction"][data-pid="' + data.pid + '"][data-reaction="' + data.reaction + '"]');
80
+ var reactionEl = $(`[component="post/reaction"][data-pid="${data.pid}"][data-reaction="${data.reaction}"]`);
81
81
 
82
82
  if (parseInt(data.reactionCount, 10) === 0) {
83
83
  reactionEl.tooltip('dispose');
@@ -94,21 +94,23 @@ $(document).ready(function () {
94
94
  reactionImage: data.reactionImage,
95
95
  }, function (html) {
96
96
  $('[component="post/reactions"][data-pid="' + data.pid + '"]').append(html);
97
- createReactionTooltips();
98
97
  });
99
98
  } else {
100
99
  reactionEl.find('.reaction-emoji-count').attr('data-count', data.reactionCount);
101
- reactionEl.attr('data-original-title', data.usernames);
100
+ reactionEl.attr('data-bs-original-title', data.usernames);
101
+ reactionEl.attr('aria-label', data.usernames);
102
102
  reactionEl.toggleClass('reacted', !(parseInt(data.uid, 10) === app.user.uid));
103
103
  }
104
+ createReactionTooltips();
104
105
  }
105
106
 
106
107
  function createReactionTooltips() {
107
108
  $('.reaction, .reaction-add').each(function () {
108
109
  if (!utils.isTouchDevice()) {
110
+ $(this).tooltip('dispose');
109
111
  $(this).tooltip({
110
112
  placement: 'top',
111
- title: $(this).attr('title'),
113
+ title: $(this).attr('title') || $(this).attr('data-bs-original-title'),
112
114
  });
113
115
  }
114
116
  });
@@ -4,13 +4,20 @@
4
4
  <div class="col-sm-10 col-xs-12">
5
5
  <div class="form-group">
6
6
  <label>[[reactions:settings.max-reactions-per-post]]</label>
7
- <input type="text" class="form-control" id="maximumReactions" name="maximumReactions">
7
+ <input type="number" min="0" class="form-control" id="maximumReactions" name="maximumReactions">
8
+
9
+ <label>[[reactions:settings.max-reactions-per-user-per-post]]</label>
10
+ <input type="number" min="0" class="form-control" id="maximumReactionsPerUserPerPost" name="maximumReactionsPerUserPerPost">
11
+ <p class="help-text">
12
+ [[reactions:settings.max-reactions-per-user-per-post-help]]
13
+ </p>
8
14
  </div>
9
15
  </div>
10
16
  </div>
11
- <div class="row">
17
+
18
+ <div class="row mt-3">
12
19
  <div class="col-sm-2 col-xs-12 settings-header">[[reactions:settings.reaction-reputations]]</div>
13
- <div class="col-sm-10 col-xs-12 mt-2">
20
+ <div class="col-sm-10 col-xs-12">
14
21
  <p class="help-text">
15
22
  [[reactions:settings.reaction-reputations-help]]
16
23
  </p>