@planningcenter/chat-react-native 4.2.1-qa-staging.9 → 4.2.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 (106) hide show
  1. package/build/components/conversation/message_form.d.ts +1 -2
  2. package/build/components/conversation/message_form.d.ts.map +1 -1
  3. package/build/components/conversation/message_form.js +370 -167
  4. package/build/components/conversation/message_form.js.map +1 -1
  5. package/build/components/conversation/message_list.d.ts +2 -5
  6. package/build/components/conversation/message_list.d.ts.map +1 -1
  7. package/build/components/conversation/message_list.js +67 -187
  8. package/build/components/conversation/message_list.js.map +1 -1
  9. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +3 -4
  10. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
  11. package/build/hooks/index.d.ts +0 -1
  12. package/build/hooks/index.d.ts.map +1 -1
  13. package/build/hooks/index.js +0 -1
  14. package/build/hooks/index.js.map +1 -1
  15. package/build/hooks/use_conversation_messages.d.ts +5 -14
  16. package/build/hooks/use_conversation_messages.d.ts.map +1 -1
  17. package/build/hooks/use_conversation_messages.js +42 -218
  18. package/build/hooks/use_conversation_messages.js.map +1 -1
  19. package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
  20. package/build/hooks/use_conversation_messages_jolt_events.js +42 -58
  21. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
  22. package/build/hooks/use_features.d.ts +1 -2
  23. package/build/hooks/use_features.d.ts.map +1 -1
  24. package/build/hooks/use_features.js +1 -2
  25. package/build/hooks/use_features.js.map +1 -1
  26. package/build/hooks/use_mark_latest_message_read.d.ts +1 -2
  27. package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
  28. package/build/hooks/use_mark_latest_message_read.js +3 -4
  29. package/build/hooks/use_mark_latest_message_read.js.map +1 -1
  30. package/build/hooks/use_read_receipts.d.ts +3 -4
  31. package/build/hooks/use_read_receipts.d.ts.map +1 -1
  32. package/build/hooks/use_suspense_api.d.ts +6 -10
  33. package/build/hooks/use_suspense_api.d.ts.map +1 -1
  34. package/build/hooks/use_suspense_api.js +63 -83
  35. package/build/hooks/use_suspense_api.js.map +1 -1
  36. package/build/screens/conversation_new/components/services_form.js +8 -9
  37. package/build/screens/conversation_new/components/services_form.js.map +1 -1
  38. package/build/screens/conversation_screen.d.ts +0 -1
  39. package/build/screens/conversation_screen.d.ts.map +1 -1
  40. package/build/screens/conversation_screen.js +203 -305
  41. package/build/screens/conversation_screen.js.map +1 -1
  42. package/build/screens/message_actions_screen.d.ts.map +1 -1
  43. package/build/screens/message_actions_screen.js +92 -103
  44. package/build/screens/message_actions_screen.js.map +1 -1
  45. package/build/screens/notification_settings/hooks/groups.d.ts +3 -4
  46. package/build/screens/notification_settings/hooks/groups.d.ts.map +1 -1
  47. package/build/types/api_primitives.d.ts +0 -1
  48. package/build/types/api_primitives.d.ts.map +1 -1
  49. package/build/types/api_primitives.js.map +1 -1
  50. package/build/types/resources/member.d.ts +0 -1
  51. package/build/types/resources/member.d.ts.map +1 -1
  52. package/build/types/resources/member.js.map +1 -1
  53. package/build/utils/cache/messages_cache.d.ts +0 -1
  54. package/build/utils/cache/messages_cache.d.ts.map +1 -1
  55. package/build/utils/cache/messages_cache.js +1 -37
  56. package/build/utils/cache/messages_cache.js.map +1 -1
  57. package/build/utils/client/types.d.ts +0 -1
  58. package/build/utils/client/types.d.ts.map +1 -1
  59. package/build/utils/client/types.js.map +1 -1
  60. package/build/utils/group_messages.js +1 -4
  61. package/build/utils/group_messages.js.map +1 -1
  62. package/package.json +3 -3
  63. package/src/__tests__/hooks/use_features.test.ts +2 -10
  64. package/src/__utils__/query_client.ts +0 -3
  65. package/src/components/conversation/message_form.tsx +3 -31
  66. package/src/components/conversation/message_list.tsx +4 -88
  67. package/src/hooks/__tests__/use_message_create_or_update.test.tsx +7 -2
  68. package/src/hooks/index.ts +0 -1
  69. package/src/hooks/use_conversation_messages.ts +17 -103
  70. package/src/hooks/use_conversation_messages_jolt_events.ts +2 -12
  71. package/src/hooks/use_features.ts +2 -3
  72. package/src/hooks/use_mark_latest_message_read.ts +3 -4
  73. package/src/hooks/use_suspense_api.ts +6 -14
  74. package/src/screens/conversation_new/components/services_form.tsx +5 -5
  75. package/src/screens/conversation_screen.tsx +13 -62
  76. package/src/screens/message_actions_screen.tsx +1 -12
  77. package/src/types/api_primitives.ts +0 -1
  78. package/src/types/resources/member.ts +0 -1
  79. package/src/utils/__tests__/group_messages.test.ts +0 -29
  80. package/src/utils/cache/__tests__/messages_cache.test.ts +1 -2
  81. package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +2 -3
  82. package/src/utils/cache/messages_cache.ts +1 -45
  83. package/src/utils/client/types.ts +0 -1
  84. package/src/utils/group_messages.ts +1 -4
  85. package/build/components/conversation/missing_message.d.ts +0 -2
  86. package/build/components/conversation/missing_message.d.ts.map +0 -1
  87. package/build/components/conversation/missing_message.js +0 -139
  88. package/build/components/conversation/missing_message.js.map +0 -1
  89. package/build/hooks/use_direct_message_eligibility.d.ts +0 -14
  90. package/build/hooks/use_direct_message_eligibility.d.ts.map +0 -1
  91. package/build/hooks/use_direct_message_eligibility.js +0 -87
  92. package/build/hooks/use_direct_message_eligibility.js.map +0 -1
  93. package/build/utils/cache/messages_window.d.ts +0 -11
  94. package/build/utils/cache/messages_window.d.ts.map +0 -1
  95. package/build/utils/cache/messages_window.js +0 -51
  96. package/build/utils/cache/messages_window.js.map +0 -1
  97. package/src/__tests__/hooks/use_direct_message_eligibility.test.tsx +0 -83
  98. package/src/__tests__/screens/conversation_new/components/services_form.test.tsx +0 -91
  99. package/src/components/conversation/missing_message.tsx +0 -66
  100. package/src/hooks/__tests__/use_conversation_messages.test.tsx +0 -333
  101. package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +0 -87
  102. package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +0 -33
  103. package/src/hooks/use_direct_message_eligibility.ts +0 -40
  104. package/src/utils/cache/__tests__/messages_cache_deletion.test.ts +0 -97
  105. package/src/utils/cache/__tests__/messages_window.test.ts +0 -78
  106. package/src/utils/cache/messages_window.ts +0 -55
