@planningcenter/chat-react-native 4.0.1-qa-staging.2 → 4.0.1-rc.1

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 (85) hide show
  1. package/build/components/conversation/message.d.ts +2 -3
  2. package/build/components/conversation/message.d.ts.map +1 -1
  3. package/build/components/conversation/message.js +22 -23
  4. package/build/components/conversation/message.js.map +1 -1
  5. package/build/components/conversation/message_read_receipts.d.ts +4 -2
  6. package/build/components/conversation/message_read_receipts.d.ts.map +1 -1
  7. package/build/components/conversation/message_read_receipts.js +3 -2
  8. package/build/components/conversation/message_read_receipts.js.map +1 -1
  9. package/build/components/conversation/reply_shadow_message.d.ts +1 -2
  10. package/build/components/conversation/reply_shadow_message.d.ts.map +1 -1
  11. package/build/components/conversation/reply_shadow_message.js +46 -47
  12. package/build/components/conversation/reply_shadow_message.js.map +1 -1
  13. package/build/hooks/use_conversation_messages.d.ts.map +1 -1
  14. package/build/hooks/use_conversation_messages.js +28 -40
  15. package/build/hooks/use_conversation_messages.js.map +1 -1
  16. package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
  17. package/build/hooks/use_conversation_messages_jolt_events.js +1 -6
  18. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
  19. package/build/hooks/use_message_create_or_update.d.ts +4 -99
  20. package/build/hooks/use_message_create_or_update.d.ts.map +1 -1
  21. package/build/hooks/use_message_create_or_update.js +6 -47
  22. package/build/hooks/use_message_create_or_update.js.map +1 -1
  23. package/build/screens/conversation_new/components/groups_form.js +80 -71
  24. package/build/screens/conversation_new/components/groups_form.js.map +1 -1
  25. package/build/screens/conversation_screen.d.ts.map +1 -1
  26. package/build/screens/conversation_screen.js +365 -184
  27. package/build/screens/conversation_screen.js.map +1 -1
  28. package/build/types/resources/message.d.ts +0 -2
  29. package/build/types/resources/message.d.ts.map +1 -1
  30. package/build/types/resources/message.js.map +1 -1
  31. package/build/utils/cache/messages_cache.d.ts +0 -1
  32. package/build/utils/cache/messages_cache.d.ts.map +1 -1
  33. package/build/utils/cache/messages_cache.js +7 -14
  34. package/build/utils/cache/messages_cache.js.map +1 -1
  35. package/build/utils/cache/optimistically_create_message.d.ts +1 -2
  36. package/build/utils/cache/optimistically_create_message.d.ts.map +1 -1
  37. package/build/utils/cache/optimistically_create_message.js +2 -4
  38. package/build/utils/cache/optimistically_create_message.js.map +1 -1
  39. package/build/utils/client/transform_response.d.ts.map +1 -1
  40. package/build/utils/client/transform_response.js +5 -9
  41. package/build/utils/client/transform_response.js.map +1 -1
  42. package/build/utils/group_messages.d.ts +0 -1
  43. package/build/utils/group_messages.d.ts.map +1 -1
  44. package/build/utils/group_messages.js +1 -10
  45. package/build/utils/group_messages.js.map +1 -1
  46. package/build/utils/jolt/transform_message_event_data_to_message_resource.d.ts.map +1 -1
  47. package/build/utils/jolt/transform_message_event_data_to_message_resource.js +0 -1
  48. package/build/utils/jolt/transform_message_event_data_to_message_resource.js.map +1 -1
  49. package/build/utils/request/messages_data_options.d.ts.map +1 -1
  50. package/build/utils/request/messages_data_options.js +2 -2
  51. package/build/utils/request/messages_data_options.js.map +1 -1
  52. package/package.json +3 -3
  53. package/src/components/conversation/message.tsx +18 -15
  54. package/src/components/conversation/message_read_receipts.tsx +5 -3
  55. package/src/components/conversation/reply_shadow_message.tsx +7 -9
  56. package/src/hooks/use_conversation_messages.ts +1 -5
  57. package/src/hooks/use_conversation_messages_jolt_events.ts +0 -7
  58. package/src/hooks/use_message_create_or_update.ts +16 -29
  59. package/src/screens/conversation_new/components/groups_form.tsx +7 -2
  60. package/src/screens/conversation_screen.tsx +104 -11
  61. package/src/types/resources/message.ts +0 -2
  62. package/src/utils/__tests__/group_messages.test.ts +0 -48
  63. package/src/utils/cache/messages_cache.ts +11 -27
  64. package/src/utils/cache/optimistically_create_message.ts +0 -3
  65. package/src/utils/client/transform_response.ts +5 -7
  66. package/src/utils/group_messages.ts +1 -18
  67. package/src/utils/jolt/transform_message_event_data_to_message_resource.ts +0 -1
  68. package/src/utils/request/messages_data_options.ts +1 -2
  69. package/build/components/conversation/message_list.d.ts +0 -21
  70. package/build/components/conversation/message_list.d.ts.map +0 -1
  71. package/build/components/conversation/message_list.js +0 -273
  72. package/build/components/conversation/message_list.js.map +0 -1
  73. package/build/utils/replace_equal_by_id.d.ts +0 -6
  74. package/build/utils/replace_equal_by_id.d.ts.map +0 -1
  75. package/build/utils/replace_equal_by_id.js +0 -41
  76. package/build/utils/replace_equal_by_id.js.map +0 -1
  77. package/src/components/conversation/__tests__/message_list.test.tsx +0 -271
  78. package/src/components/conversation/__tests__/reply_shadow_message.test.tsx +0 -119
  79. package/src/components/conversation/message_list.tsx +0 -157
  80. package/src/hooks/__tests__/use_message_create_or_update.test.tsx +0 -110
  81. package/src/utils/__tests__/replace_equal_by_id.test.ts +0 -73
  82. package/src/utils/cache/__tests__/messages_cache.test.ts +0 -89
  83. package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +0 -70
  84. package/src/utils/client/__tests__/transform_response.test.ts +0 -62
  85. package/src/utils/replace_equal_by_id.ts +0 -42
