Merge pull request #2962 from matrix-org/jryans/gif-autoplay

Always thumbnail for GIFs
This commit is contained in:
J. Ryan Stinnett 2019-05-14 14:07:58 +01:00 committed by GitHub
commit 66aabdca9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -197,12 +197,18 @@ export default class MImageBody extends React.Component {
// synapse only supports 800x600 thumbnails for now though, // synapse only supports 800x600 thumbnails for now though,
// so we'll need to download the original image for this to work // so we'll need to download the original image for this to work
// well for now. First, let's try a few cases that let us avoid // well for now. First, let's try a few cases that let us avoid
// downloading the original: // downloading the original, including:
if (pixelRatio === 1.0 || // - When displaying a GIF, we always want to thumbnail so that we can
(!content.info || !content.info.w || // properly respect the user's GIF autoplay setting (which relies on
!content.info.h || !content.info.size)) { // thumbnailing to produce the static preview image)
// always thumbnail. it may look a bit worse, but it'll save bandwidth. // - On a low DPI device, always thumbnail to save bandwidth
// which is probably desirable on a lo-dpi device anyway. // - If there's no sizing info in the event, default to thumbnail
const info = content.info;
if (
this._isGif() ||
pixelRatio === 1.0 ||
(!info || !info.w || !info.h || !info.size)
) {
return this.context.matrixClient.mxcUrlToHttp(content.url, thumbWidth, thumbHeight); return this.context.matrixClient.mxcUrlToHttp(content.url, thumbWidth, thumbHeight);
} else { } else {
// we should only request thumbnails if the image is bigger than 800x600 // we should only request thumbnails if the image is bigger than 800x600
@ -215,10 +221,10 @@ export default class MImageBody extends React.Component {
// timeline (e.g. >1MB). // timeline (e.g. >1MB).
const isLargerThanThumbnail = ( const isLargerThanThumbnail = (
content.info.w > thumbWidth || info.w > thumbWidth ||
content.info.h > thumbHeight info.h > thumbHeight
); );
const isLargeFileSize = content.info.size > 1*1024*1024; const isLargeFileSize = info.size > 1*1024*1024;
if (isLargeFileSize && isLargerThanThumbnail) { if (isLargeFileSize && isLargerThanThumbnail) {
// image is too large physically and bytewise to clutter our timeline so // image is too large physically and bytewise to clutter our timeline so