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

Commit ac4aea1

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 <bubu@bubu1.eu> Signed-off-by: Marcus Hoffmann <bubu@bubu1.eu> Signed-off-by: Tulir Asokan <tulir@maunium.net>
1 parent 5a1633d commit ac4aea1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/views/messages/MVideoBody.tsx

Lines changed: 14 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,31 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
252254
preload = "none";
253255
}
254256
}
257+
let onMouseOver, onMouseOut;
258+
if (!autoplay && !controls) {
259+
onMouseOver = event => (event.target as HTMLVideoElement).play();
260+
onMouseOut = event => {
261+
(event.target as HTMLVideoElement).pause();
262+
(event.target as HTMLVideoElement).currentTime = 0;
263+
};
264+
}
255265
return (
256266
<span className="mx_MVideoBody">
257267
<video
258268
className="mx_MVideoBody"
259269
ref={this.videoRef}
260270
src={contentUrl}
261271
title={content.body}
262-
controls
272+
controls={controls}
273+
loop={loop}
263274
preload={preload}
264275
muted={autoplay}
265276
autoPlay={autoplay}
266277
height={height}
267278
width={width}
268279
poster={poster}
280+
onMouseOver={onMouseOver}
281+
onMouseOut={onMouseOut}
269282
onPlay={this.videoOnPlay}
270283
/>
271284
{ this.props.tileShape && <MFileBody {...this.props} showGenericPlaceholder={false} /> }

0 commit comments

Comments
 (0)