Skip to content

Commit fe3900a

Browse files
committed
fix: recover profile and avatar loading
1 parent 6ccb85f commit fe3900a

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/app/components/room-avatar/RoomAvatar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JoinRule } from '$types/matrix-sdk';
22
import { AvatarFallback, Icon, Icons, color } from 'folds';
3-
import { ComponentProps, ReactNode, forwardRef, useState } from 'react';
3+
import { ComponentProps, ReactNode, forwardRef, useEffect, useState } from 'react';
44
import { getRoomIconSrc } from '$utils/room';
55
import colorMXID from '$utils/colorMXID';
66
import * as css from './RoomAvatar.css';
@@ -17,6 +17,10 @@ type RoomAvatarProps = {
1717
export function RoomAvatar({ roomId, src, alt, renderFallback, uniformIcons }: RoomAvatarProps) {
1818
const [error, setError] = useState(false);
1919

20+
useEffect(() => {
21+
setError(false);
22+
}, [src]);
23+
2024
if (!src || error) {
2125
return (
2226
<AvatarFallback

src/app/components/user-avatar/UserAvatar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AvatarFallback, AvatarImage, color } from 'folds';
2-
import { ReactEventHandler, ReactNode, useState } from 'react';
2+
import { ReactEventHandler, ReactNode, useEffect, useState } from 'react';
33
import classNames from 'classnames';
44
import colorMXID from '$utils/colorMXID';
55
import * as css from './UserAvatar.css';
@@ -14,6 +14,10 @@ type UserAvatarProps = {
1414
export function UserAvatar({ className, userId, src, alt, renderFallback }: UserAvatarProps) {
1515
const [error, setError] = useState(false);
1616

17+
useEffect(() => {
18+
setError(false);
19+
}, [src]);
20+
1721
const handleLoad: ReactEventHandler<HTMLImageElement> = (evt) => {
1822
evt.currentTarget.setAttribute('data-image-loaded', 'true');
1923
};

src/app/hooks/useUserProfile.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import colorMXID from '$utils/colorMXID';
77
import { profilesCacheAtom } from '$state/userRoomProfile';
88
import { useSetting } from '$state/hooks/settings';
99
import { settingsAtom } from '$state/settings';
10+
import { MSC1767Text } from '$types/matrix/common';
1011
import { useMatrixClient } from './useMatrixClient';
1112

1213
const inFlightProfiles = new Map<string, Promise<any>>();
1314

15+
export type MSC4440Bio = {
16+
'm.text': Array<MSC1767Text>;
17+
};
18+
1419
export type UserProfile = {
1520
avatarUrl?: string;
1621
displayName?: string;
@@ -27,6 +32,7 @@ export type UserProfile = {
2732
};
2833

2934
const normalizeInfo = (info: any): UserProfile => {
35+
const msc4440Bio = info['gay.fomx.biography'] as MSC4440Bio | undefined;
3036
const knownKeys = new Set([
3137
'avatar_url',
3238
'displayname',
@@ -35,6 +41,7 @@ const normalizeInfo = (info: any): UserProfile => {
3541
'm.tz',
3642
'moe.sable.app.bio',
3743
'chat.commet.profile_bio',
44+
'gay.fomx.biography',
3845
'chat.commet.profile_banner',
3946
'chat.commet.profile_status',
4047
'moe.sable.app.name_color',
@@ -54,7 +61,7 @@ const normalizeInfo = (info: any): UserProfile => {
5461
displayName: info.displayname,
5562
pronouns: info['io.fsky.nyx.pronouns'],
5663
timezone: info['us.cloke.msc4175.tz'] || info['m.tz'],
57-
bio: info['moe.sable.app.bio'] || info['chat.commet.profile_bio'],
64+
bio: msc4440Bio?.['m.text']?.[0]?.body || info['moe.sable.app.bio'] || info['chat.commet.profile_bio'],
5865
status: info['chat.commet.profile_status'],
5966
bannerUrl: info['chat.commet.profile_banner'],
6067
nameColor: info['moe.sable.app.name_color'],
@@ -94,7 +101,11 @@ export const useUserProfile = (
94101
const cached = useAtomValue(userSelector);
95102
const setGlobalProfiles = useSetAtom(profilesCacheAtom);
96103

97-
const needsFetch = !!userId && userId !== 'undefined' && !cached?._fetched;
104+
const hasOnlyFetchedMarker =
105+
cached?._fetched === true && Object.keys(cached).every((key) => key === '_fetched');
106+
107+
const needsFetch =
108+
!!userId && userId !== 'undefined' && (!cached?._fetched || hasOnlyFetchedMarker);
98109

99110
useEffect(() => {
100111
if (!needsFetch) return undefined;

0 commit comments

Comments
 (0)