(user: QueryUser, peerId: string)
| 336 | // A peer we already talk to comes from the conversation; anyone else, such as |
| 337 | // a profile's "Message" button, is looked up as a regular daily.dev user. |
| 338 | export const dmPeerQueryOptions = (user: QueryUser, peerId: string) => |
| 339 | queryOptions<DmPeer | null>({ |
| 340 | queryKey: generateQueryKey(RequestKey.DirectMessagePeer, user, peerId), |
| 341 | queryFn: async () => { |
| 342 | if (isDmMockMode) { |
| 343 | const conversations = await getDmTransport( |
| 344 | user!.id, |
| 345 | ).listConversations(); |
| 346 | const known = conversations.find(({ peer }) => peer.id === peerId); |
| 347 | if (known) { |
| 348 | return known.peer; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | const [res, access] = await Promise.all([ |
| 353 | gqlClient.request<{ |
| 354 | user: Omit<DmPeer, 'access'> | null; |
| 355 | }>(DM_PEER_QUERY, { id: peerId }), |
| 356 | // The mock has no backend to ask, so every real user accepts there. |
| 357 | isDmMockMode |
| 358 | ? DirectMessageAccess.Open |
| 359 | : getDirectMessageAccess(peerId), |
| 360 | ]); |
| 361 | |
| 362 | return res.user ? { ...res.user, access } : null; |
| 363 | }, |
| 364 | staleTime: StaleTime.Default, |
| 365 | enabled: !!user?.id && !!peerId, |
| 366 | }); |
| 367 | |
| 368 | // A missing or private post leaves the link as it is, so it isn't retried. |
| 369 | // Kept outside the DirectMessages key, which a chat reconnect invalidates. |
no test coverage detected