diff --git a/.changeset/add_persona_latching_when_using_shorthands.md b/.changeset/add_persona_latching_when_using_shorthands.md new file mode 100644 index 000000000..d31b91a59 --- /dev/null +++ b/.changeset/add_persona_latching_when_using_shorthands.md @@ -0,0 +1,5 @@ +--- +default: minor +--- + +# Add persona latching when using shorthands diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 4cb913fc8..f57e00ca6 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -151,6 +151,8 @@ import { convertPerMessageProfileToBeeperFormat, getCurrentlyUsedPerMessageProfileForAccount, getCurrentlyUsedPerMessageProfileForRoom, + type PerMessageProfile, + setCurrentlyUsedPerMessageProfileIdForRoom, } from '$hooks/usePerMessageProfile'; import { Bell, @@ -336,8 +338,11 @@ export const RoomInput = forwardRef( const [pkCompatEnable] = useSetting(settingsAtom, 'pkCompat'); const [pmpProxyingEnable] = useSetting(settingsAtom, 'pmpProxying'); + const [pmpLatchingEnable] = useSetting(settingsAtom, 'pmpLatching'); const [pmpPickerEnable] = useSetting(settingsAtom, 'pmpPicker'); + const [latchedPersona, setLatchedPersona] = useState(); + const emojiBtnRef = useRef(null); const gifBtnRef = useRef(null); const stickerBtnRef = useRef(null); @@ -1284,6 +1289,15 @@ export const RoomInput = forwardRef( room, }) ); + + if (pmpLatchingEnable) { + await setCurrentlyUsedPerMessageProfileIdForRoom( + mx, + roomId, + proxiedPerMessageProfile.id + ); + setLatchedPersona(proxiedPerMessageProfile); + } } } } @@ -1325,7 +1339,7 @@ export const RoomInput = forwardRef( */ 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( replyDraft, silentReply, pmpProxyingEnable, + pmpLatchingEnable, pluralkitProxyMessageHandler, scheduledTime, editingScheduledDelayId, @@ -1509,6 +1524,7 @@ export const RoomInput = forwardRef( editingEvent, getEditingContent, onCancelEdit, + latchedPersona, ]); const handleKeyDown: KeyboardEventHandler = useCallback( @@ -2162,6 +2178,7 @@ export const RoomInput = forwardRef( roomId={roomId} suppressEditorRefocus={suppressEditorRefocus} onTabChange={setPersonaPickerTab} + latchedPersona={latchedPersona} /> )} diff --git a/src/app/features/room/persona-picker/PersonaPicker.tsx b/src/app/features/room/persona-picker/PersonaPicker.tsx index 55e6d3e3c..04f16c545 100644 --- a/src/app/features/room/persona-picker/PersonaPicker.tsx +++ b/src/app/features/room/persona-picker/PersonaPicker.tsx @@ -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(); @@ -68,7 +70,9 @@ export function PersonaPicker({ const [selectedGlobalPersona, setSelectedGlobalPersona] = useState( null ); - const [selectedRoomPersona, setSelectedRoomPersona] = useState(null); + const [selectedRoomPersona, setSelectedRoomPersona] = useState( + 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_); diff --git a/src/app/features/settings/Persona/PKCompat.tsx b/src/app/features/settings/Persona/PKCompat.tsx index 06ed2ccb6..86df62eba 100644 --- a/src/app/features/settings/Persona/PKCompat.tsx +++ b/src/app/features/settings/Persona/PKCompat.tsx @@ -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 ( @@ -55,6 +56,30 @@ export function PKCompatSettings() { } /> + + + } + /> + ); } diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index 04b609745..94cdcb032 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -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',