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

Function patchDmMessage

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

Source from the content-addressed store, hash-verified

277// Changes one message wherever the cache shows it: the thread and, when it's
278// the latest, the inbox row.
279export const patchDmMessage = (
280 client: QueryClient,
281 user: QueryUser,
282 peerId: string,
283 messageId: string,
284 patch: (message: DmMessage) => DmMessage,
285): void => {
286 client.setQueryData<DmMessage[]>(dmThreadQueryKey(user, peerId), (messages) =>
287 messages?.map((message) =>
288 message.id === messageId ? patch(message) : message,
289 ),
290 );
291 client.setQueryData<DmConversation[]>(
292 dmConversationsQueryKey(user),
293 (conversations) =>
294 conversations?.map((conversation) =>
295 conversation.peer.id === peerId &&
296 conversation.lastMessage.id === messageId
297 ? { ...conversation, lastMessage: patch(conversation.lastMessage) }
298 : conversation,
299 ),
300 );
301};
302
303// An edit keeps the conversation where it is; only its preview changes.
304export const applyEditToConversations = (

Callers 1

applyFunction · 0.90

Calls 2

dmThreadQueryKeyFunction · 0.85
dmConversationsQueryKeyFunction · 0.85

Tested by

no test coverage detected