mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 17:25:50 +03:00
Hide URL preview if it will be empty (#9029)
* Hide URL preview if it will be empty * Update src/components/views/rooms/LinkPreviewWidget.tsx Co-authored-by: Šimon Brandner <simon.bra.ag@gmail.com> * Iterate * Iterate --------- Co-authored-by: Šimon Brandner <simon.bra.ag@gmail.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
252f2ebec0
commit
40de66424d
2 changed files with 6 additions and 4 deletions
|
@ -97,7 +97,12 @@ const fetchPreviews = (cli: MatrixClient, links: string[], ts: number): Promise<
|
|||
links.map(async (link): Promise<[string, IPreviewUrlResponse] | undefined> => {
|
||||
try {
|
||||
const preview = await cli.getUrlPreview(link, ts);
|
||||
if (preview && Object.keys(preview).length > 0) {
|
||||
// Ensure at least one of the rendered fields is truthy
|
||||
if (
|
||||
preview?.["og:image"]?.startsWith("mxc://") ||
|
||||
!!preview?.["og:description"] ||
|
||||
!!preview?.["og:title"]
|
||||
) {
|
||||
return [link, preview];
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -75,9 +75,6 @@ export default class LinkPreviewWidget extends React.Component<IProps> {
|
|||
|
||||
public render(): React.ReactNode {
|
||||
const p = this.props.preview;
|
||||
if (!p || Object.keys(p).length === 0) {
|
||||
return <div />;
|
||||
}
|
||||
|
||||
// FIXME: do we want to factor out all image displaying between this and MImageBody - especially for lightboxing?
|
||||
let image: string | null = p["og:image"] ?? null;
|
||||
|
|
Loading…
Reference in a new issue