Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix missing avatar for show current profiles #9563

Merged
merged 8 commits into from
Nov 11, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions src/components/views/avatars/MemberAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { useContext } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { ResizeMethod } from 'matrix-js-sdk/src/@types/partials';

Expand Down Expand Up @@ -59,25 +59,37 @@ export default function MemberAvatar({
forceHistorical: props.forceHistorical,
});

const name = member?.name ?? props.fallbackUserId;
let title: string | undefined = props.title;
let imageUrl: string | undefined;
if (member?.name) {
if (member.getMxcAvatarUrl()) {
imageUrl = mediaFromMxc(member.getMxcAvatarUrl() ?? "").getThumbnailOfSourceHttp(
width,
height,
resizeMethod,
);
const [name, setName] = useState<string>();
const [imageUrl, setImageUrl] = useState<string>();
const [title, setTitle] = useState<string>();
germain-gg marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
setName(member?.name ?? props.fallbackUserId);
}, [member?.name, props.fallbackUserId]);

useEffect(() => {
if (member?.name) {
if (member.getMxcAvatarUrl()) {
setImageUrl(mediaFromMxc(member.getMxcAvatarUrl()!).getThumbnailOfSourceHttp(
width,
height,
resizeMethod,
));
}
}
}, [height, member, resizeMethod, width]);

if (!title) {
title = UserIdentifierCustomisations.getDisplayUserIdentifier(
member?.userId ?? "", { roomId: member?.roomId ?? "" },
) ?? props.fallbackUserId;
useEffect(() => {
let title: string | undefined = props.title;
if (member?.name) {
if (!title) {
title = UserIdentifierCustomisations.getDisplayUserIdentifier!(
member?.userId ?? "", { roomId: member?.roomId ?? "" },
) ?? props.fallbackUserId;
}
}
}
const userId = member?.userId ?? props.fallbackUserId;
setTitle(title);
}, [member?.name, member?.roomId, member?.userId, props.fallbackUserId, props.title]);

return (
<BaseAvatar
Expand All @@ -87,7 +99,7 @@ export default function MemberAvatar({
resizeMethod={resizeMethod}
name={name ?? ""}
title={props.hideTitle ? undefined : title}
idName={userId}
idName={member?.userId ?? props.fallbackUserId}
url={imageUrl}
onClick={viewUserOnClick ? () => {
dis.dispatch({
Expand Down