Fallback Telegram avatars from identities in dashboard

This commit is contained in:
Ruslan Bakiev
2026-02-23 08:10:59 +07:00
parent 0f1028b0fa
commit cbc2a3b31b

View File

@@ -312,6 +312,7 @@ async function getDashboard(auth: AuthContext | null) {
include: { include: {
note: { select: { content: true } }, note: { select: { content: true } },
messages: { select: { occurredAt: true }, orderBy: { occurredAt: "desc" }, take: 1 }, messages: { select: { occurredAt: true }, orderBy: { occurredAt: "desc" }, take: 1 },
omniIdentities: { select: { channel: true, externalId: true } },
}, },
orderBy: { updatedAt: "desc" }, orderBy: { updatedAt: "desc" },
take: 500, take: 500,
@@ -364,17 +365,26 @@ async function getDashboard(auth: AuthContext | null) {
channelsByContactId.get(item.contactId)?.add(mapChannel(item.channel)); channelsByContactId.get(item.contactId)?.add(mapChannel(item.channel));
} }
const contacts = contactsRaw.map((c) => ({ const contacts = contactsRaw.map((c) => {
const telegramIdentity = c.omniIdentities.find(
(identity) => identity.channel === "TELEGRAM" && /^\d+$/.test(identity.externalId),
);
const avatar =
(c.avatarUrl ?? "").trim() ||
(telegramIdentity ? `/api/omni/telegram/avatar/${telegramIdentity.externalId}` : "");
return {
id: c.id, id: c.id,
name: c.name, name: c.name,
avatar: c.avatarUrl ?? "", avatar,
company: c.company ?? "", company: c.company ?? "",
country: c.country ?? "", country: c.country ?? "",
location: c.location ?? "", location: c.location ?? "",
channels: Array.from(channelsByContactId.get(c.id) ?? []), channels: Array.from(channelsByContactId.get(c.id) ?? []),
lastContactAt: c.messages[0]?.occurredAt?.toISOString?.() ?? c.updatedAt.toISOString(), lastContactAt: c.messages[0]?.occurredAt?.toISOString?.() ?? c.updatedAt.toISOString(),
description: c.note?.content ?? "", description: c.note?.content ?? "",
})); };
});
const communications = communicationsRaw.map((m) => ({ const communications = communicationsRaw.map((m) => ({
id: m.id, id: m.id,