+7
models.js
+7
models.js
···
233
233
return !this.isEmbed;
234
234
}
235
235
236
+
/** @returns {boolean} */
237
+
get isTruncatedFediPost() {
238
+
let handle = this.author?.handle;
239
+
240
+
return handle.endsWith('.ap.brid.gy') && (this.text.endsWith('…') || this.text.endsWith('(…)'));
241
+
}
242
+
236
243
/** @returns {string} */
237
244
get text() {
238
245
return this.record.text;
+42
post_component.js
+42
post_component.js
···
231
231
}
232
232
}
233
233
234
+
if (this.post.isTruncatedFediPost) {
235
+
if (this.post.embed && ('url' in this.post.embed) && typeof this.post.embed.url == 'string') {
236
+
let link = this.buildLoadFediPostLink(this.post.embed.url, p);
237
+
p.append(' ', link);
238
+
}
239
+
}
240
+
234
241
return p;
235
242
}
236
243
···
252
259
}
253
260
254
261
return stats;
262
+
}
263
+
264
+
/** @param {string} originalURL, @param {HTMLElement} p, @returns {AnyElement} */
265
+
266
+
buildLoadFediPostLink(originalURL, p) {
267
+
let link = $tag('a', {
268
+
href: originalURL,
269
+
text: "(Load full post)"
270
+
});
271
+
272
+
link.addEventListener('click', (e) => {
273
+
e.preventDefault();
274
+
link.remove();
275
+
276
+
this.loadFediPost(originalURL, p);
277
+
});
278
+
279
+
return link;
255
280
}
256
281
257
282
/** @returns {AnyElement} */
···
355
380
if (this.post.embed) {
356
381
let embed = new EmbedComponent(this.post, this.post.embed).buildElement();
357
382
div.appendChild(embed);
383
+
}
384
+
}
385
+
386
+
/** @param {string} url, @param {HTMLElement} p, @returns Promise<void> */
387
+
388
+
async loadFediPost(url, p) {
389
+
let host = new URL(url).host;
390
+
let postId = url.replace(/\/$/, '').split('/').reverse()[0];
391
+
let statusURL = `https://${host}/api/v1/statuses/${postId}`;
392
+
393
+
let response = await fetch(statusURL);
394
+
let json = await response.json();
395
+
396
+
if (json.content) {
397
+
// TODO: sanitize the HTML? 😈
398
+
let div = $tag('div.body', { html: json.content });
399
+
p.replaceWith(div);
358
400
}
359
401
}
360
402