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) => {
id: c.id, const telegramIdentity = c.omniIdentities.find(
name: c.name, (identity) => identity.channel === "TELEGRAM" && /^\d+$/.test(identity.externalId),
avatar: c.avatarUrl ?? "", );
company: c.company ?? "", const avatar =
country: c.country ?? "", (c.avatarUrl ?? "").trim() ||
location: c.location ?? "", (telegramIdentity ? `/api/omni/telegram/avatar/${telegramIdentity.externalId}` : "");
channels: Array.from(channelsByContactId.get(c.id) ?? []),
lastContactAt: c.messages[0]?.occurredAt?.toISOString?.() ?? c.updatedAt.toISOString(), return {
description: c.note?.content ?? "", id: c.id,
})); name: c.name,
avatar,
company: c.company ?? "",
country: c.country ?? "",
location: c.location ?? "",
channels: Array.from(channelsByContactId.get(c.id) ?? []),
lastContactAt: c.messages[0]?.occurredAt?.toISOString?.() ?? c.updatedAt.toISOString(),
description: c.note?.content ?? "",
};
});
const communications = communicationsRaw.map((m) => ({ const communications = communicationsRaw.map((m) => ({
id: m.id, id: m.id,