feat: add lastMessageText and lastMessageChannel to contacts query
Enriches the contacts resolver to include the last message preview and channel, so the sidebar can show thread previews without loading all communications. No frontend changes yet — fields returned but unused. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ query ContactsQuery {
|
||||
avatar
|
||||
channels
|
||||
lastContactAt
|
||||
lastMessageText
|
||||
lastMessageChannel
|
||||
description
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +171,8 @@ type Contact {
|
||||
avatar: String!
|
||||
channels: [String!]!
|
||||
lastContactAt: String!
|
||||
lastMessageText: String!
|
||||
lastMessageChannel: String!
|
||||
description: String!
|
||||
}
|
||||
|
||||
|
||||
@@ -460,7 +460,12 @@ async function getContacts(auth: AuthContext | null) {
|
||||
where: { teamId: ctx.teamId },
|
||||
include: {
|
||||
note: { select: { content: true } },
|
||||
messages: { select: { occurredAt: true }, orderBy: { occurredAt: "desc" }, take: 1 },
|
||||
messages: {
|
||||
...(messageWhere ? { where: messageWhere } : {}),
|
||||
select: { content: true, channel: true, occurredAt: true },
|
||||
orderBy: { occurredAt: "desc" as const },
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
orderBy: { updatedAt: "desc" },
|
||||
take: 500,
|
||||
@@ -511,6 +516,8 @@ async function getContacts(auth: AuthContext | null) {
|
||||
avatar: c.avatarUrl ?? "",
|
||||
channels: Array.from(channelsByContactId.get(c.id) ?? []),
|
||||
lastContactAt: c.messages[0]?.occurredAt?.toISOString?.() ?? c.updatedAt.toISOString(),
|
||||
lastMessageText: c.messages[0]?.content ?? "",
|
||||
lastMessageChannel: c.messages[0]?.channel ? mapChannel(c.messages[0].channel) : "",
|
||||
description: c.note?.content ?? "",
|
||||
}));
|
||||
}
|
||||
@@ -2008,6 +2015,8 @@ export const crmGraphqlSchema = buildSchema(`
|
||||
avatar: String!
|
||||
channels: [String!]!
|
||||
lastContactAt: String!
|
||||
lastMessageText: String!
|
||||
lastMessageChannel: String!
|
||||
description: String!
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user