From 8f009c8cafa0eb853d387858f20914c468d66d3b Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Tue, 2 Jun 2026 12:33:59 +0300 Subject: [PATCH] fix: show email avatars without Telegram --- frontend/src/App.svelte | 4 ++-- frontend/src/lib/webapp/gravatar.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 6c0eb53..c50d228 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -78,7 +78,7 @@ activationPaymentFailed, createActivationHandoff, } from "./lib/webapp/activationHandoff.js"; - import { buildGravatarUrl } from "./lib/webapp/gravatar.js"; + import { buildGravatarUrl, resolveProfileAvatarUrl } from "./lib/webapp/gravatar.js"; import { createBillingActions } from "./lib/webapp/billingActions.js"; import { invalidateWebappTariffOptionCaches } from "./lib/webapp/billingOptionCache.js"; import { runWebappBoot } from "./lib/webapp/webappBoot.js"; @@ -494,7 +494,7 @@ $: telegramProfileName = telegramName(user); $: profileEmail = user?.email || t("wa_settings_email_not_linked"); $: profileTelegramId = user?.telegram_id ? `TG ID ${user.telegram_id}` : t("wa_tg_id_not_linked"); - $: profileAvatarUrl = user?.telegram_photo_url || emailAvatarUrl || ""; + $: profileAvatarUrl = resolveProfileAvatarUrl(user, emailAvatarUrl); $: privacyPolicyUrl = String(CFG.privacyPolicyUrl || "").trim(); $: userAgreementUrl = String(CFG.userAgreementUrl || "").trim(); $: supportUrl = String(appSettings?.support_url || CFG.supportUrl || "").trim(); diff --git a/frontend/src/lib/webapp/gravatar.js b/frontend/src/lib/webapp/gravatar.js index bf7bfef..e89b18a 100644 --- a/frontend/src/lib/webapp/gravatar.js +++ b/frontend/src/lib/webapp/gravatar.js @@ -4,16 +4,25 @@ function bytesToHex(buffer) { async function sha256Hex(value) { const data = new TextEncoder().encode(value); - const hashBuffer = await window.crypto.subtle.digest("SHA-256", data); + const hashBuffer = await globalThis.crypto?.subtle?.digest("SHA-256", data); return bytesToHex(hashBuffer); } export async function buildGravatarUrl(emailValue) { - if (!emailValue || !window.crypto?.subtle) return ""; + const email = String(emailValue || "") + .trim() + .toLowerCase(); + if (!email || !globalThis.crypto?.subtle) return ""; try { - const hash = await sha256Hex(emailValue); - return `https://www.gravatar.com/avatar/${hash}?d=mp&s=160`; + const hash = await sha256Hex(email); + return `https://www.gravatar.com/avatar/${hash}?d=identicon&s=160`; } catch { return ""; } } + +export function resolveProfileAvatarUrl(user, emailAvatarUrl = "") { + const telegramAvatar = String(user?.telegram_photo_url || "").trim(); + if (user?.telegram_linked && telegramAvatar) return telegramAvatar; + return String(emailAvatarUrl || "").trim(); +}