@nodebb/nodebb-plugin-reactions 3.1.4 → 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,25 +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
- if (typeof sourceUrl === 'string') {
40
- try {
41
- const url = new URL(sourceUrl);
42
- const hostname = url.hostname;
43
- const metadata = await activitypub.emoji.getEmoji(name, hostname);
44
- if (metadata) {
45
- const proxyUrl = activitypub.emoji.getProxyUrl(name, hostname);
46
- return `<img class="not-responsive emoji" src="${proxyUrl}" title=":${name}:" />`;
47
- }
48
- } catch (e) {
49
- // Not a valid URL — skip custom emoji lookup
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}:" />`;
50
49
  }
51
50
  }
51
+
52
52
  return '';
53
53
  }
54
54
 
@@ -172,7 +172,7 @@ ReactionsPlugin.getPostReactions = async function (data) {
172
172
  for (const reaction of reactions) {
173
173
  const reactionSet = `pid:${post.pid}:reaction:${reaction}`;
174
174
  const uids = reactionSetToUsersMap.get(reactionSet);
175
- const reactionImage = await parseReaction(reaction, post.pid);
175
+ const reactionImage = await parseReaction(reaction);
176
176
  if (Array.isArray(uids) && reactionImage) {
177
177
  post.reactions.push({
178
178
  pid: post.pid,
@@ -237,7 +237,7 @@ ReactionsPlugin.getMessageReactions = async function (data) {
237
237
  for (const reaction of reactions) {
238
238
  const reactionSet = `mid:${msg.mid}:reaction:${reaction}`;
239
239
  const uids = reactionSetToUsersMap.get(reactionSet);
240
- const reactionImage = await parseReaction(reaction, msg.mid);
240
+ const reactionImage = await parseReaction(reaction);
241
241
  if (Array.isArray(uids) && reactionImage) {
242
242
  msg.reactions.push({
243
243
  mid: msg.mid,
@@ -312,7 +312,7 @@ async function sendPostEvent(data, eventName) {
312
312
  reaction: data.reaction,
313
313
  reactionCount,
314
314
  totalReactions,
315
- reactionImage: await parseReaction(data.reaction, data.pid),
315
+ reactionImage: await parseReaction(data.reaction),
316
316
  });
317
317
  } catch (e) {
318
318
  console.error(e);
@@ -336,7 +336,7 @@ async function sendMessageEvent(data, eventName) {
336
336
  reaction: data.reaction,
337
337
  reactionCount,
338
338
  totalReactions,
339
- reactionImage: await parseReaction(data.reaction, data.mid),
339
+ reactionImage: await parseReaction(data.reaction),
340
340
  });
341
341
  } catch (e) {
342
342
  console.error(e);
@@ -551,7 +551,16 @@ ReactionsPlugin.applyEmojiReact = async function (activity) {
551
551
  cacheTag = null;
552
552
  }
553
553
  if (cacheTag) {
554
- 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
+ }
555
564
  }
556
565
  }
557
566
 
@@ -581,7 +590,23 @@ ReactionsPlugin.undoEmojiReact = async function (activity) {
581
590
  return false;
582
591
  }
583
592
 
584
- 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
+ }
585
610
 
586
611
  activitypub.helpers.log(`[reactions/ap] undo id ${id} (${reaction}) via ${actor}`);
587
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.4",
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.4",
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.4",
3
+ "version": "3.1.6",
4
4
  "nbbpm": {
5
5
  "compatibility": "^4.16.0"
6
6
  },