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

Commit 70d9e37

Browse files
Bubutulir
authored andcommitted
Improve Telegram gif handling
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]>
1 parent 5a1633d commit 70d9e37

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/components/views/messages/MVideoBody.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
236236

237237
const contentUrl = this.getContentUrl();
238238
const thumbUrl = this.getThumbUrl();
239+
const loop = Boolean(content.info?.["fi.mau.loop"]);
240+
const controls = !content.info?.["fi.mau.hide_controls"];
239241
let height = null;
240242
let width = null;
241243
let poster = null;
@@ -252,20 +254,32 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
252254
preload = "none";
253255
}
254256
}
257+
let onMouseOver;
258+
let onMouseOut;
259+
if (!autoplay && !controls) {
260+
onMouseOver = event => (event.target as HTMLVideoElement).play();
261+
onMouseOut = event => {
262+
(event.target as HTMLVideoElement).pause();
263+
(event.target as HTMLVideoElement).currentTime = 0;
264+
};
265+
}
255266
return (
256267
<span className="mx_MVideoBody">
257268
<video
258269
className="mx_MVideoBody"
259270
ref={this.videoRef}
260271
src={contentUrl}
261272
title={content.body}
262-
controls
273+
controls={controls}
274+
loop={loop}
263275
preload={preload}
264276
muted={autoplay}
265277
autoPlay={autoplay}
266278
height={height}
267279
width={width}
268280
poster={poster}
281+
onMouseOver={onMouseOver}
282+
onMouseOut={onMouseOut}
269283
onPlay={this.videoOnPlay}
270284
/>
271285
{ this.props.tileShape && <MFileBody {...this.props} showGenericPlaceholder={false} /> }

0 commit comments

Comments
 (0)