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

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
@@ -41,14 +41,16 @@ export function ReplyShadowMessage({
41
41
  conversation_id,
42
42
  inReplyScreen,
43
43
  messageId,
44
+ replyRoot,
44
45
  isReplyShadowMessage,
45
46
  nextRendersAuthor,
46
47
  }: ReplyShadowMessageProps) {
47
- const { message, isError, isLoading } = useConversationMessage({ conversation_id, messageId })
48
+ const fetched = useConversationMessage({ conversation_id, messageId, enabled: !replyRoot })
49
+ const message = replyRoot ?? fetched.message
48
50
 
49
51
  if (inReplyScreen) return null
50
- if (isLoading) return <ShadowMessageFallback text="Loading..." />
51
- if (isError || !message) return <ShadowMessageFallback text="Message deleted" />
52
+ if (!message && fetched.isLoading) return <ShadowMessageFallback text="Loading..." />
53
+ if (!message) return <ShadowMessageFallback text="Message deleted" />
52
54
 
53
55
  const enrichedMessage = {
54
56
  ...message,
@@ -82,7 +84,7 @@ function ShadowMessageContent({ conversation_id, ...message }: ShadowMessageCont
82
84
  const handleNavigateToReplies = () => {
83
85
  navigation.navigate('ConversationReply', {
84
86
  conversation_id,
85
- reply_root_id: message.replyRootId,
87
+ reply_root_id: message.replyRootId ?? message.id,
86
88
  reply_root_author_name: message.author.name,
87
89
  })
88
90
  }
@@ -11,6 +11,7 @@ import {
11
11
  updateCacheWithMessage,
12
12
  updateCacheWithIndividualMessage,
13
13
  updateCacheWithReaction,
14
+ updateCacheReplyRoots,
14
15
  getThreadedMessagesQueryKey,
15
16
  } from '../utils/cache/messages_cache'
16
17
  import { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'
@@ -44,6 +45,7 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
44
45
  data,
45
46
  currentPersonId: currentPerson.id,
46
47
  })
48
+ const isReplyRootUpdate = e.event === 'message.updated' && data.reply_root_id === data.sort_key
47
49
 
48
50
  if (e.event === 'message.created' && data.author_id) {
49
51
  removeAllTypingEventsByAuthorId(data.author_id)
@@ -62,6 +64,11 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
62
64
  data.reply_root_id
63
65
  )
64
66
  updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)
67
+
68
+ if (isReplyRootUpdate) {
69
+ updateCacheReplyRoots(queryClient, messagesQueryKey, message)
70
+ updateCacheReplyRoots(queryClient, threadedMessagesQueryKey, message)
71
+ }
65
72
  }
66
73
 
67
74
  // Update individual message query cache so reply shadow messages update immediately
@@ -17,6 +17,7 @@ export interface MessageResource {
17
17
  reactionCounts: ReactionCountResource[]
18
18
  replyCount: number
19
19
  replyRootId?: string | null
20
+ replyRoot?: MessageResource | null
20
21
  idempotentKey?: string | null
21
22
  messageType: string
22
23
  personIdsForSystemEvent?: number[] | null
@@ -124,6 +124,54 @@ describe('groupMessages — nextRendersAuthor mirrors the newer enriched neighbo
124
124
  })
125
125
  })
126
126
 
