MCPcopy Create free account
hub / github.com/dailydotdev/apps / dmPeerQueryOptions

Function dmPeerQueryOptions

packages/shared/src/features/messages/queries.ts:356–391  ·  view source on GitHub ↗
(user: QueryUser, peerId: string)

Source from the content-addressed store, hash-verified

354// a profile's "Message" button, is looked up as a regular daily.dev user. A
355// support chat is looked up as the group it is.
356export const dmPeerQueryOptions = (user: QueryUser, peerId: string) =>
357 queryOptions<DmPeer | null>({
358 queryKey: dmPeerQueryKey(user, peerId),
359 queryFn: async () => {
360 const supportChatId = getSupportChatId(peerId);
361 if (supportChatId) {
362 const chat = await getCompanySupportChat(supportChatId);
363
364 return chat ? supportChatToPeer(chat) : null;
365 }
366
367 if (isDmMockMode) {
368 const conversations = await getDmTransport(
369 user!.id,
370 ).listConversations();
371 const known = conversations.find(({ peer }) => peer.id === peerId);
372 if (known) {
373 return known.peer;
374 }
375 }
376
377 const [res, access] = await Promise.all([
378 gqlClient.request<{
379 user: Omit<DmPeer, 'access'> | null;
380 }>(DM_PEER_QUERY, { id: peerId }),
381 // The mock has no backend to ask, so every real user accepts there.
382 isDmMockMode
383 ? DirectMessageAccess.Open
384 : getDirectMessageAccess(peerId),
385 ]);
386
387 return res.user ? { ...res.user, access } : null;
388 },
389 staleTime: StaleTime.Default,
390 enabled: !!user?.id && !!peerId,
391 });
392
393// A missing or private post leaves the link as it is, so it isn't retried.
394// Kept outside the DirectMessages key, which a chat reconnect invalidates.

Callers 2

ConversationThreadFunction · 0.90
MessageRequestComposerFunction · 0.90

Calls 6

getSupportChatIdFunction · 0.90
getCompanySupportChatFunction · 0.90
supportChatToPeerFunction · 0.90
getDmTransportFunction · 0.90
getDirectMessageAccessFunction · 0.90
dmPeerQueryKeyFunction · 0.85

Tested by

no test coverage detected