@nodebb/nodebb-plugin-reactions 3.1.5 → 3.1.6

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
@@ -30,46 +30,25 @@ function parse(name) {
30
30
  return emoji ? emojiParser.buildEmoji(emoji, '') : '';
31
31
  }
32
32
 
33
- async function parseReaction(name, sourceUrl) {
33
+ async function parseReaction(name) {
34
+ // Local emoji: name has no colon, resolve from table
34
35
  const emoji = nameToEmoji(name) || helpers.getEmojiTable()[helpers.getEmojiAliases()[name]];
35
36
  if (emoji) {
36
37
  return emojiParser.buildEmoji(emoji, '');
37
38
  }
38
39
 
39
- // Try to find the custom emoji: first by source URL hostname, then by scanning emoji:ap:lookup
40
- let hostname = null;
41
- if (typeof sourceUrl === 'string') {
42
- try {
43
- hostname = new URL(sourceUrl).hostname;
44
- } catch (e) {
45
- // Not a valid URL (e.g. numeric pid)
46
- }
47
- }
48
-
49
- let metadata = null;
50
- if (hostname) {
51
- metadata = await activitypub.emoji.getEmoji(name, hostname);
52
- }
53
-
54
- // Fallback: scan emoji:ap:lookup for any entry matching this shortcode
55
- if (!metadata) {
56
- const allKeys = await db.getObjectKeys('emoji:ap:lookup');
57
- if (allKeys && allKeys.length > 0) {
58
- const matchKey = allKeys.find(k => k.startsWith(`${name}:`));
59
- if (matchKey) {
60
- const idx = matchKey.indexOf(':');
61
- if (idx !== -1) {
62
- hostname = matchKey.slice(idx + 1);
63
- metadata = await activitypub.emoji.getEmoji(name, hostname);
64
- }
65
- }
40
+ // Custom emoji: name is stored as shortcode:hostname (buildFieldKey format)
41
+ const idx = name.indexOf(':');
42
+ if (idx !== -1) {
43
+ const shortcode = name.slice(0, idx);
44
+ const hostname = name.slice(idx + 1);
45
+ const metadata = await activitypub.emoji.getEmoji(shortcode, hostname);
46
+ if (metadata) {
47
+ const proxyUrl = activitypub.emoji.getProxyUrl(shortcode, hostname);
48
+ return `<img class="not-responsive emoji" src="${proxyUrl}" title=":${shortcode}:" />`;
66
49
  }
67
50
  }
68
51
 
69
- if (metadata) {
70
- const proxyUrl = activitypub.emoji.getProxyUrl(name, hostname);
71
- return `<img class="not-responsive emoji" src="${proxyUrl}" title=":${name}:" />`;
72
- }
73
52
  return '';
74
53
  }
75
54
 
@@ -193,7 +172,7 @@ ReactionsPlugin.getPostReactions = async function (data) {
193
172
  for (const reaction of reactions) {
194
173
  const reactionSet = `pid:${post.pid}:reaction:${reaction}`;
195
174
  const uids = reactionSetToUsersMap.get(reactionSet);
196
- const reactionImage = await parseReaction(reaction, post.pid);
175
+ const reactionImage = await parseReaction(reaction);
197
176
  if (Array.isArray(uids) && reactionImage) {
198
177
  post.reactions.push({
199
178
  pid: post.pid,
@@ -258,7 +237,7 @@ ReactionsPlugin.getMessageReactions = async function (data) {
258
237
  for (const reaction of reactions) {
259
238
  const reactionSet = `mid:${msg.mid}:reaction:${reaction}`;
260
239
  const uids = reactionSetToUsersMap.get(reactionSet);
261
- const reactionImage = await parseReaction(reaction, msg.mid);
240
+ const reactionImage = await parseReaction(reaction);
262
241
  if (Array.isArray(uids) && reactionImage) {
263
242
  msg.reactions.push({
264
243
  mid: msg.mid,
@@ -333,7 +312,7 @@ async function sendPostEvent(data, eventName) {
333
312
  reaction: data.reaction,
334
313
  reactionCount,
335
314
  totalReactions,
336
- reactionImage: await parseReaction(data.reaction, data.pid),
315
+ reactionImage: await parseReaction(data.reaction),
337
316
  });
338
317
  } catch (e) {
339
318
  console.error(e);
@@ -357,7 +336,7 @@ async function sendMessageEvent(data, eventName) {
357
336
  reaction: data.reaction,
358
337
  reactionCount,
359
338
  totalReactions,
360
- reactionImage: await parseReaction(data.reaction, data.mid),
339
+ reactionImage: await parseReaction(data.reaction),
361
340
  });
362
341
  } catch (e) {
363
342
  console.error(e);
@@ -572,7 +551,16 @@ ReactionsPlugin.applyEmojiReact = async function (activity) {
572
551
  cacheTag = null;
573
552
  }
574
553
  if (cacheTag) {
575
- await activitypub.emoji.cacheEmoji(cacheTag);
554
+ const cached = await activitypub.emoji.cacheEmoji(cacheTag);
555
+ if (cached) {
556
+ // Use the normalized icon from cacheTag to extract hostname
557
+ const hostname = activitypub.emoji.extractHostname(cacheTag.icon);
558
+ if (hostname) {
559
+ // Store reaction as qualified name: shortcode:hostname
560
+ // (matches the emoji:ap:lookup field key for direct lookup)
561
+ reaction = activitypub.emoji.buildFieldKey(reaction, hostname);
562
+ }
563
+ }
576
564
  }
577
565
  }
578
566
 
@@ -602,7 +590,23 @@ ReactionsPlugin.undoEmojiReact = async function (activity) {
602
590
  return false;
603
591
  }
604
592
 
605
- const reaction = typeof resolved === 'object' ? resolved.emoji : resolved;
593
+ let reaction;
594
+ let emojiTag;
595
+ if (typeof resolved === 'object' && resolved.emoji) {
596
+ reaction = resolved.emoji;
597
+ emojiTag = resolved.emojiTag;
598
+ } else {
599
+ reaction = resolved;
600
+ }
601
+
602
+ // Rebuild qualified name for custom emoji (must match the stored name)
603
+ if (emojiTag) {
604
+ const icon = emojiTag.icon || (emojiTag.id ? { url: emojiTag.id } : null);
605
+ const hostname = activitypub.emoji.extractHostname(icon);
606
+ if (hostname) {
607
+ reaction = activitypub.emoji.buildFieldKey(reaction, hostname);
608
+ }
609
+ }
606
610
 
607
611
  activitypub.helpers.log(`[reactions/ap] undo id ${id} (${reaction}) via ${actor}`);
608
612
  await ReactionsPlugin.removePostReaction(id, actor, reaction);
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nodebb-plugin-reactions",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "nodebb-plugin-reactions",
9
- "version": "3.1.5",
9
+ "version": "3.1.6",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "eslint": "10.6.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodebb/nodebb-plugin-reactions",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "nbbpm": {
5
5
  "compatibility": "^4.16.0"
6
6
  },