Get rid of mediaSrc and avatarSrc props

This commit is contained in:
Jaiwanth 2021-06-09 15:23:47 +05:30
parent dbb3614374
commit 573ababb8c
9 changed files with 35 additions and 43 deletions

View file

@ -42,7 +42,7 @@ export default class MAudioBody extends React.Component {
}
_getContentUrl() {
if (this.props.mediaSrc) return this.props.mediaSrc;
if (this.props.forExport) return "forExport";
const media = mediaFromContent(this.props.mxEvent.getContent());
if (media.isEncrypted) {
return this.state.decryptedUrl;
@ -52,7 +52,7 @@ export default class MAudioBody extends React.Component {
}
getFileBody() {
if (this.props.mediaSrc) return null;
if (this.props.forExport) return null;
return <MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />;
}
@ -95,7 +95,7 @@ export default class MAudioBody extends React.Component {
);
}
if (!this.props.mediaSrc && content.file !== undefined && this.state.decryptedUrl === null) {
if (!this.props.forExport && content.file !== undefined && this.state.decryptedUrl === null) {
// Need to decrypt the attachment
// The attachment is decrypted in componentDidMount.
// For now add an img tag with a 16x16 spinner.

View file

@ -102,8 +102,7 @@ export default class MFileBody extends React.Component {
tileShape: PropTypes.string,
/* whether or not to show the default placeholder for the file. Defaults to true. */
showGenericPlaceholder: PropTypes.bool,
/* to set source to local file path during export */
mediaSrc: PropTypes.string,
forExport: PropTypes.bool,
};
@ -152,6 +151,7 @@ export default class MFileBody extends React.Component {
}
_getContentUrl() {
if (this.props.forExport) return null;
const media = mediaFromContent(this.props.mxEvent.getContent());
return media.srcHttp;
}
@ -185,9 +185,9 @@ export default class MFileBody extends React.Component {
);
}
if (this.props.mediaSrc) {
if (this.props.forExport) {
return <span className="mx_MFileBody">
<a href={this.props.mediaSrc}>
<a href="forExport">
{ placeholder }
</a>
</span>;

View file

@ -172,7 +172,7 @@ export default class MImageBody extends React.Component {
}
_getContentUrl() {
if (this.props.mediaSrc) return this.props.mediaSrc;
if (this.props.forExport) return "forExport";
const media = mediaFromContent(this.props.mxEvent.getContent());
if (media.isEncrypted) {
return this.state.decryptedUrl;
@ -370,9 +370,9 @@ export default class MImageBody extends React.Component {
let gifLabel = null;
// e2e image hasn't been decrypted yet
if (!this.props.mediaSrc && content.file !== undefined && this.state.decryptedUrl === null) {
if (!this.props.forExport && content.file !== undefined && this.state.decryptedUrl === null) {
placeholder = <InlineSpinner w={32} h={32} />;
} else if (!this.props.mediaSrc && !this.state.imgLoaded) {
} else if (!this.props.forExport && !this.state.imgLoaded) {
// Deliberately, getSpinner is left unimplemented here, MStickerBody overides
placeholder = this.getPlaceholder();
}
@ -418,7 +418,7 @@ export default class MImageBody extends React.Component {
</div>
}
<div style={{display: this.props.mediaSrc ? "block" : !showPlaceholder ? undefined : 'none'}}>
<div style={{display: showPlaceholder ? 'none' : undefined}}>
{ img }
{ gifLabel }
</div>
@ -450,7 +450,7 @@ export default class MImageBody extends React.Component {
// Overidden by MStickerBody
getFileBody() {
if (this.props.mediaSrc) return null;
if (this.props.forExport) return null;
return <MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />;
}
@ -468,7 +468,7 @@ export default class MImageBody extends React.Component {
const contentUrl = this._getContentUrl();
let thumbUrl;
if ((this._isGif() && SettingsStore.getValue("autoplayGifsAndVideos")) || this.props.mediaSrc) {
if (this.props.forExport || (this._isGif() && SettingsStore.getValue("autoplayGifsAndVideos"))) {
thumbUrl = contentUrl;
} else {
thumbUrl = this._getThumbUrl();

View file

@ -30,7 +30,7 @@ interface IProps {
/* called when the video has loaded */
onHeightChanged: () => void;
/* used to refer to the local file while exporting */
mediaSrc?: string;
forExport?: boolean;
}
interface IState {
@ -78,7 +78,7 @@ export default class MVideoBody extends React.PureComponent<IProps, IState> {
}
private getContentUrl(): string|null {
if (this.props.mediaSrc) return this.props.mediaSrc;
if (this.props.forExport) return "forExport";
const media = mediaFromContent(this.props.mxEvent.getContent());
if (media.isEncrypted) {
return this.state.decryptedUrl;
@ -94,7 +94,7 @@ export default class MVideoBody extends React.PureComponent<IProps, IState> {
private getThumbUrl(): string|null {
// there's no need of thumbnail when the content is local
if (this.props.mediaSrc) return null;
if (this.props.forExport) return null;
const content = this.props.mxEvent.getContent();
const media = mediaFromContent(content);
@ -191,7 +191,7 @@ export default class MVideoBody extends React.PureComponent<IProps, IState> {
}
private getFileBody = () => {
if (this.props.mediaSrc) return null;
if (this.props.forExport) return null;
return <MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />;
}
@ -209,7 +209,7 @@ export default class MVideoBody extends React.PureComponent<IProps, IState> {
}
// Important: If we aren't autoplaying and we haven't decrypted it yet, show a video with a poster.
if (!this.props.mediaSrc && content.file !== undefined && this.state.decryptedUrl === null && autoplay) {
if (!this.props.forExport && content.file !== undefined && this.state.decryptedUrl === null && autoplay) {
// Need to decrypt the attachment
// The attachment is decrypted in componentDidMount.
// For now add an img tag with a spinner.

View file

@ -23,7 +23,7 @@ import MVoiceMessageBody from "./MVoiceMessageBody";
interface IProps {
mxEvent: MatrixEvent;
mediaSrc?: string;
forExport?: boolean;
}
@replaceableComponent("views.messages.MVoiceOrAudioBody")
@ -31,7 +31,7 @@ export default class MVoiceOrAudioBody extends React.PureComponent<IProps> {
public render() {
const isVoiceMessage = !!this.props.mxEvent.getContent()['org.matrix.msc2516.voice'];
const voiceMessagesEnabled = SettingsStore.getValue("feature_voice_messages");
if (isVoiceMessage && voiceMessagesEnabled && !this.props.mediaSrc) {
if (!this.props.forExport && isVoiceMessage && voiceMessagesEnabled) {
return <MVoiceMessageBody {...this.props} />;
} else {
return <MAudioBody {...this.props} />;

View file

@ -44,9 +44,6 @@ export default class MessageEvent extends React.Component {
/* the shape of the tile, used */
tileShape: PropTypes.string,
/* to set source to local file path during export */
mediaSrc: PropTypes.string,
/* to set source to local file path during export */
forExport: PropTypes.bool,
@ -126,7 +123,6 @@ export default class MessageEvent extends React.Component {
highlightLink={this.props.highlightLink}
showUrlPreview={this.props.showUrlPreview}
tileShape={this.props.tileShape}
mediaSrc={this.props.mediaSrc}
forExport={this.props.forExport}
maxImageHeight={this.props.maxImageHeight}
replacingEventId={this.props.replacingEventId}