feat(room): per-room "Show link previews" toggle (#493)
CI / Build & Quality Checks (push) Skipped
CI / Secret scan (gitleaks) (push) Skipped
CI / Playwright smoke (e2e) (push) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 53s
CI / Build & Quality Checks (pull_request) Successful in 4m1s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Playwright smoke (e2e) (pull_request) Successful in 17m49s

Rooms that post nothing but links (e.g. World News RSS) fill the timeline
with preview cards, and the only fix was turning previews off everywhere.

Room settings → General → Display now has "Show link previews" for that
room only, for this user only. It is saved as the standard
org.matrix.room.preview_urls room account data ({ disable }), the same
event Element reads, so it syncs across devices and works in Element.
The room's choice wins over the global setting; "Use global setting"
saves {} to go back. Room timeline and threads both follow it.

Closes #493

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-25 12:43:05 -05:00
1 parent 4fe9b97eb2
commit f63ec2e373
8 files changed
+215 -6

No files matched your search

@@ -20,6 +20,7 @@ import {
} from '../../common-settings/general';
import { useRoomCreators } from '../../../hooks/useRoomCreators';
import { useRoomPermissions } from '../../../hooks/useRoomPermissions';
import { RoomLinkPreviews } from './RoomLinkPreviews';
type GeneralProps = {
requestClose: () => void;
@@ -80,6 +81,10 @@ export function General({ requestClose }: GeneralProps) {
<Text size="L400">Advanced Options</Text>
<RoomUpgrade permissions={permissions} requestClose={requestClose} />
</Box>
<Box direction="Column" gap="100">
<Text size="L400">Display</Text>
<RoomLinkPreviews />
</Box>
<Box direction="Column" gap="100">
<Text size="L400">Privacy</Text>
<DeleteMyMessages />
@@ -0,0 +1,90 @@
import React, { useCallback, useEffect, useState } from 'react';
import { Box, Button, Switch, Text, color } from 'folds';
import { SequenceCard } from '../../../components/sequence-card';
import { SequenceCardStyle } from '../styles.css';
import { SettingTile } from '../../../components/setting-tile';
import { useMatrixClient } from '../../../hooks/useMatrixClient';
import { useRoom } from '../../../hooks/useRoom';
import { useRoomPreviewChoice, useRoomUrlPreview } from '../../../hooks/useRoomUrlPreview';
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
import { AccountDataEvent } from '../../../../types/matrix/accountData';
import { setRoomAccountData } from '../../../utils/accountData';
import { RoomPreviewUrlsContent } from '../../../utils/roomUrlPreview';
/**
* [Gitea #493] "Show link previews" for this room only, for this user only.
* Saved as `org.matrix.room.preview_urls` room account data (synced across
* devices, also read by Element). "Use global setting" saves `{}`, which every
* Lotus device reads as "follow the global setting".
*/
export function RoomLinkPreviews() {
const mx = useMatrixClient();
const room = useRoom();
const roomChoice = useRoomPreviewChoice(room);
const shown = useRoomUrlPreview(room);
const [submitState, submit] = useAsyncCallback(
useCallback(
(content: RoomPreviewUrlsContent) =>
setRoomAccountData(mx, room.roomId, AccountDataEvent.RoomPreviewUrls, content),
[mx, room.roomId],
),
);
const saving = submitState.status === AsyncStatus.Loading;
// Optimistic value until the write comes back through /sync.
const [pending, setPending] = useState<boolean>();
useEffect(() => {
if (submitState.status === AsyncStatus.Error) setPending(undefined);
}, [submitState.status]);
useEffect(() => {
if (pending !== undefined && shown === pending) setPending(undefined);
}, [pending, shown]);
const handleToggle = (next: boolean) => {
setPending(next);
submit({ disable: !next });
};
return (
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Show link previews"
description={
roomChoice === undefined
? 'Only affects you. Following your global setting (Settings → General).'
: 'Only affects you. Set for this room; overrides your global setting.'
}
after={
<Switch
variant="Primary"
value={pending ?? shown}
onChange={handleToggle}
disabled={saving}
/>
}
>
{roomChoice !== undefined && (
<Box>
<Button
size="300"
variant="Secondary"
fill="Soft"
radii="300"
disabled={saving}
onClick={() => submit({})}
>
<Text size="B300">Use global setting</Text>
</Button>
</Box>
)}
{submitState.status === AsyncStatus.Error && (
<Text style={{ color: color.Critical.Main }} size="T200">
Couldn&apos;t save:{' '}
{submitState.error instanceof Error ? submitState.error.message : 'unknown error'}
</Text>
)}
</SettingTile>
</SequenceCard>
);
}