2019-06-09 08:57:51 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2020-10-20 19:10:02 +02:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import EmbedPlayButton from 'component/embedPlayButton';
|
|
|
|
import Button from 'component/button';
|
2020-11-12 19:46:40 +01:00
|
|
|
import UriIndicator from 'component/uriIndicator';
|
2020-10-20 19:10:02 +02:00
|
|
|
import { INLINE_PLAYER_WRAPPER_CLASS } from 'component/fileRenderFloating/view';
|
2021-04-02 05:39:05 +02:00
|
|
|
import { SIMPLE_SITE } from 'config';
|
2019-06-09 08:57:51 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
claim: StreamClaim,
|
|
|
|
children: React.Node,
|
|
|
|
description: ?string,
|
|
|
|
isResolvingUri: boolean,
|
2021-04-02 05:39:05 +02:00
|
|
|
doResolveUri: (string) => void,
|
2019-06-09 08:57:51 +02:00
|
|
|
blackListedOutpoints: Array<{
|
|
|
|
txid: string,
|
|
|
|
nout: number,
|
|
|
|
}>,
|
2020-10-20 19:10:02 +02:00
|
|
|
playingUri: ?PlayingUri,
|
|
|
|
parentCommentId?: string,
|
|
|
|
isMarkdownPost?: boolean,
|
2021-04-02 05:39:05 +02:00
|
|
|
allowPreview?: boolean,
|
2019-06-09 08:57:51 +02:00
|
|
|
};
|
|
|
|
|
2019-06-20 22:59:01 +02:00
|
|
|
class ClaimLink extends React.Component<Props> {
|
2019-06-09 08:57:51 +02:00
|
|
|
static defaultProps = {
|
|
|
|
href: null,
|
2019-06-21 03:00:52 +02:00
|
|
|
link: false,
|
2019-06-13 06:18:35 +02:00
|
|
|
thumbnail: null,
|
|
|
|
description: null,
|
|
|
|
isResolvingUri: false,
|
|
|
|
};
|
|
|
|
|
2019-06-21 08:04:02 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.resolve(this.props);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.resolve(this.props);
|
|
|
|
}
|
|
|
|
|
2019-06-09 08:57:51 +02:00
|
|
|
isClaimBlackListed() {
|
|
|
|
const { claim, blackListedOutpoints } = this.props;
|
2019-08-29 03:39:21 +02:00
|
|
|
const signingChannel = claim && claim.signing_channel;
|
2019-06-09 08:57:51 +02:00
|
|
|
if (claim && blackListedOutpoints) {
|
|
|
|
let blackListed = false;
|
|
|
|
|
2019-08-29 03:39:21 +02:00
|
|
|
blackListed = blackListedOutpoints.some(
|
2021-04-02 05:39:05 +02:00
|
|
|
(outpoint) =>
|
2019-08-29 03:39:21 +02:00
|
|
|
(signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) ||
|
|
|
|
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
|
|
|
|
);
|
2019-06-09 08:57:51 +02:00
|
|
|
return blackListed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 08:04:02 +02:00
|
|
|
resolve = (props: Props) => {
|
2020-10-20 19:10:02 +02:00
|
|
|
const { isResolvingUri, doResolveUri, claim, uri } = props;
|
2019-06-09 08:57:51 +02:00
|
|
|
|
2019-06-21 08:04:02 +02:00
|
|
|
if (!isResolvingUri && claim === undefined && uri) {
|
2020-10-20 19:10:02 +02:00
|
|
|
doResolveUri(uri);
|
2019-06-09 08:57:51 +02:00
|
|
|
}
|
2019-06-21 08:04:02 +02:00
|
|
|
};
|
2019-06-09 08:57:51 +02:00
|
|
|
|
|
|
|
render() {
|
2021-04-02 05:39:05 +02:00
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
claim,
|
|
|
|
children,
|
|
|
|
isResolvingUri,
|
|
|
|
playingUri,
|
|
|
|
parentCommentId,
|
|
|
|
isMarkdownPost,
|
|
|
|
allowPreview,
|
|
|
|
} = this.props;
|
2019-06-13 06:18:35 +02:00
|
|
|
const isUnresolved = (!isResolvingUri && !claim) || !claim;
|
|
|
|
const isBlacklisted = this.isClaimBlackListed();
|
2020-10-20 19:10:02 +02:00
|
|
|
const isPlayingInline =
|
|
|
|
playingUri &&
|
|
|
|
playingUri.uri === uri &&
|
|
|
|
((playingUri.source === 'comment' && parentCommentId === playingUri.commentId) ||
|
|
|
|
playingUri.source === 'markdown');
|
2019-06-13 06:18:35 +02:00
|
|
|
|
|
|
|
if (isBlacklisted || isUnresolved) {
|
|
|
|
return <span>{children}</span>;
|
|
|
|
}
|
|
|
|
|
2020-10-08 19:36:57 +02:00
|
|
|
const { value_type: valueType } = claim;
|
2019-10-15 01:05:19 +02:00
|
|
|
const isChannel = valueType === 'channel';
|
2019-06-20 22:59:01 +02:00
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
return isChannel ? (
|
2020-11-12 19:46:40 +01:00
|
|
|
<UriIndicator uri={uri} link />
|
2020-10-20 19:10:02 +02:00
|
|
|
) : (
|
|
|
|
<div className={classnames('claim-link')}>
|
|
|
|
<div
|
|
|
|
className={classnames({
|
|
|
|
[INLINE_PLAYER_WRAPPER_CLASS]: isPlayingInline,
|
|
|
|
})}
|
|
|
|
>
|
2021-04-02 05:39:05 +02:00
|
|
|
<EmbedPlayButton
|
|
|
|
uri={uri}
|
|
|
|
parentCommentId={parentCommentId}
|
|
|
|
isMarkdownPost={isMarkdownPost}
|
|
|
|
allowPreview={allowPreview}
|
|
|
|
/>
|
2020-10-20 19:10:02 +02:00
|
|
|
</div>
|
2021-04-02 05:39:05 +02:00
|
|
|
{(allowPreview || !SIMPLE_SITE) && (
|
|
|
|
<Button button="link" className="preview-link__url" label={uri} navigate={uri} />
|
|
|
|
)}
|
|
|
|
{!allowPreview && SIMPLE_SITE && (
|
|
|
|
<div className="preview-link__unavailable">
|
|
|
|
<p>
|
|
|
|
{__("This channel isn't staking enough LBRY Credits for link previews.")}{' '}
|
|
|
|
<Button button="link" label={__('Learn more')} href="https://odysee.com/@lbry:3f/levelsonodysee:c" />.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-10-20 19:10:02 +02:00
|
|
|
</div>
|
|
|
|
);
|
2019-06-09 08:57:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ClaimLink;
|