@@ -17,8 +17,6 @@ export interface MessageResource {
17
17
  reactionCounts: ReactionCountResource[]
18
18
  replyCount: number
19
19
  replyRootId?: string | null
20
- replyRoot?: MessageResource | null
21
- idempotentKey?: string | null
22
20
  messageType: string
23
21
  personIdsForSystemEvent?: number[] | null
24
22
  systemTextParts?: { names: string[]; overflowCount: number; action: string } | null
@@ -124,54 +124,6 @@ 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
-
175
127
  describe('groupMessages — system messages', () => {
176
128
  it('flags lastInGroup true and renderAuthor false on system messages', () => {
177
129
  const messages = [
@@ -4,11 +4,7 @@ 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 {
8
- updateAllRecordsInPagesData,
9
- updateOrCreateRecordInPagesData,
10
- updateRecordInPagesData,
11
- } from './page_mutations'
7
+ import { updateOrCreateRecordInPagesData, updateRecordInPagesData } from './page_mutations'
12
8
  import { deleteRecordInPagesData } from './page_mutations'
13
9
 
14
10
  export function updateCacheWithMessage(
@@ -19,16 +15,20 @@ export function updateCacheWithMessage(
19
15
  ) {
20
16
  queryClient.setQueryData<MessagesQueryData>(queryKey, prev => {
21
17
  if (event === 'message.created') {
22
- // Before adding the new message, remove its pending temporary counterpart.
23
- // The Jolt echo can arrive before the HTTP response has swapped it out.
18
+ // Before adding the new message, remove any pending temporary messages
19
+ // with matching text to prevent duplicates from race conditions
24
20
  let dataAfterTempRemoval = prev
25
- if (prev && message.mine && message.idempotentKey) {
21
+ if (prev && message.text && message.mine) {
26
22
  dataAfterTempRemoval = deleteRecordInPagesData({
27
23
  data: prev,
28
24
  record: message,
29
- matchFn: existingMessage =>
30
- isTemporaryMessageId(existingMessage.id) &&
31
- existingMessage.idempotentKey === message.idempotentKey,
25
+ matchFn: (existingMessage, _record) => {
26
+ return (
27
+ isTemporaryMessageId(existingMessage.id) &&
28
+ existingMessage.text === message.text &&
29
+ existingMessage.mine
30
+ )
31
+ },
32
32
  })
33
33
  }
34
34
 
@@ -70,22 +70,6 @@ export function updateCacheWithIndividualMessage(
70
70
  })
71
71
  }
72
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
-
89
73
  export function updateCacheWithReaction(
90
74
  queryClient: QueryClient,
91
75
  queryKey: unknown[],
@@ -15,7 +15,6 @@ export function optimisticallyCreateMessage({
15
15
  currentPerson,
16
16
  message,
17
17
  replyRootId,
18
- idempotentKey,
19
18
  }: {
20
19
  conversationId: number
21
20
  text: string
@@ -23,7 +22,6 @@ export function optimisticallyCreateMessage({
23
22
  currentPerson: CurrentPersonResource
24
23
  message?: MessageResource
25
24
  replyRootId?: string | null
26
- idempotentKey?: string
27
25
  }) {
28
26
  const id = message?.id || generateTempMessageId()
29
27
 
@@ -55,7 +53,6 @@ export function optimisticallyCreateMessage({
55
53
  pending: true,
56
54
  replyCount: 0,
57
55
  replyRootId: replyRootId || null,
58
- idempotentKey,
59
56
  }
60
57
 
61
58
  // Add the optimistic message to the cache
@@ -32,8 +32,7 @@ const transformRelationships = relationships => {
32
32
  }, {})
33
33
  }
34
34
 
35
- const addIncludedRecords = (record, included, seen, parent) => {
36
- const { relationships } = record
35
+ const addIncludedRecords = (relationships, included, seen, parent) => {
37
36
  return Object.keys(relationships || {}).reduce((acc, key) => {
38
37
  const relationship = relationships[key]
39
38
  if (_.isArray(relationship.data)) {
@@ -44,14 +43,13 @@ const addIncludedRecords = (record, included, seen, parent) => {
44
43
  return _.set(
45
44
  acc,
46
45
  _.pluralize(key),
47
- _.map(records, related => transformRecord(related, included, seen))
46
+ _.map(records, record => transformRecord(record, included, seen))
48
47
  )
49
48
  } else {
50
49
  const [id, type] = _.at(relationship, ['data.id', 'data.type'])
51
50
  if (id && type) {
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)
51
+ const record = _.find(included, { id, type })
52
+ return _.set(acc, key, record ? transformRecord(record, included, seen) : null)
55
53
  } else {
56
54
  return acc
57
55
  }
@@ -80,7 +78,7 @@ const transformRecord = (record, included, seen) => {
80
78
 
81
79
  seen.set(record, transformed)
82
80
 
83
- return addIncludedRecords(record, included, seen, transformed)
81
+ return addIncludedRecords(relationships, included, seen, transformed)
84
82
  }
85
83
  }
86
84
 
@@ -10,7 +10,6 @@ export type ReplyShadowMessage = {
10
10
  type: 'ReplyShadowMessage'
11
11
  id: string
12
12
  messageId: string
13
- replyRoot: MessageResource | null
14
13
  isReplyShadowMessage: boolean
15
14
  nextRendersAuthor: boolean
16
15
  }
@@ -24,7 +23,6 @@ interface GroupMessagesProps {
24
23
 
25
24
  export function groupMessages({ ms, inReplyScreen }: GroupMessagesProps): EnrichedMessage[] {
26
25
  const items: EnrichedMessage[] = []
27
- const messagesById = new Map(ms.map(message => [message.id, message]))
28
26
  let myLatestSeen = false
29
27
  let nextNeighborEnriched: MessageResource | undefined
30
28
 
@@ -43,13 +41,7 @@ export function groupMessages({ ms, inReplyScreen }: GroupMessagesProps): Enrich
43
41
  const isMyLatest = !myLatestSeen && message.mine
44
42
  if (isMyLatest) myLatestSeen = true
45
43
 
46
- const enriched = enrichRegularMessage(
47
- { ...message, replyRoot: resolveReplyRoot(message, messagesById) },
48
- prev,
49
- next,
50
- isMyLatest,
51
- !!inReplyScreen
52
- )
44
+ const enriched = enrichRegularMessage(message, prev, next, isMyLatest, !!inReplyScreen)
53
45
  items.push(enriched)
54
46
 
55
47
  const shadow = replyShadowFor(enriched, prev)
@@ -69,14 +61,6 @@ function neighborsOf<T>(arr: T[], i: number): { prev: T | undefined; next: T | u
69
61
  return { prev: arr[i + 1], next: arr[i - 1] }
70
62
  }
71
63
 
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
-
80
64
  function enrichSystemMessage(
81
65
  message: MessageResource,
82
66
  next: MessageResource | undefined
@@ -187,7 +171,6 @@ function replyShadowFor(
187
171
  type: 'ReplyShadowMessage',
188
172
  id: `${message.id}-${message.replyRootId}`,
189
173
  messageId: message.replyRootId,
190
- replyRoot: message.replyRoot ?? null,
191
174
  isReplyShadowMessage: true,
192
175
  nextRendersAuthor: message.renderAuthor ?? false,
193
176
  }
@@ -29,7 +29,6 @@ export function transformMessageEventDataToMessageResource({
29
29
  reactionCounts: [],
30
30
  replyCount: data.reply_count || 0,
31
31
  replyRootId: data.reply_root_id || null,
32
- idempotentKey: data.idempotent_key ?? null,
33
32
  messageType: data.message_type,
34
33
  personIdsForSystemEvent: data.system_event_person_ids,
35
34
  systemTextParts: data.system_text_parts
@@ -10,7 +10,6 @@ export const getMessageFields = {
10
10
  'reaction_counts',
11
11
  'reply_count',
12
12
  'reply_root',
13
- 'idempotent_key',
14
13
  'message_type',
15
14
  'person_ids_for_system_event',
16
15
  'system_text_parts',
@@ -19,4 +18,4 @@ export const getMessageFields = {
19
18
  ReactionCount: ['value', 'count', 'mine', 'message_id', 'author_ids'],
20
19
  }
21
20
 
22
- export const getMessagesInclude = ['author', 'reaction_counts', 'reply_root', 'reply_root.author']
21
+ export const getMessagesInclude = ['author', 'reaction_counts']
@@ -1,21 +0,0 @@
1
- import { RefObject } from 'react';
2
- import { FlatList, FlatListProps } from 'react-native';
3
- import { ConversationResource } from '../../types/resources/conversation';
4
- import { MessageResource } from '../../types/resources/message';
5
- import { type EnrichedMessage } from '../../utils/group_messages';
6
- type ScrollHandlers = Pick<FlatListProps<EnrichedMessage>, 'onScroll' | 'onLayout' | 'onContentSizeChange' | 'onScrollEndDrag' | 'onMomentumScrollEnd'>;
7
- interface MessageListProps extends ScrollHandlers {
8
- listRef: RefObject<FlatList | null>;
9
- conversation: ConversationResource;
10
- conversationId: number;
11
- messages: MessageResource[];
12
- replyRootId?: string | null;
13
- hasNextPage: boolean;
14
- onEndReached: () => void;
15
- }
16
- /** MessageList
17
- * The inverted list of messages, reply previews, and date separators for a conversation
18
- */
19
- export declare function MessageList({ listRef, conversation, conversationId, messages, replyRootId, hasNextPage, onEndReached, onScroll, onLayout, onContentSizeChange, onScrollEndDrag, onMomentumScrollEnd, }: MessageListProps): import("react/jsx-runtime").JSX.Element;
20
- export {};
21
- //# sourceMappingURL=message_list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message_list.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_list.tsx"],"names":[],"mappings":"AACA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAoB,MAAM,cAAc,CAAA;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAAqC,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAA;AASpG,KAAK,cAAc,GAAG,IAAI,CACxB,aAAa,CAAC,eAAe,CAAC,EAC9B,UAAU,GAAG,UAAU,GAAG,qBAAqB,GAAG,iBAAiB,GAAG,qBAAqB,CAC5F,CAAA;AAED,UAAU,gBAAiB,SAAQ,cAAc;IAC/C,OAAO,EAAE,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;IACnC,YAAY,EAAE,oBAAoB,CAAA;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,EAAE,OAAO,CAAA;IACpB,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAC1B,OAAO,EACP,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,WAAW,EACX,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,mBAAmB,GACpB,EAAE,gBAAgB,2CA4DlB"}
@@ -1,273 +0,0 @@
1
- import { c as _c } from "react/compiler-runtime";
2
- import { date as formatDate } from '@planningcenter/datetime-fmt';
3
- import React from 'react';
4
- import { FlatList, StyleSheet, View } from 'react-native';
5
- import { useTheme } from '../../hooks';
6
- import { getRelativeDateStatus } from '../../utils/date';
7
- import { groupMessages } from '../../utils/group_messages';
8
- import { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles';
9
- import { isSystemMessage } from '../../utils/system_messages';
10
- import { Text } from '../display';
11
- import { ConversationStartBanner } from './conversation_start_banner';
12
- import { Message } from './message';
13
- import { ReplyShadowMessage } from './reply_shadow_message';
14
- import { SystemMessage } from './system_message';
15
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
- /** MessageList
17
- * The inverted list of messages, reply previews, and date separators for a conversation
18
- */
19
- export function MessageList(t0) {
20
- const $ = _c(26);
21
- const {
22
- listRef,
23
- conversation,
24
- conversationId,
25
- messages,
26
- replyRootId,
27
- hasNextPage,
28
- onEndReached,
29
- onScroll,
30
- onLayout,
31
- onContentSizeChange,
32
- onScrollEndDrag,
33
- onMomentumScrollEnd
34
- } = t0;
35
- const styles = useStyles();
36
- const inReplyScreen = !!replyRootId;
37
- const canDeleteNonAuthoredMessages = conversation.memberAbility?.canDeleteNonAuthoredMessages ?? false;
38
- const latestRead = conversation.latestReadMessageSortKey;
39
- let t1;
40
- if ($[0] !== inReplyScreen || $[1] !== messages) {
41
- t1 = groupMessages({
42
- ms: messages,
43
- inReplyScreen
44
- });
45
- $[0] = inReplyScreen;
46
- $[1] = messages;
47
- $[2] = t1;
48
- } else {
49
- t1 = $[2];
50
- }
51
- const messagesWithSeparators = t1;
52
- let t2;
53
- if ($[3] !== conversation || $[4] !== hasNextPage) {
54
- t2 = hasNextPage ? null : /*#__PURE__*/_jsx(ConversationStartBanner, {
55
- conversation: conversation,
56
- hasMessages: true
57
- });
58
- $[3] = conversation;
59
- $[4] = hasNextPage;
60
- $[5] = t2;
61
- } else {
62
- t2 = $[5];
63
- }
64
- let t3;
65
- if ($[6] !== canDeleteNonAuthoredMessages || $[7] !== conversationId || $[8] !== inReplyScreen || $[9] !== latestRead) {
66
- t3 = t4 => {
67
- const {
68
- item: item_0
69
- } = t4;
70
- if (item_0.type === "DateSeparator") {
71
- return /*#__PURE__*/_jsx(InlineDateSeparator, {
72
- ...item_0
73
- });
74
- }
75
- if (item_0.type === "ReplyShadowMessage") {
76
- return /*#__PURE__*/_jsx(ReplyShadowMessage, {
77
- ...item_0,
78
- conversation_id: conversationId,
79
- inReplyScreen: inReplyScreen
80
- });
81
- }
82
- if (isSystemMessage(item_0)) {
83
- return /*#__PURE__*/_jsx(SystemMessage, {
84
- message: item_0,
85
- conversationId: conversationId
86
- });
87
- }
88
- const readByOthers = item_0.mine && !!latestRead && item_0.id <= latestRead;
89
- return /*#__PURE__*/_jsx(Message, {
90
- ...item_0,
91
- canDeleteNonAuthoredMessages: canDeleteNonAuthoredMessages,
92
- conversation_id: conversationId,
93
- readByOthers: readByOthers,
94
- inReplyScreen: inReplyScreen
95
- });
96
- };
97
- $[6] = canDeleteNonAuthoredMessages;
98
- $[7] = conversationId;
99
- $[8] = inReplyScreen;
100
- $[9] = latestRead;
101
- $[10] = t3;
102
- } else {
103
- t3 = $[10];
104
- }
105
- let t4;
106
- if ($[11] !== styles.listHeader) {
107
- t4 = /*#__PURE__*/_jsx(View, {
108
- style: styles.listHeader
109
- });
110
- $[11] = styles.listHeader;
111
- $[12] = t4;
112
- } else {
113
- t4 = $[12];
114
- }
115
- let t5;
116
- if ($[13] !== listRef || $[14] !== messagesWithSeparators || $[15] !== onContentSizeChange || $[16] !== onEndReached || $[17] !== onLayout || $[18] !== onMomentumScrollEnd || $[19] !== onScroll || $[20] !== onScrollEndDrag || $[21] !== styles.listContainer || $[22] !== t2 || $[23] !== t3 || $[24] !== t4) {
117
- t5 = /*#__PURE__*/_jsx(FlatList, {
118
- inverted: true,
119
- ref: listRef,
120
- contentContainerStyle: styles.listContainer,
121
- data: messagesWithSeparators,
122
- keyExtractor: _temp,
123
- onScroll: onScroll,
124
- onLayout: onLayout,
125
- onContentSizeChange: onContentSizeChange,
126
- onScrollEndDrag: onScrollEndDrag,
127
- onMomentumScrollEnd: onMomentumScrollEnd,
128
- scrollEventThrottle: 10,
129
- ListFooterComponent: t2,
130
- renderItem: t3,
131
- onEndReached: onEndReached,
132
- ListHeaderComponent: t4
133
- });
134
- $[13] = listRef;
135
- $[14] = messagesWithSeparators;
136
- $[15] = onContentSizeChange;
137
- $[16] = onEndReached;
138
- $[17] = onLayout;
139
- $[18] = onMomentumScrollEnd;
140
- $[19] = onScroll;
141
- $[20] = onScrollEndDrag;
142
- $[21] = styles.listContainer;
143
- $[22] = t2;
144
- $[23] = t3;
145
- $[24] = t4;
146
- $[25] = t5;
147
- } else {
148
- t5 = $[25];
149
- }
150
- return t5;
151
- }
152
- function _temp(item) {
153
- return item.id;
154
- }
155
- function InlineDateSeparator(t0) {
156
- const $ = _c(17);
157
- const {
158
- date
159
- } = t0;
160
- const styles = useDateSeparatorStyles();
161
- let t1;
162
- if ($[0] !== date) {
163
- t1 = getRelativeDateStatus(date);
164
- $[0] = date;
165
- $[1] = t1;
166
- } else {
167
- t1 = $[1];
168
- }
169
- const {
170
- isThisYear
171
- } = t1;
172
- const showYear = !isThisYear;
173
- let t2;
174
- if ($[2] !== date || $[3] !== showYear) {
175
- t2 = formatDate(date, {
176
- style: "long",
177
- year: showYear
178
- });
179
- $[2] = date;
180
- $[3] = showYear;
181
- $[4] = t2;
182
- } else {
183
- t2 = $[4];
184
- }
185
- const dateStamp = t2;
186
- let t3;
187
- if ($[5] !== styles.separator) {
188
- t3 = /*#__PURE__*/_jsx(View, {
189
- style: styles.separator
190
- });
191
- $[5] = styles.separator;
192
- $[6] = t3;
193
- } else {
194
- t3 = $[6];
195
- }
196
- let t4;
197
- if ($[7] !== dateStamp || $[8] !== styles.dateText) {
198
- t4 = /*#__PURE__*/_jsx(Text, {
199
- variant: "footnote",
200
- style: styles.dateText,
201
- children: dateStamp
202
- });
203
- $[7] = dateStamp;
204
- $[8] = styles.dateText;
205
- $[9] = t4;
206
- } else {
207
- t4 = $[9];
208
- }
209
- let t5;
210
- if ($[10] !== styles.separator) {
211
- t5 = /*#__PURE__*/_jsx(View, {
212
- style: styles.separator
213
- });
214
- $[10] = styles.separator;
215
- $[11] = t5;
216
- } else {
217
- t5 = $[11];
218
- }
219
- let t6;
220
- if ($[12] !== styles.container || $[13] !== t3 || $[14] !== t4 || $[15] !== t5) {
221
- t6 = /*#__PURE__*/_jsxs(View, {
222
- style: styles.container,
223
- children: [t3, t4, t5]
224
- });
225
- $[12] = styles.container;
226
- $[13] = t3;
227
- $[14] = t4;
228
- $[15] = t5;
229
- $[16] = t6;
230
- } else {
231
- t6 = $[16];
232
- }
233
- return t6;
234
- }
235
- const useDateSeparatorStyles = () => {
236
- const $ = _c(2);
237
- const theme = useTheme();
238
- let t0;
239
- if ($[0] !== theme.colors.borderColorDefaultBase) {
240
- t0 = StyleSheet.create({
241
- container: {
242
- alignItems: "center",
243
- flexDirection: "row",
244
- paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,
245
- paddingVertical: 16
246
- },
247
- separator: {
248
- flex: 1,
249
- height: 1,
250
- borderTopWidth: 1,
251
- borderTopColor: theme.colors.borderColorDefaultBase
252
- },
253
- dateText: {
254
- paddingHorizontal: 8
255
- }
256
- });
257
- $[0] = theme.colors.borderColorDefaultBase;
258
- $[1] = t0;
259
- } else {
260
- t0 = $[1];
261
- }
262
- return t0;
263
- };
264
- const useStyles = () => StyleSheet.create({
265
- listContainer: {
266
- paddingVertical: 12
267
- },
268
- listHeader: {
269
- // Just whitespace to provide space where the typing indicator can be
270
- height: 16
271
- }
272
- });
273
- //# sourceMappingURL=message_list.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message_list.js","names":["date","formatDate","React","FlatList","StyleSheet","View","useTheme","getRelativeDateStatus","groupMessages","CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL","isSystemMessage","Text","ConversationStartBanner","Message","ReplyShadowMessage","SystemMessage","jsx","_jsx","jsxs","_jsxs","MessageList","t0","$","_c","listRef","conversation","conversationId","messages","replyRootId","hasNextPage","onEndReached","onScroll","onLayout","onContentSizeChange","onScrollEndDrag","onMomentumScrollEnd","styles","useStyles","inReplyScreen","canDeleteNonAuthoredMessages","memberAbility","latestRead","latestReadMessageSortKey","t1","ms","messagesWithSeparators","t2","hasMessages","t3","t4","item","item_0","type","InlineDateSeparator","readByOthers","mine","id","listHeader","style","t5","listContainer","inverted","contentContainerStyle","keyExtractor","_temp","scrollEventThrottle","ListFooterComponent","renderItem","ListHeaderComponent","useDateSeparatorStyles","isThisYear","showYear","year","dateStamp","separator","dateText","variant","children","t6","container","theme","colors","borderColorDefaultBase","create","alignItems","flexDirection","paddingHorizontal","paddingVertical","flex","height","borderTopWidth","borderTopColor"],"sources":["../../../src/components/conversation/message_list.tsx"],"sourcesContent":["import { date as formatDate } from '@planningcenter/datetime-fmt'\nimport React, { RefObject } from 'react'\nimport { FlatList, FlatListProps, StyleSheet, View } from 'react-native'\nimport { useTheme } from '../../hooks'\nimport { ConversationResource } from '../../types/resources/conversation'\nimport { MessageResource } from '../../types/resources/message'\nimport { getRelativeDateStatus } from '../../utils/date'\nimport { groupMessages, type DateSeparator, type EnrichedMessage } from '../../utils/group_messages'\nimport { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles'\nimport { isSystemMessage } from '../../utils/system_messages'\nimport { Text } from '../display'\nimport { ConversationStartBanner } from './conversation_start_banner'\nimport { Message } from './message'\nimport { ReplyShadowMessage } from './reply_shadow_message'\nimport { SystemMessage } from './system_message'\n\ntype ScrollHandlers = Pick<\n FlatListProps<EnrichedMessage>,\n 'onScroll' | 'onLayout' | 'onContentSizeChange' | 'onScrollEndDrag' | 'onMomentumScrollEnd'\n>\n\ninterface MessageListProps extends ScrollHandlers {\n listRef: RefObject<FlatList | null>\n conversation: ConversationResource\n conversationId: number\n messages: MessageResource[]\n replyRootId?: string | null\n hasNextPage: boolean\n onEndReached: () => void\n}\n\n/** MessageList\n * The inverted list of messages, reply previews, and date separators for a conversation\n */\nexport function MessageList({\n listRef,\n conversation,\n conversationId,\n messages,\n replyRootId,\n hasNextPage,\n onEndReached,\n onScroll,\n onLayout,\n onContentSizeChange,\n onScrollEndDrag,\n onMomentumScrollEnd,\n}: MessageListProps) {\n const styles = useStyles()\n const inReplyScreen = !!replyRootId\n const canDeleteNonAuthoredMessages =\n conversation.memberAbility?.canDeleteNonAuthoredMessages ?? false\n const latestRead = conversation.latestReadMessageSortKey\n const messagesWithSeparators = groupMessages({ ms: messages, inReplyScreen })\n\n return (\n <FlatList\n inverted\n ref={listRef}\n contentContainerStyle={styles.listContainer}\n data={messagesWithSeparators}\n keyExtractor={item => item.id}\n onScroll={onScroll}\n onLayout={onLayout}\n onContentSizeChange={onContentSizeChange}\n onScrollEndDrag={onScrollEndDrag}\n onMomentumScrollEnd={onMomentumScrollEnd}\n scrollEventThrottle={10}\n ListFooterComponent={\n hasNextPage ? null : (\n <ConversationStartBanner conversation={conversation} hasMessages={true} />\n )\n }\n renderItem={({ item }) => {\n if (item.type === 'DateSeparator') {\n return <InlineDateSeparator {...item} />\n }\n\n if (item.type === 'ReplyShadowMessage') {\n return (\n <ReplyShadowMessage\n {...(item as any)}\n conversation_id={conversationId}\n inReplyScreen={inReplyScreen}\n />\n )\n }\n\n if (isSystemMessage(item)) {\n return <SystemMessage message={item} conversationId={conversationId} />\n }\n\n const readByOthers = item.mine && !!latestRead && item.id <= latestRead\n return (\n <Message\n {...item}\n canDeleteNonAuthoredMessages={canDeleteNonAuthoredMessages}\n conversation_id={conversationId}\n readByOthers={readByOthers}\n inReplyScreen={inReplyScreen}\n />\n )\n }}\n onEndReached={onEndReached}\n ListHeaderComponent={<View style={styles.listHeader} />}\n />\n )\n}\n\nfunction InlineDateSeparator({ date }: DateSeparator) {\n const styles = useDateSeparatorStyles()\n const { isThisYear } = getRelativeDateStatus(date)\n const showYear = !isThisYear\n const dateStamp = formatDate(date, { style: 'long', year: showYear })\n\n return (\n <View style={styles.container}>\n <View style={styles.separator} />\n <Text variant=\"footnote\" style={styles.dateText}>\n {dateStamp}\n </Text>\n <View style={styles.separator} />\n </View>\n )\n}\n\nconst useDateSeparatorStyles = () => {\n const theme = useTheme()\n return StyleSheet.create({\n container: {\n alignItems: 'center',\n flexDirection: 'row',\n paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,\n paddingVertical: 16,\n },\n separator: {\n flex: 1,\n height: 1,\n borderTopWidth: 1,\n borderTopColor: theme.colors.borderColorDefaultBase,\n },\n dateText: {\n paddingHorizontal: 8,\n },\n })\n}\n\nconst useStyles = () =>\n StyleSheet.create({\n listContainer: {\n paddingVertical: 12,\n },\n listHeader: {\n // Just whitespace to provide space where the typing indicator can be\n height: 16,\n },\n })\n"],"mappings":";AAAA,SAASA,IAAI,IAAIC,UAAU,QAAQ,8BAA8B;AACjE,OAAOC,KAAK,MAAqB,OAAO;AACxC,SAASC,QAAQ,EAAiBC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AACxE,SAASC,QAAQ,QAAQ,aAAa;AAGtC,SAASC,qBAAqB,QAAQ,kBAAkB;AACxD,SAASC,aAAa,QAAkD,4BAA4B;AACpG,SAASC,4CAA4C,QAAQ,oBAAoB;AACjF,SAASC,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,uBAAuB,QAAQ,6BAA6B;AACrE,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,kBAAkB,QAAQ,wBAAwB;AAC3D,SAASC,aAAa,QAAQ,kBAAkB;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAiBhD;AACA;AACA;AACA,OAAO,SAAAC,YAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAC,EAAA;EAAqB;IAAAC,OAAA;IAAAC,YAAA;IAAAC,cAAA;IAAAC,QAAA;IAAAC,WAAA;IAAAC,WAAA;IAAAC,YAAA;IAAAC,QAAA;IAAAC,QAAA;IAAAC,mBAAA;IAAAC,eAAA;IAAAC;EAAA,IAAAd,EAaT;EACjB,MAAAe,MAAA,GAAeC,SAAS,CAAC,CAAC;EAC1B,MAAAC,aAAA,GAAsB,CAAC,CAACV,WAAW;EACnC,MAAAW,4BAAA,GACEd,YAAY,C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AK;QAAAC,iBAAA,EACD7E,4CAA4C;QAAA8E,eAAA,EAC9C;MACnB,CAAC;MAAAb,SAAA,EACU;QAAAc,IAAA,EACH,CAAC;QAAAC,MAAA,EACC,CAAC;QAAAC,cAAA,EACO,CAAC;QAAAC,cAAA,EACDX,KAAK,CAAAC,MAAO,CAAAC;MAC9B,CAAC;MAAAP,QAAA,EACS;QAAAW,iBAAA,EACW;MACrB;IACF,CAAC,CAAC;IAAAhE,CAAA,MAAA0D,KAAA,CAAAC,MAAA,CAAAC,sBAAA;IAAA5D,CAAA,MAAAD,EAAA;EAAA;IAAAA,EAAA,GAAAC,CAAA;EAAA;EAAA,OAhBKD,EAgBL;AAAA,CACH;AAED,MAAMgB,SAAS,GAAGA,CAAA,KAChBjC,UAAU,CAAC+E,MAAM,CAAC;EAChBvB,aAAa,EAAE;IACb2B,eAAe,EAAE;EACnB,CAAC;EACD9B,UAAU,EAAE;IACV;IACAgC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
@@ -1,6 +0,0 @@
1
- /** replaceEqualById
2
- * TanStack's default structural sharing compares arrays by index, so an insert or
3
- * delete gives every shifted record a new identity. Match by id instead.
4
- */
5
- export declare function replaceEqualById(oldData: unknown, newData: unknown): unknown;
6
- //# sourceMappingURL=replace_equal_by_id.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replace_equal_by_id.d.ts","sourceRoot":"","sources":["../../src/utils/replace_equal_by_id.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAgC5E"}
@@ -1,41 +0,0 @@
1
- import { replaceEqualDeep } from '@tanstack/react-query';
2
- /** replaceEqualById
3
- * TanStack's default structural sharing compares arrays by index, so an insert or
4
- * delete gives every shifted record a new identity. Match by id instead.
5
- */
6
- export function replaceEqualById(oldData, newData) {
7
- const prev = oldData;
8
- const next = newData;
9
- if (!prev?.pages || !next?.pages) return replaceEqualDeep(prev, next);
10
- const prevById = new Map();
11
- prev.pages.forEach(page => page.data.forEach(record => prevById.set(record.id, record)));
12
- let changed = prev.pages.length !== next.pages.length;
13
- const pages = next.pages.map((page, index) => {
14
- const prevPage = prev.pages[index];
15
- const data = page.data.map(record => {
16
- const previous = prevById.get(record.id);
17
- return previous ? replaceEqualDeep(previous, record) : record;
18
- });
19
- const links = replaceEqualDeep(prevPage?.links, page.links);
20
- const meta = replaceEqualDeep(prevPage?.meta, page.meta);
21
- const sameRecords = !!prevPage && data.length === prevPage.data.length && data.every((record, i) => record === prevPage.data[i]);
22
- if (prevPage && sameRecords && links === prevPage.links && meta === prevPage.meta) {
23
- return prevPage;
24
- }
25
- changed = true;
26
- return {
27
- ...page,
28
- data,
29
- links,
30
- meta
31
- };
32
- });
33
- const pageParams = replaceEqualDeep(prev.pageParams, next.pageParams);
34
- if (!changed && pageParams === prev.pageParams) return prev;
35
- return {
36
- ...next,
37
- pages,
38
- pageParams
39
- };
40
- }
41
- //# sourceMappingURL=replace_equal_by_id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replace_equal_by_id.js","names":["replaceEqualDeep","replaceEqualById","oldData","newData","prev","next","pages","prevById","Map","forEach","page","data","record","set","id","changed","length","map","index","prevPage","previous","get","links","meta","sameRecords","every","i","pageParams"],"sources":["../../src/utils/replace_equal_by_id.ts"],"sourcesContent":["import { InfiniteData, replaceEqualDeep } from '@tanstack/react-query'\nimport { ApiCollection, ResourceObject } from '../types'\n\ntype Pages = InfiniteData<ApiCollection<ResourceObject>>\n\n/** replaceEqualById\n * TanStack's default structural sharing compares arrays by index, so an insert or\n * delete gives every shifted record a new identity. Match by id instead.\n */\nexport function replaceEqualById(oldData: unknown, newData: unknown): unknown {\n const prev = oldData as Pages | undefined\n const next = newData as Pages\n if (!prev?.pages || !next?.pages) return replaceEqualDeep(prev, next)\n\n const prevById = new Map<ResourceObject['id'], ResourceObject>()\n prev.pages.forEach(page => page.data.forEach(record => prevById.set(record.id, record)))\n\n let changed = prev.pages.length !== next.pages.length\n const pages = next.pages.map((page, index) => {\n const prevPage = prev.pages[index]\n const data = page.data.map(record => {\n const previous = prevById.get(record.id)\n return previous ? replaceEqualDeep(previous, record) : record\n })\n const links = replaceEqualDeep(prevPage?.links, page.links)\n const meta = replaceEqualDeep(prevPage?.meta, page.meta)\n const sameRecords =\n !!prevPage &&\n data.length === prevPage.data.length &&\n data.every((record, i) => record === prevPage.data[i])\n\n if (prevPage && sameRecords && links === prevPage.links && meta === prevPage.meta) {\n return prevPage\n }\n changed = true\n return { ...page, data, links, meta }\n })\n const pageParams = replaceEqualDeep(prev.pageParams, next.pageParams)\n\n if (!changed && pageParams === prev.pageParams) return prev\n return { ...next, pages, pageParams }\n}\n"],"mappings":"AAAA,SAAuBA,gBAAgB,QAAQ,uBAAuB;AAKtE;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,OAAgB,EAAEC,OAAgB,EAAW;EAC5E,MAAMC,IAAI,GAAGF,OAA4B;EACzC,MAAMG,IAAI,GAAGF,OAAgB;EAC7B,IAAI,CAACC,IAAI,EAAEE,KAAK,IAAI,CAACD,IAAI,EAAEC,KAAK,EAAE,OAAON,gBAAgB,CAACI,IAAI,EAAEC,IAAI,CAAC;EAErE,MAAME,QAAQ,GAAG,IAAIC,GAAG,CAAuC,CAAC;EAChEJ,IAAI,CAACE,KAAK,CAACG,OAAO,CAACC,IAAI,IAAIA,IAAI,CAACC,IAAI,CAACF,OAAO,CAACG,MAAM,IAAIL,QAAQ,CAACM,GAAG,CAACD,MAAM,CAACE,EAAE,EAAEF,MAAM,CAAC,CAAC,CAAC;EAExF,IAAIG,OAAO,GAAGX,IAAI,CAACE,KAAK,CAACU,MAAM,KAAKX,IAAI,CAACC,KAAK,CAACU,MAAM;EACrD,MAAMV,KAAK,GAAGD,IAAI,CAACC,KAAK,CAACW,GAAG,CAAC,CAACP,IAAI,EAAEQ,KAAK,KAAK;IAC5C,MA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