diff --git a/.changeset/notification_banner_rich_body.md b/.changeset/notification_banner_rich_body.md new file mode 100644 index 00000000..ec13cbee --- /dev/null +++ b/.changeset/notification_banner_rich_body.md @@ -0,0 +1,5 @@ +--- +sable: patch +--- + +Fixed in-app notification banners in encrypted rooms showing "Encrypted Message" instead of the actual content. Banners now also render rich text (mentions, inline images) using the same pipeline as the timeline renderer. diff --git a/src/app/components/notification-banner/NotificationBanner.css.ts b/src/app/components/notification-banner/NotificationBanner.css.ts index 80c3617f..1ddfacda 100644 --- a/src/app/components/notification-banner/NotificationBanner.css.ts +++ b/src/app/components/notification-banner/NotificationBanner.css.ts @@ -110,11 +110,18 @@ export const BannerRoomName = style({ }); // Caps tall previews and fades the bottom edge when content overflows. +// Desktop: 25vh, mobile (≤768px): 35vh. export const BannerBody = style({ position: 'relative', - maxHeight: toRem(56), + maxHeight: '25vh', overflow: 'hidden', + '@media': { + '(max-width: 768px)': { + maxHeight: '35vh', + }, + }, + selectors: { '&[data-overflow=true]::after': { content: '""', diff --git a/src/app/components/notification-banner/NotificationBanner.tsx b/src/app/components/notification-banner/NotificationBanner.tsx index ad0ba026..666ec077 100644 --- a/src/app/components/notification-banner/NotificationBanner.tsx +++ b/src/app/components/notification-banner/NotificationBanner.tsx @@ -1,5 +1,5 @@ import { useAtom } from 'jotai'; -import { useCallback, useEffect, useRef, useState } from 'react'; +import { ReactNode, useCallback, useEffect, useRef, useState } from 'react'; import { Box, Icon, IconButton, Icons, Text } from 'folds'; import { inAppBannerAtom, InAppBannerNotification } from '$state/sessions'; import * as css from './NotificationBanner.css'; @@ -26,6 +26,26 @@ function BodyText({ text, hovered }: { text: string; hovered: boolean }) { ); } +// Same as BodyText but renders a pre-built ReactNode (rich HTML with mxc/mention transforms). +function BodyNode({ node, hovered }: { node: ReactNode; hovered: boolean }) { + const ref = useRef(null); + const [overflow, setOverflow] = useState(false); + + useEffect(() => { + const el = ref.current; + if (!el) return; + setOverflow(el.scrollHeight > el.clientHeight); + }, [node]); + + return ( +
+ + {node} + +
+ ); +} + type BannerItemProps = { notification: InAppBannerNotification; onDismiss: (id: string) => void; @@ -115,7 +135,11 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) { )} - {notification.body && } + {notification.bodyNode ? ( + + ) : ( + notification.body && + )} { window.focus(); diff --git a/src/app/state/sessions.ts b/src/app/state/sessions.ts index 10a4ff3b..aadf20ce 100644 --- a/src/app/state/sessions.ts +++ b/src/app/state/sessions.ts @@ -1,3 +1,4 @@ +import { ReactNode } from 'react'; import { atom } from 'jotai'; import { createLogger } from '$utils/debug'; import { @@ -185,6 +186,11 @@ export type InAppBannerNotification = { /** Display name of the sender. */ senderName?: string; body?: string; + /** + * Pre-rendered rich body with mxc/mention transforms (built in ClientNonUIFeatures). + * When present, takes precedence over the plain-text `body` fallback. + */ + bodyNode?: ReactNode; /** URL of an avatar or room icon to display inside the banner. */ icon?: string; onClick: () => void;