mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-24 11:01:17 -08:00
Add persona latching when using shorthands
This commit is contained in:
1 parent
e48d633e62
commit
fa1e57bd9b
5 files changed
+57
-4
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
# Add persona latching when using shorthands
|
||||
@@ -151,6 +151,8 @@ import {
|
||||
convertPerMessageProfileToBeeperFormat,
|
||||
getCurrentlyUsedPerMessageProfileForAccount,
|
||||
getCurrentlyUsedPerMessageProfileForRoom,
|
||||
type PerMessageProfile,
|
||||
setCurrentlyUsedPerMessageProfileIdForRoom,
|
||||
} from '$hooks/usePerMessageProfile';
|
||||
import {
|
||||
Bell,
|
||||
@@ -336,8 +338,11 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
|
||||
const [pkCompatEnable] = useSetting(settingsAtom, 'pkCompat');
|
||||
const [pmpProxyingEnable] = useSetting(settingsAtom, 'pmpProxying');
|
||||
const [pmpLatchingEnable] = useSetting(settingsAtom, 'pmpLatching');
|
||||
const [pmpPickerEnable] = useSetting(settingsAtom, 'pmpPicker');
|
||||
|
||||
const [latchedPersona, setLatchedPersona] = useState<PerMessageProfile>();
|
||||
|
||||
const emojiBtnRef = useRef<HTMLButtonElement>(null);
|
||||
const gifBtnRef = useRef<HTMLButtonElement>(null);
|
||||
const stickerBtnRef = useRef<HTMLButtonElement>(null);
|
||||
@@ -1284,6 +1289,15 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
room,
|
||||
})
|
||||
);
|
||||
|
||||
if (pmpLatchingEnable) {
|
||||
await setCurrentlyUsedPerMessageProfileIdForRoom(
|
||||
mx,
|
||||
roomId,
|
||||
proxiedPerMessageProfile.id
|
||||
);
|
||||
setLatchedPersona(proxiedPerMessageProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1325,7 +1339,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
*/
|
||||
const globalPerMessageProfile = await getCurrentlyUsedPerMessageProfileForAccount(mx);
|
||||
const roomPerMessageProfile = await getCurrentlyUsedPerMessageProfileForRoom(mx, roomId);
|
||||
let perMessageProfile = roomPerMessageProfile ?? globalPerMessageProfile;
|
||||
let perMessageProfile = latchedPersona ?? roomPerMessageProfile ?? globalPerMessageProfile;
|
||||
|
||||
if (pmpProxyingEnable) {
|
||||
if (proxiedPerMessageProfile) perMessageProfile = proxiedPerMessageProfile;
|
||||
@@ -1485,6 +1499,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
replyDraft,
|
||||
silentReply,
|
||||
pmpProxyingEnable,
|
||||
pmpLatchingEnable,
|
||||
pluralkitProxyMessageHandler,
|
||||
scheduledTime,
|
||||
editingScheduledDelayId,
|
||||
@@ -1509,6 +1524,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
editingEvent,
|
||||
getEditingContent,
|
||||
onCancelEdit,
|
||||
latchedPersona,
|
||||
]);
|
||||
|
||||
const handleKeyDown: KeyboardEventHandler = useCallback(
|
||||
@@ -2162,6 +2178,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
roomId={roomId}
|
||||
suppressEditorRefocus={suppressEditorRefocus}
|
||||
onTabChange={setPersonaPickerTab}
|
||||
latchedPersona={latchedPersona}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -53,6 +53,7 @@ type PersonaPickerProps = {
|
||||
roomId: string;
|
||||
suppressEditorRefocus: () => void;
|
||||
onTabChange: (tab: PersonaPickerTab) => void;
|
||||
latchedPersona: PerMessageProfile | undefined;
|
||||
};
|
||||
|
||||
export function PersonaPicker({
|
||||
@@ -61,6 +62,7 @@ export function PersonaPicker({
|
||||
roomId,
|
||||
suppressEditorRefocus,
|
||||
onTabChange,
|
||||
latchedPersona,
|
||||
}: PersonaPickerProps) {
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const [AddPersonaMenuAnchor, setAddPersonaMenuAnchor] = useState<RectCords>();
|
||||
@@ -68,7 +70,9 @@ export function PersonaPicker({
|
||||
const [selectedGlobalPersona, setSelectedGlobalPersona] = useState<PerMessageProfile | null>(
|
||||
null
|
||||
);
|
||||
const [selectedRoomPersona, setSelectedRoomPersona] = useState<PerMessageProfile | null>(null);
|
||||
const [selectedRoomPersona, setSelectedRoomPersona] = useState<PerMessageProfile | null>(
|
||||
latchedPersona ?? null
|
||||
);
|
||||
const isPickerMenuItemSelected = (persona: PerMessageProfile) => {
|
||||
const selectedPersona =
|
||||
tab === PersonaPickerTab.Global ? selectedGlobalPersona : selectedRoomPersona;
|
||||
@@ -94,13 +98,13 @@ export function PersonaPicker({
|
||||
useEffect(() => {
|
||||
const syncProfile = async () => {
|
||||
const syncedRoomProfile = await getCurrentlyUsedPerMessageProfileForRoom(mx, roomId);
|
||||
setSelectedRoomPersona(syncedRoomProfile ?? null);
|
||||
if (!selectedRoomPersona) setSelectedRoomPersona(syncedRoomProfile ?? null);
|
||||
|
||||
const syncedGlobalProfile = await getCurrentlyUsedPerMessageProfileForAccount(mx);
|
||||
setSelectedGlobalPersona(syncedGlobalProfile ?? null);
|
||||
};
|
||||
syncProfile();
|
||||
}, [mx, roomId, profiles]);
|
||||
}, [mx, roomId, profiles, latchedPersona, selectedRoomPersona]);
|
||||
|
||||
const fetchProfiles = async (mx_: MatrixClient) => {
|
||||
const fetchedProfiles = await getAllPerMessageProfiles(mx_);
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Box, Switch, Text } from 'folds';
|
||||
export function PKCompatSettings() {
|
||||
const [usePKCompat, setUsePKCompat] = useSetting(settingsAtom, 'pkCompat');
|
||||
const [usePmpProxying, setUsePmpProxying] = useSetting(settingsAtom, 'pmpProxying');
|
||||
const [usePmpLatching, setUsePmpLatching] = useSetting(settingsAtom, 'pmpLatching');
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
@@ -55,6 +56,30 @@ export function PKCompatSettings() {
|
||||
}
|
||||
/>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
@@ -240,6 +240,7 @@ export interface Settings {
|
||||
highlightMentions: boolean;
|
||||
pkCompat: boolean;
|
||||
pmpProxying: boolean;
|
||||
pmpLatching: boolean;
|
||||
pmpPicker: boolean;
|
||||
mentionInReplies: boolean;
|
||||
profileChangePropagation: ProfileChangePropagation;
|
||||
@@ -419,6 +420,7 @@ export const defaultSettings: Settings = {
|
||||
highlightMentions: true,
|
||||
pkCompat: false,
|
||||
pmpProxying: false,
|
||||
pmpLatching: false,
|
||||
pmpPicker: false,
|
||||
mentionInReplies: true,
|
||||
profileChangePropagation: 'unchanged',
|
||||
|
||||
Reference in new issue
Block a user