2023-04-08 21:29:38 +00:00
|
|
|
import { FormattedMessage } from "react-intl";
|
|
|
|
|
|
|
|
import MediaLink from "Element/MediaLink";
|
|
|
|
import Reveal from "Element/Reveal";
|
2023-04-14 11:33:19 +00:00
|
|
|
import useLogin from "Hooks/useLogin";
|
2023-04-08 21:29:38 +00:00
|
|
|
|
|
|
|
interface RevealMediaProps {
|
|
|
|
creator: string;
|
|
|
|
link: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function RevealMedia(props: RevealMediaProps) {
|
2023-04-14 11:33:19 +00:00
|
|
|
const login = useLogin();
|
|
|
|
const { preferences: pref, follows, publicKey } = login;
|
2023-04-08 21:29:38 +00:00
|
|
|
|
2023-04-14 11:33:19 +00:00
|
|
|
const hideNonFollows = pref.autoLoadMedia === "follows-only" && !follows.item.includes(props.creator);
|
2023-04-08 21:29:38 +00:00
|
|
|
const isMine = props.creator === publicKey;
|
|
|
|
const hideMedia = pref.autoLoadMedia === "none" || (!isMine && hideNonFollows);
|
|
|
|
const hostname = new URL(props.link).hostname;
|
|
|
|
|
|
|
|
if (hideMedia) {
|
|
|
|
return (
|
|
|
|
<Reveal
|
|
|
|
message={<FormattedMessage defaultMessage="Click to load content from {link}" values={{ link: hostname }} />}>
|
|
|
|
<MediaLink link={props.link} />
|
|
|
|
</Reveal>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return <MediaLink link={props.link} />;
|
|
|
|
}
|
|
|
|
}
|