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

Function patchDmMessage

packages/shared/src/features/messages/queries.ts:293–315  ·  view source on GitHub ↗
(
  client: QueryClient,
  user: QueryUser,
  peerId: string,
  messageId: string,
  patch: (message: DmMessage) => DmMessage,
)

Source from the content-addressed store, hash-verified

291// Changes one message wherever the cache shows it: the thread and, when it's
292// the latest, the inbox row.
293export const patchDmMessage = (
294 client: QueryClient,
295 user: QueryUser,
296 peerId: string,
297 messageId: string,
298 patch: (message: DmMessage) => DmMessage,
299): void => {
300 client.setQueryData<DmMessage[]>(dmThreadQueryKey(user, peerId), (messages) =>
301 messages?.map((message) =>
302 message.id === messageId ? patch(message) : message,
303 ),
304 );
305 client.setQueryData<DmConversation[]>(
306 dmConversationsQueryKey(user),
307 (conversations) =>
308 conversations?.map((conversation) =>
309 conversation.peer.id === peerId &&
310 conversation.lastMessage.id === messageId
311 ? { ...conversation, lastMessage: patch(conversation.lastMessage) }
312 : conversation,
313 ),
314 );
315};
316
317// An edit keeps the conversation where it is; only its preview changes.
318export const applyEditToConversations = (

Callers 1

applyFunction · 0.90

Calls 2

dmThreadQueryKeyFunction · 0.85
dmConversationsQueryKeyFunction · 0.85

Tested by

no test coverage detected