Fallback Telegram avatars from identities in dashboard
This commit is contained in:
@@ -312,6 +312,7 @@ async function getDashboard(auth: AuthContext | null) {
|
||||
include: {
|
||||
note: { select: { content: true } },
|
||||
messages: { select: { occurredAt: true }, orderBy: { occurredAt: "desc" }, take: 1 },
|
||||
omniIdentities: { select: { channel: true, externalId: true } },
|
||||
},
|
||||
orderBy: { updatedAt: "desc" },
|
||||
take: 500,
|
||||
@@ -364,17 +365,26 @@ async function getDashboard(auth: AuthContext | null) {
|
||||
channelsByContactId.get(item.contactId)?.add(mapChannel(item.channel));
|
||||
}
|
||||
|
||||
const contacts = contactsRaw.map((c) => ({
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
avatar: c.avatarUrl ?? "",
|
||||
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 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,
|
||||
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) => ({
|
||||
id: m.id,
|
||||
|
||||
Reference in New Issue
Block a user