diff --git a/.changeset/z_cat_settings.md b/.changeset/z_cat_settings.md new file mode 100644 index 00000000..686fc480 --- /dev/null +++ b/.changeset/z_cat_settings.md @@ -0,0 +1,5 @@ +--- +sable: minor +--- + +Added settings to Account that let you set if you are a cat or have cats, or not display other peoples cat status. diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 0031943d..3878bba5 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -31,8 +31,9 @@ import { } from '$plugins/react-custom-html-parser'; import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler'; import { RenderBody } from '$components/message'; -import { getSettings } from '$state/settings'; +import { getSettings, settingsAtom } from '$state/settings'; import { filterPronounsByLanguage } from '$utils/pronouns'; +import { useSetting } from '$state/hooks/settings'; import { CreatorChip } from './CreatorChip'; import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './UserModeration'; import { PowerChip } from './PowerChip'; @@ -50,6 +51,8 @@ const KNOWN_KEYS = [ 'moe.sable.app.name_color', 'avatar_url', 'displayname', + 'kitty.meow.has_cats', + 'kitty.meow.is_cat', ]; type UserExtendedSectionProps = { @@ -69,6 +72,18 @@ function UserExtendedSection({ }; const [showMore, setShowMore] = useState(false); + const [renderAnimals] = useSetting(settingsAtom, 'renderAnimals'); + const isCat = profile.isCat === true; + const hasCats = profile.hasCats === true; + + const catStatusText = useMemo(() => { + if (!renderAnimals) return null; + if (isCat && hasCats) return 'Cat with cats—needs pets & love!'; + if (isCat) return 'Is a cat—give pets & love!'; + if (hasCats) return 'Has cats—send love!'; + return null; + }, [renderAnimals, isCat, hasCats]); + const renderValue = (val: any) => { if (val === null || val === undefined) return 'n/a'; if (typeof val === 'boolean') return val ? 'Yes' : 'No'; @@ -152,6 +167,14 @@ function UserExtendedSection({ )} + {catStatusText && ( + + + + {catStatusText} + + + )} )} diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 7bbdf859..38063d24 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -1153,6 +1153,8 @@ export function RoomTimeline({ delete cleanExtended['moe.sable.app.name_color']; delete cleanExtended.avatar_url; delete cleanExtended.displayname; + delete cleanExtended['kitty.meow.has_cats']; + delete cleanExtended['kitty.meow.is_cat']; } openUserRoomProfile( diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 707c5916..85bf0bc3 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -23,6 +23,7 @@ import { Header, config, Spinner, + Switch, } from 'folds'; import FocusTrap from 'focus-trap-react'; import { useSetAtom } from 'jotai'; @@ -46,6 +47,8 @@ import { useCapabilities } from '$hooks/useCapabilities'; import { profilesCacheAtom } from '$state/userRoomProfile'; import { SequenceCardStyle } from '$features/settings/styles.css'; import { useUserPresence } from '$hooks/useUserPresence'; +import { useSetting } from '$state/hooks/settings'; +import { settingsAtom } from '$state/settings'; import { TimezoneEditor } from './TimezoneEditor'; import { PronounEditor } from './PronounEditor'; import { BioEditor } from './BioEditor'; @@ -484,9 +487,14 @@ function ProfileExtended({ profile, userId }: ProfileProps) { const presence = useUserPresence(userId); const currentStatus = presence?.status || ''; + // Keys we don't render here nor handle seperately but still need to exclude + const EXCLUDED_KEYS = ['kitty.meow.is_cat', 'kitty.meow.has_cats']; + // Unknown fields / unimplemented non-matrix-spec fields // Only renders them, can't edit or set - const extendedFields = Object.entries(profile.extended || {}); + const extendedFields = Object.entries(profile.extended || {}).filter( + ([key]) => !EXCLUDED_KEYS.includes(key) + ); const handleSaveField = useCallback( async (key: string, value: any) => { @@ -627,6 +635,70 @@ function ProfileExtended({ profile, userId }: ProfileProps) { ); } +type AnimalCosmeticsProps = { + profile: UserProfile; + userId: string; +}; +function AnimalCosmetics({ profile, userId }: AnimalCosmeticsProps) { + const mx = useMatrixClient(); + const setGlobalProfiles = useSetAtom(profilesCacheAtom); + const [renderAnimals, setRenderAnimals] = useSetting(settingsAtom, 'renderAnimals'); + + const isCat = profile.isCat || profile.extended?.['kitty.meow.is_cat'] === true; + const hasCats = profile.hasCats || profile.extended?.['kitty.meow.has_cats'] === true; + + const handleSaveField = useCallback( + async (key: string, value: boolean) => { + await mx.setExtendedProfileProperty?.(key, value); + setGlobalProfiles((prev) => { + const newCache = { ...prev }; + delete newCache[userId]; + return newCache; + }); + }, + [mx, userId, setGlobalProfiles] + ); + + return ( + + Animal Identity + + } + /> + + + handleSaveField('kitty.meow.is_cat', !isCat)} + /> + } + /> + + + handleSaveField('kitty.meow.has_cats', !hasCats)} + /> + } + /> + + + ); +} + export function Profile() { const mx = useMatrixClient(); const userId = mx.getUserId()!; @@ -662,6 +734,7 @@ export function Profile() { + ); } diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index f5af57c6..e5f1a013 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -20,6 +20,8 @@ export type UserProfile = { status?: string; bannerUrl?: string; nameColor?: string; + isCat?: boolean; + hasCats?: boolean; extended?: Record; _fetched?: boolean; }; @@ -36,6 +38,8 @@ const normalizeInfo = (info: any): UserProfile => { 'chat.commet.profile_banner', 'chat.commet.profile_status', 'moe.sable.app.name_color', + 'kitty.meow.has_cats', + 'kitty.meow.is_cat', ]; const extended: Record = {}; @@ -54,6 +58,8 @@ const normalizeInfo = (info: any): UserProfile => { status: info['chat.commet.profile_status'], bannerUrl: info['chat.commet.profile_banner'], nameColor: info['moe.sable.app.name_color'], + isCat: info['kitty.meow.is_cat'] === true, + hasCats: info['kitty.meow.has_cats'] === true, extended, _fetched: true, }; diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index b839115f..d7067171 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -80,6 +80,9 @@ export interface Settings { showPingCounts: boolean; hideReads: boolean; emojiSuggestThreshold: number; + + // furry stuff + renderAnimals: boolean; } const defaultSettings: Settings = { @@ -146,6 +149,9 @@ const defaultSettings: Settings = { showPingCounts: true, hideReads: false, emojiSuggestThreshold: 2, + + // furry stuff + renderAnimals: true, }; export const getSettings = () => {