@planningcenter/chat-react-native 4.2.1-qa-staging.6 → 4.2.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 (178) hide show
  1. package/build/components/conversation/message_form.d.ts +1 -1
  2. package/build/components/conversation/message_form.d.ts.map +1 -1
  3. package/build/components/conversation/message_form.js +167 -373
  4. package/build/components/conversation/message_form.js.map +1 -1
  5. package/build/components/conversation/message_list.d.ts +4 -2
  6. package/build/components/conversation/message_list.d.ts.map +1 -1
  7. package/build/components/conversation/message_list.js +115 -81
  8. package/build/components/conversation/message_list.js.map +1 -1
  9. package/build/components/conversation/missing_message.d.ts +2 -0
  10. package/build/components/conversation/missing_message.d.ts.map +1 -0
  11. package/build/components/conversation/missing_message.js +139 -0
  12. package/build/components/conversation/missing_message.js.map +1 -0
  13. package/build/contexts/api_provider.d.ts.map +1 -1
  14. package/build/contexts/api_provider.js +1 -2
  15. package/build/contexts/api_provider.js.map +1 -1
  16. package/build/contexts/conversation_context.d.ts +1 -3
  17. package/build/contexts/conversation_context.d.ts.map +1 -1
  18. package/build/contexts/conversation_context.js +18 -23
  19. package/build/contexts/conversation_context.js.map +1 -1
  20. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +4 -3
  21. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
  22. package/build/hooks/paginator_meta.d.ts +1 -3
  23. package/build/hooks/paginator_meta.d.ts.map +1 -1
  24. package/build/hooks/paginator_meta.js +8 -25
  25. package/build/hooks/paginator_meta.js.map +1 -1
  26. package/build/hooks/use_api.d.ts.map +1 -1
  27. package/build/hooks/use_api.js +8 -5
  28. package/build/hooks/use_api.js.map +1 -1
  29. package/build/hooks/use_conversation_messages.d.ts +10 -8
  30. package/build/hooks/use_conversation_messages.d.ts.map +1 -1
  31. package/build/hooks/use_conversation_messages.js +218 -81
  32. package/build/hooks/use_conversation_messages.js.map +1 -1
  33. package/build/hooks/use_conversation_messages_jolt_events.d.ts +1 -17
  34. package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
  35. package/build/hooks/use_conversation_messages_jolt_events.js +90 -83
  36. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
  37. package/build/hooks/use_message_create_or_update.d.ts.map +1 -1
  38. package/build/hooks/use_message_create_or_update.js +80 -91
  39. package/build/hooks/use_message_create_or_update.js.map +1 -1
  40. package/build/hooks/use_message_reaction_toggle.d.ts.map +1 -1
  41. package/build/hooks/use_message_reaction_toggle.js +40 -45
  42. package/build/hooks/use_message_reaction_toggle.js.map +1 -1
  43. package/build/hooks/use_read_receipts.d.ts +4 -3
  44. package/build/hooks/use_read_receipts.d.ts.map +1 -1
  45. package/build/hooks/use_suspense_api.d.ts +10 -6
  46. package/build/hooks/use_suspense_api.d.ts.map +1 -1
  47. package/build/hooks/use_suspense_api.js +88 -65
  48. package/build/hooks/use_suspense_api.js.map +1 -1
  49. package/build/screens/conversation_screen.d.ts +1 -1
  50. package/build/screens/conversation_screen.d.ts.map +1 -1
  51. package/build/screens/conversation_screen.js +338 -463
  52. package/build/screens/conversation_screen.js.map +1 -1
  53. package/build/screens/message_actions_screen.d.ts.map +1 -1
  54. package/build/screens/message_actions_screen.js +26 -21
  55. package/build/screens/message_actions_screen.js.map +1 -1
  56. package/build/screens/message_report_screen.d.ts.map +1 -1
  57. package/build/screens/message_report_screen.js +44 -17
  58. package/build/screens/message_report_screen.js.map +1 -1
  59. package/build/screens/notification_settings/hooks/groups.d.ts +4 -3
  60. package/build/screens/notification_settings/hooks/groups.d.ts.map +1 -1
  61. package/build/screens/reactions_screen.d.ts.map +1 -1
  62. package/build/screens/reactions_screen.js +88 -70
  63. package/build/screens/reactions_screen.js.map +1 -1
  64. package/build/types/api_primitives.d.ts +0 -1
  65. package/build/types/api_primitives.d.ts.map +1 -1
  66. package/build/types/api_primitives.js.map +1 -1
  67. package/build/utils/cache/messages_cache.d.ts +0 -1
  68. package/build/utils/cache/messages_cache.d.ts.map +1 -1
  69. package/build/utils/cache/messages_cache.js +0 -3
  70. package/build/utils/cache/messages_cache.js.map +1 -1
  71. package/build/utils/cache/messages_window.d.ts +11 -0
  72. package/build/utils/cache/messages_window.d.ts.map +1 -0
  73. package/build/utils/cache/messages_window.js +51 -0
  74. package/build/utils/cache/messages_window.js.map +1 -0
  75. package/build/utils/cache/optimistically_update_message.d.ts +1 -2
  76. package/build/utils/cache/optimistically_update_message.d.ts.map +1 -1
  77. package/build/utils/cache/optimistically_update_message.js +4 -4
  78. package/build/utils/cache/optimistically_update_message.js.map +1 -1
  79. package/build/utils/generate_placeholder_ulid.d.ts +6 -0
  80. package/build/utils/generate_placeholder_ulid.d.ts.map +1 -1
  81. package/build/utils/generate_placeholder_ulid.js +2 -2
  82. package/build/utils/generate_placeholder_ulid.js.map +1 -1
  83. package/build/utils/request/get_messages.d.ts +6 -18
  84. package/build/utils/request/get_messages.d.ts.map +1 -1
  85. package/build/utils/request/get_messages.js +12 -10
  86. package/build/utils/request/get_messages.js.map +1 -1
  87. package/package.json +3 -3
  88. package/src/__tests__/hooks/paginator_meta.test.ts +2 -73
  89. package/src/components/conversation/__tests__/message_list.test.tsx +0 -42
  90. package/src/components/conversation/message_form.tsx +30 -5
  91. package/src/components/conversation/message_list.tsx +44 -14
  92. package/src/components/conversation/missing_message.tsx +66 -0
  93. package/src/contexts/api_provider.tsx +1 -2
  94. package/src/contexts/conversation_context.tsx +1 -6
  95. package/src/hooks/__tests__/use_conversation_messages.test.tsx +333 -0
  96. package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +87 -0
  97. package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +33 -0
  98. package/src/hooks/paginator_meta.ts +5 -29
  99. package/src/hooks/use_api.ts +5 -4
  100. package/src/hooks/use_conversation_messages.ts +88 -43
  101. package/src/hooks/use_conversation_messages_jolt_events.ts +53 -62
  102. package/src/hooks/use_message_create_or_update.ts +8 -8
  103. package/src/hooks/use_message_reaction_toggle.ts +1 -3
  104. package/src/hooks/use_suspense_api.ts +17 -8
  105. package/src/screens/conversation_screen.tsx +63 -123
  106. package/src/screens/message_actions_screen.tsx +5 -3
  107. package/src/screens/message_report_screen.tsx +3 -2
  108. package/src/screens/reactions_screen.tsx +4 -2
  109. package/src/types/api_primitives.ts +0 -1
  110. package/src/utils/cache/__tests__/messages_cache.test.ts +1 -14
  111. package/src/utils/cache/__tests__/messages_window.test.ts +78 -0
  112. package/src/utils/cache/messages_cache.ts +0 -3
  113. package/src/utils/cache/messages_window.ts +55 -0
  114. package/src/utils/cache/optimistically_update_message.ts +5 -2
  115. package/src/utils/generate_placeholder_ulid.ts +2 -2
  116. package/src/utils/request/get_messages.ts +14 -12
  117. package/build/components/conversation/anchor_not_found_boundary.d.ts +0 -18
  118. package/build/components/conversation/anchor_not_found_boundary.d.ts.map +0 -1
  119. package/build/components/conversation/anchor_not_found_boundary.js +0 -20
  120. package/build/components/conversation/anchor_not_found_boundary.js.map +0 -1
  121. package/build/hooks/use_conversation_message_lookup.d.ts +0 -7
  122. package/build/hooks/use_conversation_message_lookup.d.ts.map +0 -1
  123. package/build/hooks/use_conversation_message_lookup.js +0 -52
  124. package/build/hooks/use_conversation_message_lookup.js.map +0 -1
  125. package/build/hooks/use_fetch_newer_messages.d.ts +0 -9
  126. package/build/hooks/use_fetch_newer_messages.d.ts.map +0 -1
  127. package/build/hooks/use_fetch_newer_messages.js +0 -69
  128. package/build/hooks/use_fetch_newer_messages.js.map +0 -1
  129. package/build/hooks/use_fetch_newer_on_foreground.d.ts +0 -8
  130. package/build/hooks/use_fetch_newer_on_foreground.d.ts.map +0 -1
  131. package/build/hooks/use_fetch_newer_on_foreground.js +0 -42
  132. package/build/hooks/use_fetch_newer_on_foreground.js.map +0 -1
  133. package/build/hooks/use_held_back_messages.d.ts +0 -11
  134. package/build/hooks/use_held_back_messages.d.ts.map +0 -1
  135. package/build/hooks/use_held_back_messages.js +0 -24
  136. package/build/hooks/use_held_back_messages.js.map +0 -1
  137. package/build/utils/cache/find_message_in_caches.d.ts +0 -4
  138. package/build/utils/cache/find_message_in_caches.d.ts.map +0 -1
  139. package/build/utils/cache/find_message_in_caches.js +0 -16
  140. package/build/utils/cache/find_message_in_caches.js.map +0 -1
  141. package/build/utils/cache/invalidate_refetchable_queries.d.ts +0 -3
  142. package/build/utils/cache/invalidate_refetchable_queries.d.ts.map +0 -1
  143. package/build/utils/cache/invalidate_refetchable_queries.js +0 -8
  144. package/build/utils/cache/invalidate_refetchable_queries.js.map +0 -1
  145. package/build/utils/cache/prepend_newer_page.d.ts +0 -7
  146. package/build/utils/cache/prepend_newer_page.d.ts.map +0 -1
  147. package/build/utils/cache/prepend_newer_page.js +0 -15
  148. package/build/utils/cache/prepend_newer_page.js.map +0 -1
  149. package/build/utils/gated_message_cache.d.ts +0 -7
  150. package/build/utils/gated_message_cache.d.ts.map +0 -1
  151. package/build/utils/gated_message_cache.js +0 -13
  152. package/build/utils/gated_message_cache.js.map +0 -1
  153. package/build/utils/ulid.d.ts +0 -3
  154. package/build/utils/ulid.d.ts.map +0 -1
  155. package/build/utils/ulid.js +0 -7
  156. package/build/utils/ulid.js.map +0 -1
  157. package/src/__tests__/hooks/use_conversation_messages.test.ts +0 -22
  158. package/src/__tests__/hooks/use_conversation_messages_jolt_events.test.ts +0 -33
  159. package/src/__tests__/utils/gated_message_cache.test.ts +0 -26
  160. package/src/__tests__/utils/request/get_messages.test.ts +0 -24
  161. package/src/__tests__/utils/ulid.test.ts +0 -15
  162. package/src/components/conversation/__tests__/anchor_not_found_boundary.test.tsx +0 -51
  163. package/src/components/conversation/anchor_not_found_boundary.tsx +0 -21
  164. package/src/hooks/__tests__/use_fetch_newer_messages.test.tsx +0 -95
  165. package/src/hooks/__tests__/use_held_back_messages.test.tsx +0 -60
  166. package/src/hooks/__tests__/use_message_reaction_toggle.test.tsx +0 -73
  167. package/src/hooks/use_conversation_message_lookup.ts +0 -29
  168. package/src/hooks/use_fetch_newer_messages.ts +0 -52
  169. package/src/hooks/use_fetch_newer_on_foreground.ts +0 -25
  170. package/src/hooks/use_held_back_messages.ts +0 -33
  171. package/src/utils/cache/__tests__/find_message_in_caches.test.ts +0 -37
  172. package/src/utils/cache/__tests__/invalidate_refetchable_queries.test.ts +0 -23
  173. package/src/utils/cache/__tests__/prepend_newer_page.test.ts +0 -34
  174. package/src/utils/cache/find_message_in_caches.ts +0 -20
  175. package/src/utils/cache/invalidate_refetchable_queries.ts +0 -9
  176. package/src/utils/cache/prepend_newer_page.ts +0 -19
  177. package/src/utils/gated_message_cache.ts +0 -19
  178. package/src/utils/ulid.ts +0 -11
