mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-01 22:32:32 -08:00
Add the option to remove the fallback from PMPs (#1611)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Prevents some forms of annoyances in public rooms (where people are not used to PMP users) Part of #1279 #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
This commit is contained in:
7 files changed
+122
-81
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
# Add the option to remove the fallback from PMPs
|
||||
@@ -342,6 +342,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
const [pmpProxyingEnable] = useSetting(settingsAtom, 'pmpProxying');
|
||||
const [pmpLatchingEnable] = useSetting(settingsAtom, 'pmpLatching');
|
||||
const [pmpPickerEnable] = useSetting(settingsAtom, 'pmpPicker');
|
||||
const [pmpNoFallback] = useSetting(settingsAtom, 'pmpNoFallback');
|
||||
|
||||
const [latchedPersona, setLatchedPersona] = useState<PerMessageProfileMsc4461>();
|
||||
|
||||
@@ -1101,7 +1102,8 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
eventId,
|
||||
mMentions,
|
||||
linkPreviews,
|
||||
rawPmp
|
||||
rawPmp,
|
||||
pmpNoFallback
|
||||
);
|
||||
|
||||
await mx.sendMessage(roomId, content as RoomMessageEventContent);
|
||||
@@ -1360,12 +1362,9 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
}
|
||||
if (perMessageProfile) {
|
||||
content[prefix.MATRIX_UNSTABLE_PER_MESSAGE_PROFILE_PROPERTY_NAME] =
|
||||
convertPerMessageProfileToBeeperFormat(
|
||||
perMessageProfile,
|
||||
perMessageProfile.displayname.trim() !== ''
|
||||
);
|
||||
convertPerMessageProfileToBeeperFormat(perMessageProfile, !pmpNoFallback);
|
||||
|
||||
if (perMessageProfile.displayname.trim() !== '') {
|
||||
if (!pmpNoFallback && perMessageProfile.displayname.trim() !== '') {
|
||||
// if a per-message profile is used, it must per spec include a fallback
|
||||
const pmpPrefix = `${perMessageProfile.displayname}: `;
|
||||
|
||||
@@ -1514,6 +1513,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
silentReply,
|
||||
pmpProxyingEnable,
|
||||
pmpLatchingEnable,
|
||||
pmpNoFallback,
|
||||
pluralkitProxyMessageHandler,
|
||||
scheduledTime,
|
||||
editingScheduledDelayId,
|
||||
|
||||
@@ -20,7 +20,8 @@ export function buildReplacementContent(
|
||||
eventId: string,
|
||||
mMentions: IMentions,
|
||||
linkPreviews: { matched_url: string }[],
|
||||
perMessageProfile: unknown
|
||||
perMessageProfile: unknown,
|
||||
pmpNoFallback: boolean
|
||||
): IContent {
|
||||
const pmpDisplayname =
|
||||
perMessageProfile !== null &&
|
||||
@@ -34,7 +35,7 @@ export function buildReplacementContent(
|
||||
let adjustedPlainText = plainText;
|
||||
let adjustedCustomHtml = customHtml;
|
||||
|
||||
if (pmpDisplayname) {
|
||||
if (!pmpNoFallback && pmpDisplayname) {
|
||||
const bodyPrefix = `${pmpDisplayname}: `;
|
||||
if (!adjustedPlainText.startsWith(bodyPrefix))
|
||||
adjustedPlainText = bodyPrefix + adjustedPlainText;
|
||||
|
||||
@@ -127,6 +127,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const editor = useEditor();
|
||||
const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline');
|
||||
const [pmpNoFallback] = useSetting(settingsAtom, 'pmpNoFallback');
|
||||
const isComposing = useComposingCheck();
|
||||
|
||||
const [autocompleteQuery, setAutocompleteQuery] =
|
||||
@@ -290,11 +291,12 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
eventId,
|
||||
mMentions,
|
||||
linkPreviews,
|
||||
rawPmp
|
||||
rawPmp,
|
||||
pmpNoFallback
|
||||
);
|
||||
|
||||
return mx.sendMessage(roomId, content as RoomMessageEventContent);
|
||||
}, [mx, editor, roomId, mEvent, getPrevBodyAndFormattedBody, room])
|
||||
}, [mx, editor, roomId, mEvent, getPrevBodyAndFormattedBody, room, pmpNoFallback])
|
||||
);
|
||||
|
||||
const handleSave = useCallback(() => {
|
||||
|
||||
@@ -8,78 +8,108 @@ export function PKCompatSettings() {
|
||||
const [usePKCompat, setUsePKCompat] = useSetting(settingsAtom, 'pkCompat');
|
||||
const [usePmpProxying, setUsePmpProxying] = useSetting(settingsAtom, 'pmpProxying');
|
||||
const [usePmpLatching, setUsePmpLatching] = useSetting(settingsAtom, 'pmpLatching');
|
||||
const [usePmpNoFallback, setUsePmpNoFallback] = useSetting(settingsAtom, 'pmpNoFallback');
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Limited Compatibility with PluralKit-like functions</Text>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="enable-pk-commands"
|
||||
title="Enable PK commands"
|
||||
description="If enabled, it will enable a few pk style commands, currently verry limited"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePKCompat}
|
||||
onChange={setUsePKCompat}
|
||||
title={usePKCompat ? 'disable pk; commands' : 'enable pk; commands'}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="enable-pk-shorthands"
|
||||
title="Enable Shorthands"
|
||||
description="If enabled, you can use shorthands to use a Persona for one message only (eg. '✨:test')"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePmpProxying}
|
||||
onChange={setUsePmpProxying}
|
||||
title={
|
||||
usePmpProxying
|
||||
? 'disable checking typed messages for shorthands'
|
||||
: 'enable checking typed messages for shorthands'
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="enable-pk-latching"
|
||||
title="Enable Shorthand Latching"
|
||||
description="If enabled, you change a room's persona when you use a shorthand."
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePmpLatching}
|
||||
onChange={setUsePmpLatching}
|
||||
title={
|
||||
usePmpLatching
|
||||
? 'disable latching when using a shorthand'
|
||||
: 'enable latching when using a shorthand'
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
<>
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Limited Compatibility with PluralKit-like functions</Text>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="enable-pk-commands"
|
||||
title="Enable PK commands"
|
||||
description="If enabled, it will enable a few pk style commands, currently verry limited"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePKCompat}
|
||||
onChange={setUsePKCompat}
|
||||
title={usePKCompat ? 'disable pk; commands' : 'enable pk; commands'}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="enable-pk-shorthands"
|
||||
title="Enable Shorthands"
|
||||
description="If enabled, you can use shorthands to use a Persona for one message only (eg. '✨:test')"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePmpProxying}
|
||||
onChange={setUsePmpProxying}
|
||||
title={
|
||||
usePmpProxying
|
||||
? 'disable checking typed messages for shorthands'
|
||||
: 'enable checking typed messages for shorthands'
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="enable-pk-latching"
|
||||
title="Enable Shorthand Latching"
|
||||
description="If enabled, you change a room's persona when you use a shorthand."
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePmpLatching}
|
||||
onChange={setUsePmpLatching}
|
||||
title={
|
||||
usePmpLatching
|
||||
? 'disable latching when using a shorthand'
|
||||
: 'enable latching when using a shorthand'
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">General Behavior</Text>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
>
|
||||
<SettingTile
|
||||
focusId="prevent-sending-pmp-fallback"
|
||||
title="Prevent sending Persona fallback"
|
||||
description="If enabled, your messages will not include a prefix with your name to show clients that do not support Personas."
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={usePmpNoFallback}
|
||||
onChange={setUsePmpNoFallback}
|
||||
title={
|
||||
usePmpNoFallback
|
||||
? 'do not prevent fallbacks when sending a persona attached message'
|
||||
: 'prevent fallbacks when sending a persona attached message'
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -108,6 +108,7 @@ export const settingsLinkFocusIdsBySection: Record<SettingsSectionId, readonly s
|
||||
'enable-pk-commands',
|
||||
'enable-pk-shorthands',
|
||||
'enable-pk-latching',
|
||||
'prevent-sending-pmp-fallback',
|
||||
'create-pmp',
|
||||
'enable-pmp-picker',
|
||||
],
|
||||
|
||||
@@ -243,6 +243,7 @@ export interface Settings {
|
||||
pmpProxying: boolean;
|
||||
pmpLatching: boolean;
|
||||
pmpPicker: boolean;
|
||||
pmpNoFallback: boolean;
|
||||
mentionInReplies: boolean;
|
||||
profileChangePropagation: ProfileChangePropagation;
|
||||
showPersonaSetting: boolean;
|
||||
@@ -424,6 +425,7 @@ export const defaultSettings: Settings = {
|
||||
pmpProxying: false,
|
||||
pmpLatching: false,
|
||||
pmpPicker: false,
|
||||
pmpNoFallback: false,
|
||||
mentionInReplies: true,
|
||||
profileChangePropagation: 'unchanged',
|
||||
showPersonaSetting: false,
|
||||
|
||||
Reference in new issue
Block a user