Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add_persona_latching_when_using_shorthands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: minor
---

# Add persona latching when using shorthands
19 changes: 18 additions & 1 deletion src/app/features/room/RoomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ import {
convertPerMessageProfileToBeeperFormat,
getCurrentlyUsedPerMessageProfileForAccount,
getCurrentlyUsedPerMessageProfileForRoom,
type PerMessageProfile,
setCurrentlyUsedPerMessageProfileIdForRoom,
} from '$hooks/usePerMessageProfile';
import {
Bell,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1284,6 +1289,15 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
room,
})
);

if (pmpLatchingEnable) {
await setCurrentlyUsedPerMessageProfileIdForRoom(
mx,
roomId,
proxiedPerMessageProfile.id
);
setLatchedPersona(proxiedPerMessageProfile);
}
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1485,6 +1499,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
replyDraft,
silentReply,
pmpProxyingEnable,
pmpLatchingEnable,
pluralkitProxyMessageHandler,
scheduledTime,
editingScheduledDelayId,
Expand All @@ -1509,6 +1524,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
editingEvent,
getEditingContent,
onCancelEdit,
latchedPersona,
]);

const handleKeyDown: KeyboardEventHandler = useCallback(
Expand Down Expand Up @@ -2162,6 +2178,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
roomId={roomId}
suppressEditorRefocus={suppressEditorRefocus}
onTabChange={setPersonaPickerTab}
latchedPersona={latchedPersona}
/>
)}
</>
Expand Down
10 changes: 7 additions & 3 deletions src/app/features/room/persona-picker/PersonaPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type PersonaPickerProps = {
roomId: string;
suppressEditorRefocus: () => void;
onTabChange: (tab: PersonaPickerTab) => void;
latchedPersona: PerMessageProfile | undefined;
};

export function PersonaPicker({
Expand All @@ -61,14 +62,17 @@ export function PersonaPicker({
roomId,
suppressEditorRefocus,
onTabChange,
latchedPersona,
}: PersonaPickerProps) {
const useAuthentication = useMediaAuthentication();
const [AddPersonaMenuAnchor, setAddPersonaMenuAnchor] = useState<RectCords>();
const [profiles, setProfiles] = useState<PerMessageProfile[] | undefined>(undefined);
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;
Expand All @@ -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_);
Expand Down
25 changes: 25 additions & 0 deletions src/app/features/settings/Persona/PKCompat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
);
}
2 changes: 2 additions & 0 deletions src/app/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export interface Settings {
highlightMentions: boolean;
pkCompat: boolean;
pmpProxying: boolean;
pmpLatching: boolean;
pmpPicker: boolean;
mentionInReplies: boolean;
profileChangePropagation: ProfileChangePropagation;
Expand Down Expand Up @@ -419,6 +420,7 @@ export const defaultSettings: Settings = {
highlightMentions: true,
pkCompat: false,
pmpProxying: false,
pmpLatching: false,
pmpPicker: false,
mentionInReplies: true,
profileChangePropagation: 'unchanged',
Expand Down