Show sharer preview for matrix.to links
This commit is contained in:
@@ -20,10 +20,11 @@ import { getEvent, client } from 'matrix-cypher';
|
||||
import { RoomPreviewWithTopic } from './RoomPreview';
|
||||
import InviteTile from './InviteTile';
|
||||
import { SafeLink, LinkKind } from '../parser/types';
|
||||
import UserPreview from './UserPreview';
|
||||
import UserPreview, { WrappedInviterPreview } from './UserPreview';
|
||||
import EventPreview from './EventPreview';
|
||||
import HomeserverOptions from './HomeserverOptions';
|
||||
import DefaultPreview from './DefaultPreview';
|
||||
import Toggle from './Toggle';
|
||||
import { clientMap } from '../clients';
|
||||
import {
|
||||
getRoomFromId,
|
||||
@@ -32,12 +33,7 @@ import {
|
||||
getUser,
|
||||
} from '../utils/cypher-wrapper';
|
||||
import { ClientContext } from '../contexts/ClientContext';
|
||||
import HSContext, {
|
||||
TempHSContext,
|
||||
HSOptions,
|
||||
State as HSState,
|
||||
} from '../contexts/HSContext';
|
||||
import Toggle from './Toggle';
|
||||
import useHSs from '../utils/getHS';
|
||||
|
||||
interface IProps {
|
||||
link: SafeLink;
|
||||
@@ -118,32 +114,14 @@ const Preview: React.FC<PreviewProps> = ({ link, client }: PreviewProps) => {
|
||||
return content;
|
||||
};
|
||||
|
||||
function selectedClient(link: SafeLink, hsOptions: HSState): string[] {
|
||||
switch (hsOptions.option) {
|
||||
case HSOptions.Unset:
|
||||
return [];
|
||||
case HSOptions.None:
|
||||
return [];
|
||||
case HSOptions.TrustedHSOnly:
|
||||
return [hsOptions.hs];
|
||||
case HSOptions.Any:
|
||||
return [
|
||||
'https://' + link.identifier.split(':')[1],
|
||||
...link.arguments.vias,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
const LinkPreview: React.FC<IProps> = ({ link }: IProps) => {
|
||||
let content: JSX.Element;
|
||||
const [showHSOptions, setShowHSOPtions] = useState(false);
|
||||
const [hsOptions] = useContext(HSContext);
|
||||
const [tempHSState] = useContext(TempHSContext);
|
||||
|
||||
if (
|
||||
hsOptions.option === HSOptions.Unset &&
|
||||
tempHSState.option === HSOptions.Unset
|
||||
) {
|
||||
const hses = useHSs(link);
|
||||
console.log(hses);
|
||||
|
||||
if (!hses) {
|
||||
content = (
|
||||
<>
|
||||
<DefaultPreview link={link} />
|
||||
@@ -164,11 +142,7 @@ const LinkPreview: React.FC<IProps> = ({ link }: IProps) => {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const clients =
|
||||
tempHSState.option !== HSOptions.Unset
|
||||
? selectedClient(link, tempHSState)
|
||||
: selectedClient(link, hsOptions);
|
||||
content = <Preview link={link} client={clients[0]} />;
|
||||
content = <Preview link={link} client={hses[0]} />;
|
||||
}
|
||||
|
||||
const [{ clientId }] = useContext(ClientContext);
|
||||
@@ -182,8 +156,20 @@ const LinkPreview: React.FC<IProps> = ({ link }: IProps) => {
|
||||
|
||||
const client = displayClientId ? clientMap[displayClientId] : null;
|
||||
|
||||
const sharer = link.arguments.sharer ? (
|
||||
<WrappedInviterPreview
|
||||
link={{
|
||||
kind: LinkKind.UserId,
|
||||
identifier: link.arguments.sharer,
|
||||
arguments: { vias: [] },
|
||||
originalLink: '',
|
||||
}}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<InviteTile client={client} link={link}>
|
||||
{sharer}
|
||||
{content}
|
||||
</InviteTile>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user