@@ -82,7 +82,9 @@ async function preview(url) {
82
82
} ) ;
83
83
}
84
84
85
- async function process ( content , opts ) {
85
+ async function process ( content , { type, pid, tid } ) {
86
+ const inlineTypes = [ 'default' , 'activitypub.article' ] ;
87
+ const processInline = inlineTypes . includes ( type ) ;
86
88
const { embedHtml, embedImage, embedAudio, embedVideo } = await meta . settings . get ( 'link-preview' ) ;
87
89
if ( ! [ embedHtml , embedImage , embedAudio , embedVideo ] . some ( prop => prop === 'on' ) ) {
88
90
return content ;
@@ -91,8 +93,8 @@ async function process(content, opts) {
91
93
const requests = new Map ( ) ;
92
94
93
95
// Retrieve attachments
94
- if ( opts . hasOwnProperty ( ' pid' ) && await posts . exists ( opts . pid ) ) {
95
- const attachments = await posts . attachments . get ( opts . pid ) ;
96
+ if ( pid && await posts . exists ( pid ) ) {
97
+ const attachments = await posts . attachments . get ( pid ) ;
96
98
attachments . forEach ( ( { url, _type } ) => {
97
99
const type = _type || 'attachment' ;
98
100
requests . set ( url , { type } ) ;
@@ -117,9 +119,11 @@ async function process(content, opts) {
117
119
url = `${ nconf . get ( 'url' ) } ${ url . startsWith ( '/' ) ? url : `/${ url } ` } ` ;
118
120
}
119
121
120
- const special = await handleSpecialEmbed ( url , $anchor ) ;
121
- if ( special ) {
122
- continue ;
122
+ if ( ! processInline ) {
123
+ const special = await handleSpecialEmbed ( url , $anchor ) ;
124
+ if ( special ) {
125
+ continue ;
126
+ }
123
127
}
124
128
125
129
// Inline url takes precedence over attachment
@@ -140,8 +144,10 @@ async function process(content, opts) {
140
144
if ( html ) {
141
145
switch ( options . type ) {
142
146
case 'inline' : {
143
- const $anchor = options . target ;
144
- $anchor . replaceWith ( $ ( html ) ) ;
147
+ if ( processInline ) {
148
+ const $anchor = options . target ;
149
+ $anchor . replaceWith ( $ ( html ) ) ;
150
+ }
145
151
break ;
146
152
}
147
153
@@ -174,8 +180,10 @@ async function process(content, opts) {
174
180
if ( html ) {
175
181
switch ( options . type ) {
176
182
case 'inline' : {
177
- const $anchor = options . target ;
178
- $anchor . replaceWith ( $ ( html ) ) ;
183
+ if ( processInline ) {
184
+ const $anchor = options . target ;
185
+ $anchor . replaceWith ( $ ( html ) ) ;
186
+ }
179
187
break ;
180
188
}
181
189
@@ -191,15 +199,15 @@ async function process(content, opts) {
191
199
content += attachmentHtml ? `\n\n<div class="row">${ attachmentHtml } </div>` : '' ;
192
200
193
201
// bust posts cache item
194
- if ( opts . hasOwnProperty ( ' pid' ) && await posts . exists ( opts . pid ) ) {
195
- postsCache . del ( String ( opts . pid ) ) ;
202
+ if ( pid && await posts . exists ( pid ) ) {
203
+ posts . clearCachedPost ( pid ) ;
196
204
197
205
// fire post edit event with mocked data
198
- if ( opts . hasOwnProperty ( ' tid' ) && await topics . exists ( opts . tid ) ) {
199
- websockets . in ( `topic_${ opts . tid } ` ) . emit ( 'event:post_edited' , {
206
+ if ( tid && await topics . exists ( tid ) ) {
207
+ websockets . in ( `topic_${ tid } ` ) . emit ( 'event:post_edited' , {
200
208
post : {
201
- tid : opts . tid ,
202
- pid : opts . pid ,
209
+ tid,
210
+ pid,
203
211
changed : true ,
204
212
content,
205
213
} ,
@@ -289,10 +297,12 @@ async function handleSpecialEmbed(url, $anchor) {
289
297
290
298
plugin . onParse = async ( payload ) => {
291
299
if ( typeof payload === 'string' ) { // raw
292
- payload = await process ( payload , { } ) ;
300
+ const type = 'default' ;
301
+ payload = await process ( payload , { type } ) ;
293
302
} else if ( payload && payload . postData && payload . postData . content ) { // post
294
303
const { content, pid, tid } = payload . postData ;
295
- payload . postData . content = await process ( content , { pid, tid } ) ;
304
+ const { type } = payload ;
305
+ payload . postData . content = await process ( content , { type, pid, tid } ) ;
296
306
}
297
307
298
308
return payload ;
0 commit comments