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>
pull/28217/head
Travis Ralston 2023-07-07 05:06:03 -06:00 committed by GitHub
parent 252f2ebec0
commit 40de66424d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -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) {

View File

@ -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;