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

Commit 6fa005d

Browse files
t3chguyrichvdh
andauthored
Inhibit interactions on forward dialog message previews (#11025)
* Inhibit interactions on forward dialog message previews and improve inhibiting of video message body * Consolidate prop types * Iterate * Update src/components/views/messages/IBodyProps.ts Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
1 parent 7d36c83 commit 6fa005d

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

src/components/views/dialogs/ForwardDialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
284284
mx_IRCLayout: previewLayout == Layout.IRC,
285285
})}
286286
>
287-
<EventTile mxEvent={mockEvent} layout={previewLayout} permalinkCreator={permalinkCreator} as="div" />
287+
<EventTile
288+
mxEvent={mockEvent}
289+
layout={previewLayout}
290+
permalinkCreator={permalinkCreator}
291+
as="div"
292+
inhibitInteraction
293+
/>
288294
</div>
289295
<hr />
290296
<div className="mx_ForwardList" id="mx_ForwardList">

src/components/views/messages/IBodyProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ export interface IBodyProps {
5555
getRelationsForEvent?: GetRelationsForEvent;
5656

5757
ref?: React.RefObject<any> | LegacyRef<any>;
58+
59+
// Set to `true` to disable interactions (e.g. video controls) and to remove controls from the tab order.
60+
// This may be useful when displaying a preview of the event.
61+
inhibitInteraction?: boolean;
5862
}

src/components/views/messages/MVideoBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
234234

235235
public render(): React.ReactNode {
236236
const content = this.props.mxEvent.getContent();
237-
const autoplay = SettingsStore.getValue("autoplayVideo");
237+
const autoplay = !this.props.inhibitInteraction && SettingsStore.getValue("autoplayVideo");
238238

239239
let aspectRatio;
240240
if (content.info?.w && content.info?.h) {
@@ -287,7 +287,7 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
287287
ref={this.videoRef}
288288
src={contentUrl}
289289
title={content.body}
290-
controls
290+
controls={!this.props.inhibitInteraction}
291291
// Disable downloading as it doesn't work with e2ee video,
292292
// users should use the dedicated Download button in the Message Action Bar
293293
controlsList="nodownload"

src/components/views/messages/MessageEvent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
213213
mediaEventHelper={this.mediaHelper}
214214
getRelationsForEvent={this.props.getRelationsForEvent}
215215
isSeeingThroughMessageHiddenForModeration={this.props.isSeeingThroughMessageHiddenForModeration}
216+
inhibitInteraction={this.props.inhibitInteraction}
216217
/>
217218
) : null;
218219
}

src/events/EventTileFactory.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import { MatrixClient } from "matrix-js-sdk/src/client";
2323
import { GroupCallIntent } from "matrix-js-sdk/src/webrtc/groupCall";
2424

2525
import SettingsStore from "../settings/SettingsStore";
26-
import EditorStateTransfer from "../utils/EditorStateTransfer";
27-
import { RoomPermalinkCreator } from "../utils/permalinks/Permalinks";
2826
import LegacyCallEventGrouper from "../components/structures/LegacyCallEventGrouper";
29-
import { GetRelationsForEvent } from "../components/views/rooms/EventTile";
27+
import { EventTileProps } from "../components/views/rooms/EventTile";
3028
import { TimelineRenderingType } from "../contexts/RoomContext";
3129
import MessageEvent from "../components/views/messages/MessageEvent";
3230
import MKeyVerificationConclusion from "../components/views/messages/MKeyVerificationConclusion";
@@ -56,20 +54,24 @@ import {
5654
} from "../voice-broadcast";
5755

5856
// Subset of EventTile's IProps plus some mixins
59-
export interface EventTileTypeProps {
57+
export interface EventTileTypeProps
58+
extends Pick<
59+
EventTileProps,
60+
| "mxEvent"
61+
| "highlights"
62+
| "highlightLink"
63+
| "showUrlPreview"
64+
| "onHeightChanged"
65+
| "forExport"
66+
| "getRelationsForEvent"
67+
| "editState"
68+
| "replacingEventId"
69+
| "permalinkCreator"
70+
| "callEventGrouper"
71+
| "isSeeingThroughMessageHiddenForModeration"
72+
| "inhibitInteraction"
73+
> {
6074
ref?: React.RefObject<any>; // `any` because it's effectively impossible to convince TS of a reasonable type
61-
mxEvent: MatrixEvent;
62-
highlights?: string[];
63-
highlightLink?: string;
64-
showUrlPreview?: boolean;
65-
onHeightChanged?: () => void;
66-
forExport?: boolean;
67-
getRelationsForEvent?: GetRelationsForEvent;
68-
editState?: EditorStateTransfer;
69-
replacingEventId?: string;
70-
permalinkCreator?: RoomPermalinkCreator;
71-
callEventGrouper?: LegacyCallEventGrouper;
72-
isSeeingThroughMessageHiddenForModeration?: boolean;
7375
timestamp?: JSX.Element;
7476
maxImageHeight?: number; // pixels
7577
overrideBodyTypes?: Record<string, typeof React.Component>;
@@ -322,6 +324,7 @@ export function renderTile(
322324
getRelationsForEvent,
323325
isSeeingThroughMessageHiddenForModeration,
324326
timestamp,
327+
inhibitInteraction,
325328
} = props;
326329

327330
switch (renderType) {
@@ -340,6 +343,7 @@ export function renderTile(
340343
getRelationsForEvent,
341344
isSeeingThroughMessageHiddenForModeration,
342345
permalinkCreator,
346+
inhibitInteraction,
343347
});
344348
default:
345349
// NEARLY ALL THE OPTIONS!
@@ -357,6 +361,7 @@ export function renderTile(
357361
getRelationsForEvent,
358362
isSeeingThroughMessageHiddenForModeration,
359363
timestamp,
364+
inhibitInteraction,
360365
});
361366
}
362367
}

0 commit comments

Comments
 (0)