Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web/timeline: use blurhash before image loaded and for spoilers #533

Closed

Conversation

sumnerevans
Copy link
Contributor

@sumnerevans sumnerevans commented Dec 1, 2024

This PR implements support for rendering MSC2448 blurhashes and adds partial support for MSC3725 (content warnings, spoilers).

During image load, the blurhash (if present) is shown instead of the image until the image has been loaded.

Additionally, if it is a spoiler, then it will show up like this (using the blurhash):

2024-11-30-18:35:26

then, on click

2024-11-30-18:35:31


I couldn't figure out how to include blurhash exactly correctly. There were some dependency things that couldn't be resolved. React something something

Signed-off-by: Sumner Evans <[email protected]>
@sumnerevans sumnerevans force-pushed the blurhash-and-image-spoilers branch from b282c94 to b31c92d Compare December 1, 2024 01:48
const blurhash = content.info ? content.info["xyz.amorgan.blurhash"] : undefined
const isSpoiler = content["m.content_warning"]?.type === "m.spoiler" ||
content["town.robin.msc3725.content_warning"]?.type === "town.robin.msc3725.spoiler"
const showPlaceholder = (blurhash && !loaded) || (isSpoiler && !spoilerShowing)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the correct place, seems like it should be applied to all media instead of just images

@@ -23,18 +24,65 @@ import DownloadIcon from "@/icons/download.svg?react"
export const useMediaContent = (
content: MediaMessageEventContent, evtType: EventType, containerSize?: ImageContainerSize,
): [React.ReactElement | null, string, CSSProperties] => {
const imgEl = React.useRef<HTMLImageElement>(null)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooks should be imported individually instead of using React.

@tulir tulir closed this in 42140aa Dec 1, 2024
@sumnerevans sumnerevans deleted the blurhash-and-image-spoilers branch December 2, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants