From 8c45a341af02a3ed541f0e8d04c6c095d2d9803a Mon Sep 17 00:00:00 2001 From: 7w1 Date: Tue, 24 Feb 2026 19:41:25 -0600 Subject: [PATCH 1/3] profile banner rendering --- CHANGELOG.md | 4 ++++ src/app/components/user-profile/UserHero.tsx | 23 +++++++++++++------ .../user-profile/UserRoomProfile.tsx | 6 +++++ src/app/components/user-profile/styles.css.ts | 6 ++++- src/app/features/room/RoomTimeline.tsx | 5 ++++ src/app/hooks/useUserProfile.ts | 5 +++- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3073bb4e..9b17a34a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Sable Client Changelog +## Version 1.1.2 + +- Profile banners. + ## Version 1.1.1 - More cache fixes and improvements. diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index dac5b208..6f807790 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -28,25 +28,34 @@ import { useNickname } from '../../hooks/useNickname'; type UserHeroProps = { userId: string; avatarUrl?: string; + bannerUrl?: string; presence?: UserPresence; }; -export function UserHero({ userId, avatarUrl, presence }: UserHeroProps) { +export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroProps) { const [viewAvatar, setViewAvatar] = useState(); + const coverUrl = bannerUrl || avatarUrl; + const isFallbackCover = !bannerUrl && !!avatarUrl; + + return (
- {avatarUrl && ( - {userId} + {coverUrl && ( + {`${userId} )}
diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 8e47b110..ba1fed83 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -35,6 +35,7 @@ import { useSpoilerClickHandler } from '../../hooks/useSpoilerClickHandler'; const KNOWN_KEYS = [ 'moe.sable.app.bio', 'chat.commet.profile_bio', + 'chat.commet.profile_banner', 'io.fsky.nyx.pronouns', 'us.cloke.msc4175.tz', 'm.tz', @@ -212,6 +213,10 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps ? fetchedProfile : (initialProfile as UserProfile) || fetchedProfile; + const bannerHttpUrl = extendedProfile?.bannerUrl + ? mxcUrlToHttp(mx, extendedProfile.bannerUrl, useAuthentication) + : undefined; + const handleMessage = () => { closeUserRoomProfile(); const directSearchParam: DirectCreateSearchParams = { @@ -252,6 +257,7 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps diff --git a/src/app/components/user-profile/styles.css.ts b/src/app/components/user-profile/styles.css.ts index 62272a2e..88e96dff 100644 --- a/src/app/components/user-profile/styles.css.ts +++ b/src/app/components/user-profile/styles.css.ts @@ -22,7 +22,11 @@ export const UserHeroCover = style({ height: '100%', width: '100%', objectFit: 'cover', - filter: 'blur(16px)', + objectPosition: 'center', +}); + +export const UserHeroCoverFallback = style({ + filter: 'blur(16px) brightness(50%)', transform: 'scale(2)', }); diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index c1c919bc..2f3f0d03 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -977,12 +977,16 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli return; } + const rawBanner = (info as any)['chat.commet.profile_banner']; + const parsedBanner = typeof rawBanner === 'string' ? rawBanner.replace(/^"|"$/g, '') : undefined; + const normalized: any = { avatarUrl: info.avatar_url, displayName: info.displayname, pronouns: (info as any)['io.fsky.nyx.pronouns'], timezone: (info as any)['us.cloke.msc4175.tz'] || (info as any)['m.tz'], bio: (info as any)['moe.sable.app.bio'] || (info as any)['chat.commet.profile_bio'], + bannerUrl: parsedBanner, extended: info, _updatedAt: now, }; @@ -1081,6 +1085,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli delete cleanExtended['chat.commet.profile_bio']; delete cleanExtended['us.cloke.msc4175.tz']; delete cleanExtended['m.tz']; + delete cleanExtended['chat.commet.profile_banner']; delete cleanExtended['avatar_url']; delete cleanExtended['displayname']; } diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 65918a02..b82c18fc 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -10,6 +10,7 @@ export type UserProfile = { pronouns?: any[]; timezone?: string; bio?: string; + bannerUrl?: string; extended?: Record; }; @@ -24,6 +25,7 @@ export const useUserProfile = (userId: string, initialProfile?: Partial { From 3176a66568d051139f185331ef180511e619e3c5 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Tue, 24 Feb 2026 20:20:57 -0600 Subject: [PATCH 2/3] Cache profile banners & avatars with blobs --- CHANGELOG.md | 2 +- src/app/components/user-profile/UserHero.tsx | 7 +++- .../user-profile/UserRoomProfile.tsx | 8 +++- src/app/hooks/useBlobCache.ts | 42 +++++++++++++++++++ src/app/hooks/useUserProfile.ts | 1 + 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/app/hooks/useBlobCache.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b17a34a..2515af23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Version 1.1.2 -- Profile banners. +- Profile banners. Cached after first load. ## Version 1.1.1 diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index 6f807790..e5fa8daf 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -24,6 +24,7 @@ import { stopPropagation } from '../../utils/keyboard'; import { useRoom } from '../../hooks/useRoom'; import { useSableCosmetics } from '../../hooks/useSableCosmetics'; import { useNickname } from '../../hooks/useNickname'; +import { useBlobCache } from '../../hooks/useBlobCache'; type UserHeroProps = { userId: string; @@ -34,9 +35,11 @@ type UserHeroProps = { export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroProps) { const [viewAvatar, setViewAvatar] = useState(); - const coverUrl = bannerUrl || avatarUrl; - const isFallbackCover = !bannerUrl && !!avatarUrl; + const cachedBannerUrl = useBlobCache(bannerUrl); + const cachedAvatarUrl = useBlobCache(avatarUrl); + const coverUrl = cachedBannerUrl || cachedAvatarUrl; + const isFallbackCover = !cachedBannerUrl && !!cachedAvatarUrl; return ( diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index ba1fed83..384426ce 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -213,8 +213,12 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps ? fetchedProfile : (initialProfile as UserProfile) || fetchedProfile; - const bannerHttpUrl = extendedProfile?.bannerUrl - ? mxcUrlToHttp(mx, extendedProfile.bannerUrl, useAuthentication) + const parsedBanner = typeof extendedProfile.bannerUrl === 'string' + ? extendedProfile.bannerUrl.replace(/^"|"$/g, '') + : undefined; + + const bannerHttpUrl = parsedBanner + ? mxcUrlToHttp(mx, parsedBanner, useAuthentication) ?? undefined : undefined; const handleMessage = () => { diff --git a/src/app/hooks/useBlobCache.ts b/src/app/hooks/useBlobCache.ts new file mode 100644 index 00000000..3b5475da --- /dev/null +++ b/src/app/hooks/useBlobCache.ts @@ -0,0 +1,42 @@ +import { useState, useEffect } from 'react'; + +const imageBlobCache = new Map(); + +export function useBlobCache(url?: string): string | undefined { + const [cacheState, setCacheState] = useState<{ sourceUrl?: string; blobUrl?: string }>({ + sourceUrl: url, + blobUrl: url ? imageBlobCache.get(url) : undefined, + }); + + if (url !== cacheState.sourceUrl) { + setCacheState({ + sourceUrl: url, + blobUrl: url ? imageBlobCache.get(url) : undefined, + }); + } + + useEffect(() => { + let isMounted = true; + + if (url && !imageBlobCache.has(url)) { + fetch(url, { mode: 'cors' }) + .then((res) => (res.ok ? res.blob() : Promise.reject())) + .then((blob) => { + if (isMounted) { + const objectUrl = URL.createObjectURL(blob); + imageBlobCache.set(url, objectUrl); + setCacheState({ sourceUrl: url, blobUrl: objectUrl }); + } + }) + .catch(() => { + // silently fail... mrow + }); + } + + return () => { + isMounted = false; + }; + }, [url]); + + return cacheState.blobUrl || url; +} \ No newline at end of file diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index b82c18fc..0d1f01c6 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -56,6 +56,7 @@ export const useUserProfile = (userId: string, initialProfile?: Partial Date: Tue, 24 Feb 2026 20:55:55 -0600 Subject: [PATCH 3/3] finish implementation --- CHANGELOG.md | 2 +- src/app/features/settings/account/Profile.tsx | 174 ++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2515af23..712040c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Version 1.1.2 -- Profile banners. Cached after first load. +- Profile banners. Support's Commet's format. ## Version 1.1.1 diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 3a61c6cc..23bff743 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -214,6 +214,179 @@ function ProfileAvatar({ profile, userId }: ProfileProps) { ); } +function ProfileBanner({ profile, userId }: ProfileProps) { + const mx = useMatrixClient(); + const useAuthentication = useMediaAuthentication(); + const [alertRemove, setAlertRemove] = useState(false); + + const [stagedUrl, setStagedUrl] = useState(); + const [isRemoving, setIsRemoving] = useState(false); + + const bannerUrl = profile.bannerUrl + ? mxcUrlToHttp(mx, profile.bannerUrl, useAuthentication) ?? undefined + : undefined; + + useEffect(() => { + if (bannerUrl) { + setStagedUrl(undefined); + } + }, [bannerUrl]); + + const [imageFile, setImageFile] = useState(); + const imageFileURL = useObjectURL(imageFile); + + const uploadAtom = useMemo(() => { + if (imageFile) return createUploadAtom(imageFile); + return undefined; + }, [imageFile]); + + const pickFile = useFilePicker(setImageFile, false); + + const handlePick = useCallback(() => { + setIsRemoving(false); + setStagedUrl(undefined); + pickFile('image/*'); + }, [pickFile]); + + const handleRemoveUpload = useCallback(() => { + setImageFile(undefined); + }, []); + + const handleUploaded = useCallback( + (upload: UploadSuccess) => { + const { mxc } = upload; + + if (imageFileURL) setStagedUrl(imageFileURL); + + mx.setExtendedProfileProperty?.("chat.commet.profile_banner", mxc); + setImageFile(undefined); + }, + [mx, imageFileURL] + ); + + const handleRemoveBanner = async () => { + setIsRemoving(true); + setStagedUrl(undefined); + setImageFile(undefined); + + await mx.setExtendedProfileProperty?.("chat.commet.profile_banner", null); + + setAlertRemove(false); + }; + + const previewUrl = isRemoving ? undefined : (imageFileURL || stagedUrl || bannerUrl); + + return ( + + Profile Banner + + } + > + + + {previewUrl ? ( + Banner Preview + ) : ( + + No Banner Set + + )} + + + {uploadAtom ? ( + + + + ) : ( + + + {bannerUrl && ( + + )} + + )} + + + }> + + setAlertRemove(false), + clickOutsideDeactivates: true, + escapeDeactivates: stopPropagation, + }} + > + +
+ + Remove Banner + + setAlertRemove(false)} radii="300"> + + +
+ + Are you sure you want to remove profile banner? + + +
+
+
+
+
+ ); +} + function ProfileDisplayName({ profile, userId }: ProfileProps) { const mx = useMatrixClient(); const capabilities = useCapabilities(); @@ -402,6 +575,7 @@ export function Profile() { direction="Column" gap="400" > +