@@ -1,5 +1,5 @@
1
1
  import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'
2
- import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
2
+ import React, { useCallback, useContext, useEffect, useState } from 'react'
3
3
  import {
4
4
  Linking,
5
5
  Platform,
@@ -34,7 +34,6 @@ import {
34
34
  FileAttachment,
35
35
  } from '../../types/resources/denormalized_attachment_resource_for_create'
36
36
  import {
37
- Log,
38
37
  MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
39
38
  platformFontWeightMedium,
40
39
  platformPressedOpacityStyle,
@@ -72,7 +71,6 @@ interface MessagesFormRootProps extends ViewProps {
72
71
  replyRootId?: string | null
73
72
  replyRootAuthorFirstName?: string | null
74
73
  onFlaggedInMessageForm?: (id: string) => void
75
- onBeforeSubmit?: () => void | Promise<void>
76
74
  }
77
75
 
78
76
  const MessageFormContext = React.createContext<{
@@ -115,7 +113,6 @@ function MessageFormRoot({
115
113
  replyRootId,
116
114
  replyRootAuthorFirstName,
117
115
  onFlaggedInMessageForm,
118
- onBeforeSubmit,
119
116
  }: MessagesFormRootProps) {
120
117
  const { giphyApiKey } = useContext(ChatContext)
121
118
  const canGiphy = !!giphyApiKey && !currentlyEditingMessage
@@ -227,31 +224,10 @@ function MessageFormRoot({
227
224
  }
228
225
  }, [conversation.id, navigation, text])
229
226
 
230
- const catchingUp = useRef(false)
231
-
232
- // A send from a window behind the live edge would leave a gap above it, so a failed
233
- // catch-up stops the send and keeps what was typed.
234
- const catchUpBeforeSend = async () => {
235
- if (catchingUp.current) return false
236
-
237
- catchingUp.current = true
238
- try {
239
- await onBeforeSubmit?.()
240
- return true
241
- } catch (error) {
242
- Log.error('send stopped: live window fetch failed', error)
243
- return false
244
- } finally {
245
- catchingUp.current = false
246
- }
247
- }
248
-
249
- const handleSubmit = async () => {
227
+ const handleSubmit = () => {
250
228
  if (!canSubmit) return
251
229
 
252
230
  if (canGiphy && usingGiphy) {
253
- if (!(await catchUpBeforeSend())) return
254
-
255
231
  TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput())
256
232
  Haptic.impactLight()
257
233
  navigateToSendGiphyAfterKeyboardHides()
@@ -272,12 +248,8 @@ function MessageFormRoot({
272
248
  mutateAsync({ text: messageText })
273
249
  reset()
274
250
  } else {
275
- // The live-window fetch replaces the cache, which would wipe an optimistic row
276
- // added earlier.
277
- if (!(await catchUpBeforeSend())) return
278
-
279
- reset()
280
251
  mutateAsync({ text: messageText, attachments: attachmentsForSubmit })
252
+ reset()
281
253
  }
282
254
  }
283
255
  }
@@ -1,6 +1,5 @@
1
1
  import { date as formatDate } from '@planningcenter/datetime-fmt'
2
- import { noop } from 'lodash'
3
- import React, { RefObject, useRef } from 'react'
2
+ import React, { RefObject } from 'react'
4
3
  import { FlatList, FlatListProps, StyleSheet, View } from 'react-native'
5
4
  import { useTheme } from '../../hooks'
6
5
  import { ConversationResource } from '../../types/resources/conversation'
@@ -12,23 +11,12 @@ import { isSystemMessage } from '../../utils/system_messages'
12
11
  import { Text } from '../display'
13
12
  import { ConversationStartBanner } from './conversation_start_banner'
14
13
  import { Message } from './message'
15
- import { MissingMessage } from './missing_message'
16
14
  import { ReplyShadowMessage } from './reply_shadow_message'
17
15
  import { SystemMessage } from './system_message'
18
16
 
19
- // While behind, the bottom of the window isn't the live edge. Following there pulls
20
- // each newly paged-in page into view and chains the next fetch.
21
- const HOLD_AND_FOLLOW = { minIndexForVisible: 0, autoscrollToTopThreshold: 100 }
22
- const HOLD_ONLY = { minIndexForVisible: 0 }
23
-
24
17
  type ScrollHandlers = Pick<
25
18
  FlatListProps<EnrichedMessage>,
26
- | 'onScroll'
27
- | 'onLayout'
28
- | 'onContentSizeChange'
29
- | 'onScrollBeginDrag'
30
- | 'onScrollEndDrag'
31
- | 'onMomentumScrollEnd'
19
+ 'onScroll' | 'onLayout' | 'onContentSizeChange' | 'onScrollEndDrag' | 'onMomentumScrollEnd'
32
20
  >
33
21
 
34
22
  interface MessageListProps extends ScrollHandlers {
@@ -37,15 +25,10 @@ interface MessageListProps extends ScrollHandlers {
37
25
  conversationId: number
38
26
  messages: MessageResource[]
39
27
  replyRootId?: string | null
40
- anchorMessageId?: string | null
41
- behind?: boolean
42
28
  hasNextPage: boolean
43
29
  onEndReached: () => void
44
- onStartReached?: () => void
45
30
  }
46
31
 
47
- const ANCHOR_CLEARS_JUMP_BUTTON = 56
48
-
49
32
  /** MessageList
50
33
  * The inverted list of messages, reply previews, and date separators for a conversation
51
34
  */
@@ -55,15 +38,11 @@ export function MessageList({
55
38
  conversationId,
56
39
  messages,
57
40
  replyRootId,
58
- anchorMessageId,
59
- behind = false,
60
41
  hasNextPage,
61
42
  onEndReached,
62
- onStartReached,
63
43
  onScroll,
64
44
  onLayout,
65
45
  onContentSizeChange,
66
- onScrollBeginDrag,
67
46
  onScrollEndDrag,
68
47
  onMomentumScrollEnd,
69
48
  }: MessageListProps) {
@@ -73,60 +52,6 @@ export function MessageList({
73
52
  conversation.memberAbility?.canDeleteNonAuthoredMessages ?? false
74
53
  const latestRead = conversation.latestReadMessageSortKey
75
54
  const messagesWithSeparators = groupMessages({ ms: messages, inReplyScreen })
76
- const anchorIndex = anchorMessageId
77
- ? messagesWithSeparators.findIndex(item => item.id === anchorMessageId)
78
- : -1
79
- const layoutHeight = useRef(0)
80
- const contentHeight = useRef(0)
81
- const userHasScrolled = useRef(false)
82
- const draggedSinceStartReached = useRef(false)
83
-
84
- // Row heights keep settling after the first layout (images, attachments), so we
85
- // re-pin on every layout pass until the reader takes over with a drag.
86
- const pinAnchorToBottomEdge = () => {
87
- const anchorIsLoaded = anchorIndex >= 0
88
- if (!anchorIsLoaded || userHasScrolled.current) return
89
-
90
- const scrollable = layoutHeight.current > 0 && contentHeight.current > layoutHeight.current
91
- if (!scrollable) return
92
-
93
- listRef.current?.scrollToIndex({
94
- index: anchorIndex,
95
- viewPosition: 0,
96
- viewOffset: ANCHOR_CLEARS_JUMP_BUTTON,
97
- animated: false,
98
- })
99
- }
100
-
101
- const handleLayout: FlatListProps<EnrichedMessage>['onLayout'] = event => {
102
- onLayout?.(event)
103
- layoutHeight.current = event.nativeEvent.layout.height
104
- pinAnchorToBottomEdge()
105
- }
106
-
107
- const handleContentSizeChange: FlatListProps<EnrichedMessage>['onContentSizeChange'] = (
108
- width,
109
- height
110
- ) => {
111
- onContentSizeChange?.(width, height)
112
- contentHeight.current = height
113
- pinAnchorToBottomEdge()
114
- }
115
-
116
- const handleScrollBeginDrag: FlatListProps<EnrichedMessage>['onScrollBeginDrag'] = event => {
117
- userHasScrolled.current = true
118
- draggedSinceStartReached.current = true
119
- onScrollBeginDrag?.(event)
120
- }
121
-
122
- // VirtualizedList re-checks its edges on every content size change using a JS offset
123
- // the native hold never updates, so without this each merged page re-fires it.
124
- const handleStartReached = () => {
125
- if (!draggedSinceStartReached.current) return
126
-
127
- draggedSinceStartReached.current = false
128
- onStartReached?.()
129
- }
130
55
 
131
56
  return (
132
57
  <FlatList
@@ -136,15 +61,11 @@ export function MessageList({
136
61
  data={messagesWithSeparators}
137
62
  keyExtractor={item => item.id}
138
63
  onScroll={onScroll}
139
- onLayout={handleLayout}
140
- onContentSizeChange={handleContentSizeChange}
141
- onScrollBeginDrag={handleScrollBeginDrag}
142
- // Expected while rows are still measuring; the next layout pass pins again.
143
- onScrollToIndexFailed={noop}
64
+ onLayout={onLayout}
65
+ onContentSizeChange={onContentSizeChange}
144
66
  onScrollEndDrag={onScrollEndDrag}
145
67
  onMomentumScrollEnd={onMomentumScrollEnd}
146
68
  scrollEventThrottle={10}
147
- maintainVisibleContentPosition={behind ? HOLD_ONLY : HOLD_AND_FOLLOW}
148
69
  ListFooterComponent={
149
70
  hasNextPage ? null : (
150
71
  <ConversationStartBanner conversation={conversation} hasMessages={true} />
@@ -155,10 +76,6 @@ export function MessageList({
155
76
  return <InlineDateSeparator {...item} />
156
77
  }
157
78
 
158
- if (item.type === 'Message' && item.deletedAt && !item.replyRootId) {
159
- return <MissingMessage />
160
- }
161
-
162
79
  if (item.type === 'ReplyShadowMessage') {
163
80
  return (
164
81
  <ReplyShadowMessage
@@ -185,7 +102,6 @@ export function MessageList({
185
102
  )
186
103
  }}
187
104
  onEndReached={onEndReached}
188
- onStartReached={handleStartReached}
189
105
  ListHeaderComponent={<View style={styles.listHeader} />}
190
106
  />
191
107
  )
@@ -7,8 +7,13 @@ import { getMessagesQueryKey } from '../../utils/request/get_messages'
7
7
  import { useMessageCreateOrUpdate } from '../use_message_create_or_update'
8
8
 
9
9
  jest.mock('../../contexts/api_provider', () => {
10
- const { buildTestQueryClient } = require('../../__utils__/query_client')
11
- return { chatQueryClient: buildTestQueryClient() }
10
+ const { QueryClient } = require('@tanstack/react-query')
11
+ // gcTime 0 so nothing outlives the test and keeps jest from exiting
12
+ return {
13
+ chatQueryClient: new QueryClient({
14
+ defaultOptions: { queries: { gcTime: 0 }, mutations: { gcTime: 0 } },
15
+ }),
16
+ }
12
17
  })
13
18
 
14
19
  const mockPost = jest.fn()
@@ -8,7 +8,6 @@ export * from './use_chat_permissions'
8
8
  export * from './use_create_android_ripple_color'
9
9
  export * from './use_current_person'
10
10
  export * from './use_deleting_ids'
11
- export * from './use_direct_message_eligibility'
12
11
  export * from './use_direct_messages_eligible'
13
12
  export * from './use_font_scale'
14
13
  export * from './use_has_direct_messages'
@@ -1,119 +1,33 @@
1
- import { useQueryClient } from '@tanstack/react-query'
2
- import { useEffect, useMemo } from 'react'
3
- import { chatQueryClient } from '../contexts/api_provider'
4
- import { ApiCollection, MessageResource } from '../types'
5
- import {
6
- anchoredPageParam,
7
- isBehindLiveEdge,
8
- livePageParam,
9
- markLiveIfCaughtUp,
10
- MessagesWindow,
11
- newerPageParam,
12
- newestFirst,
13
- } from '../utils/cache/messages_window'
1
+ import { useMemo } from 'react'
2
+ import { MessageResource } from '../types'
14
3
  import { replaceEqualById } from '../utils/replace_equal_by_id'
15
4
  import { getMessagesQueryKey, getMessagesRequestArgs } from '../utils/request/get_messages'
16
- import { useApiClient } from './use_api_client'
17
5
  import { SuspensePaginatorOptions, useSuspensePaginator } from './use_suspense_api'
18
6
 
19
- type WindowOptions = { conversation_id: number; reply_root_id?: string | null }
20
- type Options = WindowOptions & { anchor?: string | null }
21
-
22
7
  export const useConversationMessages = (
23
- { conversation_id, reply_root_id, anchor }: Options,
8
+ { conversation_id, reply_root_id }: { conversation_id: number; reply_root_id?: string | null },
24
9
  opts?: SuspensePaginatorOptions
25
10
  ) => {
26
- const queryClient = useQueryClient()
27
- const apiClient = useApiClient()
11
+ const { data, refetch, isRefetching, fetchNextPage, hasNextPage } =
12
+ useSuspensePaginator<MessageResource>(
13
+ getMessagesRequestArgs({ conversation_id, reply_root_id }),
14
+ {
15
+ structuralSharing: replaceEqualById,
16
+ ...opts,
17
+ }
18
+ )
28
19
  const queryKey = getMessagesQueryKey({ conversation_id, reply_root_id })
29
- const requestArgs = getMessagesRequestArgs({ conversation_id, reply_root_id })
30
- const {
31
- data,
32
- infiniteData,
33
- refetch,
34
- isRefetching,
35
- fetchNextPage,
36
- fetchPreviousPage,
37
- hasNextPage,
38
- hasPreviousPage,
39
- } = useSuspensePaginator<MessageResource>(requestArgs, {
40
- structuralSharing: replaceEqualById,
41
- initialPageParam: anchor ? anchoredPageParam(anchor) : livePageParam,
42
- getPreviousPageParam: newerPageParam,
43
- transformPage: newestFirst,
44
- ...opts,
45
- })
46
- const behind = isBehindLiveEdge(infiniteData)
47
-
48
- const fetchOlder = () => fetchNextPage({ cancelRefetch: false })
49
-
50
- const fetchNewer = async () => {
51
- if (!hasPreviousPage) return
52
-
53
- await fetchPreviousPage({ cancelRefetch: false })
54
- }
55
-
56
- const fetchLiveWindow = async () => {
57
- if (!behind) return
58
-
59
- const page = await apiClient.chat.get<ApiCollection<MessageResource>>(requestArgs)
60
- await queryClient.cancelQueries({ queryKey, exact: true })
61
- queryClient.setQueryData<MessagesWindow>(queryKey, {
62
- pages: [page],
63
- pageParams: [livePageParam],
64
- })
65
- }
66
-
67
20
  const messages = useMemo(
68
21
  () =>
69
22
  data
70
- .filter(message => message.deletedAt || message.attachments?.length || message.text?.length)
23
+ .filter(
24
+ message =>
25
+ (!message.deletedAt || message.replyRootId) &&
26
+ (message.attachments?.length || message.text?.length)
27
+ )
71
28
  .sort((a, b) => -a.id.localeCompare(b.id)),
72
29
  [data]
73
30
  )
74
31
 
75
- // Once nothing newer remains, the top of the window is the live edge. Without this,
76
- // a refetch would replay from the anchor and drop rows Jolt has added since.
77
- useEffect(() => {
78
- const settled = markLiveIfCaughtUp(infiniteData)
79
-
80
- if (settled !== infiniteData) {
81
- queryClient.setQueryData(queryKey, settled)
82
- }
83
- }, [infiniteData, queryClient, queryKey])
84
-
85
- useEnsureWindowHoldsAnchor({ conversation_id, reply_root_id, anchor })
86
-
87
- return {
88
- messages,
89
- behind,
90
- refetch,
91
- isRefetching,
92
- fetchNextPage: fetchOlder,
93
- fetchNewer,
94
- fetchLiveWindow,
95
- hasNextPage,
96
- queryKey,
97
- }
98
- }
99
-
100
- const useEnsureWindowHoldsAnchor = ({ conversation_id, reply_root_id, anchor }: Options) => {
101
- const queryClient = useQueryClient()
102
-
103
- useEffect(() => {
104
- if (!anchor) return
105
-
106
- const queryKey = getMessagesQueryKey({ conversation_id, reply_root_id })
107
- const cached = queryClient.getQueryData<MessagesWindow>(queryKey)
108
- const holdsAnchor = cached?.pages.some(page => page.data.some(m => m.id === anchor))
109
- if (cached && !holdsAnchor) {
110
- queryClient.resetQueries({ queryKey, exact: true })
111
- }
112
- }, [anchor, conversation_id, reply_root_id, queryClient])
113
- }
114
-
115
- export const dropMessagesWindowIfBehind = (options: WindowOptions) => {
116
- const queryKey = getMessagesQueryKey(options)
117
- const cached = chatQueryClient.getQueryData<MessagesWindow>(queryKey)
118
- if (isBehindLiveEdge(cached)) chatQueryClient.removeQueries({ queryKey, exact: true })
32
+ return { messages, refetch, isRefetching, fetchNextPage, hasNextPage, queryKey }
119
33
  }
@@ -14,7 +14,6 @@ import {
14
14
  updateCacheReplyRoots,
15
15
  getThreadedMessagesQueryKey,
16
16
  } from '../utils/cache/messages_cache'
17
- import { isBehindLiveEdge, MessagesWindow } from '../utils/cache/messages_window'
18
17
  import { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'
19
18
  import { completeMessageCreationTracking } from '../utils/performance_tracking'
20
19
  import { getMessageQueryKey } from '../utils/request/get_message'
@@ -40,17 +39,12 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
40
39
  const { addTypingEvent, removeTypingEventById, removeAllTypingEventsByAuthorId } =
41
40
  useTypingStatusCache(conversationId)
42
41
 
43
- // While behind, a new message would land after a gap; the newer fetch brings it in.
44
- const acceptsCreates = (queryKey: unknown[]) =>
45
- !isBehindLiveEdge(queryClient.getQueryData<MessagesWindow>(queryKey))
46
-
47
42
  const handleMessageUpdateOrCreate = async (e: MessageCreatedEvent | MessageUpdatedEvent) => {
48
43
  const { data } = e.data
49
44
  const message = transformMessageEventDataToMessageResource({
50
45
  data,
51
46
  currentPersonId: currentPerson.id,
52
47
  })
53
- const isCreate = e.event === 'message.created'
54
48
  const isReplyRootUpdate = e.event === 'message.updated' && data.reply_root_id === data.sort_key
55
49
 
56
50
  if (e.event === 'message.created' && data.author_id) {
@@ -61,9 +55,7 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
61
55
  }
62
56
 
63
57
  // Update the main conversation cache
64
- if (!isCreate || acceptsCreates(messagesQueryKey)) {
65
- updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)
66
- }
58
+ updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)
67
59
 
68
60
  // If message has a reply_root_id, also update the threaded cache
69
61
  if (data.reply_root_id) {
@@ -71,9 +63,7 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
71
63
  conversationId,
72
64
  data.reply_root_id
73
65
  )
74
- if (!isCreate || acceptsCreates(threadedMessagesQueryKey)) {
75
- updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)
76
- }
66
+ updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)
77
67
 
78
68
  if (isReplyRootUpdate) {
79
69
  updateCacheReplyRoots(queryClient, messagesQueryKey, message)
@@ -55,9 +55,8 @@ export const availableFeatures = {
55
55
  conversation_safety_lock: 'ROLLOUT_conversation_safety_lock',
56
56
  video_moderation: 'ROLLOUT_MOBILE_video_moderation',
57
57
  dm_search_clear_fix: 'ROLLOUT_MOBILE_dm_search_clear_fix',
58
- search: 'QA_MOBILE_search',
59
- search_rollout: 'ROLLOUT_MOBILE_search',
60
- } as const satisfies Record<string, `${'QA' | 'ROLLOUT'}_${string}`>
58
+ search: 'ROLLOUT_search',
59
+ } as const satisfies Record<string, `ROLLOUT_${string}`>
61
60
 
62
61
  const stableEmptyFeatures: ApiCollection<FeatureResource> = {
63
62
  data: [],
@@ -7,10 +7,9 @@ import { useConversationsMarkRead } from './use_conversations_actions'
7
7
  interface Props {
8
8
  conversation: ConversationResource
9
9
  messages: MessageResource[]
10
- enabled?: boolean
11
10
  }
12
11
 
13
- export function useMarkLatestMessageRead({ conversation, enabled = true }: Props) {
12
+ export function useMarkLatestMessageRead({ conversation }: Props) {
14
13
  const firedOnce = useRef<boolean>(false)
15
14
  const { markRead } = useConversationsMarkRead({ conversation })
16
15
  const debouncedMarkRead = useMemo(
@@ -25,10 +24,10 @@ export function useMarkLatestMessageRead({ conversation, enabled = true }: Props
25
24
  const isActive = appState === 'active'
26
25
 
27
26
  useEffect(() => {
28
- if (!enabled || !isActive || !shouldMarkRead) return
27
+ if (!isActive || !shouldMarkRead) return
29
28
 
30
29
  firedOnce.current = true
31
30
 
32
31
  debouncedMarkRead(true)
33
- }, [debouncedMarkRead, enabled, isActive, shouldMarkRead, unreadReaction])
32
+ }, [debouncedMarkRead, isActive, shouldMarkRead, unreadReaction])
34
33
  }
@@ -47,23 +47,17 @@ export const useSuspenseGet = <T extends ResourceObject | ResourceObject[]>(
47
47
  export type SuspensePaginatorOptions = Omit<
48
48
  AnyUseSuspenseInfiniteQueryOptions,
49
49
  'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'
50
- > & {
51
- initialPageParam?: Partial<RequestData>
52
- transformPage?(
53
- page: ApiCollection<ResourceObject>,
54
- pageParam: Partial<RequestData> | undefined
55
- ): ApiCollection<ResourceObject>
56
- }
50
+ >
57
51
 
58
52
  export const useSuspensePaginator = <T extends ResourceObject>(
59
53
  args: SuspenseGetOptions,
60
- { transformPage, ...opts }: SuspensePaginatorOptions = {}
54
+ opts?: SuspensePaginatorOptions
61
55
  ) => {
62
56
  const apiClient = useApiClient()
63
57
  const query = useSuspenseInfiniteQuery<
64
58
  ApiCollection<T>,
65
59
  Response,
66
- InfiniteData<ApiCollection<T>, Partial<RequestData> | undefined>,
60
+ InfiniteData<ApiCollection<T>>,
67
61
  any,
68
62
  Partial<RequestData> | undefined
69
63
  >({
@@ -76,8 +70,7 @@ export const useSuspensePaginator = <T extends ResourceObject>(
76
70
  const where = { ...argsWhere, ...pageParmWhere }
77
71
  const app = args.app || 'chat'
78
72
  const offset = pageParam?.offset || args.data.offset
79
- const order = pageParam?.order || args.data.order
80
- const data = { ...args.data, where, offset, ...(order && { order }) }
73
+ const data = { ...args.data, where, offset }
81
74
 
82
75
  return apiClient[app]
83
76
  .get<ApiCollection<T>>({
@@ -85,17 +78,16 @@ export const useSuspensePaginator = <T extends ResourceObject>(
85
78
  data,
86
79
  })
87
80
  .catch(throwResponseError)
88
- .then(page => (transformPage ? (transformPage(page, pageParam) as ApiCollection<T>) : page))
89
81
  },
90
82
  initialPageParam: {} as Partial<RequestData>,
91
83
  getNextPageParam: lastPage => getNextPageParamFromMeta(lastPage.meta?.next),
92
- ...opts,
84
+ ...(opts || {}),
93
85
  })
94
86
 
95
87
  const data: T[] = query.data?.pages.flatMap(page => page.data) || []
96
88
  const totalCount = query.data?.pages[0]?.meta?.totalCount || data.length
97
89
 
98
- return { ...query, data, totalCount, infiniteData: query.data }
90
+ return { ...query, data, totalCount }
99
91
  }
100
92
 
101
93
  export type RequestQueryKey = [
@@ -45,7 +45,6 @@ export const ServicesForm = ({
45
45
  const customAvatarsEnabled = featureEnabled(availableFeatures.custom_conversation_avatars)
46
46
  const safetyLockEnabled = featureEnabled(availableFeatures.conversation_safety_lock)
47
47
  const [selectedPlanId, setSelectedPlanId] = useState<number | undefined>(initialPlanId)
48
- const [filterByPlan, setFilterByPlan] = useState<boolean>(!!initialPlanId)
49
48
  const initialState = useMemo(() => uniq(initialTeamIds) || [], [initialTeamIds]) // Uniq here because services can send duplicates in the teams_i_lead response.
50
49
  const [selectedTeamIds, setSelectedTeamIds] = useState<number[]>(initialState)
51
50
 
@@ -53,7 +52,6 @@ export const ServicesForm = ({
53
52
  useEffect(() => {
54
53
  setSelectedTeamIds(initialState)
55
54
  setSelectedPlanId(initialPlanId)
56
- setFilterByPlan(!!initialPlanId)
57
55
  }, [initialState, initialPlanId])
58
56
 
59
57
  const removeSelection = useCallback(
@@ -63,7 +61,9 @@ export const ServicesForm = ({
63
61
  [selectedTeamIds]
64
62
  )
65
63
 
66
- const activePlanId = filterByPlan ? selectedPlanId : undefined
64
+ const [filerByPlan, setFilterByPlan] = useState(false)
65
+
66
+ const activePlanId = filerByPlan ? selectedPlanId : undefined
67
67
 
68
68
  const { payload, isLoading: isLoadingPayload } = useServicesChatConversationPayload({
69
69
  teamIds: selectedTeamIds,
@@ -79,7 +79,7 @@ export const ServicesForm = ({
79
79
 
80
80
  const { members, isError: isMemberError } = useTeamMembersForNewConversation({
81
81
  teamIds: selectedTeamIds,
82
- planId: activePlanId,
82
+ planId: selectedPlanId,
83
83
  })
84
84
  const adultMembers = useMemo(() => members.filter(member => !member.child), [members])
85
85
 
@@ -118,7 +118,7 @@ export const ServicesForm = ({
118
118
  removeSelection={removeSelection}
119
119
  selectedPlanId={selectedPlanId}
120
120
  setSelectedPlanId={setSelectedPlanId}
121
- filterByPlan={filterByPlan}
121
+ filterByPlan={filerByPlan}
122
122
  setFilterByPlan={setFilterByPlan}
123
123
  members={members}
124
124
  isMemberError={isMemberError}