From 7d81c098ebf7a9eb670f2c7258cb7a74df60a9ed Mon Sep 17 00:00:00 2001 From: Shea Date: Wed, 29 Jul 2026 04:40:41 +0300 Subject: [PATCH 1/3] fix per-account setting Signed-off-by: Shea --- src/app/features/settings/account/Profile.tsx | 60 ++++++++++--------- src/app/hooks/useUserProfile.ts | 15 ++++- src/unstable/prefixes/misc.ts | 2 + src/unstable/prefixes/msc/profile.ts | 6 ++ src/unstable/prefixes/sable/profile.ts | 12 ++++ 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 35438d767..2347c616f 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -8,7 +8,7 @@ import type { SettingMenuOption } from '$components/setting-menu-selector'; import { SettingMenuSelector } from '$components/setting-menu-selector'; import { SettingTile } from '$components/setting-tile'; import { useMatrixClient } from '$hooks/useMatrixClient'; -import type { UserProfile, MSC4440Bio } from '$hooks/useUserProfile'; +import type { UserProfile, MSC4440Bio, ColorSet } from '$hooks/useUserProfile'; import { useUserProfile } from '$hooks/useUserProfile'; import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix'; import { UserAvatar } from '$components/user-avatar'; @@ -393,6 +393,7 @@ function ProfileExtended({ profile, userId }: Readonly) { const EXCLUDED_KEYS = new Set([ prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_IS_CAT_PROPERTY_NAME, prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_HAS_CAT_PROPERTY_NAME, + prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME, ]); // Unknown fields / unimplemented non-matrix-spec fields @@ -425,6 +426,25 @@ function ProfileExtended({ profile, userId }: Readonly) { [mx, presence] ); + const color_on_dark = + profile.nameColors?.on_dark ?? + (profile.extended?.[prefix.MATRIX_UNSTABLE_COLORS] as ColorSet | undefined)?.on_dark; + const color_on_light = + profile.nameColors?.on_light ?? + (profile.extended?.[prefix.MATRIX_UNSTABLE_COLORS] as ColorSet | undefined)?.on_light; + + // Deletes the depricated key, the color specific ones should be depricated too at a later date + if (profile.nameColor || (profile.extended?.[prefix.MATRIX_UNSTABLE_COLORS] as string)) { + const fallback = + profile.nameColor ?? (profile.extended?.[prefix.MATRIX_UNSTABLE_COLORS] as string); + if (!color_on_light || !color_on_dark) + handleSaveField(prefix.MATRIX_UNSTABLE_COLORS, { + on_dark: color_on_dark ?? fallback, + on_light: color_on_light ?? fallback, + }); + handleSaveField(prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME, null); + } + return ( Extended Profile @@ -442,46 +462,28 @@ function ProfileExtended({ profile, userId }: Readonly) { direction="Column" gap="400" > - - handleSaveField(prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME, color) - } - /> - handleSaveField(prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME, color) + handleSaveField(prefix.MATRIX_UNSTABLE_COLORS, { + on_dark: color, + on_light: color_on_light, + }) } /> - handleSaveField(prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME, color) + handleSaveField(prefix.MATRIX_UNSTABLE_COLORS, { + on_dark: color_on_dark, + on_light: color, + }) } /> diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 78cfd62dc..8bb21043f 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -25,6 +25,11 @@ const inFlightProfiles = new WeakMap(); const profileRequestQueues = new WeakMap void>>(); +export type ColorSet = { + on_light?: string; + on_dark?: string; +}; + const scheduleProfileRequest = ( mx: MatrixClient, task: () => Promise> @@ -66,6 +71,7 @@ export type UserProfile = { nameColor?: string; nameColorDark?: string; nameColorLight?: string; + nameColors?: ColorSet; heroColorScheme?: Record; isCat?: boolean; hasCats?: boolean; @@ -92,6 +98,7 @@ const normalizeInfo = (info: Record): UserProfile => { prefix.MATRIX_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME, prefix.MATRIX_UNSTABLE_PROFILE_BANNER_PROPERTY_NAME, prefix.MATRIX_COMMET_UNSTABLE_PROFILE_STATUS_PROPERTY_NAME, + prefix.MATRIX_UNSTABLE_COLORS, prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME, prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME, prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME, @@ -131,6 +138,7 @@ const normalizeInfo = (info: Record): UserProfile => { nameColorLight: info[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME] as | string | undefined, + nameColors: info[prefix.MATRIX_UNSTABLE_COLORS] as ColorSet | undefined, heroColorScheme: info[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_COLOR_SCHEME_PROPERTY_NAME] as | Record | undefined, @@ -319,9 +327,12 @@ export const useUserProfile = ( } } + const colorArray = data.nameColors; + const validGlobalVal = isValidHex(data?.nameColor); - const validGlobalValDark = isValidHex(data?.nameColorDark); - const validGlobalValLight = isValidHex(data?.nameColorLight); + const validGlobalValDark = isValidHex(colorArray?.on_dark) ?? isValidHex(data?.nameColorDark); + const validGlobalValLight = + isValidHex(colorArray?.on_light) ?? isValidHex(data?.nameColorLight); const validGlobalGeneral = (renderGlobalColors || userId === mx.getUserId()) && !!validGlobalVal diff --git a/src/unstable/prefixes/misc.ts b/src/unstable/prefixes/misc.ts index 09fc536d8..0f648c32a 100644 --- a/src/unstable/prefixes/misc.ts +++ b/src/unstable/prefixes/misc.ts @@ -19,3 +19,5 @@ export const MATRIX_ELEMENT_UNSTABLE_STATE_ROOM_WIDGET_PROPERTY_NAME = 'im.vecto export const MATRIX_UNSTABLE_STATE_ROOM_BANNER_PROPERTY_NAME = 'page.codeberg.everypizza.room.banner'; + +export const MATRIX_UNSTABLE_ROLE_COLOR = 'eu.she-a.powerlevels_style'; diff --git a/src/unstable/prefixes/msc/profile.ts b/src/unstable/prefixes/msc/profile.ts index 65444b298..b0826d17b 100644 --- a/src/unstable/prefixes/msc/profile.ts +++ b/src/unstable/prefixes/msc/profile.ts @@ -20,3 +20,9 @@ export const MATRIX_STABLE_PROFILE_TIMEZONE_PROPERTY_NAME = 'm.tz'; */ export const MATRIX_UNSTABLE_MSC4466_FEATURE = 'computer.gingershaped.msc4466'; export const MATRIX_UNSTABLE_MSC4466_PROPAGATE_TO = 'computer.gingershaped.msc4466.propagate_to'; + +/** + * Unstable prefix for username colors. defined in https://github.com/matrix-org/matrix-spec-proposals/pull/4522 + */ + +export const MATRIX_UNSTABLE_COLORS = 'eu.she-a.colors'; diff --git a/src/unstable/prefixes/sable/profile.ts b/src/unstable/prefixes/sable/profile.ts index 103261bcc..034628ebe 100644 --- a/src/unstable/prefixes/sable/profile.ts +++ b/src/unstable/prefixes/sable/profile.ts @@ -5,9 +5,21 @@ * @deprecated in favor of MSC4440 */ export const MATRIX_SABLE_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME = 'moe.sable.app.bio'; + +/** + * @deprecated in favor of MSC4522 + */ export const MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME = 'moe.sable.app.name_color'; + +/** + * @deprecated in favor of MSC4522 + */ export const MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME = 'moe.sable.app.name_color_dark_theme'; + +/** + * @deprecated in favor of MSC4522 + */ export const MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME = 'moe.sable.app.name_color_light_theme'; export const MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_IS_CAT_PROPERTY_NAME = 'kitty.meow.is_cat'; From 164e03862a88a0dbf144f3806c739820876e7617 Mon Sep 17 00:00:00 2001 From: Shea Date: Wed, 29 Jul 2026 07:39:52 +0300 Subject: [PATCH 2/3] fix per-room setting Signed-off-by: Shea --- .../common-settings/cosmetics/Cosmetics.tsx | 54 +++--- .../settings/account/NameColorEditor.tsx | 5 +- src/app/features/settings/account/Profile.tsx | 2 +- src/app/hooks/commands/profile.ts | 165 ++++++++++++------ src/app/hooks/useMemberEventParser.tsx | 44 ++++- src/app/hooks/useUserProfile.ts | 26 ++- src/app/utils/roomMemberProfile.ts | 4 +- src/unstable/CustomRoomMemberEventContent.ts | 22 +++ 8 files changed, 235 insertions(+), 87 deletions(-) create mode 100644 src/unstable/CustomRoomMemberEventContent.ts diff --git a/src/app/features/common-settings/cosmetics/Cosmetics.tsx b/src/app/features/common-settings/cosmetics/Cosmetics.tsx index c9cc300dd..3cdbf2854 100644 --- a/src/app/features/common-settings/cosmetics/Cosmetics.tsx +++ b/src/app/features/common-settings/cosmetics/Cosmetics.tsx @@ -37,9 +37,11 @@ import { useCapabilities } from '$hooks/useCapabilities'; import { NameColorEditor } from '$features/settings/account/NameColorEditor'; import { PronounEditor } from '$features/settings/account/PronounEditor'; import type { PronounSet } from '$utils/pronouns'; -import { EventType } from '$types/matrix-sdk'; +import { EventTimeline, EventType } from '$types/matrix-sdk'; import { CustomStateEvent } from '$types/matrix/room'; import { AvatarUploadTile } from '$components/avatar-upload-tile/AvatarUploadTile'; +import type { CustomRoomMemberEventContent } from '$unstable/CustomRoomMemberEventContent'; +import * as prefix from '$unstable/prefixes'; const log = createLogger('Cosmetics'); @@ -250,6 +252,14 @@ export function Cosmetics({ requestBack, requestClose }: CosmeticsProps) { const powerLevels = usePowerLevels(room); const isSpace = room.isSpaceRoom(); + const mEvent = room + .getLiveTimeline() + .getState(EventTimeline.FORWARDS) + ?.getStateEvents(EventType.RoomMember, mx.getSafeUserId()); + const content = mEvent?.getContent(); + const colorOnDark = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark; + const colorOnLight = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_light; + const permissions = useRoomPermissions(creators, powerLevels); const canEditPermissions = permissions.stateEvent(EventType.RoomPowerLevels, mx.getSafeUserId()); @@ -257,7 +267,6 @@ export function Cosmetics({ requestBack, requestClose }: CosmeticsProps) { const getLevel = (eventType: string) => (powerLevels.events ?? {})?.[eventType] ?? 50; - const canHaveRoomColor = getLevel(CustomStateEvent.RoomCosmeticsColor) === 0; const canHaveRoomPronouns = getLevel(CustomStateEvent.RoomCosmeticsPronouns) === 0; const canHaveRoomFont = getLevel(CustomStateEvent.RoomCosmeticsFont) === 0; @@ -331,11 +340,27 @@ export function Cosmetics({ requestBack, requestClose }: CosmeticsProps) { gap="400" > - commands[isSpace ? Command.SColor : Command.Color].exe(color ?? 'clear') + commands[isSpace ? Command.SColor : Command.Color].exe( + color ? `dark ${color}` : 'dark reset' + ) + } + /> + + commands[isSpace ? Command.SColor : Command.Color].exe( + color ? `light ${color}` : 'light reset' + ) } /> @@ -381,22 +406,7 @@ export function Cosmetics({ requestBack, requestClose }: CosmeticsProps) { variant="SurfaceVariant" direction="Column" gap="400" - > - - handleToggle(CustomStateEvent.RoomCosmeticsColor, enabled) - } - disabled={!canEditPermissions} - /> - } - /> - + > { - if (/^#[0-9A-F]{6}$/i.test(tempColor)) { + if (isValidHex(tempColor)) { onSave(tempColor); setHasChanged(false); } @@ -81,7 +82,7 @@ export function NameColorEditor({ size="300" radii="Pill" onClick={handleSave} - disabled={!/^#[0-9A-F]{6}$/i.test(tempColor)} + disabled={!isValidHex(tempColor)} > Save diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 2347c616f..652691c69 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -444,7 +444,7 @@ function ProfileExtended({ profile, userId }: Readonly) { }); handleSaveField(prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME, null); } - + return ( Extended Profile diff --git a/src/app/hooks/commands/profile.ts b/src/app/hooks/commands/profile.ts index aadf3350f..c64a882ad 100644 --- a/src/app/hooks/commands/profile.ts +++ b/src/app/hooks/commands/profile.ts @@ -1,4 +1,3 @@ -import type { RoomMemberEventContent } from '$types/matrix-sdk'; import { EventTimeline, EventType, MatrixError } from '$types/matrix-sdk'; import { setOwnRoomMemberProfile } from '$utils/roomMemberProfile'; import { parsePronounsInput } from '$utils/pronouns'; @@ -7,6 +6,9 @@ import { CustomStateEvent } from '$types/matrix/room'; import { ErrorCode } from '../../cs-errorcode'; import type { CommandContext, CommandRecord } from './types'; import { Command } from './types'; +import { isValidHex } from '$hooks/useUserProfile'; +import * as prefix from '$unstable/prefixes'; +import type { CustomRoomMemberEventContent } from '$unstable/CustomRoomMemberEventContent'; export const createProfileCommands = (ctx: CommandContext): Partial => { const { mx, room, profileDisplayName } = ctx; @@ -21,10 +23,12 @@ export const createProfileCommands = (ctx: CommandContext): Partial(); + const content = mEvent?.getContent(); if (!content) return; - const updatedContent: RoomMemberEventContent = { ...content }; - const withDisplay = updatedContent as RoomMemberEventContent & { displayname?: string }; + const updatedContent: CustomRoomMemberEventContent = { ...content }; + const withDisplay = updatedContent as CustomRoomMemberEventContent & { + displayname?: string; + }; if (nick == null || nick === '') { delete withDisplay.displayname; } else { @@ -43,56 +47,85 @@ export const createProfileCommands = (ctx: CommandContext): Partial(); + const content = mEvent?.getContent(); if (!content) return; - const updatedContent: RoomMemberEventContent = { ...content }; + const updatedContent: CustomRoomMemberEventContent = { ...content }; if (isRemove) { // Reset to global avatar const globalAvatar = mx.getUser(mx.getSafeUserId())?.avatarUrl ?? undefined; - (updatedContent as RoomMemberEventContent & { avatar_url?: string }).avatar_url = + (updatedContent as CustomRoomMemberEventContent & { avatar_url?: string }).avatar_url = globalAvatar; } else { if (!trimmed.match(/^mxc:\/\/\S+$/)) { // bad mxc return; } - (updatedContent as RoomMemberEventContent & { avatar_url?: string }).avatar_url = trimmed; + (updatedContent as CustomRoomMemberEventContent & { avatar_url?: string }).avatar_url = + trimmed; } await setOwnRoomMemberProfile(mx, room, updatedContent); }, }, [Command.Color]: { name: Command.Color, - description: 'Set a room-specific color. Example: /color #ff00ff | /color reset', + description: 'Set a room-specific color. Example: /color light #ff00ff | /color reset', exe: async (payload) => { - const input = payload.trim().toLowerCase(); + const input = payload.trim().toLowerCase().split(' '); const userId = mx.getSafeUserId(); + const completeClear = input.length >= 0 && (input[0] === 'reset' || input[0] === 'clear'); + const isLight = + input.length === 2 && + (input[0] === 'light' || input[0] === 'on_light' || input[0] === 'both'); + const isDark = + input.length === 2 && + (input[0] === 'dark' || input[0] === 'on_dark' || input[0] === 'both'); + const color = + input[1] === 'reset' || input[1] === 'clear' + ? undefined + : input[1]?.length + ? input[1] + : ''; try { - if (input === 'reset' || input === 'clear') { - await mx.sendStateEvent(room.roomId, CustomStateEvent.RoomCosmeticsColor, {}, userId); - sendFeedback('Room color has been reset.', room, userId); - return; - } + if (!color || isValidHex(color) || completeClear) { + const mEvent = room + .getLiveTimeline() + .getState(EventTimeline.FORWARDS) + ?.getStateEvents(EventType.RoomMember, mx.getSafeUserId()); + const content = mEvent?.getContent(); + if (!content) return; + const updatedContent: CustomRoomMemberEventContent = { ...content }; + if (completeClear) { + // Reset + updatedContent[prefix.MATRIX_UNSTABLE_COLORS] = undefined; - if (/^#[0-9A-F]{6}$/i.test(input)) { - await mx.sendStateEvent( - room.roomId, - CustomStateEvent.RoomCosmeticsColor, - { color: input }, - userId - ); - sendFeedback(`Room color set to ${input}.`, room, userId); - } else { - sendFeedback('Invalid format. Use #RRGGBB.', room, userId); - } - } catch (e: unknown) { - if (e instanceof MatrixError && e.errcode === ErrorCode.M_FORBIDDEN) { + await mx.sendStateEvent(room.roomId, CustomStateEvent.RoomCosmeticsColor, {}, userId); + } else { + if (color && !isValidHex(color)) { + return; + } + updatedContent[prefix.MATRIX_UNSTABLE_COLORS] = { + on_dark: isDark ? color : content[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark, + on_light: isLight ? color : content[prefix.MATRIX_UNSTABLE_COLORS]?.on_light, + }; + } + await setOwnRoomMemberProfile(mx, room, updatedContent); sendFeedback( - 'Permission Denied. An admin must enable "Room Colors" in Settings > Cosmetics in app.sable.moe or another supported client.', + `Room color set to:\nOver dark themes ${updatedContent[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark},\nOver light themes ${updatedContent[prefix.MATRIX_UNSTABLE_COLORS]?.on_light}.`, room, userId ); + await mx.sendStateEvent(room.roomId, CustomStateEvent.RoomCosmeticsColor, {}, userId); + } else { + sendFeedback( + 'Invalid format. Use #RRGGBB for colors and specify which color.', + room, + userId + ); + } + } catch (e: unknown) { + if (e instanceof MatrixError && e.errcode === ErrorCode.M_FORBIDDEN) { + sendFeedback('Permission Denied.', room, userId); } } }, @@ -101,7 +134,7 @@ export const createProfileCommands = (ctx: CommandContext): Partial { - const input = payload.trim().toLowerCase(); + const input = payload.trim().toLowerCase().split(' '); const userId = mx.getSafeUserId(); const parents = room @@ -111,38 +144,64 @@ export const createProfileCommands = (ctx: CommandContext): Partial 0 ? parents[0]!.getStateKey() : room.roomId; + const targetRoom = mx.getRoom(targetSpaceId); + const completeClear = input.length >= 0 && (input[0] === 'reset' || input[0] === 'clear'); + const isLight = + input.length === 2 && + (input[0] === 'light' || input[0] === 'on_light' || input[0] === 'both'); + const isDark = + input.length === 2 && + (input[0] === 'dark' || input[0] === 'on_dark' || input[0] === 'both'); + const color = + input[1] === 'reset' || input[1] === 'clear' + ? undefined + : input[1]?.length + ? input[1] + : ''; try { - if (input === 'reset' || input === 'clear') { - await mx.sendStateEvent( - targetSpaceId as string, - CustomStateEvent.RoomCosmeticsColor, - {}, - userId - ); - sendFeedback('Global space color reset.', room, userId); - return; - } + if (!color || isValidHex(color) || completeClear) { + const mEvent = room + .getLiveTimeline() + .getState(EventTimeline.FORWARDS) + ?.getStateEvents(EventType.RoomMember, mx.getSafeUserId()); + const content = mEvent?.getContent(); + if (!content) return; + const updatedContent: CustomRoomMemberEventContent = { ...content }; + if (completeClear) { + // Reset + updatedContent[prefix.MATRIX_UNSTABLE_COLORS] = undefined; - if (/^#[0-9A-F]{6}$/i.test(input)) { - await mx.sendStateEvent( - targetSpaceId as string, - CustomStateEvent.RoomCosmeticsColor, - { color: input }, - userId - ); - sendFeedback(`Global space color set to ${input}.`, room, userId); + await mx.sendStateEvent(room.roomId, CustomStateEvent.RoomCosmeticsColor, {}, userId); + } else { + if (color && !isValidHex(color)) { + return; + } + updatedContent[prefix.MATRIX_UNSTABLE_COLORS] = { + on_dark: isDark ? color : content[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark, + on_light: isLight ? color : content[prefix.MATRIX_UNSTABLE_COLORS]?.on_light, + }; + } + if (targetRoom) { + await setOwnRoomMemberProfile(mx, targetRoom, updatedContent); + sendFeedback( + `Room color set to:\nOver dark themes ${updatedContent[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark},\nOver light themes ${updatedContent[prefix.MATRIX_UNSTABLE_COLORS]?.on_light}.`, + room, + userId + ); + await mx.sendStateEvent(room.roomId, CustomStateEvent.RoomCosmeticsColor, {}, userId); + } } else { - sendFeedback('Invalid format. Use #RRGGBB.', room, userId); - } - } catch (e: unknown) { - if (e instanceof MatrixError && e.errcode === ErrorCode.M_FORBIDDEN) { sendFeedback( - 'Permission Denied. An admin must enable "Space-Wide Colors" in Settings > Cosmetics in app.sable.moe or another supported client.', + 'Invalid format. Use #RRGGBB for colors and specify which color (on_light|on_dark).', room, userId ); } + } catch (e: unknown) { + if (e instanceof MatrixError && e.errcode === ErrorCode.M_FORBIDDEN) { + sendFeedback('Permission Denied.', room, userId); + } } }, }, diff --git a/src/app/hooks/useMemberEventParser.tsx b/src/app/hooks/useMemberEventParser.tsx index dd19e02c0..f10cf5abe 100644 --- a/src/app/hooks/useMemberEventParser.tsx +++ b/src/app/hooks/useMemberEventParser.tsx @@ -2,10 +2,10 @@ import type { MouseEventHandler, ReactNode } from 'react'; import { useCallback } from 'react'; import { Text } from 'folds'; import type { MatrixEvent, Room } from '$types/matrix-sdk'; -import type { IMemberContent } from '$types/matrix/room'; import { At, EnvelopeSimple, + PaintBrush, SignIn, SignOut, timelineIcon, @@ -20,6 +20,8 @@ import { useOpenUserRoomProfile } from '$state/hooks/userRoomProfile'; import { useSableCosmetics } from './useSableCosmetics'; import { useMatrixClient } from './useMatrixClient'; import { KnownMembership } from '$types/matrix-sdk'; +import type { CustomRoomMemberEventContent } from '$unstable/CustomRoomMemberEventContent'; +import { MATRIX_UNSTABLE_COLORS } from '$unstable/prefixes'; type DecoratedUserProps = { roomId: string; @@ -57,8 +59,8 @@ export type ParsedResult = { export type MemberEventParser = (mEvent: MatrixEvent) => ParsedResult; const parseMemberEvent: MemberEventParser = (mEvent) => { - const content = mEvent.getContent(); - const prevContent = mEvent.getPrevContent() as IMemberContent; + const content = mEvent.getContent(); + const prevContent = mEvent.getPrevContent() as CustomRoomMemberEventContent; const senderId = mEvent.getSender(); const userId = mEvent.getStateKey(); const roomId = mEvent.getRoomId(); @@ -279,6 +281,42 @@ const parseMemberEvent: MemberEventParser = (mEvent) => { ), }; } + if (content[MATRIX_UNSTABLE_COLORS]?.on_dark !== prevContent[MATRIX_UNSTABLE_COLORS]?.on_dark) { + return { + icon: timelineIcon(PaintBrush), + body: + content[MATRIX_UNSTABLE_COLORS]?.on_dark && + typeof content[MATRIX_UNSTABLE_COLORS]?.on_dark === 'string' ? ( + <> + + {' changed one of their room name colors'} + + ) : ( + <> + + {' removed one of their room name colors '} + + ), + }; + } + if (content[MATRIX_UNSTABLE_COLORS]?.on_light !== prevContent[MATRIX_UNSTABLE_COLORS]?.on_light) { + return { + icon: timelineIcon(PaintBrush), + body: + content[MATRIX_UNSTABLE_COLORS]?.on_light && + typeof content[MATRIX_UNSTABLE_COLORS]?.on_light === 'string' ? ( + <> + + {' changed one of their room name colors'} + + ) : ( + <> + + {' removed one of their room name colors '} + + ), + }; + } return { icon: timelineIcon(User), diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 8bb21043f..64c91977f 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -161,7 +161,7 @@ const normalizeInfo = (info: Record): UserProfile => { }; }; -const isValidHex = (c: unknown): string | undefined => { +export const isValidHex = (c: unknown): string | undefined => { if (typeof c !== 'string') return undefined; // silly tuwunel smh const cleaned = c.replaceAll(/["']/g, '').trim(); @@ -280,8 +280,17 @@ export const useUserProfile = ( const state = room.getLiveTimeline().getState(EventTimeline.FORWARDS); if (renderRoomColors) { + const roomMemberEvent = state?.getStateEvents(EventType.RoomMember, userId); + const roomColorContent = ( + Array.isArray(roomMemberEvent) ? roomMemberEvent[0] : roomMemberEvent + )?.getContent(); + const roomColorObject = roomColorContent?.[prefix.MATRIX_UNSTABLE_COLORS]; + const roomColorNew = + themeKind === ThemeKind.Light ? roomColorObject?.on_light : roomColorObject?.on_dark; const localEvent = state?.getStateEvents(CustomStateEvent.RoomCosmeticsColor, userId); - localColor = (Array.isArray(localEvent) ? localEvent[0] : localEvent)?.getContent()?.color; + const localColorOld = (Array.isArray(localEvent) ? localEvent[0] : localEvent)?.getContent() + ?.color; + localColor = roomColorNew ?? localColorOld; } if (renderRoomFonts) { @@ -305,9 +314,18 @@ export const useUserProfile = ( const pState = parentSpace?.getLiveTimeline().getState(EventTimeline.FORWARDS); if (renderRoomColors) { + const spaceMemberEvent = pState?.getStateEvents(EventType.RoomMember, userId); + const spaceColorContent = ( + Array.isArray(spaceMemberEvent) ? spaceMemberEvent[0] : spaceMemberEvent + )?.getContent(); + const spaceColorObject = spaceColorContent?.[prefix.MATRIX_UNSTABLE_COLORS]; + const spaceColorNew = + themeKind === ThemeKind.Light ? spaceColorObject?.on_light : spaceColorObject?.on_dark; const spaceEvent = pState?.getStateEvents(CustomStateEvent.RoomCosmeticsColor, userId); - spaceColor = (Array.isArray(spaceEvent) ? spaceEvent[0] : spaceEvent)?.getContent() - ?.color; + const spaceColorOld = ( + Array.isArray(spaceEvent) ? spaceEvent[0] : spaceEvent + )?.getContent()?.color; + spaceColor = spaceColorNew ?? spaceColorOld; } if (renderRoomFonts) { diff --git a/src/app/utils/roomMemberProfile.ts b/src/app/utils/roomMemberProfile.ts index 6c92b3a50..91992d81e 100644 --- a/src/app/utils/roomMemberProfile.ts +++ b/src/app/utils/roomMemberProfile.ts @@ -1,11 +1,11 @@ -import type { MatrixClient, Room, RoomMemberEventContent } from '$types/matrix-sdk'; +import type { MatrixClient, Room, CustomRoomMemberEventContent } from '$types/matrix-sdk'; import { EventType, MatrixEvent } from '$types/matrix-sdk'; /** Send an own-membership profile update and immediately reflect the accepted state locally. */ export async function setOwnRoomMemberProfile( mx: MatrixClient, room: Room, - content: RoomMemberEventContent + content: CustomRoomMemberEventContent ): Promise { const userId = mx.getSafeUserId(); const response = await mx.sendStateEvent(room.roomId, EventType.RoomMember, content, userId); diff --git a/src/unstable/CustomRoomMemberEventContent.ts b/src/unstable/CustomRoomMemberEventContent.ts new file mode 100644 index 000000000..6033089a0 --- /dev/null +++ b/src/unstable/CustomRoomMemberEventContent.ts @@ -0,0 +1,22 @@ +import type { ColorSet } from '$hooks/useUserProfile'; +import type * as prefix from '$unstable/prefixes'; +import type { KnownMembership } from 'matrix-js-sdk'; + +// moving the type here as the sdk is not updated to permit the changes and will not be for a very long while +export interface CustomRoomMemberEventContent { + avatar_url?: string; + displayname?: string; + is_direct?: boolean; + [prefix.MATRIX_UNSTABLE_COLORS]?: ColorSet; + join_authorised_via_users_server?: string; + membership: KnownMembership; + reason?: string; + third_party_invite?: { + display_name: string; + signed: { + mxid: string; + token: string; + ts: number; + }; + }; +} From 67e400d9e7fae4f05b5fe87c8ae3617e9ed07460 Mon Sep 17 00:00:00 2001 From: Shea Date: Fri, 31 Jul 2026 08:18:22 +0300 Subject: [PATCH 3/3] clean everything up Signed-off-by: Shea --- .../common-settings/cosmetics/Cosmetics.tsx | 10 ++++++-- src/app/hooks/commands/profile.ts | 23 +++++++++++++++---- src/app/utils/roomMemberProfile.ts | 3 ++- src/types/matrix/room.ts | 6 +++++ src/unstable/prefixes/misc.ts | 2 -- src/unstable/prefixes/msc/state_events.ts | 2 ++ 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/app/features/common-settings/cosmetics/Cosmetics.tsx b/src/app/features/common-settings/cosmetics/Cosmetics.tsx index 3cdbf2854..90de9a01c 100644 --- a/src/app/features/common-settings/cosmetics/Cosmetics.tsx +++ b/src/app/features/common-settings/cosmetics/Cosmetics.tsx @@ -256,9 +256,15 @@ export function Cosmetics({ requestBack, requestClose }: CosmeticsProps) { .getLiveTimeline() .getState(EventTimeline.FORWARDS) ?.getStateEvents(EventType.RoomMember, mx.getSafeUserId()); + + const oldColorState = room.getLiveTimeline().getState(EventTimeline.FORWARDS); + const oldColorEvent = oldColorState?.getStateEvents(CustomStateEvent.RoomCosmeticsColor, userId); + const localColorOld = ( + Array.isArray(oldColorEvent) ? oldColorEvent[0] : oldColorEvent + )?.getContent()?.color; const content = mEvent?.getContent(); - const colorOnDark = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark; - const colorOnLight = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_light; + const colorOnDark = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_dark ?? localColorOld; + const colorOnLight = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_light ?? localColorOld; const permissions = useRoomPermissions(creators, powerLevels); const canEditPermissions = permissions.stateEvent(EventType.RoomPowerLevels, mx.getSafeUserId()); diff --git a/src/app/hooks/commands/profile.ts b/src/app/hooks/commands/profile.ts index c64a882ad..f0e04deab 100644 --- a/src/app/hooks/commands/profile.ts +++ b/src/app/hooks/commands/profile.ts @@ -132,7 +132,8 @@ export const createProfileCommands = (ctx: CommandContext): Partial { const input = payload.trim().toLowerCase().split(' '); const userId = mx.getSafeUserId(); @@ -171,8 +172,15 @@ export const createProfileCommands = (ctx: CommandContext): Partial