diff --git a/web/src/api/rpc.ts b/web/src/api/rpc.ts index 9530a8a..083ca75 100644 --- a/web/src/api/rpc.ts +++ b/web/src/api/rpc.ts @@ -19,7 +19,8 @@ import type { ClientWellKnown, EventID, EventRowID, - EventType, JSONValue, + EventType, + JSONValue, LoginFlowsResponse, LoginRequest, Mentions, diff --git a/web/src/api/types/mxtypes.ts b/web/src/api/types/mxtypes.ts index 31d9d95..9b84fde 100644 --- a/web/src/api/types/mxtypes.ts +++ b/web/src/api/types/mxtypes.ts @@ -76,6 +76,21 @@ export interface UserProfile { [custom: string]: unknown } +export interface PronounSet { + subject?: string + object?: string + possessive_determiner?: string + possessive_pronoun?: string + reflexive?: string + summary: string + language: string +} + +export interface ExtendedUserProfile extends UserProfile { + "us.cloke.msc4175.tz"?: string + "io.fsky.nyx.pronouns"?: PronounSet[] +} + export type Membership = "join" | "leave" | "ban" | "invite" | "knock" export interface MemberEventContent extends UserProfile { @@ -294,18 +309,3 @@ export interface RespOpenIDToken { matrix_server_name: string token_type: "Bearer" } - -export interface PronounSet { - subject?: string - object?: string - possessive_determiner?: string - possessive_pronoun?: string - reflexive?: string - summary: string - language: string -} - -export interface ExtendedProfileAttributes { - "us.cloke.msc4175.tz"?: string - "io.fsky.nyx.pronouns"?: PronounSet[] -} diff --git a/web/src/ui/rightpanel/UserExtendedProfile.tsx b/web/src/ui/rightpanel/UserExtendedProfile.tsx index 54bbd9d..e0f351c 100644 --- a/web/src/ui/rightpanel/UserExtendedProfile.tsx +++ b/web/src/ui/rightpanel/UserExtendedProfile.tsx @@ -1,10 +1,10 @@ import { useEffect, useState } from "react" import Client from "@/api/client.ts" -import { ExtendedProfileAttributes, PronounSet, UserProfile } from "@/api/types" -import { ensureArray } from "@/util/validation.ts" +import { ExtendedUserProfile, PronounSet } from "@/api/types" +import { ensureArray, ensureString } from "@/util/validation.ts" interface ExtendedProfileProps { - profile: UserProfile & ExtendedProfileAttributes + profile: ExtendedUserProfile client: Client userID: string } @@ -51,54 +51,52 @@ function SetTimezoneElement({ tz, client }: SetTimezoneProps) { // The defaulting to the current timezone causes `newTz !== tz` to never be true when the user has // no timezone set. - return ( - <> - setTz(e.currentTarget.value)} - /> - - > - ) + return <> + setTz(e.currentTarget.value)} + /> + + > } export default function UserExtendedProfile({ profile, client, userID }: ExtendedProfileProps) { - if (!profile) return null + if (!profile) { + return null + } const extendedProfileKeys = ["us.cloke.msc4175.tz", "io.fsky.nyx.pronouns"] - const hasExtendedProfile = extendedProfileKeys.some((key) => key in profile) - if (!hasExtendedProfile && client.userID !== userID) return null + const hasExtendedProfile = extendedProfileKeys.some((key) => profile[key]) + if (!hasExtendedProfile && client.userID !== userID) { + return null + } // Explicitly only return something if the profile has the keys we're looking for. // otherwise there's an ugly and pointless