@@ -7,11 +7,10 @@ import {
7
7
  useTheme as useNavigationTheme,
8
8
  useRoute,
9
9
  } from '@react-navigation/native'
10
- import React, { startTransition, useCallback, useEffect, useRef, useState } from 'react'
10
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
11
11
  import { FlatList, Platform, StyleSheet, useWindowDimensions, View } from 'react-native'
12
12
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
13
13
  import { Badge, Icon } from '../components'
14
- import { AnchorNotFoundBoundary } from '../components/conversation/anchor_not_found_boundary'
15
14
  import { ConversationStartBanner } from '../components/conversation/conversation_start_banner'
16
15
  import { JumpToBottomButton } from '../components/conversation/jump_to_bottom_button'
17
16
  import { MessageForm } from '../components/conversation/message_form'
@@ -29,11 +28,11 @@ import { ConversationContextProvider } from '../contexts/conversation_context'
29
28
  import { useMessageAvailableMembersAction } from '../hooks/direct_messages/use_message_available_members_action'
30
29
  import { useConversation } from '../hooks/use_conversation'
31
30
  import { useConversationJoltEvents } from '../hooks/use_conversation_jolt_events'
32
- import { useConversationMessages } from '../hooks/use_conversation_messages'
31
+ import {
32
+ dropMessagesWindowIfBehind,
33
+ useConversationMessages,
34
+ } from '../hooks/use_conversation_messages'
33
35
  import { useConversationMessagesJoltEvents } from '../hooks/use_conversation_messages_jolt_events'
