This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 819
Move download button for media to the action bar #6386
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0a99f76
Simple POC for moving download button to action bar
turt2live 703cf73
Convert MessageEvent to TS and hoist MediaEventHelper
turt2live 584ffbd
Fix refreshing the page not showing a download
turt2live 040802e
Clean up after POC
turt2live 5fce0cc
Convert images, audio, and voice messages over to the new helper
turt2live ea7513f
Convert MFileBody to TS and use media helper
turt2live d156a56
Share body prop types with an interface
turt2live 7ba0adb
Appease type system
turt2live 623f2e7
Only show download link below media if it's not in the timeline
turt2live b57fff5
Update visual style and sandbox properly
turt2live 31d7de6
Small tweaks
turt2live 4d38218
Appease the linter
turt2live 70e525d
Fix component export
turt2live 32d8da2
Remove useless image reference
turt2live 44e240e
Doc some values
turt2live 5994111
Merge remote-tracking branch 'origin/develop' into travis/voice-messa…
turt2live 7892539
delint
turt2live File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { MatrixEvent } from "matrix-js-sdk/src"; | ||
import { MediaEventHelper } from "../../../utils/MediaEventHelper"; | ||
import React, { createRef } from "react"; | ||
import { RovingAccessibleTooltipButton } from "../../../accessibility/RovingTabIndex"; | ||
import Spinner from "../elements/Spinner"; | ||
import classNames from "classnames"; | ||
import { _t } from "../../../languageHandler"; | ||
import { replaceableComponent } from "../../../utils/replaceableComponent"; | ||
import { DOWNLOAD_ICON_URL } from "./MFileBody"; | ||
|
||
interface IProps { | ||
mxEvent: MatrixEvent; | ||
|
||
// XXX: It can take a cycle or two for the MessageActionBar to have all the props/setup | ||
// required to get us a MediaEventHelper, so we use a getter function instead to prod for | ||
// one. | ||
mediaEventHelperGet: () => MediaEventHelper; | ||
} | ||
|
||
interface IState { | ||
loading: boolean; | ||
blob?: Blob; | ||
} | ||
|
||
@replaceableComponent("views.messages.DownloadActionButton") | ||
export default class DownloadActionButton extends React.PureComponent<IProps, IState> { | ||
private iframe: React.RefObject<HTMLIFrameElement> = createRef(); | ||
|
||
public constructor(props: IProps) { | ||
super(props); | ||
|
||
this.state = { | ||
loading: false, | ||
}; | ||
} | ||
|
||
private onDownloadClick = async () => { | ||
if (this.state.loading) return; | ||
|
||
this.setState({ loading: true }); | ||
|
||
if (this.state.blob) { | ||
// Cheat and trigger a download, again. | ||
return this.onFrameLoad(); | ||
} | ||
|
||
const blob = await this.props.mediaEventHelperGet().sourceBlob.value; | ||
this.setState({ blob }); | ||
}; | ||
|
||
private onFrameLoad = () => { | ||
this.setState({ loading: false }); | ||
|
||
// we aren't showing the iframe, so we can send over the bare minimum styles and such. | ||
this.iframe.current.contentWindow.postMessage({ | ||
imgSrc: DOWNLOAD_ICON_URL, | ||
imgStyle: null, | ||
style: "", | ||
blob: this.state.blob, | ||
download: this.props.mediaEventHelperGet().fileName, | ||
textContent: "", | ||
auto: true, // autodownload | ||
}, '*'); | ||
}; | ||
|
||
public render() { | ||
let spinner: JSX.Element; | ||
if (this.state.loading) { | ||
spinner = <Spinner w={18} h={18} />; | ||
} | ||
|
||
const classes = classNames({ | ||
'mx_MessageActionBar_maskButton': true, | ||
'mx_MessageActionBar_downloadButton': true, | ||
'mx_MessageActionBar_downloadSpinnerButton': !!spinner, | ||
}); | ||
|
||
return <RovingAccessibleTooltipButton | ||
className={classes} | ||
title={spinner ? _t("Downloading") : _t("Download")} | ||
onClick={this.onDownloadClick} | ||
disabled={!!spinner} | ||
> | ||
{ spinner } | ||
{ this.state.blob && <iframe | ||
src={"usercontent/" /* XXX: Like MFileBody, this should come from the skin */} | ||
ref={this.iframe} | ||
onLoad={this.onFrameLoad} | ||
sandbox="allow-scripts allow-downloads allow-downloads-without-user-activation" | ||
style={{ display: "none" }} | ||
/> } | ||
</RovingAccessibleTooltipButton>; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { MatrixEvent } from "matrix-js-sdk/src"; | ||
import { TileShape } from "../rooms/EventTile"; | ||
import { MediaEventHelper } from "../../../utils/MediaEventHelper"; | ||
import EditorStateTransfer from "../../../utils/EditorStateTransfer"; | ||
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks"; | ||
|
||
export interface IBodyProps { | ||
mxEvent: MatrixEvent; | ||
|
||
/* a list of words to highlight */ | ||
highlights: string[]; | ||
|
||
/* link URL for the highlights */ | ||
highlightLink: string; | ||
|
||
/* callback called when dynamic content in events are loaded */ | ||
onHeightChanged: () => void; | ||
|
||
showUrlPreview?: boolean; | ||
tileShape: TileShape; | ||
maxImageHeight?: number; | ||
replacingEventId?: string; | ||
editState?: EditorStateTransfer; | ||
onMessageAllowed: () => void; // TODO: Docs | ||
permalinkCreator: RoomPermalinkCreator; | ||
mediaEventHelper: MediaEventHelper; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { MediaEventHelper } from "../../../utils/MediaEventHelper"; | ||
|
||
export interface IMediaBody { | ||
getMediaHelper(): MediaEventHelper; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.