feat: sender favicon avatars
This commit is contained in:
@@ -1,4 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useSettingsStore } from "@/stores/settings-store";
|
||||
|
||||
// Personal email domains where the favicon is the mail provider logo, not the sender
|
||||
const PERSONAL_DOMAINS = new Set([
|
||||
"gmail.com", "googlemail.com", "outlook.com", "hotmail.com", "live.com",
|
||||
"msn.com", "yahoo.com", "yahoo.fr", "yahoo.co.uk", "yahoo.co.jp",
|
||||
"aol.com", "icloud.com", "me.com", "mac.com", "mail.com",
|
||||
"proton.me", "protonmail.com", "pm.me", "tutanota.com", "tuta.com",
|
||||
"zoho.com", "yandex.com", "yandex.ru", "gmx.com", "gmx.net",
|
||||
"fastmail.com", "hey.com", "posteo.de", "mailbox.org",
|
||||
]);
|
||||
|
||||
interface AvatarProps {
|
||||
name?: string;
|
||||
@@ -8,6 +22,9 @@ interface AvatarProps {
|
||||
}
|
||||
|
||||
export function Avatar({ name, email, size = "md", className }: AvatarProps) {
|
||||
const [faviconError, setFaviconError] = useState(false);
|
||||
const senderFavicons = useSettingsStore((s) => s.senderFavicons);
|
||||
|
||||
const getInitials = () => {
|
||||
if (name) {
|
||||
const parts = name.trim().split(/\s+/);
|
||||
@@ -38,17 +55,30 @@ export function Avatar({ name, email, size = "md", className }: AvatarProps) {
|
||||
lg: "w-12 h-12 text-base",
|
||||
};
|
||||
|
||||
const domain = email?.split("@")[1]?.toLowerCase();
|
||||
const showFavicon =
|
||||
senderFavicons && domain && !PERSONAL_DOMAINS.has(domain) && !faviconError;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-full flex items-center justify-center font-semibold text-white",
|
||||
"rounded-full flex items-center justify-center font-semibold text-white overflow-hidden",
|
||||
sizeClasses[size],
|
||||
className
|
||||
)}
|
||||
style={{ backgroundColor: getBackgroundColor() }}
|
||||
title={name || email}
|
||||
>
|
||||
{getInitials()}
|
||||
{showFavicon ? (
|
||||
<img
|
||||
src={`/api/favicon?domain=${encodeURIComponent(domain)}`}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
onError={() => setFaviconError(true)}
|
||||
/>
|
||||
) : (
|
||||
getInitials()
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user