34
- import { useFetchNewerMessages } from '../hooks/use_fetch_newer_messages'
35
- import { useFetchNewerOnForeground } from '../hooks/use_fetch_newer_on_foreground'
36
- import { useHeldBackMessages } from '../hooks/use_held_back_messages'
37
36
  import { useMarkLatestMessageRead } from '../hooks/use_mark_latest_message_read'
38
37
  import {
39
38
  analyticsEvents,
@@ -45,19 +44,16 @@ import { useVideoModerationJoltEvents } from '../hooks/use_video_moderation_jolt
45
44
  import { ConversationResource } from '../types/resources/conversation'
46
45
  import { ConversationBadgeResource } from '../types/resources/conversation_badge'
47
46
  import { MessageResource } from '../types/resources/message'
48
- import { newestPersistedMessageId } from '../utils/cache/messages_cache'
49
- import { gatedMessageCache } from '../utils/gated_message_cache'
50
- import { getMessagesQueryKey } from '../utils/request/get_messages'
51
- import { decodeUlidTime } from '../utils/ulid'
47
+ import { Log } from '../utils'
52
48
 
53
49
  export type ConversationRouteProps = {
54
50
  conversation_id: number
55
51
  reply_root_id?: string | null
52
+ initial_message_id?: string | null
56
53
  reply_root_author_name?: string
57
54
  chat_group_graph_id?: string
58
55
  clear_input?: boolean
59
56
  editing_message_id?: number | null
60
- initial_message_id?: string | null
61
57
  title?: string
62
58
  subtitle?: string
63
59
  badge?: ConversationBadgeResource
@@ -68,16 +64,9 @@ export type ConversationRouteProps = {
68
64
  export type ConversationScreenProps = StaticScreenProps<ConversationRouteProps>
69
65
 
70
66
  export function ConversationScreen({ route }: ConversationScreenProps) {
71
- const { conversation_id, reply_root_id, initial_message_id } = route.params
67
+ const { conversation_id, reply_root_id } = route.params
72
68
 
73
69
  const { data: conversation } = useConversation({ conversation_id })
74
- const [anchor, setAnchor] = useState(() =>
75
- isBeforeLatestMessage(initial_message_id, conversation?.lastMessageCreatedAt)
76
- ? initial_message_id
77
- : null
78
- )
79
- const exitAnchoredMode = useCallback(() => startTransition(() => setAnchor(null)), [])
80
- const dropAnchor = useCallback(() => setAnchor(null), [])
81
70
 
82
71
  usePublishProductAnalyticsEvent(analyticsEvents.conversation_show_opened, {
83
72
  reply_root_id,
@@ -88,83 +77,34 @@ export function ConversationScreen({ route }: ConversationScreenProps) {
88
77
  <ConversationContextProvider
89
78
  conversationId={conversation_id}
90
79
  currentPageReplyRootId={reply_root_id ?? null}
91
- messagesQueryKey={getMessagesQueryKey({ conversation_id, reply_root_id, anchor })}
92
80
  >
93
- {anchor ? (
94
- <AnchorNotFoundBoundary onAnchorNotFound={dropAnchor}>
95
- <ConversationScreenContent
96
- route={route}
97
- anchor={anchor}
98
- onExitAnchoredMode={exitAnchoredMode}
99
- />
100
- </AnchorNotFoundBoundary>
101
- ) : (
102
- <ConversationScreenContent
103
- route={route}
104
- anchor={null}
105
- onExitAnchoredMode={exitAnchoredMode}
106
- />
107
- )}
81
+ <ConversationScreenContent route={route} />
108
82
  </ConversationContextProvider>
109
83
  )
110
84
  }
111
85
 
112
- interface ConversationScreenContentProps extends ConversationScreenProps {
113
- anchor: string | null | undefined
114
- onExitAnchoredMode: () => void
115
- }
116
-
117
- function ConversationScreenContent({
118
- route,
119
- anchor,
120
- onExitAnchoredMode,
121
- }: ConversationScreenContentProps) {
86
+ function ConversationScreenContent({ route }: ConversationScreenProps) {
122
87
  const styles = useStyles()
123
88
  const navigation = useNavigation()
124
- const { conversation_id, editing_message_id, reply_root_id, reply_root_author_name } =
125
- route.params
126
- const { data: conversation } = useConversation(route.params)
127
- const anchored = !!anchor
128
89
  const {
129
- messages,
130
- fetchNextPage,
131
- hasNextPage,
132
- fetchPreviousPage,
133
- hasPreviousPage,
134
- isFetchingPreviousPage,
135
- queryKey,
136
- } = useConversationMessages({ conversation_id, reply_root_id, anchor })
137
- const behindLatest = anchored && hasPreviousPage
138
- const caughtUp = !hasPreviousPage
139
- const [showJumpToBottomButton, setShowJumpToBottomButton] = useState(false)
140
- const readingHistory = showJumpToBottomButton
141
- const newestMessageId = newestPersistedMessageId(messages)
142
- const fetchNewer = useFetchNewerMessages({
143
90
  conversation_id,
91
+ editing_message_id,
144
92
  reply_root_id,
145
- queryKey,
146
- onTooFarBehind: anchored ? onExitAnchoredMode : undefined,
147
- })
148
- const { onSkippedNewMessage } = useHeldBackMessages({
149
- fetchNewer,
150
- newestMessageId,
151
- readingHistory,
152
- caughtUp,
153
- })
93
+ reply_root_author_name,
94
+ initial_message_id,
95
+ } = route.params
96
+ const { data: conversation } = useConversation(route.params)
97
+ const { messages, behind, fetchNextPage, fetchNewer, fetchLiveWindow, hasNextPage } =
98
+ useConversationMessages({
99
+ conversation_id,
100
+ reply_root_id,
101
+ anchor: initial_message_id,
102
+ })
154
103
  useConversationJoltEvents({ conversationId: conversation_id })
155
- useConversationMessagesJoltEvents({
156
- conversationId: conversation_id,
157
- replyRootId: reply_root_id ?? null,
158
- messageCache: gatedMessageCache({
159
- queryKey,
160
- acceptNewMessages: caughtUp && !readingHistory,
161
- onSkippedNewMessage,
162
- }),
163
- })
104
+ useConversationMessagesJoltEvents({ conversationId: conversation_id })
164
105
  const { markHandledByMessageForm } = useVideoModerationJoltEvents()
165
106
  useEnsureConversationsRouteExists()
166
- useMarkLatestMessageRead({ conversation, messages, enabled: !behindLatest })
167
- useFetchNewerOnForeground({ fetchNewer, newestMessageId, enabled: anchored && caughtUp })
107
+ useMarkLatestMessageRead({ conversation, messages, enabled: !behind })
168
108
  const noMessages = messages.length === 0
169
109
 
170
110
  const { repliesDisabled, memberAbility, badges, title } = conversation
@@ -179,8 +119,12 @@ function ConversationScreenContent({
179
119
  const muted = conversation.conversationMembership?.muted ?? conversation.muted
180
120
 
181
121
  const listRef = useRef<FlatList>(null)
182
- const [hasDragged, setHasDragged] = useState(false)
183
- const holdListPosition = behindLatest || readingHistory
122
+ const [showJumpToBottomButton, setShowJumpToBottomButton] = useState(false)
123
+
124
+ const trackScroll = (event: any) => {
125
+ const offsetY = event.nativeEvent.contentOffset.y
126
+ setShowJumpToBottomButton(offsetY > 200)
127
+ }
184
128
 
185
129
  const { restOffset, onLayout, onContentSizeChange, onMomentumScrollEnd, onScrollEndDrag } =
186
130
  useRestAwayFromDismissEdge({
@@ -188,32 +132,23 @@ function ConversationScreenContent({
188
132
  enabled: Platform.OS === 'ios',
189
133
  })
190
134
 
191
- const handleReturnToBottom = useCallback(() => {
192
- listRef.current?.scrollToOffset({
193
- offset: restOffset,
194
- })
195
- }, [restOffset])
196
-
197
- const exitAnchoredMode = useCallback(() => {
198
- onExitAnchoredMode()
199
- handleReturnToBottom()
200
- }, [handleReturnToBottom, onExitAnchoredMode])
201
- const jumpToLatest = useCallback(() => {
202
- setShowJumpToBottomButton(false)
203
- if (anchored) exitAnchoredMode()
204
- else handleReturnToBottom()
205
- }, [anchored, exitAnchoredMode, handleReturnToBottom])
135
+ const [anchorMessageId, setAnchorMessageId] = useState(initial_message_id)
136
+ const releaseAnchor = useCallback(() => setAnchorMessageId(null), [])
206
137
 
207
- const trackScroll = (event: any) => {
208
- const offsetY = event.nativeEvent.contentOffset.y
209
- setShowJumpToBottomButton(offsetY > 200)
210
- }
138
+ const handleReturnToBottom = useCallback(
139
+ (animated = true) => {
140
+ releaseAnchor()
141
+ listRef.current?.scrollToOffset({ offset: restOffset, animated })
142
+ },
143
+ [releaseAnchor, restOffset]
144
+ )
211
145
 
212
- const loadNewerMessages = () => {
213
- if (!hasPreviousPage || isFetchingPreviousPage) return
146
+ const logWindowFetchFailure = (error: unknown) =>
147
+ Log.error('conversation window fetch failed', error)
214
148
 
215
- setHasDragged(false)
216
- fetchPreviousPage()
149
+ const returnToLatest = async () => {
150
+ if (behind) await fetchLiveWindow()
151
+ handleReturnToBottom(false)
217
152
  }
218
153
 
219
154
  useEffect(() => {
@@ -231,6 +166,18 @@ function ConversationScreenContent({
231
166
  }
232
167
  }, [navigation, title, badges, conversation?.deleted, reply_root_id, replyHeaderTitle, muted])
233
168
 
169
+ useEffect(() => {
170
+ if (!initial_message_id) return
171
+
172
+ navigation.setParams({ initial_message_id: null })
173
+ }, [initial_message_id, navigation])
174
+
175
+ // A window left behind the live edge would make the next open from the list start
176
+ // mid-history with no pill, so we only keep windows that are live.
177
+ useEffect(() => {
178
+ return () => dropMessagesWindowIfBehind({ conversation_id, reply_root_id })
179
+ }, [conversation_id, reply_root_id])
180
+
234
181
  if (!conversation || conversation.deleted) {
235
182
  return (
236
183
  <View style={styles.container}>
@@ -264,25 +211,23 @@ function ConversationScreenContent({
264
211
  conversationId={conversation_id}
265
212
  messages={messages}
266
213
  replyRootId={reply_root_id}
267
- anchorMessageId={anchor}
214
+ anchorMessageId={anchorMessageId}
215
+ behind={behind}
268
216
  hasNextPage={hasNextPage}
269
217
  onEndReached={() => fetchNextPage()}
218
+ onStartReached={() => fetchNewer().catch(logWindowFetchFailure)}
270
219
  onScroll={trackScroll}
271
220
  onLayout={onLayout}
272
221
  onContentSizeChange={onContentSizeChange}
273
222
  onScrollEndDrag={onScrollEndDrag}
274
223
  onMomentumScrollEnd={onMomentumScrollEnd}
275
- onScrollBeginDrag={anchored ? () => setHasDragged(true) : undefined}
276
- onStartReached={anchored && hasDragged ? loadNewerMessages : undefined}
277
- onStartReachedThreshold={anchored ? 0.5 : undefined}
278
- maintainVisibleContentPosition={
279
- holdListPosition ? { minIndexForVisible: 0 } : undefined
280
- }
281
224
  />
282
225
  )}
283
226
  <JumpToBottomButton
284
- onPress={jumpToLatest}
285
- visible={behindLatest || showJumpToBottomButton}
227
+ onPress={() =>
228
+ behind ? returnToLatest().catch(logWindowFetchFailure) : handleReturnToBottom()
229
+ }
230
+ visible={showJumpToBottomButton || behind}
286
231
  />
287
232
  {!noMessages && <TypingIndicator />}
288
233
  {showLeaderDisabledReplyBanner && <LeaderMessagesDisabledBanner />}
@@ -293,7 +238,7 @@ function ConversationScreenContent({
293
238
  replyRootId={reply_root_id}
294
239
  currentlyEditingMessage={currentlyEditingMessage}
295
240
  onFlaggedInMessageForm={markHandledByMessageForm}
296
- onBeforeSubmit={jumpToLatest}
241
+ onBeforeSubmit={returnToLatest}
297
242
  />
298
243
  </KeyboardView>
299
244
  </View>
@@ -351,11 +296,6 @@ function ConversationBottomBar({
351
296
  )
352
297
  }
353
298
 
354
- const isBeforeLatestMessage = (anchor?: string | null, latestMessageCreatedAt?: string) =>
355
- !!anchor &&
356
- !!latestMessageCreatedAt &&
357
- decodeUlidTime(anchor) < Date.parse(latestMessageCreatedAt)
358
-
359
299
  interface ConversationScreenTitleProps extends HeaderTitleProps {
360
300
  conversation_id: number
361
301
  badge?: ConversationBadgeResource
@@ -9,7 +9,6 @@ import { useReactionStyles } from '../components/conversation/message_reaction'
9
9
  import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
10
10
  import { useCreateAndroidRippleColor, useFontScale, useTheme } from '../hooks'
11
11
  import { useApiClient } from '../hooks/use_api_client'
12
- import { useConversationMessageLookup } from '../hooks/use_conversation_message_lookup'
13
12
  import { useConversationMessages } from '../hooks/use_conversation_messages'
14
13
  import { availableFeatures, useFeatures } from '../hooks/use_features'
15
14
  import { useMessageReactionToggle } from '../hooks/use_message_reaction_toggle'
@@ -46,8 +45,11 @@ export function MessageActionsScreen({ route }: MessageActionsScreenProps) {
46
45
  isSystemMessage,
47
46
  } = route.params
48
47
 
49
- const { refetch } = useConversationMessages({ conversation_id }, { refetchOnMount: false })
50
- const message = useConversationMessageLookup({ conversation_id, message_id })
48
+ const { messages, refetch } = useConversationMessages(
49
+ { conversation_id },
50
+ { refetchOnMount: false }
51
+ )
52
+ const message = messages.find(m => m.id === message_id)
51
53
 
52
54
  if (!message) return null
53
55
 
@@ -14,7 +14,7 @@ import {
14
14
  } from '../components/display/platform_modal_header_buttons'
15
15
  import BlankState from '../components/primitive/blank_state_primitive'
16
16
  import { useTheme } from '../hooks'
17
- import { useConversationMessageLookup } from '../hooks/use_conversation_message_lookup'
17
+ import { useConversationMessages } from '../hooks/use_conversation_messages'
18
18
  import { useReportMessage } from '../hooks/use_report_message'
19
19
  import { MessageResource } from '../types'
20
20
  import { MessageReportReason } from '../types/resources/message_report'
@@ -51,7 +51,8 @@ export type MessageReportScreenProps = StaticScreenProps<{
51
51
  export function MessageReportScreen({ route }: MessageReportScreenProps) {
52
52
  const { conversation_id, message_id } = route.params
53
53
 
54
- const message = useConversationMessageLookup({ conversation_id, message_id })
54
+ const { messages } = useConversationMessages({ conversation_id }, { refetchOnMount: false })
55
+ const message = messages.find(m => m.id === message_id)
55
56
 
56
57
  if (!message) return null
57
58
 
@@ -7,7 +7,7 @@ import { Avatar, Text } from '../components'
7
7
  import { Tabs } from '../components/display/tabs'
8
8
  import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
9
9
  import { useSuspenseGet, useTheme } from '../hooks'
10
- import { useConversationMessageLookup } from '../hooks/use_conversation_message_lookup'
10
+ import { useConversationMessages } from '../hooks/use_conversation_messages'
11
11
  import { useFontScale } from '../hooks/use_font_scale'
12
12
  import { MemberResource } from '../types'
13
13
  import { ReactionCountResource } from '../types/resources/reaction'
@@ -31,7 +31,9 @@ export function ReactionsScreen({ route }: ReactionScreenProps) {
31
31
  const { conversation_id, message_id, reaction_value } = route.params
32
32
  const styles = useStyles()
33
33
 
34
- const message = useConversationMessageLookup({ conversation_id, message_id })
34
+ const { messages } = useConversationMessages({ conversation_id }, { refetchOnMount: false })
35
+
36
+ const message = messages.find(m => m.id === message_id)
35
37
  const reactionCounts = message?.reactionCounts || []
36
38
  const initialReactionCount =
37
39
  reactionCounts.find(r => r.value === reaction_value) || reactionCounts[0]
@@ -33,7 +33,6 @@ export interface NextPageCursor {
33
33
  idLte?: string
34
34
  idGt?: string
35
35
  idGte?: string
36
- order?: 'asc' | 'desc'
37
36
  }
38
37
 
39
38
  export interface CollectionMeta {
@@ -1,7 +1,7 @@
1
1
  import { InfiniteData, QueryClient } from '@tanstack/react-query'
2
2
  import type { ApiCollection, MessageResource } from '../../../types'
3
3
  import type { PersonResource } from '../../../types/resources/person'
4
- import { newestPersistedMessageId, updateCacheWithMessage } from '../messages_cache'
4
+ import { updateCacheWithMessage } from '../messages_cache'
5
5
 
6
6
  type MessagesQueryData = InfiniteData<ApiCollection<MessageResource>>
7
7
 
@@ -87,16 +87,3 @@ describe('updateCacheWithMessage on message.created', () => {
87
87
  expect(idsInCache(queryClient)).toEqual(['01F', '01B-temp', '01A-temp'])
88
88
  })
89
89
  })
90
-
91
- describe('newestPersistedMessageId', () => {
92
- it('skips optimistic rows so a failed send cannot become the catch-up cursor', () => {
93
- const messages = [message({ id: '01ZZZ-temp' }), message({ id: '01B' }), message({ id: '01A' })]
94
-
95
- expect(newestPersistedMessageId(messages)).toBe('01B')
96
- })
97
-
98
- it('is undefined when nothing has been persisted', () => {
99
- expect(newestPersistedMessageId([message({ id: '01ZZZ-temp' })])).toBeUndefined()
100
- expect(newestPersistedMessageId([])).toBeUndefined()
101
- })
102
- })
@@ -0,0 +1,78 @@
1
+ import type { ApiCollection, MessageResource } from '../../../types'
2
+ import {
3
+ anchoredPageParam,
4
+ isBehindLiveEdge,
5
+ livePageParam,
6
+ markLiveIfCaughtUp,
7
+ MessagesWindow,
8
+ newestFirst,
9
+ } from '../messages_window'
10
+
11
+ const page = (meta: Partial<ApiCollection<MessageResource>['meta']> = {}) => ({
12
+ data: [],
13
+ links: {},
14
+ meta: { count: 0, totalCount: 0, ...meta },
15
+ })
16
+
17
+ const window = (
18
+ pageParam: MessagesWindow['pageParams'][number],
19
+ meta?: Partial<ApiCollection<MessageResource>['meta']>
20
+ ): MessagesWindow => ({ pages: [page(meta)], pageParams: [pageParam] })
21
+
22
+ describe('isBehindLiveEdge', () => {
23
+ it('is behind while the first page reports newer messages', () => {
24
+ expect(isBehindLiveEdge(window(anchoredPageParam('A'), { prev: { idGt: 'A' } }))).toBe(true)
25
+ })
26
+
27
+ it('is live otherwise', () => {
28
+ expect(isBehindLiveEdge(window(livePageParam))).toBe(false)
29
+ expect(isBehindLiveEdge(window(anchoredPageParam('A')))).toBe(false)
30
+ expect(isBehindLiveEdge(undefined)).toBe(false)
31
+ })
32
+ })
33
+
34
+ describe('markLiveIfCaughtUp', () => {
35
+ it('turns an anchored window with no newer side into the live window', () => {
36
+ const data = window(anchoredPageParam('A'))
37
+
38
+ expect(markLiveIfCaughtUp(data)?.pageParams).toEqual([livePageParam])
39
+ })
40
+
41
+ it('turns a window topped by a newer page into the live window once it catches up', () => {
42
+ const data = window({ where: { id_gt: 'A' }, order: 'asc' })
43
+
44
+ expect(markLiveIfCaughtUp(data)?.pageParams).toEqual([livePageParam])
45
+ })
46
+
47
+ it('leaves an anchored window that is still behind untouched', () => {
48
+ const data = window(anchoredPageParam('A'), { prev: { idGt: 'A' } })
49
+
50
+ expect(markLiveIfCaughtUp(data)).toBe(data)
51
+ })
52
+
53
+ it('leaves a live window untouched', () => {
54
+ const data = window(livePageParam)
55
+
56
+ expect(markLiveIfCaughtUp(data)).toBe(data)
57
+ })
58
+ })
59
+
60
+ describe('newestFirst', () => {
61
+ const row = (id: string) => ({ id, type: 'Message' }) as MessageResource
62
+ const ascPage = {
63
+ ...page({ next: { idGt: 'E' } }),
64
+ data: [row('D'), row('E')],
65
+ }
66
+
67
+ it('stores a newer page newest first, linking newer onward and back to older rows', () => {
68
+ const result = newestFirst(ascPage, { where: { id_gt: 'C' }, order: 'asc' })
69
+
70
+ expect(result.data.map(m => m.id)).toEqual(['E', 'D'])
71
+ expect(result.meta.prev).toEqual({ idGt: 'E' })
72
+ expect(result.meta.next).toEqual({ idLt: 'D' })
73
+ })
74
+
75
+ it('leaves newest-first pages alone', () => {
76
+ expect(newestFirst(ascPage, anchoredPageParam('A'))).toBe(ascPage)
77
+ })
78
+ })
@@ -136,9 +136,6 @@ type MessagesQueryData = InfiniteData<ApiCollection<MessageResource>>
136
136
  export function isTemporaryMessageId(messageId?: string | null): boolean {
137
137
  return !!messageId && messageId.endsWith('-temp')
138
138
  }
139
- export function newestPersistedMessageId(messages: MessageResource[]): string | undefined {
140
- return messages.find(message => !isTemporaryMessageId(message.id))?.id
141
- }
142
139
  export function isNewMessage(message?: MessageResource): boolean {
143
140
  return !message?.id || isTemporaryMessageId(message.id)
144
141
  }
@@ -0,0 +1,55 @@
1
+ import { InfiniteData } from '@tanstack/react-query'
2
+ import { ApiCollection, MessageResource } from '../../types'
3
+ import { RequestData } from '../client'
4
+
5
+ export type MessagesWindow = InfiniteData<
6
+ ApiCollection<MessageResource>,
7
+ Partial<RequestData> | undefined
8
+ >
9
+
10
+ export const livePageParam: Partial<RequestData> = {}
11
+
12
+ export const anchoredPageParam = (anchor: string): Partial<RequestData> => ({
13
+ where: { id_around: anchor },
14
+ })
15
+
16
+ export function isBehindLiveEdge(data: MessagesWindow | undefined): boolean {
17
+ return !!data?.pages[0]?.meta?.prev
18
+ }
19
+
20
+ export function newerPageParam(
21
+ firstPage: ApiCollection<MessageResource>
22
+ ): Partial<RequestData> | undefined {
23
+ const newestId = firstPage.meta?.prev?.idGt
24
+ if (!newestId) return undefined
25
+
26
+ // Without asc the server hands back the newest page instead, leaving a gap.
27
+ return { where: { id_gt: newestId }, order: 'asc' }
28
+ }
29
+
30
+ // The server returns newer pages oldest first, linking only to the next newer page.
31
+ // Storing them newest first with an older link lets a refetch replay the window
32
+ // forward from its top page like any other.
33
+ export function newestFirst<Page extends ApiCollection<MessageResource>>(
34
+ page: Page,
35
+ pageParam: Partial<RequestData> | undefined
36
+ ): Page {
37
+ if (pageParam?.order !== 'asc') return page
38
+
39
+ const data = [...page.data].reverse()
40
+ const oldest = data[data.length - 1]
41
+ return {
42
+ ...page,
43
+ data,
44
+ meta: { ...page.meta, prev: page.meta?.next, next: oldest && { idLt: oldest.id } },
45
+ }
46
+ }
47
+
48
+ export function markLiveIfCaughtUp(data: MessagesWindow | undefined): MessagesWindow | undefined {
49
+ if (!data) return data
50
+
51
+ const topIsLive = !data.pageParams[0]?.where
52
+ if (topIsLive || isBehindLiveEdge(data)) return data
53
+
54
+ return { ...data, pageParams: [livePageParam, ...data.pageParams.slice(1)] }
55
+ }
@@ -9,16 +9,19 @@ export function optimisticallyUpdateMessage({
9
9
  message,
10
10
  text,
11
11
  replyRootId,
12
- queryKey = getMessagesQueryKey({ conversation_id: conversationId, reply_root_id: replyRootId }),
13
12
  }: {
14
13
  conversationId: number
15
14
  message: MessageResource
16
15
  text: string
17
16
  replyRootId?: string | null
18
- queryKey?: unknown[]
19
17
  }) {
20
18
  type QueryData = InfiniteData<ApiCollection<MessageResource>>
21
19
 
20
+ const queryKey = getMessagesQueryKey({
21
+ conversation_id: conversationId,
22
+ reply_root_id: replyRootId,
23
+ })
24
+
22
25
  let optimisticMessage = message
23
26
 
24
27
  chatQueryClient.setQueryData<QueryData>(queryKey, data =>
@@ -1,5 +1,3 @@
1
- import { ULID_CHARS } from './ulid'
2
-
3
1
  /**
4
2
  * The actual `ulid` library depends on a secure random number generator, which looks like it
5
3
  * may require a native dependency to polyfill in React Native.
@@ -7,6 +5,8 @@ import { ULID_CHARS } from './ulid'
7
5
  * implementation that doesn't require any native dependencies.
8
6
  */
9
7
 
8
+ const ULID_CHARS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ' // Crockford's Base32
9
+
10
10
  function encodeBase32(value: number, length: number) {
11
11
  let result = ''
12
12
  for (let i = 0; i < length; i++) {
@@ -1,22 +1,17 @@
1
1
  import { getRequestQueryKey } from '../../hooks/use_suspense_api'
2
2
  import { getMessageFields, getMessagesInclude } from './messages_data_options'
3
3
 
4
- type MessagesRequestOptions = {
5
- conversation_id: number
6
- reply_root_id?: string | null
7
- anchor?: string | null
8
- }
9
-
10
4
  export const getMessagesRequestArgs = ({
11
5
  conversation_id,
12
6
  reply_root_id,
13
- anchor,
14
- }: MessagesRequestOptions) => {
7
+ }: {
8
+ conversation_id: number
9
+ reply_root_id?: string | null
10
+ }) => {
15
11
  const normalizedReplyRootId = reply_root_id ?? null
16
12
  const url = normalizedReplyRootId
17
13
  ? `/me/conversations/${conversation_id}/messages/${normalizedReplyRootId}/replies`
18
14
  : `/me/conversations/${conversation_id}/messages`
19
- const anchored = anchor ? { where: { id_around: anchor } } : {}
20
15
 
21
16
  return {
22
17
  url,
@@ -24,11 +19,18 @@ export const getMessagesRequestArgs = ({
24
19
  perPage: 25,
25
20
  fields: getMessageFields,
26
21
  include: getMessagesInclude,
27
- ...anchored,
28
22
  },
29
23
  reply_root_id: normalizedReplyRootId,
30
24
  }
31
25
  }
32
26
 
33
- export const getMessagesQueryKey = (options: MessagesRequestOptions) =>
34
- getRequestQueryKey(getMessagesRequestArgs(options))
27
+ export const getMessagesQueryKey = ({
28
+ conversation_id,
29
+ reply_root_id,
30
+ }: {
31
+ conversation_id: number
32
+ reply_root_id?: string | null
33
+ }) => {
34
+ const requestArgs = getMessagesRequestArgs({ conversation_id, reply_root_id })
35
+ return getRequestQueryKey(requestArgs)
36
+ }
@@ -1,18 +0,0 @@
1
- import React, { PropsWithChildren } from 'react';
2
- type Props = PropsWithChildren<{
3
- onAnchorNotFound: () => void;
4
- }>;
5
- export declare class AnchorNotFoundBoundary extends React.Component<Props, {
6
- recovering: boolean;
7
- }> {
8
- state: {
9
- recovering: boolean;
10
- };
11
- static getDerivedStateFromError(error: Error): {
12
- recovering: boolean;
13
- };
14
- componentDidCatch(): void;
15
- render(): React.ReactNode;
16
- }
17
- export {};
18
- //# sourceMappingURL=anchor_not_found_boundary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anchor_not_found_boundary.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/anchor_not_found_boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAGhD,KAAK,KAAK,GAAG,iBAAiB,CAAC;IAAE,gBAAgB,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC,CAAA;AAEhE,qBAAa,sBAAuB,SAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC;IACzF,KAAK;;MAAwB;IAE7B,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;IAK5C,iBAAiB;IAIjB,MAAM;CAGP"}