Skip to content

Commit 8802476

Browse files
committed
added settings toggle
1 parent 210d340 commit 8802476

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

src/app/features/settings/experimental/Experimental.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { InfoCard } from '$components/info-card';
44
import { LanguageSpecificPronouns } from '../cosmetics/LanguageSpecificPronouns';
55
import { Sync } from '../general';
66
import { BandwidthSavingEmojis } from './BandwithSavingEmojis';
7+
import { MSC4268HistoryShare } from './MSC4268HistoryShare';
78

89
type ExperimentalProps = {
910
requestClose: () => void;
@@ -43,6 +44,7 @@ export function Experimental({ requestClose }: ExperimentalProps) {
4344
<br />
4445
<Box direction="Column" gap="700">
4546
<Sync />
47+
<MSC4268HistoryShare />
4648
<LanguageSpecificPronouns />
4749
<BandwidthSavingEmojis />
4850
</Box>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { SequenceCard } from '$components/sequence-card';
2+
import { SettingTile } from '$components/setting-tile';
3+
import { useSetting } from '$state/hooks/settings';
4+
import { settingsAtom } from '$state/settings';
5+
import { Box, Switch, Text } from 'folds';
6+
import { SequenceCardStyle } from '../styles.css';
7+
8+
export function MSC4268HistoryShare() {
9+
const [enabledMSC4268Command, setEnabledMSC4268Command] = useSetting(
10+
settingsAtom,
11+
'enableMSC4268CMD'
12+
);
13+
14+
return (
15+
<Box direction="Column" gap="100">
16+
<Text size="L400">Enable Sharing of Encrypted History</Text>
17+
<SequenceCard
18+
className={SequenceCardStyle}
19+
variant="SurfaceVariant"
20+
direction="Column"
21+
gap="100"
22+
>
23+
<SettingTile
24+
title="Enable the /sharehistory command"
25+
description="If enabled, this command will allow users to share encrypted history with other newly joined users, as per MSC4268."
26+
after={
27+
<Switch
28+
variant="Primary"
29+
value={enabledMSC4268Command}
30+
onChange={setEnabledMSC4268Command}
31+
title={
32+
enabledMSC4268Command
33+
? 'Disable /sharehistory command'
34+
: 'Enable /sharehistory command'
35+
}
36+
/>
37+
}
38+
/>
39+
</SequenceCard>
40+
</Box>
41+
);
42+
}

src/app/hooks/useCommands.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export type CommandRecord = Record<Command, CommandContent>;
266266
export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
267267
const { navigateRoom } = useRoomNavigate();
268268
const [developerTools] = useSetting(settingsAtom, 'developerTools');
269+
const [enableMSC4268CMD] = useSetting(settingsAtom, 'enableMSC4268CMD');
269270
const profile = useUserProfile(mx.getSafeUserId());
270271
const openBugReport = useOpenBugReportModal();
271272

@@ -1186,6 +1187,14 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
11861187
exe: async (payload) => {
11871188
const targetUserId = payload.trim();
11881189
const { roomId } = room;
1190+
if (!enableMSC4268CMD) {
1191+
sendFeedback(
1192+
'This command is disabled. Enable it under experimental settings to use it.',
1193+
room,
1194+
mx.getSafeUserId()
1195+
);
1196+
return;
1197+
}
11891198
if (!targetUserId) {
11901199
sendFeedback('Usage: /sharee2eehistory @user:example.org', room, mx.getSafeUserId());
11911200
return;
@@ -1296,7 +1305,16 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
12961305
},
12971306
},
12981307
}),
1299-
[mx, navigateRoom, room, profile.displayName, profile.avatarUrl, developerTools, openBugReport]
1308+
[
1309+
mx,
1310+
navigateRoom,
1311+
room,
1312+
profile.displayName,
1313+
profile.avatarUrl,
1314+
developerTools,
1315+
enableMSC4268CMD,
1316+
openBugReport,
1317+
]
13001318
);
13011319

13021320
return commands;

src/app/state/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface Settings {
6464
dateFormatString: string;
6565

6666
developerTools: boolean;
67+
enableMSC4268CMD: boolean;
6768

6869
// Cosmetics!
6970
jumboEmojiSize: JumboEmojiSize;
@@ -129,6 +130,8 @@ const defaultSettings: Settings = {
129130
legacyUsernameColor: false,
130131
allowPipVideos: false,
131132

133+
enableMSC4268CMD: false,
134+
132135
// Push notifications (SW/Sygnal): default on for mobile, opt-in on desktop.
133136
// In-app pill banner: default on for mobile (primary foreground alert), opt-in on desktop.
134137
// System (OS) notifications: desktop-only; hidden and disabled on mobile.

0 commit comments

Comments
 (0)