nodebb-plugin-link-preview 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/library.js +23 -2
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -9,6 +9,8 @@ const { load } = require('cheerio');
9
9
  const meta = require.main.require('./src/meta');
10
10
  const cache = require.main.require('./src/cache');
11
11
  const posts = require.main.require('./src/posts');
12
+ const topics = require.main.require('./src/topics');
13
+ const websockets = require.main.require('./src/socket.io');
12
14
  const postsCache = require.main.require('./src/posts/cache');
13
15
 
14
16
  const controllers = require('./lib/controllers');
@@ -49,7 +51,8 @@ async function process(content, opts) {
49
51
  const url = $anchor.attr('href');
50
52
 
51
53
  if ($anchor.hasClass('plugin-mentions-a')) {
52
- break;
54
+ // eslint-disable-next-line no-continue
55
+ continue;
53
56
  }
54
57
 
55
58
  const cached = cache.get(`link-preview:${url}`);
@@ -93,8 +96,23 @@ async function process(content, opts) {
93
96
  winston.verbose(`[link-preview] ${preview.url} (${preview.contentType}, cache: miss)`);
94
97
  cache.set(`link-preview:${url}`, preview);
95
98
 
99
+ // bust posts cache item
96
100
  if (opts.hasOwnProperty('pid') && await posts.exists(opts.pid)) {
97
101
  postsCache.del(String(opts.pid));
102
+
103
+ // fire post edit event with mocked data
104
+ if (opts.hasOwnProperty('tid') && await topics.exists(opts.tid)) {
105
+ $anchor.replaceWith($(await render(preview)));
106
+ websockets.in(`topic_${opts.tid}`).emit('event:post_edited', {
107
+ post: {
108
+ tid: opts.tid,
109
+ pid: opts.pid,
110
+ changed: true,
111
+ content: $.html(),
112
+ },
113
+ topic: {},
114
+ });
115
+ }
98
116
  }
99
117
  }).catch(() => {
100
118
  winston.verbose(`[link-preview] ${url} (invalid, cache: miss)`);
@@ -138,7 +156,10 @@ plugin.onParse = async (payload) => {
138
156
  if (typeof payload === 'string') { // raw
139
157
  payload = await process(payload, {});
140
158
  } else if (payload && payload.postData && payload.postData.content) { // post
141
- payload.postData.content = await process(payload.postData.content, { pid: payload.postData.pid });
159
+ payload.postData.content = await process(payload.postData.content, {
160
+ pid: payload.postData.pid,
161
+ tid: payload.postData.tid,
162
+ });
142
163
  }
143
164
 
144
165
  return payload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-link-preview",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A starter kit for quickly creating NodeBB plugins",
5
5
  "main": "library.js",
6
6
  "repository": {