diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d092d27..f5481d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Sable Client Changelog +## 1.5.3 (2026-03-08) + +### Fixes + +* Fix scroll clamping to bottom while scrolling up. +* Fix message links sometimes scrolling to bottom of timeline instead of message + maybe other scroll bugs. +* Merge upstream call fixes +* Fix crash when invalid location events are sent. +* Add rendering of per-message-profiles. +* custom emojis are now also visible in forwards, instead of being reduced to it's shortcode + +* fix: default badge unread counts to off + +## 1.5.2 (2026-03-08) + +### Fixes + +* Add `/hug`, `/cuddle`, `/wave`, `/headpat`, and `/poke` slash commands. +* Swap Caddy port to 8080 + fixes for MDAD setups. +* Adjust media sizing and URL preview layout +* Fix picture in picture setting not effecting element-call +* Fixed an issue where the app would fail to load after completing SSO login (e.g., logging in with matrix.org). Users are now correctly redirected to the app after SSO authentication completes. + ## 1.5.1 (2026-03-08) ### Fixes diff --git a/Caddyfile b/Caddyfile index 78700b4c..d807e8c2 100644 --- a/Caddyfile +++ b/Caddyfile @@ -4,7 +4,7 @@ } } -:80 { +:8080 { root * /app # Enable on-the-fly compression for things not pre-compressed diff --git a/Dockerfile b/Dockerfile index d039ccf7..a0b76dfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,5 +21,11 @@ COPY --from=builder /src/dist / ## App FROM caddy:2-alpine +# Strip the file capability set by the base image (cap_net_bind_service=+ep). +# With --cap-drop=ALL the bounding set is empty, and the kernel refuses to exec +# any binary that has file capabilities not present in the bounding set — even +# if those capabilities aren't actually needed at runtime (we listen on :8080). +RUN setcap -r /usr/bin/caddy + COPY --from=site-dist / /app COPY Caddyfile /etc/caddy/Caddyfile diff --git a/README.md b/README.md index e29839ce..606258a1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Prebuilt images are published to `ghcr.io/7w1/sable`. Run the latest image with: ```sh -docker run --rm -p 8080:80 ghcr.io/7w1/sable:latest +docker run --rm -p 8080:8080 ghcr.io/7w1/sable:latest ``` Then open `http://localhost:8080`. @@ -42,7 +42,7 @@ services: sable: image: ghcr.io/7w1/sable:latest ports: - - '8080:80' + - '8080:8080' volumes: - ./config.json:/app/config.json:ro ``` diff --git a/index.html b/index.html index 403a0618..21c34e6d 100644 --- a/index.html +++ b/index.html @@ -92,6 +92,6 @@
- + diff --git a/package-lock.json b/package-lock.json index 76cc709f..5683a6d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sable", - "version": "1.5.1", + "version": "1.5.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "sable", - "version": "1.5.1", + "version": "1.5.3", "hasInstallScript": true, "license": "AGPL-3.0-only", "dependencies": { diff --git a/package.json b/package.json index fb527cd3..2667d148 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sable", - "version": "1.5.1", + "version": "1.5.3", "description": "Yet another matrix client fork", "type": "module", "packageManager": "npm@11.11.0", diff --git a/src/app/components/CallEmbedProvider.tsx b/src/app/components/CallEmbedProvider.tsx index 0fc084f5..ba29f3b7 100644 --- a/src/app/components/CallEmbedProvider.tsx +++ b/src/app/components/CallEmbedProvider.tsx @@ -6,6 +6,7 @@ import { useCallHangupEvent, useCallJoined, useCallThemeSync, + useCallMemberSoundSync, } from '../hooks/useCallEmbed'; import { callChatAtom, callEmbedAtom } from '../state/callEmbed'; import { CallEmbed } from '../plugins/call'; @@ -15,6 +16,7 @@ import { ScreenSize, useScreenSizeContext } from '../hooks/useScreenSize'; function CallUtils({ embed }: { embed: CallEmbed }) { const setCallEmbed = useSetAtom(callEmbedAtom); + useCallMemberSoundSync(embed); useCallThemeSync(embed); useCallHangupEvent( embed, diff --git a/src/app/components/RenderMessageContent.tsx b/src/app/components/RenderMessageContent.tsx index 5fcfb472..3c2ded07 100644 --- a/src/app/components/RenderMessageContent.tsx +++ b/src/app/components/RenderMessageContent.tsx @@ -33,6 +33,7 @@ import { ImageViewer } from './image-viewer'; import { PdfViewer } from './Pdf-viewer'; import { TextViewer } from './text-viewer'; import { ClientSideHoverFreeze } from './ClientSideHoverFreeze'; +import { CuteEventType, MCuteEvent } from './message/MCuteEvent'; type RenderMessageContentProps = { displayName: string; @@ -348,6 +349,23 @@ function RenderMessageContentInternal({ if (msgType === MsgType.Location) return ; if (msgType === 'm.bad.encrypted') return ; + // cute events + if (msgType === 'im.fluffychat.cute_event') + return ( + + ); + if (msgType === 'fyi.cisnt.headpat') + return ( + + ); return ; } diff --git a/src/app/components/media/media.css.ts b/src/app/components/media/media.css.ts index b563ef3e..aad194fd 100644 --- a/src/app/components/media/media.css.ts +++ b/src/app/components/media/media.css.ts @@ -4,7 +4,7 @@ import { DefaultReset } from 'folds'; export const Image = style([ DefaultReset, { - objectFit: 'cover', + objectFit: 'contain', width: '100%', height: '100%', }, diff --git a/src/app/components/message/MCuteEvent.tsx b/src/app/components/message/MCuteEvent.tsx new file mode 100644 index 00000000..0cfa8463 --- /dev/null +++ b/src/app/components/message/MCuteEvent.tsx @@ -0,0 +1,62 @@ +// rendering for cute events (e.g. hug, cuddle, etc.) + +import { MessageTextBody } from './layout'; + +export enum CuteEventType { + Hug = 'hug', + Cuddle = 'cuddle', + Wave = 'wave', + Poke = 'poke', + Headpat = 'headpat', + // currently unused, but could be added in the future if there's demand for it + Kiss = 'kiss', +} + +type MCuteEventProps = { + // Content is only used to check if the event is valid, the actual text is generated based on the type and mentioned users + content: string | undefined; + // The type of cute event (e.g. hug, cuddle, etc.) + type: CuteEventType; + // The user IDs mentioned in the event (e.g. the target of the hug/cuddle/etc.) + mentionedUserIds?: string[]; +}; + +export function MCuteEvent({ content, type, mentionedUserIds }: MCuteEventProps) { + if (!content) return null; + + let cuteText = ''; + switch (type) { + case CuteEventType.Hug: + cuteText = `hugs ${mentionedUserIds?.[0] || 'you'}`; + break; + case CuteEventType.Cuddle: + cuteText = `cuddles ${mentionedUserIds?.[0] || 'you'}`; + break; + case CuteEventType.Kiss: + // in here for future expansion + // would need some kind of filtering to prevent abuse (e.g. someone sending a kiss event to a random user to harass them) + // cuteText = `kisses ${mentionedUserIds?.[0] || 'you'}`; + cuteText = + 'currently disabled kiss event, in light of potential abuse, may be added in the future with proper filtering'; + break; + case CuteEventType.Wave: + cuteText = `waves at ${mentionedUserIds?.[0] || 'you'}`; + break; + case CuteEventType.Poke: + cuteText = `pokes ${mentionedUserIds?.[0] || 'you'}`; + break; + case CuteEventType.Headpat: + cuteText = `gives headpats to ${mentionedUserIds?.[0] || 'you'}`; + break; + default: + cuteText = `sends ${mentionedUserIds?.[0] || 'you'} a cute event`; + } + + return ( + + + {cuteText} + + + ); +} diff --git a/src/app/components/message/MsgTypeRenderers.tsx b/src/app/components/message/MsgTypeRenderers.tsx index 275cfefe..44b4b83c 100644 --- a/src/app/components/message/MsgTypeRenderers.tsx +++ b/src/app/components/message/MsgTypeRenderers.tsx @@ -250,19 +250,26 @@ export function MImage({ content, renderImageContent, outlined }: MImageProps) { if (typeof mxcUrl !== 'string') { return ; } - const height = scaleYDimension(imgInfo?.w || 400, 400, imgInfo?.h || 400); + const MAX_SIZE = 400; + const imgW = imgInfo?.w ?? MAX_SIZE; + const imgH = imgInfo?.h ?? MAX_SIZE; + const aspectRatio = imgInfo?.w && imgInfo?.h ? `${imgW} / ${imgH}` : undefined; + // this garbage is for portrait images, we cap the width so the card doesn't exceed the bounds of the image + const displayWidth = imgH > imgW ? Math.round(MAX_SIZE * (imgW / imgH)) : MAX_SIZE; return ( {renderImageContent({ @@ -306,7 +313,7 @@ export function MVideo({ content, renderAsFile, renderVideoContent, outlined }: return ; } - const height = scaleYDimension(videoInfo.w || 400, 400, videoInfo.h || 400); + const height = Math.min(scaleYDimension(videoInfo.w || 400, 400, videoInfo.h || 400), 400); const filename = content.filename ?? content.body ?? 'Video'; @@ -455,7 +462,10 @@ type MLocationProps = { export function MLocation({ content }: MLocationProps) { const geoUri = content.geo_uri; if (typeof geoUri !== 'string') return ; + const location = parseGeoUri(geoUri); + if (!location) return ; + return ( {geoUri} diff --git a/src/app/components/message/attachment/Attachment.css.ts b/src/app/components/message/attachment/Attachment.css.ts index 4c417611..dad95f61 100644 --- a/src/app/components/message/attachment/Attachment.css.ts +++ b/src/app/components/message/attachment/Attachment.css.ts @@ -23,7 +23,7 @@ export const Attachment = recipe({ export type AttachmentVariants = RecipeVariants; export const AttachmentHeader = style({ - padding: config.space.S300, + padding: config.space.S100, }); export const AttachmentBox = style([ diff --git a/src/app/components/message/modals/MessageForward.tsx b/src/app/components/message/modals/MessageForward.tsx index d113cbec..84979272 100644 --- a/src/app/components/message/modals/MessageForward.tsx +++ b/src/app/components/message/modals/MessageForward.tsx @@ -153,26 +153,52 @@ export function MessageForwardInternal({ room, mEvent, onClose }: MessageForward type SendEventContent = Parameters[3]; const eventType = mEvent.getType() as SendEventType; + const originalContent = mEvent.getContent(); + const isTextMessage = originalContent.msgtype === 'm.text'; // using reference relation to indicate that this is a forwarded message, // which allows clients to display it as such - const bodyModifText = `(Forwarded message from ${isPrivate ? 'a private room' : (getRoom(room.roomId)?.name ?? 'a room')})`; + const originalBody = typeof originalContent.body === 'string' ? originalContent.body : ''; + const originalFormattedBody = + originalContent.format === 'org.matrix.custom.html' && + typeof originalContent.formatted_body === 'string' + ? originalContent.formatted_body + : undefined; + + const bodyModifText = `(Forwarded message from ${ + isPrivate ? 'a private room' : (getRoom(room.roomId)?.name ?? 'a room') + })`; + let newBodyPlain = ''; let newBodyHtml = ''; // transform if msgtype is m.text - if (mEvent.getContent().msgtype === 'm.text') { - const original = mEvent.getContent().body; - newBodyPlain = `${bodyModifText}\n\n${original + if (isTextMessage) { + const quotedBody = originalBody .split('\n') - .map((l: string) => `> ${l}`) - .join('\n')}`; - const safeHtml = sanitizeCustomHtml(original).replace(/\n/g, '
'); + .map((line) => `> ${line}`) + .join('\n'); + + newBodyPlain = originalBody.length > 0 ? `${bodyModifText}\n\n${quotedBody}` : bodyModifText; + + const safeHtml = + originalFormattedBody !== undefined + ? sanitizeCustomHtml(originalFormattedBody) + : sanitizeCustomHtml(originalBody).replace(/\n/g, '
'); + newBodyHtml = - `
` + + `
` + `

${sanitizeCustomHtml(bodyModifText)}

` + `
${safeHtml}
` + `
`; } + // the quoted body + const forwardedTextContent = isTextMessage + ? { + body: newBodyPlain, + format: 'org.matrix.custom.html', + formatted_body: newBodyHtml, + } + : {}; let content; // handle privacy stuff if (isPrivate) { @@ -180,9 +206,7 @@ export function MessageForwardInternal({ room, mEvent, onClose }: MessageForward // we can still include the original message content in the body of the message, so we'll just use a fallback text/plain content with the original message body content = { ...mEvent.getContent(), - body: newBodyPlain, - format: 'org.matrix.custom.html', - formatted_body: newBodyHtml, + ...forwardedTextContent, 'moe.sable.message.forward': { v: 1, is_forwarded: true, @@ -193,9 +217,7 @@ export function MessageForwardInternal({ room, mEvent, onClose }: MessageForward } else { content = { ...mEvent.getContent(), - body: newBodyPlain, - format: 'org.matrix.custom.html', - formatted_body: newBodyHtml, + ...forwardedTextContent, 'm.relates_to': { rel_type: 'm.reference', event_id: eventId, diff --git a/src/app/components/url-preview/UrlPreview.css.tsx b/src/app/components/url-preview/UrlPreview.css.tsx index 3192dc49..90adc127 100644 --- a/src/app/components/url-preview/UrlPreview.css.tsx +++ b/src/app/components/url-preview/UrlPreview.css.tsx @@ -5,7 +5,6 @@ export const UrlPreview = style([ DefaultReset, { width: toRem(400), - minHeight: toRem(102), backgroundColor: color.SurfaceVariant.Container, color: color.SurfaceVariant.OnContainer, border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`, diff --git a/src/app/components/url-preview/UrlPreviewCard.tsx b/src/app/components/url-preview/UrlPreviewCard.tsx index 3855085d..129614ce 100644 --- a/src/app/components/url-preview/UrlPreviewCard.tsx +++ b/src/app/components/url-preview/UrlPreviewCard.tsx @@ -54,69 +54,14 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s return ( - {(prev['og:video'] && ( - ); }; @@ -197,9 +206,7 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s maxWidth: '100%', margin: 0, } - : { - width: '600px', - } + : undefined } > {previewContent} diff --git a/src/app/features/call-status/CallControl.tsx b/src/app/features/call-status/CallControl.tsx index 5b7625e8..bb682a36 100644 --- a/src/app/features/call-status/CallControl.tsx +++ b/src/app/features/call-status/CallControl.tsx @@ -20,12 +20,12 @@ function MicrophoneButton({ enabled, onToggle }: MicrophoneButtonProps) { {(anchorRef) => ( onToggle()} - outlined={!enabled} + outlined > @@ -51,12 +51,12 @@ function SoundButton({ enabled, onToggle }: SoundButtonProps) { {(anchorRef) => ( onToggle()} - outlined={!enabled} + outlined > ( onToggle()} - outlined={enabled} + outlined > ( setEnabled(!enabled)} - outlined={enabled} + outlined > @@ -144,9 +144,6 @@ export function CallControl({ callEmbed }: { callEmbed: CallEmbed }) { onToggle={() => callEmbed.control.toggleMicrophone()} /> callEmbed.control.toggleSound()} /> - - - callEmbed.control.toggleVideo()} /> {false && } diff --git a/src/app/features/call-status/CallStatus.tsx b/src/app/features/call-status/CallStatus.tsx index 33e3a5f2..7a9177d4 100644 --- a/src/app/features/call-status/CallStatus.tsx +++ b/src/app/features/call-status/CallStatus.tsx @@ -11,6 +11,8 @@ import { MemberGlance } from './MemberGlance'; import { StatusDivider } from './components'; import { CallEmbed } from '../../plugins/call/CallEmbed'; import { useCallJoined } from '../../hooks/useCallEmbed'; +import { useCallSpeakers } from '../../hooks/useCallSpeakers'; +import { MemberSpeaking } from './MemberSpeaking'; type CallStatusProps = { callEmbed: CallEmbed; @@ -22,28 +24,51 @@ export function CallStatus({ callEmbed }: CallStatusProps) { const callMembers = useCallMembers(room, callSession); const screenSize = useScreenSize(); const callJoined = useCallJoined(callEmbed); + const speakers = useCallSpeakers(callEmbed); + + const compact = screenSize === ScreenSize.Mobile; + + const memberVisible = callJoined && callMembers.length > 0; return ( - - {callJoined && callMembers.length > 0 ? ( - - + + {memberVisible ? ( + ) : ( )} - - + + + {speakers.size > 0 && !compact && ( + <> + + + + + )} + + {memberVisible && ( + + + + )} - + {memberVisible && !compact && } + diff --git a/src/app/features/call-status/MemberGlance.tsx b/src/app/features/call-status/MemberGlance.tsx index 3773ff3a..88c114d5 100644 --- a/src/app/features/call-status/MemberGlance.tsx +++ b/src/app/features/call-status/MemberGlance.tsx @@ -9,13 +9,15 @@ import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { StackedAvatar } from '../../components/stacked-avatar'; import { useOpenUserRoomProfile } from '../../state/hooks/userRoomProfile'; import { getMouseEventCords } from '../../utils/dom'; +import * as css from './styles.css'; type MemberGlanceProps = { room: Room; members: CallMembership[]; + speakers: Set; max?: number; }; -export function MemberGlance({ room, members, max = 6 }: MemberGlanceProps) { +export function MemberGlance({ room, members, speakers, max = 6 }: MemberGlanceProps) { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); const openUserProfile = useOpenUserRoomProfile(); @@ -37,6 +39,7 @@ export function MemberGlance({ room, members, max = 6 }: MemberGlanceProps) { return ( ; +}; +export function MemberSpeaking({ room, speakers }: MemberSpeakingProps) { + const speakingNames = Array.from(speakers).map( + (userId) => getMemberDisplayName(room, userId) ?? getMxIdLocalPart(userId) ?? userId + ); + return ( + + + + {speakingNames.length === 1 && ( + <> + {speakingNames[0]} + + {' is speaking...'} + + + )} + {speakingNames.length === 2 && ( + <> + {speakingNames[0]} + + {' and '} + + {speakingNames[1]} + + {' are speaking...'} + + + )} + {speakingNames.length === 3 && ( + <> + {speakingNames[0]} + + {', '} + + {speakingNames[1]} + + {' and '} + + {speakingNames[2]} + + {' are speaking...'} + + + )} + {speakingNames.length > 3 && ( + <> + {speakingNames[0]} + + {', '} + + {speakingNames[1]} + + {', '} + + {speakingNames[2]} + + {' and '} + + {speakingNames.length - 3} others + + {' are speaking...'} + + + )} + + + ); +} diff --git a/src/app/features/call-status/styles.css.ts b/src/app/features/call-status/styles.css.ts index 26b08f0b..dd32bc3d 100644 --- a/src/app/features/call-status/styles.css.ts +++ b/src/app/features/call-status/styles.css.ts @@ -15,3 +15,7 @@ export const CallStatus = style([ export const ControlDivider = style({ height: toRem(16), }); + +export const SpeakerAvatarOutline = style({ + boxShadow: `0 0 0 ${config.borderWidth.B600} ${color.Success.Main}`, +}); diff --git a/src/app/features/call/CallView.tsx b/src/app/features/call/CallView.tsx index 96955466..ff59e711 100644 --- a/src/app/features/call/CallView.tsx +++ b/src/app/features/call/CallView.tsx @@ -1,7 +1,7 @@ import { useRef } from 'react'; import { Badge, Box, color, Header, Scroll, Text, toRem } from 'folds'; import { EventType } from '$types/matrix-sdk'; -import { useCallEmbed, useCallJoined, useSyncCallEmbedPlacement } from '$hooks/useCallEmbed'; +import { useCallEmbed, useCallEmbedPlacementSync, useCallJoined } from '$hooks/useCallEmbed'; import { ContainerColor } from '$styles/ContainerColor.css'; import { usePowerLevelsContext } from '$hooks/usePowerLevels'; import { useRoom } from '$hooks/useRoom'; @@ -44,7 +44,7 @@ export function CallView() { const room = useRoom(); const callViewRef = useRef(null); - useSyncCallEmbedPlacement(callViewRef); + useCallEmbedPlacementSync(callViewRef); const powerLevels = usePowerLevelsContext(); const creators = useRoomCreators(room); diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 4ea606b8..c6736e27 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -103,7 +103,6 @@ import { useIntersectionObserver, } from '$hooks/useIntersectionObserver'; import { markAsRead } from '$utils/notifications'; -import { useDebounce } from '$hooks/useDebounce'; import { getResizeObserverEntry, useResizeObserver } from '$hooks/useResizeObserver'; import { inSameDay, minuteDifference, timeDayMonthYear, today, yesterday } from '$utils/time'; import { createMentionElement, isEmptyEditor, moveCursor } from '$components/editor'; @@ -620,9 +619,13 @@ export function RoomTimeline({ } const atBottomAnchorRef = useRef(null); - const [atBottom, setAtBottom] = useState(true); + + const [atBottom, setAtBottomState] = useState(true); const atBottomRef = useRef(atBottom); - atBottomRef.current = atBottom; + const setAtBottom = useCallback((val: boolean) => { + setAtBottomState(val); + atBottomRef.current = val; + }, []); const scrollRef = useRef(null); const scrollToBottomRef = useRef({ @@ -734,6 +737,7 @@ export function RoomTimeline({ if (!alive()) return; const evLength = getTimelinesEventsCount(lTimelines); + setAtBottom(false); setFocusItem({ index: evtAbsIndex, scrollTo: true, @@ -747,7 +751,7 @@ export function RoomTimeline({ }, }); }, - [alive] + [alive, setAtBottom] ), useCallback(() => { if (!alive()) return; @@ -829,6 +833,8 @@ export function RoomTimeline({ evtTimeline && getEventIdAbsoluteIndex(timeline.linkedTimelines, evtTimeline, evtId); if (typeof absoluteIndex === 'number') { + setAtBottom(false); + const scrolled = scrollToItem(absoluteIndex, { behavior: reducedMotion ? 'instant' : 'smooth', align: 'center', @@ -837,14 +843,14 @@ export function RoomTimeline({ if (onScroll) onScroll(scrolled); setFocusItem({ index: absoluteIndex, - scrollTo: false, + scrollTo: !scrolled, highlight, }); } else { loadEventTimeline(evtId); } }, - [room, timeline, scrollToItem, loadEventTimeline, reducedMotion] + [room, timeline, scrollToItem, loadEventTimeline, reducedMotion, setAtBottom] ); useLiveTimelineRefresh( @@ -910,29 +916,26 @@ export function RoomTimeline({ } }, [mx, room, hideReads]); - const debounceSetAtBottom = useDebounce( - useCallback((entry: IntersectionObserverEntry) => { - if (!entry.isIntersecting) setAtBottom(false); - }, []), - { wait: 1000 } - ); useIntersectionObserver( useCallback( (entries) => { const target = atBottomAnchorRef.current; if (!target) return; const targetEntry = getIntersectionObserverEntry(target, entries); - if (targetEntry) debounceSetAtBottom(targetEntry); - if (targetEntry?.isIntersecting) { - // Track scroll position independently of atLiveEndRef so that atBottom - // is always accurate. tryAutoMarkAsRead still requires atLiveEndRef. + if (!targetEntry) return; + + if (targetEntry.isIntersecting) { + // User has reached the bottom setAtBottom(true); if (atLiveEndRef.current && document.hasFocus()) { tryAutoMarkAsRead(); } + } else { + // User has intentionally scrolled up. + setAtBottom(false); } }, - [debounceSetAtBottom, tryAutoMarkAsRead] + [tryAutoMarkAsRead, setAtBottom] ), useCallback( () => ({ @@ -1006,36 +1009,20 @@ export function RoomTimeline({ const contentEl = scrollEl?.firstElementChild as HTMLElement; if (!scrollEl || !contentEl) return () => {}; - let lastScrollTop = scrollEl.scrollTop; - let userIsScrollingUp = false; - - // Track if user is scrolling up - const handleScroll = () => { - if (scrollEl.scrollTop < lastScrollTop) { - userIsScrollingUp = true; - } else if (scrollEl.scrollHeight - scrollEl.scrollTop <= scrollEl.clientHeight + 10) { - userIsScrollingUp = false; - } - lastScrollTop = scrollEl.scrollTop; - }; - const forceScroll = () => { // if the user isn't scrolling jump down to latest content - if (!userIsScrollingUp) { - scrollToBottom(scrollEl, 'instant'); - } + if (!atBottomRef.current) return; + scrollToBottom(scrollEl, 'instant'); }; const resizeObserver = new ResizeObserver(() => { requestAnimationFrame(forceScroll); }); - scrollEl.addEventListener('scroll', handleScroll, { passive: true }); resizeObserver.observe(contentEl); return () => { resizeObserver.disconnect(); - scrollEl.removeEventListener('scroll', handleScroll); }; }, [room]); @@ -1090,7 +1077,9 @@ export function RoomTimeline({ // reach the true bottom (e.g. after images finish loading or the // virtual keyboard shifts the viewport). if (behavior === 'instant') { - setTimeout(() => scrollToBottom(scrollEl, 'instant'), 80); + setTimeout(() => { + scrollToBottom(scrollEl, 'instant'); + }, 80); } } } diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index 9199990f..f20f6a18 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -350,6 +350,18 @@ function MessageInternal( const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); + const pmp = useMemo( + () => + mEvent.event.content?.['com.beeper.per_message_profile'] as + | { + avatar_url: string | undefined; + displayname: string | undefined; + id: string | undefined; + } + | undefined, + [mEvent] + ); + // Profiles and Colors const profile = useUserProfile(senderId, room); const { color: usernameColor, font: usernameFont } = useSableCosmetics(senderId, room); @@ -359,9 +371,14 @@ function MessageInternal( // avatar so per-room avatar overrides are respected in the timeline. const avatarUrl = useMemo(() => { if (collapse) return undefined; - const mxc = getMemberAvatarMxc(room, senderId) || profile.avatarUrl; + const mxc = pmp?.avatar_url || getMemberAvatarMxc(room, senderId) || profile.avatarUrl; return mxc ? mxcUrlToHttp(mx, mxc, useAuthentication, 48, 48, 'crop') : undefined; - }, [collapse, profile.avatarUrl, senderId, mx, room, useAuthentication]); + }, [pmp, collapse, profile.avatarUrl, senderId, mx, room, useAuthentication]); + + const displayName = useMemo( + () => pmp?.displayname || senderDisplayName, + [pmp, senderDisplayName] + ); const cachedAvatar = useBlobCache(avatarUrl ?? undefined); @@ -425,7 +442,7 @@ function MessageInternal( onClick={onUsernameClick} > - {senderDisplayName} + {displayName} {showPronouns && ( @@ -468,7 +485,7 @@ function MessageInternal( } /> @@ -882,7 +899,7 @@ function MessageInternal( autoFocus value={nickDraft} onChange={(e) => setNickDraft(e.target.value)} - placeholder={senderDisplayName} + placeholder={displayName} onKeyDown={(e) => { if (e.key === 'Enter') { setNickname(senderId, nickDraft || undefined, mx); diff --git a/src/app/hooks/useCall.ts b/src/app/hooks/useCall.ts index a4374fcd..1364e459 100644 --- a/src/app/hooks/useCall.ts +++ b/src/app/hooks/useCall.ts @@ -53,3 +53,12 @@ export const useCallMembers = (room: Room, session: MatrixRTCSession): CallMembe return memberships; }; + +export const useCallMembersChange = (session: MatrixRTCSession, callback: () => void): void => { + useEffect(() => { + session.on(MatrixRTCSessionEvent.MembershipsChanged, callback); + return () => { + session.removeListener(MatrixRTCSessionEvent.MembershipsChanged, callback); + }; + }, [session, callback]); +}; diff --git a/src/app/hooks/useCallEmbed.ts b/src/app/hooks/useCallEmbed.ts index e04182dd..620530d5 100644 --- a/src/app/hooks/useCallEmbed.ts +++ b/src/app/hooks/useCallEmbed.ts @@ -2,6 +2,8 @@ import { createContext, RefObject, useCallback, useContext, useEffect, useState import { MatrixRTCSession } from 'matrix-js-sdk/lib/matrixrtc/MatrixRTCSession'; import { MatrixClient, Room } from 'matrix-js-sdk'; import { useSetAtom } from 'jotai'; +import { settingsAtom } from '$state/settings'; +import { useSetting } from '$state/hooks/settings'; import { CallEmbed, ElementCallThemeKind, @@ -13,6 +15,7 @@ import { ThemeKind, useTheme } from './useTheme'; import { callEmbedAtom } from '../state/callEmbed'; import { useResizeObserver } from './useResizeObserver'; import { CallControlState } from '../plugins/call/CallControlState'; +import { useCallMembersChange, useCallSession } from './useCall'; const CallEmbedContext = createContext(undefined); @@ -77,6 +80,19 @@ export const useCallStart = (dm = false) => { export const useCallJoined = (embed?: CallEmbed): boolean => { const [joined, setJoined] = useState(embed?.joined ?? false); + const [allowPip] = useSetting(settingsAtom, 'allowPipVideos'); + + if (embed && allowPip) { + const removeDisablePictureInPicture = (mutated: any) => { + mutated.forEach((event: any) => { + Array.from(event.target.getElementsByTagName('video')).forEach((video: any) => { + video.removeAttribute('disablepictureinpicture'); + }); + }); + }; + const pipObserver = new MutationObserver(removeDisablePictureInPicture); + pipObserver.observe(embed.iframe.contentDocument!, { subtree: true, childList: true }); + } useClientWidgetApiEvent( embed?.call, @@ -99,6 +115,14 @@ export const useCallHangupEvent = (embed: CallEmbed, callback: () => void) => { useClientWidgetApiEvent(embed.call, ElementWidgetActions.HangupCall, callback); }; +export const useCallMemberSoundSync = (embed: CallEmbed) => { + const callSession = useCallSession(embed.room); + useCallMembersChange( + callSession, + useCallback(() => embed.control.applySound(), [embed]) + ); +}; + export const useCallThemeSync = (embed: CallEmbed) => { const theme = useTheme(); @@ -109,7 +133,7 @@ export const useCallThemeSync = (embed: CallEmbed) => { }, [theme.kind, embed]); }; -export const useSyncCallEmbedPlacement = (containerViewRef: RefObject): void => { +export const useCallEmbedPlacementSync = (containerViewRef: RefObject): void => { const callEmbedRef = useCallEmbedRef(); const syncCallEmbedPlacement = useCallback(() => { diff --git a/src/app/hooks/useCallSpeakers.ts b/src/app/hooks/useCallSpeakers.ts new file mode 100644 index 00000000..24003678 --- /dev/null +++ b/src/app/hooks/useCallSpeakers.ts @@ -0,0 +1,60 @@ +import { useCallback, useEffect, useMemo, useState } from 'react'; +import { CallEmbed } from '../plugins/call'; +import { useMutationObserver } from './useMutationObserver'; +import { isUserId } from '../utils/matrix'; +import { useCallMembers, useCallSession } from './useCall'; +import { useCallJoined } from './useCallEmbed'; + +export const useCallSpeakers = (callEmbed: CallEmbed): Set => { + const [speakers, setSpeakers] = useState(new Set()); + const callSession = useCallSession(callEmbed.room); + const callMembers = useCallMembers(callEmbed.room, callSession); + const joined = useCallJoined(callEmbed); + + const videoContainers = useMemo(() => { + if (callMembers && joined) return callEmbed.document?.querySelectorAll('[data-video-fit]'); + return undefined; + }, [callEmbed, callMembers, joined]); + + const mutationObserver = useMutationObserver( + useCallback( + (mutations) => { + const s = new Set(); + + mutations.forEach((mutation) => { + if (mutation.type !== 'attributes') return; + const el = mutation.target as HTMLElement; + + const style = callEmbed.iframe.contentWindow?.getComputedStyle(el, '::before'); + if (!style) return; + const tileBackgroundImage = style.getPropertyValue('background-image'); + const speaking = tileBackgroundImage !== 'none'; + if (!speaking) return; + + const speakerId = el.querySelector('[aria-label]')?.getAttribute('aria-label'); + if (speakerId && isUserId(speakerId)) { + s.add(speakerId); + } + }); + + setSpeakers(s); + }, + [callEmbed] + ) + ); + + useEffect(() => { + videoContainers?.forEach((element) => { + mutationObserver.observe(element, { + attributes: true, + attributeFilter: ['class', 'style'], + }); + }); + + return () => { + mutationObserver.disconnect(); + }; + }, [videoContainers, mutationObserver]); + + return speakers; +}; diff --git a/src/app/hooks/useCommands.ts b/src/app/hooks/useCommands.ts index fb171874..11a7936e 100644 --- a/src/app/hooks/useCommands.ts +++ b/src/app/hooks/useCommands.ts @@ -241,6 +241,13 @@ export enum Command { SetExt = 'setext', DelExt = 'delext', DiscardSession = 'discardsession', + // Cute Events + Hug = 'hug', + Cuddle = 'cuddle', + // our own cute events, not part of FluffyChat or other clients + Wave = 'wave', + Poke = 'poke', + Headpat = 'headpat', } export type CommandContent = { @@ -1295,6 +1302,83 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => { } }, }, + // Cute Events + [Command.Hug]: { + name: Command.Hug, + description: 'Send a hug to someone. Example: /hug [@user:example.org]', + exe: async (payload) => { + const target = payload.trim(); + await mx.sendMessage(room.roomId, { + msgtype: 'im.fluffychat.cute_event', + 'm.mentions': { + user_ids: target ? [target] : [], + }, + cute_type: 'hug', + body: `🤗`, + } as any); + }, + }, + [Command.Cuddle]: { + name: Command.Cuddle, + description: 'Send a cuddle to someone. Example: /cuddle [@user:example.org]', + exe: async (payload) => { + const target = payload.trim(); + await mx.sendMessage(room.roomId, { + msgtype: 'im.fluffychat.cute_event', + cute_type: 'cuddle', + 'm.mentions': { + user_ids: target ? [target] : [], + }, + body: `😊`, + } as any); + }, + }, + [Command.Wave]: { + name: Command.Wave, + description: 'Send a wave to someone. Example: /wave [@user:example.org]', + exe: async (payload) => { + const target = payload.trim(); + await mx.sendMessage(room.roomId, { + msgtype: 'im.fluffychat.cute_event', + cute_type: 'wave', + 'm.mentions': { + user_ids: target ? [target] : [], + }, + body: `👋`, + } as any); + }, + }, + [Command.Poke]: { + name: Command.Poke, + description: 'Send a poke to someone. Example: /poke [@user:example.org]', + exe: async (payload) => { + const target = payload.trim(); + await mx.sendMessage(room.roomId, { + msgtype: 'im.fluffychat.cute_event', + cute_type: 'poke', + 'm.mentions': { + user_ids: target ? [target] : [], + }, + body: `🫵`, + } as any); + }, + }, + [Command.Headpat]: { + name: Command.Headpat, + description: 'Send a headpat to someone. Example: /headpat [@user:example.org]', + // not really like any of the other cute events, but it was too good not to include + // using a custom msgtype to avoid confusion with the other existing cute events + exe: async (payload) => { + const target = payload.trim(); + await mx.sendMessage(room.roomId, { + msgtype: 'fyi.cisnt.headpat', + 'm.mentions': { + user_ids: target ? [target] : [], + }, + body: `*pat pat*`, + } as any); + }, + }, }), [mx, navigateRoom, room, profile.displayName, profile.avatarUrl, developerTools] ); diff --git a/src/app/hooks/useMutationObserver.ts b/src/app/hooks/useMutationObserver.ts new file mode 100644 index 00000000..5d0ce2ab --- /dev/null +++ b/src/app/hooks/useMutationObserver.ts @@ -0,0 +1,37 @@ +import { useEffect, useMemo } from 'react'; + +export type OnMutationCallback = (mutations: MutationRecord[]) => void; + +export const getMutationRecord = ( + target: Node, + mutations: MutationRecord[] +): MutationRecord | undefined => mutations.find((mutation) => mutation.target === target); + +export const useMutationObserver = ( + onMutationCallback: OnMutationCallback, + observeElement?: Node | null | (() => Node | null), + options?: MutationObserverInit +): MutationObserver => { + const mutationObserver = useMemo( + () => new MutationObserver(onMutationCallback), + [onMutationCallback] + ); + + useEffect(() => () => mutationObserver?.disconnect(), [mutationObserver]); + + useEffect(() => { + const element = typeof observeElement === 'function' ? observeElement() : observeElement; + + if (element) { + mutationObserver.observe(element, options); + } + + return () => { + if (element) { + mutationObserver.disconnect(); + } + }; + }, [mutationObserver, observeElement, options]); + + return mutationObserver; +}; diff --git a/src/app/plugins/call/CallControl.ts b/src/app/plugins/call/CallControl.ts index c2087fe0..44dcacd7 100644 --- a/src/app/plugins/call/CallControl.ts +++ b/src/app/plugins/call/CallControl.ts @@ -47,6 +47,10 @@ export class CallControl extends EventEmitter implements CallControlState { this.emitStateUpdate(); } + public applySound() { + this.setSound(this.sound); + } + private setMediaState(state: ElementMediaStatePayload) { return this.call.transport.send(ElementWidgetActions.DeviceMute, state); } @@ -55,10 +59,8 @@ export class CallControl extends EventEmitter implements CallControlState { const callDocument = this.iframe.contentDocument ?? this.iframe.contentWindow?.document; if (callDocument) { callDocument.querySelectorAll('audio').forEach((el) => { - if (el instanceof HTMLAudioElement) { - // eslint-disable-next-line no-param-reassign - el.muted = !sound; - } + // eslint-disable-next-line no-param-reassign + el.muted = !sound; }); } } diff --git a/src/app/plugins/call/CallEmbed.ts b/src/app/plugins/call/CallEmbed.ts index b5491447..c0c02f9c 100644 --- a/src/app/plugins/call/CallEmbed.ts +++ b/src/app/plugins/call/CallEmbed.ts @@ -163,6 +163,10 @@ export class CallEmbed { return this.room.roomId; } + get document(): Document | undefined { + return this.iframe.contentDocument ?? this.iframe.contentWindow?.document; + } + public setTheme(theme: ElementCallThemeKind) { return this.call.transport.send(WidgetApiToWidgetAction.ThemeChange, { name: theme, diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index a9c1f2ec..7174b981 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -157,7 +157,7 @@ const defaultSettings: Settings = { rightSwipeAction: RightSwipeAction.Reply, hideMembershipInReadOnly: true, useRightBubbles: false, - showUnreadCounts: true, + showUnreadCounts: false, badgeCountDMsOnly: false, showPingCounts: true, hideReads: false, diff --git a/src/app/utils/common.ts b/src/app/utils/common.ts index 678f1b6e..8507e06c 100644 --- a/src/app/utils/common.ts +++ b/src/app/utils/common.ts @@ -87,9 +87,17 @@ export const scaleYDimension = (x: number, scaledX: number, y: number): number = }; export const parseGeoUri = (location: string) => { + if (!location) return null; + const [, data] = location.split(':'); + if (!data) return null; + const [cords] = data.split(';'); + if (!cords) return null; + const [latitude, longitude] = cords.split(','); + if (!latitude || !longitude) return null; + return { latitude, longitude,