element-portable/src/components/views/avatars/SearchResultAvatar.tsx
David Langley 491f0cd08a
Change license (#13)
* Copyright headers 1

* Licence headers 2

* Copyright Headers 3

* Copyright Headers 4

* Copyright Headers 5

* Copyright Headers 6

* Copyright headers 7

* Add copyright headers for html and config file

* Replace license files and update package.json

* Update with CLA

* lint
2024-09-09 13:57:16 +00:00

48 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import { RoomMember } from "matrix-js-sdk/src/matrix";
import emailPillAvatar from "../../../../res/img/icon-email-pill-avatar.svg";
import { mediaFromMxc } from "../../../customisations/Media";
import { Member, ThreepidMember } from "../../../utils/direct-messages";
import BaseAvatar from "./BaseAvatar";
interface SearchResultAvatarProps {
user: Member | RoomMember;
size: string;
}
export function SearchResultAvatar({ user, size }: SearchResultAvatarProps): JSX.Element {
if ((user as ThreepidMember).isEmail) {
// we cant show a real avatar here, but we try to create the exact same markup that a real avatar would have
// BaseAvatar makes the avatar, if it's not clickable but just for decoration, invisible to screenreaders by
// specifically setting an empty alt text, so we do the same.
return (
<img
className="mx_SearchResultAvatar mx_SearchResultAvatar_threepidAvatar"
alt=""
src={emailPillAvatar}
width={size}
height={size}
/>
);
} else {
const avatarUrl = user.getMxcAvatarUrl();
return (
<BaseAvatar
className="mx_SearchResultAvatar"
url={avatarUrl ? mediaFromMxc(avatarUrl).getSquareThumbnailHttp(parseInt(size, 10)) : null}
name={user.name}
idName={user.userId}
size={size}
/>
);
}
}