127
+ describe('groupMessages — reply roots', () => {
128
+ const findShadow = (items: ReturnType<typeof groupMessages>, id: string) =>
129
+ items.find(item => 'type' in item && item.type === 'ReplyShadowMessage' && item.id === id)
130
+
131
+ it('carries the root from the page onto the reply and its shadow', () => {
132
+ const messages = [
133
+ message('03', { replyRootId: 'rootA' }),
134
+ message('02'),
135
+ message('rootA', { replyRootId: 'rootA', text: 'fresh' }),
136
+ ]
137
+
138
+ const enriched = groupMessages({ ms: messages })
139
+
140
+ expect((findEnriched(enriched, '03') as MessageResource).replyRoot?.text).toBe('fresh')
141
+ expect(findShadow(enriched, '03-rootA')).toMatchObject({ replyRoot: { id: 'rootA' } })
142
+ })
143
+
144
+ it('prefers the page copy of the root over the reply’s included snapshot', () => {
145
+ const snapshot = message('rootA', { replyRootId: 'rootA', text: 'stale' })
146
+ const messages = [
147
+ message('03', { replyRootId: 'rootA', replyRoot: snapshot }),
148
+ message('02'),
149
+ message('rootA', { replyRootId: 'rootA', text: 'fresh' }),
150
+ ]
151
+
152
+ const enriched = groupMessages({ ms: messages })
153
+
154
+ expect(findShadow(enriched, '03-rootA')).toMatchObject({ replyRoot: { text: 'fresh' } })
155
+ })
156
+
157
+ it('falls back to the included snapshot when the root is not on the page', () => {
158
+ const snapshot = message('rootA', { replyRootId: 'rootA', text: 'included' })
159
+ const messages = [message('02', { replyRootId: 'rootA', replyRoot: snapshot })]
160
+
161
+ const enriched = groupMessages({ ms: messages })
162
+
163
+ expect(findShadow(enriched, '02-rootA')).toMatchObject({ replyRoot: { text: 'included' } })
164
+ })
165
+
166
+ it('leaves replyRoot null when the root is neither on the page nor included', () => {
167
+ const messages = [message('02', { replyRootId: 'rootA' })]
168
+
169
+ const enriched = groupMessages({ ms: messages })
170
+
171
+ expect(findShadow(enriched, '02-rootA')).toMatchObject({ replyRoot: null })
172
+ })
173
+ })
174
+
127
175
  describe('groupMessages — system messages', () => {
128
176
  it('flags lastInGroup true and renderAuthor false on system messages', () => {
129
177
  const messages = [
@@ -0,0 +1,71 @@
1
+ import { InfiniteData, QueryClient } from '@tanstack/react-query'
2
+ import type { ApiCollection } from '../../../types'
3
+ import type { MessageResource } from '../../../types/resources/message'
4
+ import type { PersonResource } from '../../../types/resources/person'
5
+ import { updateCacheReplyRoots } from '../messages_cache'
6
+
7
+ const author = { id: 1, type: 'Person', name: 'A', avatar: null } as unknown as PersonResource
8
+
9
+ const message = (id: string, overrides: Partial<MessageResource> = {}): MessageResource =>
10
+ ({
11
+ type: 'Message',
12
+ id,
13
+ text: `msg ${id}`,
14
+ html: '',
15
+ createdAt: '2026-01-01T00:00:00Z',
16
+ deletedAt: null,
17
+ textEditedAt: null,
18
+ mine: false,
19
+ attachments: [],
20
+ author,
21
+ reactionCounts: [],
22
+ replyCount: 0,
23
+ replyRootId: null,
24
+ messageType: 'message',
25
+ ...overrides,
26
+ }) as MessageResource
27
+
28
+ const queryKey = ['messages']
29
+
30
+ const seedPages = (queryClient: QueryClient, messages: MessageResource[]) => {
31
+ queryClient.setQueryData<InfiniteData<ApiCollection<MessageResource>>>(queryKey, {
32
+ pageParams: [{}],
33
+ pages: [{ data: messages, links: {}, meta: { count: messages.length, totalCount: 1 } }],
34
+ })
35
+ }
36
+
37
+ const pageMessages = (queryClient: QueryClient) =>
38
+ queryClient.getQueryData<InfiniteData<ApiCollection<MessageResource>>>(queryKey)!.pages[0].data
39
+
40
+ describe('updateCacheReplyRoots', () => {
41
+ it('merges a root update into every reply carrying that root', () => {
42
+ const queryClient = new QueryClient()
43
+ const root = message('rootA', { replyRootId: 'rootA', text: 'before' })
44
+ seedPages(queryClient, [
45
+ message('03', { replyRootId: 'rootA', replyRoot: root }),
46
+ message('02', { replyRootId: 'rootB', replyRoot: message('rootB', { text: 'other' }) }),
47
+ message('01', { replyRootId: 'rootA', replyRoot: root }),
48
+ ])
49
+
50
+ updateCacheReplyRoots(
51
+ queryClient,
52
+ queryKey,
53
+ message('rootA', { replyRootId: 'rootA', text: 'after', deletedAt: '2026-01-02T00:00:00Z' })
54
+ )
55
+
56
+ const [newest, other, oldest] = pageMessages(queryClient)
57
+ expect(newest.replyRoot).toMatchObject({ text: 'after', deletedAt: '2026-01-02T00:00:00Z' })
58
+ expect(oldest.replyRoot).toMatchObject({ text: 'after' })
59
+ expect(other.replyRoot?.text).toBe('other')
60
+ })
61
+
62
+ it('leaves the cache untouched when no reply carries the root', () => {
63
+ const queryClient = new QueryClient()
64
+ seedPages(queryClient, [message('01', { replyRootId: 'rootB' })])
65
+ const before = pageMessages(queryClient)
66
+
67
+ updateCacheReplyRoots(queryClient, queryKey, message('rootA', { replyRootId: 'rootA' }))
68
+
69
+ expect(pageMessages(queryClient)).toBe(before)
70
+ })
71
+ })
@@ -4,7 +4,11 @@ import { ApiCollection, ApiResource, MessageResource } from '../../types'
4
4
  import { JoltReactionEvent } from '../../types/jolt_events'
5
5
  import { transformReactionEventDataToReactionCountResource } from '../jolt/transform_reaction_event_data_to_reaction_count_resource'
6
6
  import { getMessagesRequestArgs } from '../request/get_messages'
7
- import { updateOrCreateRecordInPagesData, updateRecordInPagesData } from './page_mutations'
7
+ import {
8
+ updateAllRecordsInPagesData,
9
+ updateOrCreateRecordInPagesData,
10
+ updateRecordInPagesData,
11
+ } from './page_mutations'
8
12
  import { deleteRecordInPagesData } from './page_mutations'
9
13
 
10
14
  export function updateCacheWithMessage(
@@ -66,6 +70,22 @@ export function updateCacheWithIndividualMessage(
66
70
  })
67
71
  }
68
72
 
73
+ export function updateCacheReplyRoots(
74
+ queryClient: QueryClient,
75
+ queryKey: unknown[],
76
+ root: MessageResource
77
+ ) {
78
+ queryClient.setQueryData<MessagesQueryData>(queryKey, prev =>
79
+ updateAllRecordsInPagesData({
80
+ data: prev,
81
+ processRecord: message =>
82
+ message.replyRoot?.id === root.id
83
+ ? { ...message, replyRoot: mergeMessageUpdate(root, message.replyRoot) }
84
+ : message,
85
+ })
86
+ )
87
+ }
88
+
69
89
  export function updateCacheWithReaction(
70
90
  queryClient: QueryClient,
71
91
  queryKey: unknown[],
@@ -0,0 +1,62 @@
1
+ import transformResponse from '../transform_response'
2
+
3
+ const person = (id: string, name: string) => ({
4
+ type: 'Person',
5
+ id,
6
+ attributes: { name, avatar: null },
7
+ })
8
+
9
+ const message = (
10
+ id: string,
11
+ { authorId, replyRootId }: { authorId: string; replyRootId: string | null }
12
+ ) => ({
13
+ type: 'Message',
14
+ id,
15
+ attributes: { text: `msg ${id}` },
16
+ relationships: {
17
+ author: { data: { type: 'Person', id: authorId } },
18
+ reply_root: { data: replyRootId ? { type: 'Message', id: replyRootId } : null },
19
+ reaction_counts: { data: [] },
20
+ },
21
+ })
22
+
23
+ const root = message('01ROOT', { authorId: '2', replyRootId: '01ROOT' })
24
+ const reply = message('01REPLY', { authorId: '1', replyRootId: '01ROOT' })
25
+
26
+ describe('transformResponse — reply_root include', () => {
27
+ it('attaches the included root and its author to a reply', () => {
28
+ const result = transformResponse({
29
+ data: [reply],
30
+ included: [root, person('1', 'Replier'), person('2', 'Root Author')],
31
+ })
32
+
33
+ const [transformedReply] = result.data
34
+ expect(transformedReply.replyRootId).toBe('01ROOT')
35
+ expect(transformedReply.replyRoot.id).toBe('01ROOT')
36
+ expect(transformedReply.replyRoot.text).toBe('msg 01ROOT')
37
+ expect(transformedReply.replyRoot.author.name).toBe('Root Author')
38
+ })
39
+
40
+ it('drops a record’s self reference so the result stays acyclic', () => {
41
+ const result = transformResponse({
42
+ data: [reply, root],
43
+ included: [root, person('1', 'Replier'), person('2', 'Root Author')],
44
+ })
45
+
46
+ const [transformedReply, transformedRoot] = result.data
47
+ expect(transformedReply.replyRoot.replyRoot).toBeNull()
48
+ expect(transformedRoot.replyRootId).toBe('01ROOT')
49
+ expect(transformedRoot.replyRoot).toBeNull()
50
+ expect(() => JSON.stringify(result)).not.toThrow()
51
+ })
52
+
53
+ it('leaves replyRoot null when the root is not included', () => {
54
+ const result = transformResponse({
55
+ data: [reply],
56
+ included: [person('1', 'Replier')],
57
+ })
58
+
59
+ expect(result.data[0].replyRootId).toBe('01ROOT')
60
+ expect(result.data[0].replyRoot).toBeNull()
61
+ })
62
+ })
@@ -32,7 +32,8 @@ const transformRelationships = relationships => {
32
32
  }, {})
33
33
  }
34
34
 
35
- const addIncludedRecords = (relationships, included, seen, parent) => {
35
+ const addIncludedRecords = (record, included, seen, parent) => {
36
+ const { relationships } = record
36
37
  return Object.keys(relationships || {}).reduce((acc, key) => {
37
38
  const relationship = relationships[key]
38
39
  if (_.isArray(relationship.data)) {
@@ -43,13 +44,14 @@ const addIncludedRecords = (relationships, included, seen, parent) => {
43
44
  return _.set(
44
45
  acc,
45
46
  _.pluralize(key),
46
- _.map(records, record => transformRecord(record, included, seen))
47
+ _.map(records, related => transformRecord(related, included, seen))
47
48
  )
48
49
  } else {
49
50
  const [id, type] = _.at(relationship, ['data.id', 'data.type'])
50
51
  if (id && type) {
51
- const record = _.find(included, { id, type })
52
- return _.set(acc, key, record ? transformRecord(record, included, seen) : null)
52
+ const isSelfReference = id === record.id && type === record.type
53
+ const related = isSelfReference ? undefined : _.find(included, { id, type })
54
+ return _.set(acc, key, related ? transformRecord(related, included, seen) : null)
53
55
  } else {
54
56
  return acc
55
57
  }
@@ -78,7 +80,7 @@ const transformRecord = (record, included, seen) => {
78
80
 
79
81
  seen.set(record, transformed)
80
82
 
81
- return addIncludedRecords(relationships, included, seen, transformed)
83
+ return addIncludedRecords(record, included, seen, transformed)
82
84
  }
83
85
  }
84
86
 
@@ -10,6 +10,7 @@ export type ReplyShadowMessage = {
10
10
  type: 'ReplyShadowMessage'
11
11
  id: string
12
12
  messageId: string
13
+ replyRoot: MessageResource | null
13
14
  isReplyShadowMessage: boolean
14
15
  nextRendersAuthor: boolean
15
16
  }
@@ -23,6 +24,7 @@ interface GroupMessagesProps {
23
24
 
24
25
  export function groupMessages({ ms, inReplyScreen }: GroupMessagesProps): EnrichedMessage[] {
25
26
  const items: EnrichedMessage[] = []
27
+ const messagesById = new Map(ms.map(message => [message.id, message]))
26
28
  let myLatestSeen = false
27
29
  let nextNeighborEnriched: MessageResource | undefined
28
30
 
@@ -41,7 +43,13 @@ export function groupMessages({ ms, inReplyScreen }: GroupMessagesProps): Enrich
41
43
  const isMyLatest = !myLatestSeen && message.mine
42
44
  if (isMyLatest) myLatestSeen = true
43
45
 
44
- const enriched = enrichRegularMessage(message, prev, next, isMyLatest, !!inReplyScreen)
46
+ const enriched = enrichRegularMessage(
47
+ { ...message, replyRoot: resolveReplyRoot(message, messagesById) },
48
+ prev,
49
+ next,
50
+ isMyLatest,
51
+ !!inReplyScreen
52
+ )
45
53
  items.push(enriched)
46
54
 
47
55
  const shadow = replyShadowFor(enriched, prev)
@@ -61,6 +69,14 @@ function neighborsOf<T>(arr: T[], i: number): { prev: T | undefined; next: T | u
61
69
  return { prev: arr[i + 1], next: arr[i - 1] }
62
70
  }
63
71
 
72
+ function resolveReplyRoot(
73
+ message: MessageResource,
74
+ messagesById: Map<string, MessageResource>
75
+ ): MessageResource | null {
76
+ if (!message.replyRootId || message.replyRootId === message.id) return null
77
+ return messagesById.get(message.replyRootId) ?? message.replyRoot ?? null
78
+ }
79
+
64
80
  function enrichSystemMessage(
65
81
  message: MessageResource,
66
82
  next: MessageResource | undefined
@@ -171,6 +187,7 @@ function replyShadowFor(
171
187
  type: 'ReplyShadowMessage',
172
188
  id: `${message.id}-${message.replyRootId}`,
173
189
  messageId: message.replyRootId,
190
+ replyRoot: message.replyRoot ?? null,
174
191
  isReplyShadowMessage: true,
175
192
  nextRendersAuthor: message.renderAuthor ?? false,
176
193
  }
@@ -19,4 +19,4 @@ export const getMessageFields = {
19
19
  ReactionCount: ['value', 'count', 'mine', 'message_id', 'author_ids'],
20
20
  }
21
21
 
22
- export const getMessagesInclude = ['author', 'reaction_counts']
22
+ export const getMessagesInclude = ['author', 'reaction_counts', 'reply_root', 'reply_root.author']