@planningcenter/chat-react-native 3.45.1-qa-staging.6 → 3.45.1-qa-staging.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/build/components/conversation/message.d.ts.map +1 -1
  2. package/build/components/conversation/message.js +8 -7
  3. package/build/components/conversation/message.js.map +1 -1
  4. package/build/components/conversation/reply_shadow_message.d.ts +1 -1
  5. package/build/components/conversation/reply_shadow_message.d.ts.map +1 -1
  6. package/build/components/conversation/reply_shadow_message.js +44 -43
  7. package/build/components/conversation/reply_shadow_message.js.map +1 -1
  8. package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
  9. package/build/hooks/use_conversation_messages_jolt_events.js +6 -1
  10. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
  11. package/build/types/resources/message.d.ts +1 -0
  12. package/build/types/resources/message.d.ts.map +1 -1
  13. package/build/types/resources/message.js.map +1 -1
  14. package/build/utils/cache/messages_cache.d.ts +1 -0
  15. package/build/utils/cache/messages_cache.d.ts.map +1 -1
  16. package/build/utils/cache/messages_cache.js +10 -1
  17. package/build/utils/cache/messages_cache.js.map +1 -1
  18. package/build/utils/client/transform_response.d.ts.map +1 -1
  19. package/build/utils/client/transform_response.js +9 -5
  20. package/build/utils/client/transform_response.js.map +1 -1
  21. package/build/utils/group_messages.d.ts +1 -0
  22. package/build/utils/group_messages.d.ts.map +1 -1
  23. package/build/utils/group_messages.js +10 -1
  24. package/build/utils/group_messages.js.map +1 -1
  25. package/build/utils/request/messages_data_options.d.ts.map +1 -1
  26. package/build/utils/request/messages_data_options.js +1 -1
  27. package/build/utils/request/messages_data_options.js.map +1 -1
  28. package/package.json +3 -3
  29. package/src/components/conversation/__tests__/reply_shadow_message.test.tsx +119 -0
  30. package/src/components/conversation/message.tsx +8 -7
  31. package/src/components/conversation/reply_shadow_message.tsx +6 -4
  32. package/src/hooks/use_conversation_messages_jolt_events.ts +7 -0
  33. package/src/types/resources/message.ts +1 -0
  34. package/src/utils/__tests__/group_messages.test.ts +48 -0
  35. package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +71 -0
  36. package/src/utils/cache/messages_cache.ts +21 -1
  37. package/src/utils/client/__tests__/transform_response.test.ts +62 -0
  38. package/src/utils/client/transform_response.ts +7 -5
  39. package/src/utils/group_messages.ts +18 -1
  40. package/src/utils/request/messages_data_options.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"use_conversation_messages_jolt_events.js","names":["useQueryClient","deleteRecordInPagesData","updateCacheWithMessage","updateCacheWithIndividualMessage","updateCacheWithReaction","getThreadedMessagesQueryKey","transformMessageEventDataToMessageResource","completeMessageCreationTracking","getMessageQueryKey","getMessagesRequestArgs","useApiClient","useCurrentPerson","useJoltChannel","useJoltEvent","getRequestQueryKey","TYPING_TIMEOUT_INTERVAL","useTypingStatusCache","useConversationMessagesJoltEvents","t0","$","_c","conversationId","queryClient","currentPerson","joltChannel","t1","messagesRequestArgs","conversation_id","messagesQueryKey","apiClient","addTypingEvent","removeTypingEventById","removeAllTypingEventsByAuthorId","t2","id","e","data","message","currentPersonId","event","author_id","idempotent_key","idempotentKey","reply_root_id","threadedMessagesQueryKey","individualMessageQueryKey","messageId","sort_key","handleMessageUpdateOrCreate","t3","e_0","data_0","message_0","setQueryData","prev","record","threadedMessagesQueryKey_0","prev_0","handleMessageDeleted","t4","e_1","replyRootId","threadedMessagesQueryKey_1","handleReactionJoltEvent","t5","e_2","data_1","setTimeout","handleTypingEvent"],"sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"sourcesContent":["import { InfiniteData, useQueryClient } from '@tanstack/react-query'\nimport { ApiCollection, MessageResource } from '../types'\nimport { JoltReactionEvent, JoltTypingEvent } from '../types/jolt_events'\nimport {\n MessageCreatedEvent,\n MessageUpdatedEvent,\n MessageDeletedEvent,\n} from '../types/jolt_events/message_events'\nimport { deleteRecordInPagesData } from '../utils'\nimport {\n updateCacheWithMessage,\n updateCacheWithIndividualMessage,\n updateCacheWithReaction,\n getThreadedMessagesQueryKey,\n} from '../utils/cache/messages_cache'\nimport { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'\nimport { completeMessageCreationTracking } from '../utils/performance_tracking'\nimport { getMessageQueryKey } from '../utils/request/get_message'\nimport { getMessagesRequestArgs } from '../utils/request/get_messages'\nimport { useApiClient } from './use_api_client'\nimport { useCurrentPerson } from './use_current_person'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\nimport { getRequestQueryKey } from './use_suspense_api'\nimport { TYPING_TIMEOUT_INTERVAL, useTypingStatusCache } from './use_typing_status_cache'\n\ninterface Props {\n conversationId: number\n}\n\nexport function useConversationMessagesJoltEvents({ conversationId }: Props) {\n const queryClient = useQueryClient()\n const currentPerson = useCurrentPerson()\n const joltChannel = useJoltChannel(`chat.conversations.${conversationId}`)\n const messagesRequestArgs = getMessagesRequestArgs({ conversation_id: conversationId })\n const messagesQueryKey = getRequestQueryKey(messagesRequestArgs)\n const apiClient = useApiClient()\n\n const { addTypingEvent, removeTypingEventById, removeAllTypingEventsByAuthorId } =\n useTypingStatusCache(conversationId)\n\n const handleMessageUpdateOrCreate = async (e: MessageCreatedEvent | MessageUpdatedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n if (e.event === 'message.created' && data.author_id) {\n removeAllTypingEventsByAuthorId(data.author_id)\n if (data.idempotent_key && data.author_id === currentPerson.id) {\n completeMessageCreationTracking({ apiClient, idempotentKey: data.idempotent_key })\n }\n }\n\n // Update the main conversation cache\n updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)\n\n // If message has a reply_root_id, also update the threaded cache\n if (data.reply_root_id) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(\n conversationId,\n data.reply_root_id\n )\n updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)\n }\n\n // Update individual message query cache so reply shadow messages update immediately\n if (e.event === 'message.updated') {\n const individualMessageQueryKey = getMessageQueryKey({\n conversation_id: conversationId,\n messageId: data.sort_key,\n })\n updateCacheWithIndividualMessage(queryClient, individualMessageQueryKey, message)\n }\n }\n\n const handleMessageDeleted = async (e: MessageDeletedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n // Update the main conversation cache\n queryClient.setQueryData<QueryData>(messagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n\n // If message has a reply_root_id, also update the threaded cache\n if (data.reply_root_id) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(\n conversationId,\n data.reply_root_id\n )\n queryClient.setQueryData<QueryData>(threadedMessagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n }\n }\n\n const handleReactionJoltEvent = async (e: JoltReactionEvent) => {\n // Update the main conversation cache and capture the reply_root_id if present\n updateCacheWithReaction(queryClient, messagesQueryKey, e, currentPerson.id)\n\n const replyRootId = e.data.data.reply_root_id\n\n // If the message has a reply_root_id, also update the threaded cache\n if (replyRootId) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(conversationId, replyRootId)\n updateCacheWithReaction(queryClient, threadedMessagesQueryKey, e, currentPerson.id)\n }\n }\n\n const handleTypingEvent = async (e: JoltTypingEvent) => {\n const { data } = e.data\n addTypingEvent(data)\n setTimeout(() => removeTypingEventById(data.id), TYPING_TIMEOUT_INTERVAL)\n }\n\n useJoltEvent(joltChannel, 'message.created', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.updated', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.destroyed', handleMessageDeleted)\n useJoltEvent(joltChannel, 'reaction.*', handleReactionJoltEvent)\n useJoltEvent(joltChannel, 'typing.broadcast', handleTypingEvent)\n}\n\ntype QueryData = InfiniteData<ApiCollection<MessageResource>>\n"],"mappings":";AAAA,SAAuBA,cAAc,QAAQ,uBAAuB;AA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;IAAAA,EAAA,GAAA7C,CAAA;EAAA;EAJD,MAAAiD,iBAAA,GAA0BJ,EAIzB;EAEDnD,YAAY,CAACW,WAAW,EAAE,iBAAiB,EAAEwB,2BAA2B,CAAC;EACzEnC,YAAY,CAACW,WAAW,EAAE,iBAAiB,EAAEwB,2BAA2B,CAAC;EACzEnC,YAAY,CAACW,WAAW,EAAE,mBAAmB,EAAEkC,oBAAoB,CAAC;EACpE7C,YAAY,CAACW,WAAW,EAAE,YAAY,EAAEuC,uBAAuB,CAAC;EAChElD,YAAY,CAACW,WAAW,EAAE,kBAAkB,EAAE4C,iBAAiB,CAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"use_conversation_messages_jolt_events.js","names":["useQueryClient","deleteRecordInPagesData","updateCacheWithMessage","updateCacheWithIndividualMessage","updateCacheWithReaction","updateCacheReplyRoots","getThreadedMessagesQueryKey","transformMessageEventDataToMessageResource","completeMessageCreationTracking","getMessageQueryKey","getMessagesRequestArgs","useApiClient","useCurrentPerson","useJoltChannel","useJoltEvent","getRequestQueryKey","TYPING_TIMEOUT_INTERVAL","useTypingStatusCache","useConversationMessagesJoltEvents","t0","$","_c","conversationId","queryClient","currentPerson","joltChannel","t1","messagesRequestArgs","conversation_id","messagesQueryKey","apiClient","addTypingEvent","removeTypingEventById","removeAllTypingEventsByAuthorId","t2","id","e","data","message","currentPersonId","isReplyRootUpdate","event","reply_root_id","sort_key","author_id","idempotent_key","idempotentKey","threadedMessagesQueryKey","individualMessageQueryKey","messageId","handleMessageUpdateOrCreate","t3","e_0","data_0","message_0","setQueryData","prev","record","threadedMessagesQueryKey_0","prev_0","handleMessageDeleted","t4","e_1","replyRootId","threadedMessagesQueryKey_1","handleReactionJoltEvent","t5","e_2","data_1","setTimeout","handleTypingEvent"],"sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"sourcesContent":["import { InfiniteData, useQueryClient } from '@tanstack/react-query'\nimport { ApiCollection, MessageResource } from '../types'\nimport { JoltReactionEvent, JoltTypingEvent } from '../types/jolt_events'\nimport {\n MessageCreatedEvent,\n MessageUpdatedEvent,\n MessageDeletedEvent,\n} from '../types/jolt_events/message_events'\nimport { deleteRecordInPagesData } from '../utils'\nimport {\n updateCacheWithMessage,\n updateCacheWithIndividualMessage,\n updateCacheWithReaction,\n updateCacheReplyRoots,\n getThreadedMessagesQueryKey,\n} from '../utils/cache/messages_cache'\nimport { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'\nimport { completeMessageCreationTracking } from '../utils/performance_tracking'\nimport { getMessageQueryKey } from '../utils/request/get_message'\nimport { getMessagesRequestArgs } from '../utils/request/get_messages'\nimport { useApiClient } from './use_api_client'\nimport { useCurrentPerson } from './use_current_person'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\nimport { getRequestQueryKey } from './use_suspense_api'\nimport { TYPING_TIMEOUT_INTERVAL, useTypingStatusCache } from './use_typing_status_cache'\n\ninterface Props {\n conversationId: number\n}\n\nexport function useConversationMessagesJoltEvents({ conversationId }: Props) {\n const queryClient = useQueryClient()\n const currentPerson = useCurrentPerson()\n const joltChannel = useJoltChannel(`chat.conversations.${conversationId}`)\n const messagesRequestArgs = getMessagesRequestArgs({ conversation_id: conversationId })\n const messagesQueryKey = getRequestQueryKey(messagesRequestArgs)\n const apiClient = useApiClient()\n\n const { addTypingEvent, removeTypingEventById, removeAllTypingEventsByAuthorId } =\n useTypingStatusCache(conversationId)\n\n const handleMessageUpdateOrCreate = async (e: MessageCreatedEvent | MessageUpdatedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n const isReplyRootUpdate = e.event === 'message.updated' && data.reply_root_id === data.sort_key\n\n if (e.event === 'message.created' && data.author_id) {\n removeAllTypingEventsByAuthorId(data.author_id)\n if (data.idempotent_key && data.author_id === currentPerson.id) {\n completeMessageCreationTracking({ apiClient, idempotentKey: data.idempotent_key })\n }\n }\n\n // Update the main conversation cache\n updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)\n\n // If message has a reply_root_id, also update the threaded cache\n if (data.reply_root_id) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(\n conversationId,\n data.reply_root_id\n )\n updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)\n\n if (isReplyRootUpdate) {\n updateCacheReplyRoots(queryClient, messagesQueryKey, message)\n updateCacheReplyRoots(queryClient, threadedMessagesQueryKey, message)\n }\n }\n\n // Update individual message query cache so reply shadow messages update immediately\n if (e.event === 'message.updated') {\n const individualMessageQueryKey = getMessageQueryKey({\n conversation_id: conversationId,\n messageId: data.sort_key,\n })\n updateCacheWithIndividualMessage(queryClient, individualMessageQueryKey, message)\n }\n }\n\n const handleMessageDeleted = async (e: MessageDeletedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n // Update the main conversation cache\n queryClient.setQueryData<QueryData>(messagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n\n // If message has a reply_root_id, also update the threaded cache\n if (data.reply_root_id) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(\n conversationId,\n data.reply_root_id\n )\n queryClient.setQueryData<QueryData>(threadedMessagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n }\n }\n\n const handleReactionJoltEvent = async (e: JoltReactionEvent) => {\n // Update the main conversation cache and capture the reply_root_id if present\n updateCacheWithReaction(queryClient, messagesQueryKey, e, currentPerson.id)\n\n const replyRootId = e.data.data.reply_root_id\n\n // If the message has a reply_root_id, also update the threaded cache\n if (replyRootId) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(conversationId, replyRootId)\n updateCacheWithReaction(queryClient, threadedMessagesQueryKey, e, currentPerson.id)\n }\n }\n\n const handleTypingEvent = async (e: JoltTypingEvent) => {\n const { data } = e.data\n addTypingEvent(data)\n setTimeout(() => removeTypingEventById(data.id), TYPING_TIMEOUT_INTERVAL)\n }\n\n useJoltEvent(joltChannel, 'message.created', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.updated', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.destroyed', handleMessageDeleted)\n useJoltEvent(joltChannel, 'reaction.*', handleReactionJoltEvent)\n useJoltEvent(joltChannel, 'typing.broadcast', handleTypingEvent)\n}\n\ntype QueryData = InfiniteData<ApiCollection<MessageResource>>\n"],"mappings":";AAAA,SAAuBA,cAAc,QAAQ,uBAAuB;AAQpE,SAASC,uBAAuB,QAAQ,UAAU;AAClD,SACEC,sBAAsB,EACtBC,gCAAgC,EAChCC,uBAAuB,EACvBC,qBAAqB,EACrBC,2BAA2B,QACtB,+BAA+B;AACtC,SAASC,0CAA0C,QAAQ,gEAAgE;AAC3H,SAASC,+BAA+B,QAAQ,+BAA+B;AAC/E,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,sBAAsB,QAAQ,+BAA+B;AACtE,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,cAAc,EAAEC,YAAY,QAAQ,YAAY;AACzD,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,uBAAuB,EAAEC,oBAAoB,QAAQ,2BAA2B;AAMzF,OAAO,SAAAC,kCAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAC,EAAA;EAA2C;IAAAC;EAAA,IAAAH,EAAyB;EACzE,MAAAI,WAAA,GAAoBvB,cAAc,CAAC,CAAC;EACpC,MAAAwB,aAAA,GAAsBZ,gBAAgB,CAAC,CAAC;EACxC,MAAAa,WAAA,GAAoBZ,cAAc,CAAC,sBAAsBS,cAAc,EAAE,CAAC;EAAA,IAAAI,EAAA;EAAA,IAAAN,CAAA,QAAAE,cAAA;IAC1E,MAAAK,mBAAA,GAA4BjB,sBAAsB,CAAC;MAAAkB,eAAA,EAAmBN;IAAe,CAAC,CAAC;IAC9DI,EAAA,GAAAX,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AAAf,CAAA,OAAAE,cAAA;IAAAF,CAAA,OAAAI,aAAA,CAAAW,EAAA;IAAAf,CAAA,OAAAS,gBAAA;IAAAT,CAAA,OAAAG,WAAA;IAAAH,CAAA,OAAAyC,EAAA;EAAA;IAAAA,EAAA,GAAAzC,CAAA;EAAA;EAXD,MAAA6C,uBAAA,GAAgCJ,EAW/B;EAAA,IAAAK,EAAA;EAAA,IAAA9C,CAAA,SAAAW,cAAA,IAAAX,CAAA,SAAAY,qBAAA;IAEyBkC,EAAA,SAAAC,GAAA;MACxB;QAAA9B,IAAA,EAAA+B;MAAA,IAAiBhC,GAAC,CAAAC,IAAK;MACvBN,cAAc,CAACM,MAAI,CAAC;MACpBgC,UAAU,CAAC,MAAMrC,qBAAqB,CAACK,MAAI,CAAAF,EAAG,CAAC,EAAEnB,uBAAuB,CAAC;IAAA,CAC1E;IAAAI,CAAA,OAAAW,cAAA;IAAAX,CAAA,OAAAY,qBAAA;IAAAZ,CAAA,OAAA8C,EAAA;EAAA;IAAAA,EAAA,GAAA9C,CAAA;EAAA;EAJD,MAAAkD,iBAAA,GAA0BJ,EAIzB;EAEDpD,YAAY,CAACW,WAAW,EAAE,iBAAiB,EAAEyB,2BAA2B,CAAC;EACzEpC,YAAY,CAACW,WAAW,EAAE,iBAAiB,EAAEyB,2BAA2B,CAAC;EACzEpC,YAAY,CAACW,WAAW,EAAE,mBAAmB,EAAEmC,oBAAoB,CAAC;EACpE9C,YAAY,CAACW,WAAW,EAAE,YAAY,EAAEwC,uBAAuB,CAAC;EAChEnD,YAAY,CAACW,WAAW,EAAE,kBAAkB,EAAE6C,iBAAiB,CAAC;AAAA","ignoreList":[]}
@@ -16,6 +16,7 @@ export interface MessageResource {
16
16
  reactionCounts: ReactionCountResource[];
17
17
  replyCount: number;
18
18
  replyRootId?: string | null;
19
+ replyRoot?: MessageResource | null;
19
20
  idempotentKey?: string | null;
20
21
  messageType: string;
21
22
  personIdsForSystemEvent?: number[] | null;
@@ -1 +1 @@
1
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,CAAA;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IACzC,eAAe,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAGnF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,cAAc,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;IACnD,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAGlC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,uCAAuC,EAAE,CAAA;CACjE"}
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","names":[],"sources":["../../../src/types/resources/message.ts"],"sourcesContent":["import { DenormalizedAttachmentResource } from './denormalized_attachment_resource'\nimport { DenormalizedAttachmentResourceForCreate } from './denormalized_attachment_resource_for_create'\nimport type { PersonResource } from './person'\nimport type { ReactionCountResource } from './reaction'\n\nexport interface MessageResource {\n type: 'Message'\n id: string\n text: string | null\n html: string\n createdAt: string\n deletedAt: string | null\n textEditedAt: string | null\n mine: boolean\n attachments: DenormalizedAttachmentResource[]\n author: PersonResource\n reactionCounts: ReactionCountResource[]\n replyCount: number\n replyRootId?: string | null\n idempotentKey?: string | null\n messageType: string\n personIdsForSystemEvent?: number[] | null\n systemTextParts?: { names: string[]; overflowCount: number; action: string } | null\n\n // Custom Local Properties we set for rendering\n renderAuthor?: boolean\n renderTime?: boolean\n myLatestInConversation?: boolean\n lastInGroup?: boolean\n threadPosition?: 'first' | 'center' | 'last' | null\n prevIsMyReply?: boolean\n nextIsMyReply?: boolean\n nextRendersAuthor?: boolean\n isReplyShadowMessage?: boolean\n nextIsReplyShadowMessage?: boolean\n\n // Properties for mutation state\n pending?: boolean // Indicates if the message is optimistically created and pending server response\n error?: string // Error message if the message failed to send\n attachmentsForCreate?: DenormalizedAttachmentResourceForCreate[]\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"message.js","names":[],"sources":["../../../src/types/resources/message.ts"],"sourcesContent":["import { DenormalizedAttachmentResource } from './denormalized_attachment_resource'\nimport { DenormalizedAttachmentResourceForCreate } from './denormalized_attachment_resource_for_create'\nimport type { PersonResource } from './person'\nimport type { ReactionCountResource } from './reaction'\n\nexport interface MessageResource {\n type: 'Message'\n id: string\n text: string | null\n html: string\n createdAt: string\n deletedAt: string | null\n textEditedAt: string | null\n mine: boolean\n attachments: DenormalizedAttachmentResource[]\n author: PersonResource\n reactionCounts: ReactionCountResource[]\n replyCount: number\n replyRootId?: string | null\n replyRoot?: MessageResource | null\n idempotentKey?: string | null\n messageType: string\n personIdsForSystemEvent?: number[] | null\n systemTextParts?: { names: string[]; overflowCount: number; action: string } | null\n\n // Custom Local Properties we set for rendering\n renderAuthor?: boolean\n renderTime?: boolean\n myLatestInConversation?: boolean\n lastInGroup?: boolean\n threadPosition?: 'first' | 'center' | 'last' | null\n prevIsMyReply?: boolean\n nextIsMyReply?: boolean\n nextRendersAuthor?: boolean\n isReplyShadowMessage?: boolean\n nextIsReplyShadowMessage?: boolean\n\n // Properties for mutation state\n pending?: boolean // Indicates if the message is optimistically created and pending server response\n error?: string // Error message if the message failed to send\n attachmentsForCreate?: DenormalizedAttachmentResourceForCreate[]\n}\n"],"mappings":"","ignoreList":[]}
@@ -3,6 +3,7 @@ import { MessageResource } from '../../types';
3
3
  import { JoltReactionEvent } from '../../types/jolt_events';
4
4
  export declare function updateCacheWithMessage(queryClient: QueryClient, queryKey: unknown[], message: MessageResource, event: 'message.created' | 'message.updated'): void;
5
5
  export declare function updateCacheWithIndividualMessage(queryClient: QueryClient, queryKey: unknown[], message: MessageResource): void;
6
+ export declare function updateCacheReplyRoots(queryClient: QueryClient, queryKey: unknown[], root: MessageResource): void;
6
7
  export declare function updateCacheWithReaction(queryClient: QueryClient, queryKey: unknown[], event: JoltReactionEvent, currentPersonId: number): void;
7
8
  export declare function isTemporaryMessageId(messageId?: string | null): boolean;
8
9
  export declare function isNewMessage(message?: MessageResource): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"messages_cache.d.ts","sourceRoot":"","sources":["../../../src/utils/cache/messages_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEjE,OAAO,EAA8B,eAAe,EAAE,MAAM,aAAa,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAM3D,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,iBAAiB,GAAG,iBAAiB,QA8B7C;AAID,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,EAAE,eAAe,QAgBzB;AAED,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,iBAAiB,EACxB,eAAe,EAAE,MAAM,QAuCxB;AAGD,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEvE;AACD,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAE/D;AAED,wBAAgB,2BA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}
@@ -1,7 +1,7 @@
1
1
  import { getRequestQueryKey } from '../../hooks/use_suspense_api';
2
2
  import { transformReactionEventDataToReactionCountResource } from '../jolt/transform_reaction_event_data_to_reaction_count_resource';
3
3
  import { getMessagesRequestArgs } from '../request/get_messages';
4
- import { updateOrCreateRecordInPagesData, updateRecordInPagesData } from './page_mutations';
4
+ import { updateAllRecordsInPagesData, updateOrCreateRecordInPagesData, updateRecordInPagesData } from './page_mutations';
5
5
  import { deleteRecordInPagesData } from './page_mutations';
6
6
  export function updateCacheWithMessage(queryClient, queryKey, message, event) {
7
7
  queryClient.setQueryData(queryKey, prev => {
@@ -45,6 +45,15 @@ export function updateCacheWithIndividualMessage(queryClient, queryKey, message)
45
45
  };
46
46
  });
47
47
  }
48
+ export function updateCacheReplyRoots(queryClient, queryKey, root) {
49
+ queryClient.setQueryData(queryKey, prev => updateAllRecordsInPagesData({
50
+ data: prev,
51
+ processRecord: message => message.replyRoot?.id === root.id ? {
52
+ ...message,
53
+ replyRoot: mergeMessageUpdate(root, message.replyRoot)
54
+ } : message
55
+ }));
56
+ }
48
57
  export function updateCacheWithReaction(queryClient, queryKey, event, currentPersonId) {
49
58
  const message = {
50
59
  id: event.data.data.message_sort_key
@@ -1 +1 @@
1
- {"version":3,"file":"messages_cache.js","names":["getRequestQueryKey","transformReactionEventDataToReactionCountResource","getMessagesRequestArgs","updateOrCreateRecordInPagesData","updateRecordInPagesData","deleteRecordInPagesData","updateCacheWithMessage","queryClient","queryKey","message","event","setQueryData","prev","dataAfterTempRemoval","mine","idempotentKey","data","record","matchFn","existingMessage","isTemporaryMessageId","id","processRecord","current","mergeMessageUpdate","updateCacheWithIndividualMessage","links","meta","updateCacheWithReaction","currentPersonId","message_sort_key","oldMessage","reactionCounts","foundMatch","newReactionCounts","map","reactionCount","value","oldData","newReactionCount","count","messageId","endsWith","isNewMessage","getThreadedMessagesQueryKey","conversationId","replyRootId","requestArgs","conversation_id","reply_root_id"],"sources":["../../../src/utils/cache/messages_cache.ts"],"sourcesContent":["import { InfiniteData, QueryClient } from '@tanstack/react-query'\nimport { getRequestQueryKey } from '../../hooks/use_suspense_api'\nimport { ApiCollection, ApiResource, MessageResource } from '../../types'\nimport { JoltReactionEvent } from '../../types/jolt_events'\nimport { transformReactionEventDataToReactionCountResource } from '../jolt/transform_reaction_event_data_to_reaction_count_resource'\nimport { getMessagesRequestArgs } from '../request/get_messages'\nimport { updateOrCreateRecordInPagesData, updateRecordInPagesData } from './page_mutations'\nimport { deleteRecordInPagesData } from './page_mutations'\n\nexport function updateCacheWithMessage(\n queryClient: QueryClient,\n queryKey: unknown[],\n message: MessageResource,\n event: 'message.created' | 'message.updated'\n) {\n queryClient.setQueryData<MessagesQueryData>(queryKey, prev => {\n if (event === 'message.created') {\n // Before adding the new message, remove its pending temporary counterpart.\n // The Jolt echo can arrive before the HTTP response has swapped it out.\n let dataAfterTempRemoval = prev\n if (prev && message.mine && message.idempotentKey) {\n dataAfterTempRemoval = deleteRecordInPagesData({\n data: prev,\n record: message,\n matchFn: existingMessage =>\n isTemporaryMessageId(existingMessage.id) &&\n existingMessage.idempotentKey === message.idempotentKey,\n })\n }\n\n return updateOrCreateRecordInPagesData({\n data: dataAfterTempRemoval,\n record: message,\n processRecord: (record, current) => mergeMessageUpdate(record, current),\n })\n } else {\n return updateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, current) => mergeMessageUpdate(record, current),\n })\n }\n })\n}\n\ntype IndividualMessageQueryData = ApiResource<MessageResource>\n\nexport function updateCacheWithIndividualMessage(\n queryClient: QueryClient,\n queryKey: unknown[],\n message: MessageResource\n) {\n queryClient.setQueryData<IndividualMessageQueryData>(queryKey, prev => {\n if (!prev) {\n return {\n data: message,\n links: {},\n meta: {},\n }\n }\n\n return {\n ...prev,\n data: mergeMessageUpdate(message, prev.data),\n }\n })\n}\n\nexport function updateCacheWithReaction(\n queryClient: QueryClient,\n queryKey: unknown[],\n event: JoltReactionEvent,\n currentPersonId: number\n) {\n const message = { id: event.data.data.message_sort_key } as MessageResource\n queryClient.setQueryData<MessagesQueryData>(queryKey, prev =>\n updateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, oldMessage) => {\n const reactionCounts = oldMessage.reactionCounts || []\n let foundMatch = false\n let newReactionCounts = reactionCounts.map(reactionCount => {\n if (reactionCount.value === event.data.data.value) {\n foundMatch = true\n return transformReactionEventDataToReactionCountResource({\n data: event.data.data,\n oldData: reactionCount,\n event: event.event,\n currentPersonId,\n })\n }\n return reactionCount\n })\n\n if (!foundMatch) {\n const newReactionCount = transformReactionEventDataToReactionCountResource({\n data: event.data.data,\n event: event.event,\n currentPersonId,\n })\n\n if (newReactionCount?.count) {\n newReactionCounts = [...newReactionCounts, newReactionCount]\n }\n }\n\n return { ...oldMessage, reactionCounts: newReactionCounts }\n },\n })\n )\n}\n\ntype MessagesQueryData = InfiniteData<ApiCollection<MessageResource>>\nexport function isTemporaryMessageId(messageId?: string | null): boolean {\n return !!messageId && messageId.endsWith('-temp')\n}\nexport function isNewMessage(message?: MessageResource): boolean {\n return !message?.id || isTemporaryMessageId(message.id)\n}\n\nexport function getThreadedMessagesQueryKey(conversationId: number, replyRootId: string) {\n const requestArgs = getMessagesRequestArgs({\n conversation_id: conversationId,\n reply_root_id: replyRootId,\n })\n return getRequestQueryKey(requestArgs)\n}\n\nexport function mergeMessageUpdate(\n record: MessageResource,\n current?: MessageResource\n): MessageResource {\n if (!current) {\n return record\n }\n\n return {\n ...current,\n ...record,\n // Preserve reactions from cache - they're managed via separate reaction events\n reactionCounts: current.reactionCounts || [],\n }\n}\n"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,8BAA8B;AAGjE,SAASC,iDAAiD,QAAQ,kEAAkE;AACpI,SAASC,sBAAsB,QAAQ,yBAAyB;AAChE,SAASC,+BAA+B,EAAEC,uBAAuB,QAAQ,kBAAkB;AAC3F,SAASC,uBAAuB,QAAQ,kBAAkB;AAE1D,OAAO,SAASC,sBAAsBA,CACpCC,WAAwB,EACxBC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AgB,CAAC;QAC9D;MACF;MAEA,OAAO;QAAE,GAAGR,UAAU;QAAEC,cAAc,EAAEE;MAAkB,CAAC;IAC7D;EACF,CAAC,CACH,CAAC;AACH;AAGA,OAAO,SAASd,oBAAoBA,CAACqB,SAAyB,EAAW;EACvE,OAAO,CAAC,CAACA,SAAS,IAAIA,SAAS,CAACC,QAAQ,CAAC,OAAO,CAAC;AACnD;AACA,OAAO,SAASC,YAAYA,CAAClC,OAAyB,EAAW;EAC/D,OAAO,CAACA,OAAO,EAAEY,EAAE,IAAID,oBAAoB,CAACX,OAAO,CAACY,EAAE,CAAC;AACzD;AAEA,OAAO,SAASuB,2BAA2BA,CAACC,cAAsB,EAAEC,WAAmB,EAAE;EACvF,MAAMC,WAAW,GAAG7C,sBAAsB,CAAC;IACzC8C,eAAe,EAAEH,cAAc;IAC/BI,aAAa,EAAEH;EACjB,CAAC,CAAC;EACF,OAAO9C,kBAAkB,CAAC+C,WAAW,CAAC;AACxC;AAEA,OAAO,SAASvB,kBAAkBA,CAChCP,MAAuB,EACvBM,OAAyB,EACR;EACjB,IAAI,CAACA,OAAO,EAAE;IACZ,OAAON,MAAM;EACf;EAEA,OAAO;IACL,GAAGM,OAAO;IACV,GAAGN,MAAM;IACT;IACAe,cAAc,EAAET,OAAO,CAACS,cAAc,IAAI;EAC5C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"messages_cache.js","names":["getRequestQueryKey","transformReactionEventDataToReactionCountResource","getMessagesRequestArgs","updateAllRecordsInPagesData","updateOrCreateRecordInPagesData","updateRecordInPagesData","deleteRecordInPagesData","updateCacheWithMessage","queryClient","queryKey","message","event","setQueryData","prev","dataAfterTempRemoval","mine","idempotentKey","data","record","matchFn","existingMessage","isTemporaryMessageId","id","processRecord","current","mergeMessageUpdate","updateCacheWithIndividualMessage","links","meta","updateCacheReplyRoots","root","replyRoot","updateCacheWithReaction","currentPersonId","message_sort_key","oldMessage","reactionCounts","foundMatch","newReactionCounts","map","reactionCount","value","oldData","newReactionCount","count","messageId","endsWith","isNewMessage","getThreadedMessagesQueryKey","conversationId","replyRootId","requestArgs","conversation_id","reply_root_id"],"sources":["../../../src/utils/cache/messages_cache.ts"],"sourcesContent":["import { InfiniteData, QueryClient } from '@tanstack/react-query'\nimport { getRequestQueryKey } from '../../hooks/use_suspense_api'\nimport { ApiCollection, ApiResource, MessageResource } from '../../types'\nimport { JoltReactionEvent } from '../../types/jolt_events'\nimport { transformReactionEventDataToReactionCountResource } from '../jolt/transform_reaction_event_data_to_reaction_count_resource'\nimport { getMessagesRequestArgs } from '../request/get_messages'\nimport {\n updateAllRecordsInPagesData,\n updateOrCreateRecordInPagesData,\n updateRecordInPagesData,\n} from './page_mutations'\nimport { deleteRecordInPagesData } from './page_mutations'\n\nexport function updateCacheWithMessage(\n queryClient: QueryClient,\n queryKey: unknown[],\n message: MessageResource,\n event: 'message.created' | 'message.updated'\n) {\n queryClient.setQueryData<MessagesQueryData>(queryKey, prev => {\n if (event === 'message.created') {\n // Before adding the new message, remove its pending temporary counterpart.\n // The Jolt echo can arrive before the HTTP response has swapped it out.\n let dataAfterTempRemoval = prev\n if (prev && message.mine && message.idempotentKey) {\n dataAfterTempRemoval = deleteRecordInPagesData({\n data: prev,\n record: message,\n matchFn: existingMessage =>\n isTemporaryMessageId(existingMessage.id) &&\n existingMessage.idempotentKey === message.idempotentKey,\n })\n }\n\n return updateOrCreateRecordInPagesData({\n data: dataAfterTempRemoval,\n record: message,\n processRecord: (record, current) => mergeMessageUpdate(record, current),\n })\n } else {\n return updateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, current) => mergeMessageUpdate(record, current),\n })\n }\n })\n}\n\ntype IndividualMessageQueryData = ApiResource<MessageResource>\n\nexport function updateCacheWithIndividualMessage(\n queryClient: QueryClient,\n queryKey: unknown[],\n message: MessageResource\n) {\n queryClient.setQueryData<IndividualMessageQueryData>(queryKey, prev => {\n if (!prev) {\n return {\n data: message,\n links: {},\n meta: {},\n }\n }\n\n return {\n ...prev,\n data: mergeMessageUpdate(message, prev.data),\n }\n })\n}\n\nexport function updateCacheReplyRoots(\n queryClient: QueryClient,\n queryKey: unknown[],\n root: MessageResource\n) {\n queryClient.setQueryData<MessagesQueryData>(queryKey, prev =>\n updateAllRecordsInPagesData({\n data: prev,\n processRecord: message =>\n message.replyRoot?.id === root.id\n ? { ...message, replyRoot: mergeMessageUpdate(root, message.replyRoot) }\n : message,\n })\n )\n}\n\nexport function updateCacheWithReaction(\n queryClient: QueryClient,\n queryKey: unknown[],\n event: JoltReactionEvent,\n currentPersonId: number\n) {\n const message = { id: event.data.data.message_sort_key } as MessageResource\n queryClient.setQueryData<MessagesQueryData>(queryKey, prev =>\n updateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, oldMessage) => {\n const reactionCounts = oldMessage.reactionCounts || []\n let foundMatch = false\n let newReactionCounts = reactionCounts.map(reactionCount => {\n if (reactionCount.value === event.data.data.value) {\n foundMatch = true\n return transformReactionEventDataToReactionCountResource({\n data: event.data.data,\n oldData: reactionCount,\n event: event.event,\n currentPersonId,\n })\n }\n return reactionCount\n })\n\n if (!foundMatch) {\n const newReactionCount = transformReactionEventDataToReactionCountResource({\n data: event.data.data,\n event: event.event,\n currentPersonId,\n })\n\n if (newReactionCount?.count) {\n newReactionCounts = [...newReactionCounts, newReactionCount]\n }\n }\n\n return { ...oldMessage, reactionCounts: newReactionCounts }\n },\n })\n )\n}\n\ntype MessagesQueryData = InfiniteData<ApiCollection<MessageResource>>\nexport function isTemporaryMessageId(messageId?: string | null): boolean {\n return !!messageId && messageId.endsWith('-temp')\n}\nexport function isNewMessage(message?: MessageResource): boolean {\n return !message?.id || isTemporaryMessageId(message.id)\n}\n\nexport function getThreadedMessagesQueryKey(conversationId: number, replyRootId: string) {\n const requestArgs = getMessagesRequestArgs({\n conversation_id: conversationId,\n reply_root_id: replyRootId,\n })\n return getRequestQueryKey(requestArgs)\n}\n\nexport function mergeMessageUpdate(\n record: MessageResource,\n current?: MessageResource\n): MessageResource {\n if (!current) {\n return record\n }\n\n return {\n ...current,\n ...record,\n // Preserve reactions from cache - they're managed via separate reaction events\n reactionCounts: current.reactionCounts || [],\n }\n}\n"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,8BAA8B;AAGjE,SAASC,iDAAiD,QAAQ,kEAAkE;AACpI,SAASC,sBAAsB,QAAQ,yBAAyB;AAChE,SACEC,2BAA2B,EAC3BC,+BAA+B,EAC/BC,uBAAuB,QAClB,kBAAkB;AACzB,SAASC,uBAAuB,QAAQ,kBAAkB;AAE1D,OAAO,SAASC,sBAAsBA,CACpCC,WAAwB,EACxBC,QAAmB,EACnBC,OAAwB,EACxBC,KAA4C,EAC5C;EACAH,WAAW,CAACI,YAAY,CAAoBH,QAAQ,EAAEI,IAAI,IAAI;IAC5D,IAAIF,KAAK,KAAK,iBAAiB,EAAE;MAC/B;MACA;MACA,IAAIG,oBAAoB,GAAGD,IAAI;MAC/B,IAAIA,IAAI,IAAIH,OAAO,CAACK,IAAI,IAAIL,OAAO,CAACM,aAAa,EAAE;QACjDF,oBAAoB,GAAGR,uBAAuB,CAAC;UAC7CW,IAAI,EAAEJ,IAAI;UACVK,MAAM,EAAER,OAAO;UACfS,OAAO,EAAEC,eAAe,IACtBC,oBAAoB,CAACD,eAAe,CAACE,EAAE,CAAC,IACxCF,eAAe,CAACJ,aAAa,KAAKN,OAAO,CAACM;QAC9C,CAAC,CAAC;MACJ;MAEA,OAAOZ,+BAA+B,CAAC;QACrCa,IAAI,EAAEH,oBAAoB;QAC1BI,MAAM,EAAER,OAAO;QACfa,aAAa,EAAEA,CAACL,MAAM,EAAEM,OAAO,KAAKC,kBAAkB,CAACP,MAAM,EAAEM,OAAO;MACxE,CAAC,CAAC;IACJ,CAAC,MAAM;MACL,OAAOnB,uBAAuB,CAAC;QAC7BY,IAAI,EAAEJ,IAAI;QACVK,MAAM,EAAER,OAAO;QACfa,aAAa,EAAEA,CAACL,MAAM,EAAEM,OAAO,KAAKC,kBAAkB,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AAsB,EAAEC,WAAmB,EAAE;EACvF,MAAMC,WAAW,GAAGjD,sBAAsB,CAAC;IACzCkD,eAAe,EAAEH,cAAc;IAC/BI,aAAa,EAAEH;EACjB,CAAC,CAAC;EACF,OAAOlD,kBAAkB,CAACmD,WAAW,CAAC;AACxC;AAEA,OAAO,SAAS1B,kBAAkBA,CAChCP,MAAuB,EACvBM,OAAyB,EACR;EACjB,IAAI,CAACA,OAAO,EAAE;IACZ,OAAON,MAAM;EACf;EAEA,OAAO;IACL,GAAGM,OAAO;IACV,GAAGN,MAAM;IACT;IACAkB,cAAc,EAAEZ,OAAO,CAACY,cAAc,IAAI;EAC5C,CAAC;AACH","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"transform_response.d.ts","sourceRoot":"","sources":["../../../src/utils/client/transform_response.ts"],"names":[],"mappings":"AAiGA,QAAA,MAAM,iBAAiB,yBAAyD,CAAA;AAEhF,eAAe,iBAAiB,CAAA"}
1
+ {"version":3,"file":"transform_response.d.ts","sourceRoot":"","sources":["../../../src/utils/client/transform_response.ts"],"names":[],"mappings":"AAmGA,QAAA,MAAM,iBAAiB,yBAAyD,CAAA;AAEhF,eAAe,iBAAiB,CAAA"}
@@ -36,21 +36,25 @@ const transformRelationships = relationships => {
36
36
  }
37
37
  }, {});
38
38
  };
39
- const addIncludedRecords = (relationships, included, seen, parent) => {
39
+ const addIncludedRecords = (record, included, seen, parent) => {
40
+ const {
41
+ relationships
42
+ } = record;
40
43
  return Object.keys(relationships || {}).reduce((acc, key) => {
41
44
  const relationship = relationships[key];
42
45
  if (_.isArray(relationship.data)) {
43
46
  const records = _(relationship.data).map(elem => _.find(included, elem)).compact() // account for orphans
44
47
  .value();
45
- return _.set(acc, _.pluralize(key), _.map(records, record => transformRecord(record, included, seen)));
48
+ return _.set(acc, _.pluralize(key), _.map(records, related => transformRecord(related, included, seen)));
46
49
  } else {
47
50
  const [id, type] = _.at(relationship, ['data.id', 'data.type']);
48
51
  if (id && type) {
49
- const record = _.find(included, {
52
+ const isSelfReference = id === record.id && type === record.type;
53
+ const related = isSelfReference ? undefined : _.find(included, {
50
54
  id,
51
55
  type
52
56
  });
53
- return _.set(acc, key, record ? transformRecord(record, included, seen) : null);
57
+ return _.set(acc, key, related ? transformRecord(related, included, seen) : null);
54
58
  } else {
55
59
  return acc;
56
60
  }
@@ -77,7 +81,7 @@ const transformRecord = (record, included, seen) => {
77
81
  ..._.mapKeys(attributes, (v, k) => k === 'length' ? `${type.charAt(0).toLowerCase()}${type.slice(1)}Length` : k, {})
78
82
  };
79
83
  seen.set(record, transformed);
80
- return addIncludedRecords(relationships, included, seen, transformed);
84
+ return addIncludedRecords(record, included, seen, transformed);
81
85
  }
82
86
  };
83
87
  const defaultTransformResponse = response => {
@@ -1 +1 @@
1
- {"version":3,"file":"transform_response.js","names":["_","inflection","keysToCamelCase","mixin","singular","plural","transformId","id","thru","parseInt","int","transformRelationships","relationships","Object","keys","reduce","acc","key","relationship","isArray","data","ids","map","singularize","get","type","addIncludedRecords","included","seen","parent","records","elem","find","compact","value","set","pluralize","record","transformRecord","at","attributes","links","has","transformed","mapKeys","v","k","charAt","toLowerCase","slice","defaultTransformResponse","response","isEmpty","meta","WeakMap","result","d","transformResponse","flowRight"],"sources":["../../../src/utils/client/transform_response.ts"],"sourcesContent":["// @ts-nocheck\n// TODO: Fix this file but write tests first\n\nimport _ from 'lodash'\nimport inflection from 'lodash-inflection/lib/lodash-inflection'\nimport { keysToCamelCase } from './utils'\n\n_.mixin({ ...inflection })\n\n// Teach some bad grammar\n_.singular(/^(media)$/i, '$1')\n_.plural(/^(media)$/i, '$1')\n\n// eslint-disable-next-line eqeqeq\nconst transformId = id => _.thru(parseInt(id, 10), int => (int == id ? int : id))\n\nconst transformRelationships = relationships => {\n return Object.keys(relationships || {}).reduce((acc, key) => {\n const relationship = relationships[key]\n if (_.isArray(relationship.data)) {\n const ids = _.map(relationship.data, ({ id }) => transformId(id))\n return { ...acc, [`${_.singularize(key)}_ids`]: ids }\n } else {\n const id = _.get(relationship, 'data.id')\n const type = _.get(relationship, 'data.type', null)\n return {\n ...acc,\n [`${key}_id`]: id ? transformId(id) : null,\n [`${key}_type`]: type,\n }\n }\n }, {})\n}\n\nconst addIncludedRecords = (relationships, included, seen, parent) => {\n return Object.keys(relationships || {}).reduce((acc, key) => {\n const relationship = relationships[key]\n if (_.isArray(relationship.data)) {\n const records = _(relationship.data)\n .map(elem => _.find(included, elem))\n .compact() // account for orphans\n .value()\n return _.set(\n acc,\n _.pluralize(key),\n _.map(records, record => transformRecord(record, included, seen))\n )\n } else {\n const [id, type] = _.at(relationship, ['data.id', 'data.type'])\n if (id && type) {\n const record = _.find(included, { id, type })\n return _.set(acc, key, record ? transformRecord(record, included, seen) : null)\n } else {\n return acc\n }\n }\n }, parent)\n}\n\nconst transformRecord = (record, included, seen) => {\n if (!record) return record\n const { id, attributes, links, relationships, type } = record\n\n if (seen.has(record)) {\n return seen.get(record)\n } else {\n const transformed = {\n id: transformId(id),\n type,\n links,\n ...transformRelationships(relationships),\n ..._.mapKeys(\n attributes,\n (v, k) => (k === 'length' ? `${type.charAt(0).toLowerCase()}${type.slice(1)}Length` : k),\n {}\n ),\n }\n\n seen.set(record, transformed)\n\n return addIncludedRecords(relationships, included, seen, transformed)\n }\n}\n\nconst defaultTransformResponse = response => {\n if (_.isEmpty(response)) return response\n const { data, included, meta, links } = response\n const seen = new WeakMap()\n\n if (_.isArray(data)) {\n const result = data.map(d => transformRecord(d, included, seen))\n return { data: result, meta, links, ...data }\n } else {\n return { data: { ...transformRecord(data, included, seen) }, meta, links }\n }\n}\n\nconst transformResponse = _.flowRight(keysToCamelCase, defaultTransformResponse)\n\nexport default transformResponse\n"],"mappings":"AAAA;AACA;;AAEA,OAAOA,CAAC,MAAM,QAAQ;AACtB,OAAOC,UAAU,MAAM,yCAAyC;AAChE,SAASC,eAAe,QAAQ,SAAS;AAEzCF,CAAC,CAACG,KAAK,CAAC;EAAE,GAAGF;AAAW,CAAC,CAA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AC,CAAC;EAE1B,IAAItD,CAAC,CAACmB,OAAO,CAACC,IAAI,CAAC,EAAE;IACnB,MAAMmC,MAAM,GAAGnC,IAAI,CAACE,GAAG,CAACkC,CAAC,IAAIlB,eAAe,CAACkB,CAAC,EAAE7B,QAAQ,EAAEC,IAAI,CAAC,CAAC;IAChE,OAAO;MAAER,IAAI,EAAEmC,MAAM;MAAEF,IAAI;MAAEZ,KAAK;MAAE,GAAGrB;IAAK,CAAC;EAC/C,CAAC,MAAM;IACL,OAAO;MAAEA,IAAI,EAAE;QAAE,GAAGkB,eAAe,CAAClB,IAAI,EAAEO,QAAQ,EAAEC,IAAI;MAAE,CAAC;MAAEyB,IAAI;MAAEZ;IAAM,CAAC;EAC5E;AACF,CAAC;AAED,MAAMgB,iBAAiB,GAAGzD,CAAC,CAAC0D,SAAS,CAACxD,eAAe,EAAEgD,wBAAwB,CAAC;AAEhF,eAAeO,iBAAiB","ignoreList":[]}
1
+ {"version":3,"file":"transform_response.js","names":["_","inflection","keysToCamelCase","mixin","singular","plural","transformId","id","thru","parseInt","int","transformRelationships","relationships","Object","keys","reduce","acc","key","relationship","isArray","data","ids","map","singularize","get","type","addIncludedRecords","record","included","seen","parent","records","elem","find","compact","value","set","pluralize","related","transformRecord","at","isSelfReference","undefined","attributes","links","has","transformed","mapKeys","v","k","charAt","toLowerCase","slice","defaultTransformResponse","response","isEmpty","meta","WeakMap","result","d","transformResponse","flowRight"],"sources":["../../../src/utils/client/transform_response.ts"],"sourcesContent":["// @ts-nocheck\n// TODO: Fix this file but write tests first\n\nimport _ from 'lodash'\nimport inflection from 'lodash-inflection/lib/lodash-inflection'\nimport { keysToCamelCase } from './utils'\n\n_.mixin({ ...inflection })\n\n// Teach some bad grammar\n_.singular(/^(media)$/i, '$1')\n_.plural(/^(media)$/i, '$1')\n\n// eslint-disable-next-line eqeqeq\nconst transformId = id => _.thru(parseInt(id, 10), int => (int == id ? int : id))\n\nconst transformRelationships = relationships => {\n return Object.keys(relationships || {}).reduce((acc, key) => {\n const relationship = relationships[key]\n if (_.isArray(relationship.data)) {\n const ids = _.map(relationship.data, ({ id }) => transformId(id))\n return { ...acc, [`${_.singularize(key)}_ids`]: ids }\n } else {\n const id = _.get(relationship, 'data.id')\n const type = _.get(relationship, 'data.type', null)\n return {\n ...acc,\n [`${key}_id`]: id ? transformId(id) : null,\n [`${key}_type`]: type,\n }\n }\n }, {})\n}\n\nconst addIncludedRecords = (record, included, seen, parent) => {\n const { relationships } = record\n return Object.keys(relationships || {}).reduce((acc, key) => {\n const relationship = relationships[key]\n if (_.isArray(relationship.data)) {\n const records = _(relationship.data)\n .map(elem => _.find(included, elem))\n .compact() // account for orphans\n .value()\n return _.set(\n acc,\n _.pluralize(key),\n _.map(records, related => transformRecord(related, included, seen))\n )\n } else {\n const [id, type] = _.at(relationship, ['data.id', 'data.type'])\n if (id && type) {\n const isSelfReference = id === record.id && type === record.type\n const related = isSelfReference ? undefined : _.find(included, { id, type })\n return _.set(acc, key, related ? transformRecord(related, included, seen) : null)\n } else {\n return acc\n }\n }\n }, parent)\n}\n\nconst transformRecord = (record, included, seen) => {\n if (!record) return record\n const { id, attributes, links, relationships, type } = record\n\n if (seen.has(record)) {\n return seen.get(record)\n } else {\n const transformed = {\n id: transformId(id),\n type,\n links,\n ...transformRelationships(relationships),\n ..._.mapKeys(\n attributes,\n (v, k) => (k === 'length' ? `${type.charAt(0).toLowerCase()}${type.slice(1)}Length` : k),\n {}\n ),\n }\n\n seen.set(record, transformed)\n\n return addIncludedRecords(record, included, seen, transformed)\n }\n}\n\nconst defaultTransformResponse = response => {\n if (_.isEmpty(response)) return response\n const { data, included, meta, links } = response\n const seen = new WeakMap()\n\n if (_.isArray(data)) {\n const result = data.map(d => transformRecord(d, included, seen))\n return { data: result, meta, links, ...data }\n } else {\n return { data: { ...transformRecord(data, included, seen) }, meta, links }\n }\n}\n\nconst transformResponse = _.flowRight(keysToCamelCase, defaultTransformResponse)\n\nexport default transformResponse\n"],"mappings":"AAAA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,OAAOpB,kBAAkB,CAACC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEiB,WAAW,CAAC;EAChE;AACF,CAAC;AAED,MAAMO,wBAAwB,GAAGC,QAAQ,IAAI;EAC3C,IAAItD,CAAC,CAACuD,OAAO,CAACD,QAAQ,CAAC,EAAE,OAAOA,QAAQ;EACxC,MAAM;IAAElC,IAAI;IAAEQ,QAAQ;IAAE4B,IAAI;IAAEZ;EAAM,CAAC,GAAGU,QAAQ;EAChD,MAAMzB,IAAI,GAAG,IAAI4B,OAAO,CAAC,CAAC;EAE1B,IAAIzD,CAAC,CAACmB,OAAO,CAACC,IAAI,CAAC,EAAE;IACnB,MAAMsC,MAAM,GAAGtC,IAAI,CAACE,GAAG,CAACqC,CAAC,IAAIpB,eAAe,CAACoB,CAAC,EAAE/B,QAAQ,EAAEC,IAAI,CAAC,CAAC;IAChE,OAAO;MAAET,IAAI,EAAEsC,MAAM;MAAEF,IAAI;MAAEZ,KAAK;MAAE,GAAGxB;IAAK,CAAC;EAC/C,CAAC,MAAM;IACL,OAAO;MAAEA,IAAI,EAAE;QAAE,GAAGmB,eAAe,CAACnB,IAAI,EAAEQ,QAAQ,EAAEC,IAAI;MAAE,CAAC;MAAE2B,IAAI;MAAEZ;IAAM,CAAC;EAC5E;AACF,CAAC;AAED,MAAMgB,iBAAiB,GAAG5D,CAAC,CAAC6D,SAAS,CAAC3D,eAAe,EAAEmD,wBAAwB,CAAC;AAEhF,eAAeO,iBAAiB","ignoreList":[]}
@@ -8,6 +8,7 @@ export type ReplyShadowMessage = {
8
8
  type: 'ReplyShadowMessage';
9
9
  id: string;
10
10
  messageId: string;
11
+ replyRoot: MessageResource | null;
11
12
  isReplyShadowMessage: boolean;
12
13
  nextRendersAuthor: boolean;
13
14
  };
@@ -1 +1 @@
1
- {"version":3,"file":"group_messages.d.ts","sourceRoot":"","sources":["../../src/utils/group_messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAA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B,EAAE,EAAE,eAAe,EAAE,CAAA;IACrB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,eAAe,EAAE,CAyC1F"}
@@ -6,6 +6,7 @@ export function groupMessages({
6
6
  inReplyScreen
7
7
  }) {
8
8
  const items = [];
9
+ const messagesById = new Map(ms.map(message => [message.id, message]));
9
10
  let myLatestSeen = false;
10
11
  let nextNeighborEnriched;
11
12
  ms.forEach((message, i) => {
@@ -22,7 +23,10 @@ export function groupMessages({
22
23
  }
23
24
  const isMyLatest = !myLatestSeen && message.mine;
24
25
  if (isMyLatest) myLatestSeen = true;
25
- const enriched = enrichRegularMessage(message, prev, next, isMyLatest, !!inReplyScreen);
26
+ const enriched = enrichRegularMessage({
27
+ ...message,
28
+ replyRoot: resolveReplyRoot(message, messagesById)
29
+ }, prev, next, isMyLatest, !!inReplyScreen);
26
30
  items.push(enriched);
27
31
  const shadow = replyShadowFor(enriched, prev);
28
32
  if (shadow) items.push(shadow);
@@ -39,6 +43,10 @@ function neighborsOf(arr, i) {
39
43
  next: arr[i - 1]
40
44
  };
41
45
  }
46
+ function resolveReplyRoot(message, messagesById) {
47
+ if (!message.replyRootId || message.replyRootId === message.id) return null;
48
+ return messagesById.get(message.replyRootId) ?? message.replyRoot ?? null;
49
+ }
42
50
  function enrichSystemMessage(message, next) {
43
51
  return {
44
52
  ...message,
@@ -114,6 +122,7 @@ function replyShadowFor(message, prev) {
114
122
  type: 'ReplyShadowMessage',
115
123
  id: `${message.id}-${message.replyRootId}`,
116
124
  messageId: message.replyRootId,
125
+ replyRoot: message.replyRoot ?? null,
117
126
  isReplyShadowMessage: true,
118
127
  nextRendersAuthor: message.renderAuthor ?? false
119
128
  };
@@ -1 +1 @@
1
- {"version":3,"file":"group_messages.js","names":["dayjs","isSystemMessage","FIVE_MINUTES_MS","groupMessages","ms","inReplyScreen","items","myLatestSeen","nextNeighborEnriched","forEach","message","i","prev","neighborsOf","next","enriched","enrichSystemMessage","push","datesDifferBetween","dateSeparator","isMyLatest","mine","enrichRegularMessage","shadow","replyShadowFor","arr","myLatestInConversation","lastInGroup","renderAuthor","nextRendersAuthor","isReplyShadowMessage","nextIsReplyShadowMessage","threadPosition","inThread","replyRootId","showThreadDetails","startsNewGroup","nextIntroducesReplyShadow","threadPositionFor","prevIsMyReply","undefined","nextIsMyReply","a","b","author","id","differsByMoreThan5Min","Math","abs","toMillis","createdAt","iso","Date","getTime","dateKey","format","type","date","isThreadRoot","isLast","current","nextInThread","nextIsThreadRoot","differentThread","enteringNewThread","messageId"],"sources":["../../src/utils/group_messages.ts"],"sourcesContent":["import type { MessageResource } from '../types/resources/message'\nimport dayjs from './dayjs'\nimport { isSystemMessage } from './system_messages'\n\nconst FIVE_MINUTES_MS = 5 * 60 * 1000\n\nexport type DateSeparator = { type: 'DateSeparator'; id: string; date: string }\n\nexport type ReplyShadowMessage = {\n type: 'ReplyShadowMessage'\n id: string\n messageId: string\n isReplyShadowMessage: boolean\n nextRendersAuthor: boolean\n}\n\nexport type EnrichedMessage = MessageResource | DateSeparator | ReplyShadowMessage\n\ninterface GroupMessagesProps {\n ms: MessageResource[]\n inReplyScreen?: boolean\n}\n\nexport function groupMessages({ ms, inReplyScreen }: GroupMessagesProps): EnrichedMessage[] {\n const items: EnrichedMessage[] = []\n let myLatestSeen = false\n let nextNeighborEnriched: MessageResource | undefined\n\n ms.forEach((message, i) => {\n const { prev } = neighborsOf(ms, i)\n const next = nextNeighborEnriched\n\n if (isSystemMessage(message)) {\n const enriched = enrichSystemMessage(message, next)\n items.push(enriched)\n if (datesDifferBetween(message, prev)) items.push(dateSeparator(message))\n nextNeighborEnriched = enriched\n return\n }\n\n const isMyLatest = !myLatestSeen && message.mine\n if (isMyLatest) myLatestSeen = true\n\n const enriched = enrichRegularMessage(message, prev, next, isMyLatest, !!inReplyScreen)\n items.push(enriched)\n\n const shadow = replyShadowFor(enriched, prev)\n if (shadow) items.push(shadow)\n\n if (!prev || datesDifferBetween(message, prev)) {\n items.push(dateSeparator(message))\n }\n\n nextNeighborEnriched = enriched\n })\n\n return items\n}\n\nfunction neighborsOf<T>(arr: T[], i: number): { prev: T | undefined; next: T | undefined } {\n return { prev: arr[i + 1], next: arr[i - 1] }\n}\n\nfunction enrichSystemMessage(\n message: MessageResource,\n next: MessageResource | undefined\n): MessageResource {\n return {\n ...message,\n myLatestInConversation: false,\n lastInGroup: true,\n renderAuthor: false,\n nextRendersAuthor: next?.renderAuthor,\n isReplyShadowMessage: false,\n nextIsReplyShadowMessage: false,\n threadPosition: null,\n }\n}\n\nfunction enrichRegularMessage(\n message: MessageResource,\n prev: MessageResource | undefined,\n next: MessageResource | undefined,\n isMyLatest: boolean,\n inReplyScreen: boolean\n): MessageResource {\n const inThread = message.replyRootId !== null\n const showThreadDetails = !inReplyScreen && inThread\n\n return {\n ...message,\n myLatestInConversation: isMyLatest,\n lastInGroup: !next || startsNewGroup(next, message),\n renderAuthor: !message.mine && (!prev || startsNewGroup(message, prev)),\n nextRendersAuthor: next?.renderAuthor,\n isReplyShadowMessage: false,\n nextIsReplyShadowMessage: nextIntroducesReplyShadow(next, message),\n threadPosition: showThreadDetails ? threadPositionFor(message, next) : null,\n prevIsMyReply: showThreadDetails ? prev?.mine : undefined,\n nextIsMyReply: showThreadDetails ? next?.mine : undefined,\n }\n}\n\nfunction startsNewGroup(a: MessageResource, b: MessageResource): boolean {\n return (\n a.author?.id !== b.author?.id ||\n differsByMoreThan5Min(a, b) ||\n a.replyRootId !== b.replyRootId ||\n datesDifferBetween(a, b)\n )\n}\n\nfunction differsByMoreThan5Min(a: MessageResource, b: MessageResource): boolean {\n return Math.abs(toMillis(a.createdAt) - toMillis(b.createdAt)) > FIVE_MINUTES_MS\n}\n\nfunction toMillis(iso: string): number {\n return new Date(iso).getTime()\n}\n\nfunction datesDifferBetween(a: MessageResource, b: MessageResource | undefined): boolean {\n if (!b) return false\n return dateKey(a) !== dateKey(b)\n}\n\nfunction dateKey(message: MessageResource): string {\n return dayjs(message.createdAt).format('YYYY-MM-DD')\n}\n\nfunction dateSeparator(message: MessageResource): DateSeparator {\n return { type: 'DateSeparator', id: `day-divider-${message.id}`, date: dateKey(message) }\n}\n\nfunction threadPositionFor(\n message: MessageResource,\n next: MessageResource | undefined\n): 'first' | 'center' | 'last' | null {\n const isThreadRoot = message.replyRootId === message.id\n const isLast =\n !next || next.replyRootId !== message.replyRootId || datesDifferBetween(next, message)\n\n if (isThreadRoot && isLast) return null\n if (isThreadRoot) return 'first'\n if (isLast) return 'last'\n return 'center'\n}\n\nfunction nextIntroducesReplyShadow(\n next: MessageResource | undefined,\n current: MessageResource\n): boolean {\n if (!next) return false\n const nextInThread = next.replyRootId !== null\n const nextIsThreadRoot = next.replyRootId === next.id\n const differentThread = next.replyRootId !== current.replyRootId\n return nextInThread && !nextIsThreadRoot && (differentThread || datesDifferBetween(next, current))\n}\n\nfunction replyShadowFor(\n message: MessageResource,\n prev: MessageResource | undefined\n): ReplyShadowMessage | undefined {\n if (!message.replyRootId) return undefined\n if (message.replyRootId === message.id) return undefined\n\n const enteringNewThread =\n !prev || prev.replyRootId !== message.replyRootId || datesDifferBetween(prev, message)\n if (!enteringNewThread) return undefined\n\n return {\n type: 'ReplyShadowMessage',\n id: `${message.id}-${message.replyRootId}`,\n messageId: message.replyRootId,\n isReplyShadowMessage: true,\n nextRendersAuthor: message.renderAuthor ?? false,\n }\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,SAAS;AAC3B,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,MAAMC,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI;AAmBrC,OAAO,SAASC,aAAaA,CAAC;EAAEC,EAAE;EAAEC;AAAkC,CAAC,EAAqB;EAC1F,MAAMC,KAAwB,GAAG,EAAE;EACnC,IAAIC,YAAY,GAAG,KAAK;EACxB,IAAIC,oBAAiD;EAErDJ,EAAE,CAACK,OA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AC1C+B,SAAS,EAAEvD,OAAO,CAACwB,WAAW;IAC9BJ,oBAAoB,EAAE,IAAI;IAC1BD,iBAAiB,EAAEnB,OAAO,CAACkB,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"group_messages.js","names":["dayjs","isSystemMessage","FIVE_MINUTES_MS","groupMessages","ms","inReplyScreen","items","messagesById","Map","map","message","id","myLatestSeen","nextNeighborEnriched","forEach","i","prev","neighborsOf","next","enriched","enrichSystemMessage","push","datesDifferBetween","dateSeparator","isMyLatest","mine","enrichRegularMessage","replyRoot","resolveReplyRoot","shadow","replyShadowFor","arr","replyRootId","get","myLatestInConversation","lastInGroup","renderAuthor","nextRendersAuthor","isReplyShadowMessage","nextIsReplyShadowMessage","threadPosition","inThread","showThreadDetails","startsNewGroup","nextIntroducesReplyShadow","threadPositionFor","prevIsMyReply","undefined","nextIsMyReply","a","b","author","differsByMoreThan5Min","Math","abs","toMillis","createdAt","iso","Date","getTime","dateKey","format","type","date","isThreadRoot","isLast","current","nextInThread","nextIsThreadRoot","differentThread","enteringNewThread","messageId"],"sources":["../../src/utils/group_messages.ts"],"sourcesContent":["import type { MessageResource } from '../types/resources/message'\nimport dayjs from './dayjs'\nimport { isSystemMessage } from './system_messages'\n\nconst FIVE_MINUTES_MS = 5 * 60 * 1000\n\nexport type DateSeparator = { type: 'DateSeparator'; id: string; date: string }\n\nexport type ReplyShadowMessage = {\n type: 'ReplyShadowMessage'\n id: string\n messageId: string\n replyRoot: MessageResource | null\n isReplyShadowMessage: boolean\n nextRendersAuthor: boolean\n}\n\nexport type EnrichedMessage = MessageResource | DateSeparator | ReplyShadowMessage\n\ninterface GroupMessagesProps {\n ms: MessageResource[]\n inReplyScreen?: boolean\n}\n\nexport function groupMessages({ ms, inReplyScreen }: GroupMessagesProps): EnrichedMessage[] {\n const items: EnrichedMessage[] = []\n const messagesById = new Map(ms.map(message => [message.id, message]))\n let myLatestSeen = false\n let nextNeighborEnriched: MessageResource | undefined\n\n ms.forEach((message, i) => {\n const { prev } = neighborsOf(ms, i)\n const next = nextNeighborEnriched\n\n if (isSystemMessage(message)) {\n const enriched = enrichSystemMessage(message, next)\n items.push(enriched)\n if (datesDifferBetween(message, prev)) items.push(dateSeparator(message))\n nextNeighborEnriched = enriched\n return\n }\n\n const isMyLatest = !myLatestSeen && message.mine\n if (isMyLatest) myLatestSeen = true\n\n const enriched = enrichRegularMessage(\n { ...message, replyRoot: resolveReplyRoot(message, messagesById) },\n prev,\n next,\n isMyLatest,\n !!inReplyScreen\n )\n items.push(enriched)\n\n const shadow = replyShadowFor(enriched, prev)\n if (shadow) items.push(shadow)\n\n if (!prev || datesDifferBetween(message, prev)) {\n items.push(dateSeparator(message))\n }\n\n nextNeighborEnriched = enriched\n })\n\n return items\n}\n\nfunction neighborsOf<T>(arr: T[], i: number): { prev: T | undefined; next: T | undefined } {\n return { prev: arr[i + 1], next: arr[i - 1] }\n}\n\nfunction resolveReplyRoot(\n message: MessageResource,\n messagesById: Map<string, MessageResource>\n): MessageResource | null {\n if (!message.replyRootId || message.replyRootId === message.id) return null\n return messagesById.get(message.replyRootId) ?? message.replyRoot ?? null\n}\n\nfunction enrichSystemMessage(\n message: MessageResource,\n next: MessageResource | undefined\n): MessageResource {\n return {\n ...message,\n myLatestInConversation: false,\n lastInGroup: true,\n renderAuthor: false,\n nextRendersAuthor: next?.renderAuthor,\n isReplyShadowMessage: false,\n nextIsReplyShadowMessage: false,\n threadPosition: null,\n }\n}\n\nfunction enrichRegularMessage(\n message: MessageResource,\n prev: MessageResource | undefined,\n next: MessageResource | undefined,\n isMyLatest: boolean,\n inReplyScreen: boolean\n): MessageResource {\n const inThread = message.replyRootId !== null\n const showThreadDetails = !inReplyScreen && inThread\n\n return {\n ...message,\n myLatestInConversation: isMyLatest,\n lastInGroup: !next || startsNewGroup(next, message),\n renderAuthor: !message.mine && (!prev || startsNewGroup(message, prev)),\n nextRendersAuthor: next?.renderAuthor,\n isReplyShadowMessage: false,\n nextIsReplyShadowMessage: nextIntroducesReplyShadow(next, message),\n threadPosition: showThreadDetails ? threadPositionFor(message, next) : null,\n prevIsMyReply: showThreadDetails ? prev?.mine : undefined,\n nextIsMyReply: showThreadDetails ? next?.mine : undefined,\n }\n}\n\nfunction startsNewGroup(a: MessageResource, b: MessageResource): boolean {\n return (\n a.author?.id !== b.author?.id ||\n differsByMoreThan5Min(a, b) ||\n a.replyRootId !== b.replyRootId ||\n datesDifferBetween(a, b)\n )\n}\n\nfunction differsByMoreThan5Min(a: MessageResource, b: MessageResource): boolean {\n return Math.abs(toMillis(a.createdAt) - toMillis(b.createdAt)) > FIVE_MINUTES_MS\n}\n\nfunction toMillis(iso: string): number {\n return new Date(iso).getTime()\n}\n\nfunction datesDifferBetween(a: MessageResource, b: MessageResource | undefined): boolean {\n if (!b) return false\n return dateKey(a) !== dateKey(b)\n}\n\nfunction dateKey(message: MessageResource): string {\n return dayjs(message.createdAt).format('YYYY-MM-DD')\n}\n\nfunction dateSeparator(message: MessageResource): DateSeparator {\n return { type: 'DateSeparator', id: `day-divider-${message.id}`, date: dateKey(message) }\n}\n\nfunction threadPositionFor(\n message: MessageResource,\n next: MessageResource | undefined\n): 'first' | 'center' | 'last' | null {\n const isThreadRoot = message.replyRootId === message.id\n const isLast =\n !next || next.replyRootId !== message.replyRootId || datesDifferBetween(next, message)\n\n if (isThreadRoot && isLast) return null\n if (isThreadRoot) return 'first'\n if (isLast) return 'last'\n return 'center'\n}\n\nfunction nextIntroducesReplyShadow(\n next: MessageResource | undefined,\n current: MessageResource\n): boolean {\n if (!next) return false\n const nextInThread = next.replyRootId !== null\n const nextIsThreadRoot = next.replyRootId === next.id\n const differentThread = next.replyRootId !== current.replyRootId\n return nextInThread && !nextIsThreadRoot && (differentThread || datesDifferBetween(next, current))\n}\n\nfunction replyShadowFor(\n message: MessageResource,\n prev: MessageResource | undefined\n): ReplyShadowMessage | undefined {\n if (!message.replyRootId) return undefined\n if (message.replyRootId === message.id) return undefined\n\n const enteringNewThread =\n !prev || prev.replyRootId !== message.replyRootId || datesDifferBetween(prev, message)\n if (!enteringNewThread) return undefined\n\n return {\n type: 'ReplyShadowMessage',\n id: `${message.id}-${message.replyRootId}`,\n messageId: message.replyRootId,\n replyRoot: message.replyRoot ?? null,\n isReplyShadowMessage: true,\n nextRendersAuthor: message.renderAuthor ?? false,\n }\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,SAAS;AAC3B,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,MAAMC,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI;AAoBrC,OAAO,SAASC,aAAaA,CAAC;EAAEC,EAAE;EAAEC;AAAkC,CAAC,EAAqB;EAC1F,MAAMC,KAAwB,GAAG,EAAE;EACnC,MAAMC,YAAY,GAAG,IAAIC,GAAG,CAACJ,EAAE,CAACK,GAAG,CAACC,OAAO,IAAI,CAACA,OAAO,CAACC,EAAE,EAAED,OAAO,CAAC,CAAC,CAAC;EACtE,IAAIE,YAAY,GAAG,KAAK;EACxB,IAAIC,oBAAiD;EAErDT,EAAE,CAACU,OAAO,CAAC,CAACJ,OAAO,EAAEK,CAAC,KAAK;IACzB,MAAM;MAAEC;IAAK,CAAC,GAAGC,WAAW,CAACb,EAAE,EAAEW,CAAC,CAAC;IACnC,MAAMG,IAAI,GAAGL,oBAAoB;IAEjC,IAAIZ,eAAe,CAACS,OAAO,CAAC,EAAE;MAC5B,MAAMS,QAAQ,GAAGC,mBAAmB,CAACV,OAAO,EAAEQ,IAAI,CAAC;MACnDZ,KAAK,CAACe,IAAI,CAACF,QAAQ,CAAC;MACpB,IAAIG,kBAAkB,CAACZ,OAAO,EAAEM,IAAI,CAAC,EAAEV,KAAK,CAACe,IAAI,CAACE,aAAa,CAACb,OAAO,CAAC,CAAC;MACzEG,oBAAoB,GAAGM,QAAQ;MAC/B;IACF;IAEA,MAAMK,UAAU,GAAG,CAACZ,YAAY,IAAIF,OAAO,CAACe,IAAI;IAChD,IAAID,UA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ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"messages_data_options.d.ts","sourceRoot":"","sources":["../../../src/utils/request/messages_data_options.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;CAmB5B,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAgC,CAAA"}
1
+ {"version":3,"file":"messages_data_options.d.ts","sourceRoot":"","sources":["../../../src/utils/request/messages_data_options.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;CAmB5B,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAmE,CAAA"}
@@ -3,5 +3,5 @@ export const getMessageFields = {
3
3
  Person: ['name', 'avatar'],
4
4
  ReactionCount: ['value', 'count', 'mine', 'message_id', 'author_ids']
5
5
  };
6
- export const getMessagesInclude = ['author', 'reaction_counts'];
6
+ export const getMessagesInclude = ['author', 'reaction_counts', 'reply_root', 'reply_root.author'];
7
7
  //# sourceMappingURL=messages_data_options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages_data_options.js","names":["getMessageFields","Message","Person","ReactionCount","getMessagesInclude"],"sources":["../../../src/utils/request/messages_data_options.ts"],"sourcesContent":["export const getMessageFields = {\n Message: [\n 'text',\n 'text_edited_at',\n 'mine',\n 'attachments',\n 'created_at',\n 'deleted_at',\n 'author',\n 'reaction_counts',\n 'reply_count',\n 'reply_root',\n 'idempotent_key',\n 'message_type',\n 'person_ids_for_system_event',\n 'system_text_parts',\n ],\n Person: ['name', 'avatar'],\n ReactionCount: ['value', 'count', 'mine', 'message_id', 'author_ids'],\n}\n\nexport const getMessagesInclude = ['author', 'reaction_counts']\n"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,GAAG;EAC9BC,OAAO,EAAE,CACP,MAAM,EACN,gBAAgB,EAChB,MAAM,EACN,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,CACpB;EACDC,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;EAC1BC,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;AACtE,CAAC;AAED,OAAO,MAAMC,kBAAkB,GAAG,CAAC,QAAQ,EAAE,iBAAiB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"messages_data_options.js","names":["getMessageFields","Message","Person","ReactionCount","getMessagesInclude"],"sources":["../../../src/utils/request/messages_data_options.ts"],"sourcesContent":["export const getMessageFields = {\n Message: [\n 'text',\n 'text_edited_at',\n 'mine',\n 'attachments',\n 'created_at',\n 'deleted_at',\n 'author',\n 'reaction_counts',\n 'reply_count',\n 'reply_root',\n 'idempotent_key',\n 'message_type',\n 'person_ids_for_system_event',\n 'system_text_parts',\n ],\n Person: ['name', 'avatar'],\n ReactionCount: ['value', 'count', 'mine', 'message_id', 'author_ids'],\n}\n\nexport const getMessagesInclude = ['author', 'reaction_counts', 'reply_root', 'reply_root.author']\n"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,GAAG;EAC9BC,OAAO,EAAE,CACP,MAAM,EACN,gBAAgB,EAChB,MAAM,EACN,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,CACpB;EACDC,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;EAC1BC,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;AACtE,CAAC;AAED,OAAO,MAAMC,kBAAkB,GAAG,CAAC,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/chat-react-native",
3
- "version": "3.45.1-qa-staging.6",
3
+ "version": "3.45.1-qa-staging.7",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@fortawesome/fontawesome-svg-core": "^7.2.0",
35
35
  "@fortawesome/react-native-fontawesome": "^0.3.2",
36
- "@planningcenter/emoji-keyboard": "3.45.1-qa-staging.6",
36
+ "@planningcenter/emoji-keyboard": "3.45.1-qa-staging.7",
37
37
  "lodash-inflection": "^1.5.0"
38
38
  },
39
39
  "peerDependencies": {
@@ -84,5 +84,5 @@
84
84
  "sf-symbols-typescript": "^2.2.0",
85
85
  "typescript": "~6.0.3"
86
86
  },
87
- "gitHead": "98bb0da85de3b8f82c469f0cc7cfce6e11ea52ef"
87
+ "gitHead": "edb40832f89d7a62f0193d0699e68c817a9bb222"
88
88
  }
@@ -0,0 +1,119 @@
1
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2
+ import { render } from '@testing-library/react-native'
3
+ import React from 'react'
4
+ import { buildTestQueryClient } from '../../../__utils__/query_client'
5
+ import { ChatProvider } from '../../../contexts/chat_context'
6
+ import { useConversationMessage } from '../../../hooks/use_conversation_message'
7
+ import type { MessageResource } from '../../../types/resources/message'
8
+ import type { PersonResource } from '../../../types/resources/person'
9
+ import { ReplyShadowMessage } from '../reply_shadow_message'
10
+
11
+ jest.mock('../../../hooks/use_conversation_message')
12
+ jest.mock('@react-navigation/native', () => ({
13
+ useNavigation: () => ({ navigate: jest.fn() }),
14
+ }))
15
+
16
+ const mockedUseConversationMessage = useConversationMessage as jest.MockedFunction<
17
+ typeof useConversationMessage
18
+ >
19
+
20
+ const author = { id: 1, type: 'Person', name: 'A', avatar: null } as unknown as PersonResource
21
+
22
+ const root = (text: string): MessageResource =>
23
+ ({
24
+ type: 'Message',
25
+ id: 'rootA',
26
+ text,
27
+ html: '',
28
+ createdAt: '2026-01-01T00:00:00Z',
29
+ deletedAt: null,
30
+ textEditedAt: null,
31
+ mine: false,
32
+ attachments: [],
33
+ author,
34
+ reactionCounts: [],
35
+ replyCount: 1,
36
+ replyRootId: 'rootA',
37
+ messageType: 'message',
38
+ }) as MessageResource
39
+
40
+ let queryClient: QueryClient
41
+
42
+ const hookResult = (overrides: { message?: MessageResource; isError?: boolean }) =>
43
+ ({ message: undefined, isError: false, isLoading: false, ...overrides }) as ReturnType<
44
+ typeof useConversationMessage
45
+ >
46
+
47
+ const Wrapper = ({ children }: { children: React.ReactNode }) => (
48
+ <QueryClientProvider client={queryClient}>
49
+ <ChatProvider
50
+ value={{
51
+ token: {
52
+ access_token: '',
53
+ created_at: 0,
54
+ expires_in: 0,
55
+ scope: '',
56
+ refresh_token: '',
57
+ token_type: '',
58
+ },
59
+ onUnauthorizedResponse: () => {},
60
+ theme: { theme: { colors: { interaction: 'rgb(0, 0, 255)' } } },
61
+ }}
62
+ >
63
+ {children}
64
+ </ChatProvider>
65
+ </QueryClientProvider>
66
+ )
67
+
68
+ const renderShadow = (replyRoot: MessageResource | null) =>
69
+ render(
70
+ <ReplyShadowMessage
71
+ {...({} as MessageResource)}
72
+ conversation_id={1}
73
+ messageId="rootA"
74
+ replyRoot={replyRoot}
75
+ isReplyShadowMessage
76
+ nextRendersAuthor={false}
77
+ />,
78
+ { wrapper: Wrapper }
79
+ )
80
+
81
+ beforeEach(() => {
82
+ queryClient = buildTestQueryClient()
83
+ mockedUseConversationMessage.mockReturnValue(hookResult({}))
84
+ })
85
+
86
+ afterEach(() => {
87
+ queryClient.clear()
88
+ jest.clearAllMocks()
89
+ })
90
+
91
+ describe('ReplyShadowMessage', () => {
92
+ it('renders the inline root without enabling the root fetch', () => {
93
+ const view = renderShadow(root('inline root'))
94
+
95
+ expect(view.getByText('inline root')).toBeTruthy()
96
+ expect(mockedUseConversationMessage).toHaveBeenCalledWith(
97
+ expect.objectContaining({ enabled: false })
98
+ )
99
+ })
100
+
101
+ it('falls back to fetching the root when none is inline', () => {
102
+ mockedUseConversationMessage.mockReturnValue(hookResult({ message: root('fetched root') }))
103
+
104
+ const view = renderShadow(null)
105
+
106
+ expect(view.getByText('fetched root')).toBeTruthy()
107
+ expect(mockedUseConversationMessage).toHaveBeenCalledWith(
108
+ expect.objectContaining({ messageId: 'rootA', enabled: true })
109
+ )
110
+ })
111
+
112
+ it('shows the deleted placeholder when the fallback fetch finds nothing', () => {
113
+ mockedUseConversationMessage.mockReturnValue(hookResult({ isError: true }))
114
+
115
+ const view = renderShadow(null)
116
+
117
+ expect(view.getByText('Message deleted')).toBeTruthy()
118
+ })
119
+ })
@@ -73,11 +73,15 @@ export function Message({
73
73
  const [messageBubbleHeight, setMessageBubbleHeight] = React.useState(0)
74
74
  const { animatedBackgroundColor, handleMessagePressIn, handleMessagePressOut } =
75
75
  useAnimatedMessageBackgroundColor()
76
- const { message: replyRootMessage } = useConversationMessage({
76
+ const isReplyRootMessage = message.replyRootId === message.id
77
+ const isDeletedReplyRootMessage = isReplyRootMessage && !!message.deletedAt
78
+ const replyToReplyRootMessage = !isReplyRootMessage && !!message.replyRootId
79
+ const { message: fetchedReplyRoot } = useConversationMessage({
77
80
  conversation_id,
78
81
  messageId: message.replyRootId || '',
79
- enabled: !!message.replyRootId,
82
+ enabled: replyToReplyRootMessage && !message.replyRoot,
80
83
  })
84
+ const replyRoot = message.replyRoot ?? fetchedReplyRoot
81
85
 
82
86
  const metaProps = {
83
87
  authorName: author.name,
@@ -85,14 +89,11 @@ export function Message({
85
89
  }
86
90
 
87
91
  const renderAuthor = (!message.mine && message.renderAuthor) || false
88
- const showReplyCountButton = !inReplyScreen && message.replyRootId === message.id
89
- const isReplyRootMessage = message.replyRootId === message.id
90
- const isDeletedReplyRootMessage = isReplyRootMessage && !!message.deletedAt
91
- const replyToReplyRootMessage = !isReplyRootMessage && !!message.replyRootId
92
+ const showReplyCountButton = !inReplyScreen && isReplyRootMessage
92
93
 
93
94
  const replyCountText = pluralize(message.replyCount, 'reply')
94
95
  const messagePendingLabel = isPersisted ? 'Saving' : 'Sending'
95
- const replyRootAuthorName = message.replyRootId ? replyRootMessage?.author.name : author.name
96
+ const replyRootAuthorName = replyToReplyRootMessage ? replyRoot?.author.name : author.name
96
97
  const messageText = isDeletedReplyRootMessage ? 'Message deleted' : text
97
98
 
98
99
  const messageBottomMargin =