diff --git a/src/app/features/common-settings/cosmetics/Cosmetics.tsx b/src/app/features/common-settings/cosmetics/Cosmetics.tsx index c9cc300dd..90de9a01c 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,20 @@ 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 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 ?? localColorOld; + const colorOnLight = content?.[prefix.MATRIX_UNSTABLE_COLORS]?.on_light ?? localColorOld; + const permissions = useRoomPermissions(creators, powerLevels); const canEditPermissions = permissions.stateEvent(EventType.RoomPowerLevels, mx.getSafeUserId()); @@ -257,7 +273,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 +346,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 +412,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 35438d767..652691c69 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/commands/profile.ts b/src/app/hooks/commands/profile.ts index aadf3350f..f0e04deab 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,65 +47,95 @@ 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); } } }, }, [Command.SColor]: { name: Command.SColor, - description: 'Set your color for the current Space. Example: /scolor #ff00ff | /scolor reset', + description: + 'Set your color for the current Space. Example: /scolor light #ff00ff | /scolor reset', exe: async (payload) => { - const input = payload.trim().toLowerCase(); + const input = payload.trim().toLowerCase().split(' '); const userId = mx.getSafeUserId(); const parents = room @@ -111,38 +145,78 @@ 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 (/^#[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); + 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; + //This may be ignored since it is to delete the old key when updated + try { + await mx.sendStateEvent( + room.roomId, + CustomStateEvent.RoomCosmeticsColor, + {}, + userId + ); + } catch {} + } 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 + ); + try { + await mx.sendStateEvent( + room.roomId, + CustomStateEvent.RoomCosmeticsColor, + {}, + userId + ); + } catch {} + } } 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 42b708597..a5fdaa83d 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(); @@ -266,6 +268,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 78cfd62dc..64c91977f 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, @@ -153,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(); @@ -272,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) { @@ -297,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) { @@ -319,9 +345,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/app/utils/roomMemberProfile.ts b/src/app/utils/roomMemberProfile.ts index 6c92b3a50..f40ab07c7 100644 --- a/src/app/utils/roomMemberProfile.ts +++ b/src/app/utils/roomMemberProfile.ts @@ -1,11 +1,12 @@ -import type { MatrixClient, Room, RoomMemberEventContent } from '$types/matrix-sdk'; +import type { MatrixClient, Room } from '$types/matrix-sdk'; import { EventType, MatrixEvent } from '$types/matrix-sdk'; +import type { CustomRoomMemberEventContent } from '$unstable/CustomRoomMemberEventContent'; /** 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/types/matrix/room.ts b/src/types/matrix/room.ts index dca3462a3..3f5037e4e 100644 --- a/src/types/matrix/room.ts +++ b/src/types/matrix/room.ts @@ -1,5 +1,6 @@ import type { IImageInfo } from './common'; import * as prefix from '$unstable/prefixes'; +import type { ColorSet } from '$hooks/useUserProfile'; export type IMemberContent = { avatar_url?: string; @@ -71,3 +72,8 @@ export type MemberPowerTag = { color?: string; icon?: MemberPowerTagIcon; }; + +export type MemberPowerStyle = { + name: string; + color?: ColorSet; +}; 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; + }; + }; +} 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/msc/state_events.ts b/src/unstable/prefixes/msc/state_events.ts index 1823fd28d..e12ad0c1c 100644 --- a/src/unstable/prefixes/msc/state_events.ts +++ b/src/unstable/prefixes/msc/state_events.ts @@ -8,3 +8,5 @@ export const MATRIX_UNSTABLE_STATE_ROOM_EMOTES_PROPERTY_NAME = 'im.ponies.room_e * defined in MSC3401 https://github.com/matrix-org/matrix-spec-proposals/pull/3401 */ export const MATRIX_UNSTABLE_ROOM_TYPE_CALL_PROPERTY_NAME = 'org.matrix.msc3401.call'; + +export const MATRIX_UNSTABLE_ROOM_STYLING = 'eu.she-a.powerlevels_style'; 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';