Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Improve Telegram gif handling
Browse files Browse the repository at this point in the history
Telegram (and basically all other modern chat apps) use video files instead of
actual .gif files for any features called "gifs", which makes sense because gif
files are huge. However, Matrix doesn't have such modern features, so users
will see a full video player instead of a nice looping gif. This change adds
support for simple custom flags that can be used to make the video player
behave similar to actual .gif files.

The flags are set by the Telegram bridge here: https://github.com/mautrix/telegram/blob/v0.10.1/mautrix_telegram/portal/telegram.py#L252-L260

Co-authored-by: Marcus Hoffmann <[email protected]>
Signed-off-by: Marcus Hoffmann <[email protected]>
Signed-off-by: Tulir Asokan <[email protected]>
  • Loading branch information
Bubu authored and tulir committed Aug 20, 2021
1 parent 5a1633d commit ac4aea1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/views/messages/MVideoBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>

const contentUrl = this.getContentUrl();
const thumbUrl = this.getThumbUrl();
const loop = Boolean(content.info?.["fi.mau.loop"]);
const controls = !content.info?.["fi.mau.hide_controls"];
let height = null;
let width = null;
let poster = null;
Expand All @@ -252,20 +254,31 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
preload = "none";
}
}
let onMouseOver, onMouseOut;
if (!autoplay && !controls) {
onMouseOver = event => (event.target as HTMLVideoElement).play();
onMouseOut = event => {
(event.target as HTMLVideoElement).pause();
(event.target as HTMLVideoElement).currentTime = 0;
};
}
return (
<span className="mx_MVideoBody">
<video
className="mx_MVideoBody"
ref={this.videoRef}
src={contentUrl}
title={content.body}
controls
controls={controls}
loop={loop}
preload={preload}
muted={autoplay}
autoPlay={autoplay}
height={height}
width={width}
poster={poster}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
onPlay={this.videoOnPlay}
/>
{ this.props.tileShape && <MFileBody {...this.props} showGenericPlaceholder={false} /> }
Expand Down

0 comments on commit ac4aea1

Please sign in to comment.