feat: remove CommunicationsQuery, load messages on-demand only
- Remove bulk CommunicationsQuery from useContacts (was loading ALL messages for ALL contacts on init) - Rebuild commThreads from contacts + contactInboxes using the new lastMessageText field from Phase 1 - Per-contact messages now load on-demand via getClientTimeline - Remove commItems from useWorkspaceRouting, use clientTimelineItems Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import { ref, computed, watch, watchEffect, type ComputedRef } from "vue";
|
||||
import { useQuery } from "@vue/apollo-composable";
|
||||
import {
|
||||
ContactsQueryDocument,
|
||||
CommunicationsQueryDocument,
|
||||
} from "~~/graphql/generated";
|
||||
import { ContactsQueryDocument } from "~~/graphql/generated";
|
||||
|
||||
export type Contact = {
|
||||
id: string;
|
||||
@@ -11,6 +8,8 @@ export type Contact = {
|
||||
avatar: string;
|
||||
channels: string[];
|
||||
lastContactAt: string;
|
||||
lastMessageText: string;
|
||||
lastMessageChannel: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
@@ -41,32 +40,13 @@ export function useContacts(opts: { apolloAuthReady: ComputedRef<boolean> }) {
|
||||
{ enabled: opts.apolloAuthReady },
|
||||
);
|
||||
|
||||
const { result: communicationsResult, refetch: refetchCommunications } = useQuery(
|
||||
CommunicationsQueryDocument,
|
||||
null,
|
||||
{ enabled: opts.apolloAuthReady },
|
||||
);
|
||||
|
||||
const contacts = ref<Contact[]>([]);
|
||||
const commItems = ref<CommItem[]>([]);
|
||||
|
||||
watch(
|
||||
[() => contactsResult.value?.contacts, () => communicationsResult.value?.communications],
|
||||
([rawContacts, rawComms]) => {
|
||||
() => contactsResult.value?.contacts,
|
||||
(rawContacts) => {
|
||||
if (!rawContacts) return;
|
||||
const contactsList = [...rawContacts] as Contact[];
|
||||
const commsList = (rawComms ?? []) as CommItem[];
|
||||
|
||||
const byName = new Map<string, Set<string>>();
|
||||
for (const item of commsList) {
|
||||
if (!byName.has(item.contact)) byName.set(item.contact, new Set());
|
||||
byName.get(item.contact)?.add(item.channel);
|
||||
}
|
||||
contacts.value = contactsList.map((c) => ({
|
||||
...c,
|
||||
channels: Array.from(byName.get(c.name) ?? c.channels ?? []),
|
||||
}));
|
||||
commItems.value = commsList;
|
||||
contacts.value = [...rawContacts] as Contact[];
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@@ -166,7 +146,6 @@ export function useContacts(opts: { apolloAuthReady: ComputedRef<boolean> }) {
|
||||
|
||||
return {
|
||||
contacts,
|
||||
commItems,
|
||||
contactSearch,
|
||||
selectedChannel,
|
||||
sortMode,
|
||||
@@ -181,6 +160,5 @@ export function useContacts(opts: { apolloAuthReady: ComputedRef<boolean> }) {
|
||||
markAvatarBroken,
|
||||
contactInitials,
|
||||
refetchContacts,
|
||||
refetchCommunications,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user