aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/messages.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/messages.js')
-rw-r--r--src/features/messages.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 245e1ce..91fc22d 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -36,7 +36,7 @@ import { loadMediaIndex, saveMediaIndex, wipeMediaIndex } from '../media-cache.j
import { mergeFeedWindow } from '../feed-window.js';
import { createThreadStore } from '../thread-cache.js';
import { createThreadPrefetch } from '../thread-prefetch.js';
-import { makeImageThumbnails } from '../image-thumbnails.js';
+import { makeImageThumbnails, loopGif } from '../image-thumbnails.js';
import { createFeedCache, FEED_CACHE_POSTS, FEED_SEED_POSTS } from '../feed-cache.js';
import { POPULAR_RELAYS, FIREHOSE_RELAYS, popularCandidates } from '../popular-feed.js';
import { makeSearcher, resultRows, fallbackAvatar, warmSearch, punkImageUrl, punkSmallUrl, primalCache, searchRecipients, searchable, setLocalPeople } from '../recipient-search.js';
@@ -6988,6 +6988,8 @@ export function messagesFeature(ctx) {
if (!r) return null;
const dims = JSON.parse(r.headers.get('x-dims') || 'null');
if (!dims || !dims.width) return null;
+ // a GIF kept before GIFs were looped: made again, to loop
+ if (r.headers.get('x-original') === '1' && r.headers.get('x-gif') !== '1' && /\.gif(\?|$)/i.test(url)) return null;
const src = r.headers.get('x-original') === '1' ? null : URL.createObjectURL(await r.blob());
return { ...dims, thumb: src };
} catch { return null; }
@@ -7003,17 +7005,22 @@ export function messagesFeature(ctx) {
if (e && e.corsRefused) { noteNoCors(url); corsRefused.add(url); } // refused, as corsFetch confirmed
return null;
}
+ const gif = /gif/i.test(blob.type);
+ // a GIF that would play once and stop is painted from a copy that loops
+ let looped = null;
+ // (up to 4 MB: the copy is kept on disk beside the column copies)
+ if (gif && blob.size < 4e6) { try { const fixed = loopGif(await blob.arrayBuffer()); if (fixed) looped = new Blob([fixed], { type: 'image/gif' }); } catch {} }
const result = await makeImageThumbnails(blob, {
width: MEDIA_THUMB_W, tileSize: tileThumbs.has(url) ? 0 : TILE_PX,
});
if (!result) return null;
- const dims = { width: result.width, height: result.height }, out = result.media;
+ const dims = { width: result.width, height: result.height }, out = result.media || looped;
// Both sizes share one decode in the worker; only cache writes and object
// URLs come back to the page. The lightbox still uses the original.
if (result.tile) await saveTileThumb(url, result.tile).catch(() => {});
try {
const store = await thumbStore();
- await store.put(url, new Response(out || new Blob(), { headers: { 'x-dims': JSON.stringify(dims), 'x-original': out ? '0' : '1' } }));
+ await store.put(url, new Response(out || new Blob(), { headers: { 'x-dims': JSON.stringify(dims), 'x-original': out ? '0' : '1', ...(gif ? { 'x-gif': '1' } : {}) } }));
const keys = await store.keys();
for (const k of keys.slice(0, Math.max(0, keys.length - MEDIA_THUMB_MAX))) store.delete(k);
} catch {}
@@ -10959,7 +10966,7 @@ export function messagesFeature(ctx) {
return h('img', {
src: mediaSrc(url, known), 'data-pic': url, class: 'note-img clickable', loading: feedPaint || known ? 'eager' : 'lazy', alt: label || '',
// a few-ms decode of the copy paints with the page; an original never holds the page for its decode
- decoding: known && known.thumb ? 'sync' : 'async',
+ decoding: known && known.thumb && !/\.gif(\?|$)/i.test(url) ? 'sync' : 'async', // (a looped GIF's copy is the whole animation)
width: size?.width, height: size?.height,
style: size ? 'height:auto;aspect-ratio:' + size.width + '/' + size.height + ';--ar:' + (size.width / size.height).toFixed(4) : undefined,
onClick: (e) => { if (!onPicture(e)) return; e.stopPropagation(); openPicture(url, e); },