@planningcenter/chat-react-native 4.3.0-rc.1 → 4.3.0-rc.11
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.
- package/build/components/conversation/message_form.d.ts +2 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +167 -370
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts +5 -2
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +187 -67
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/missing_message.d.ts +2 -0
- package/build/components/conversation/missing_message.d.ts.map +1 -0
- package/build/components/conversation/missing_message.js +139 -0
- package/build/components/conversation/missing_message.js.map +1 -0
- package/build/components/display/conversation_avatar.d.ts +1 -2
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +4 -3
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts +14 -5
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +218 -42
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +58 -42
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/hooks/use_features.d.ts +2 -1
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +2 -1
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts +2 -1
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +4 -3
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_read_receipts.d.ts +4 -3
- package/build/hooks/use_read_receipts.d.ts.map +1 -1
- package/build/hooks/use_search_results.d.ts +19 -0
- package/build/hooks/use_search_results.d.ts.map +1 -0
- package/build/hooks/use_search_results.js +145 -0
- package/build/hooks/use_search_results.js.map +1 -0
- package/build/hooks/use_suspense_api.d.ts +10 -6
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +83 -63
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_screen.d.ts +1 -0
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +305 -203
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.d.ts +2 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.js +39 -24
- package/build/screens/conversation_select_recipients/components/view_more_link_row.js.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.js +159 -133
- package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
- package/build/screens/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +103 -92
- package/build/screens/message_actions_screen.js.map +1 -1
- package/build/screens/notification_settings/hooks/groups.d.ts +4 -3
- package/build/screens/notification_settings/hooks/groups.d.ts.map +1 -1
- package/build/screens/search/components/conversation_result_row.d.ts +8 -0
- package/build/screens/search/components/conversation_result_row.d.ts.map +1 -0
- package/build/screens/search/components/conversation_result_row.js +80 -0
- package/build/screens/search/components/conversation_result_row.js.map +1 -0
- package/build/screens/search/components/conversation_results.d.ts +8 -0
- package/build/screens/search/components/conversation_results.d.ts.map +1 -0
- package/build/screens/search/components/conversation_results.js +77 -0
- package/build/screens/search/components/conversation_results.js.map +1 -0
- package/build/screens/search/components/message_result_row.d.ts +8 -0
- package/build/screens/search/components/message_result_row.d.ts.map +1 -0
- package/build/screens/search/components/message_result_row.js +152 -0
- package/build/screens/search/components/message_result_row.js.map +1 -0
- package/build/screens/search/components/result_row.d.ts +10 -0
- package/build/screens/search/components/result_row.d.ts.map +1 -0
- package/build/screens/search/components/result_row.js +102 -0
- package/build/screens/search/components/result_row.js.map +1 -0
- package/build/screens/search/components/results_section.d.ts +9 -0
- package/build/screens/search/components/results_section.d.ts.map +1 -0
- package/build/screens/search/components/results_section.js +51 -0
- package/build/screens/search/components/results_section.js.map +1 -0
- package/build/screens/search/components/search_blank_states.d.ts +7 -0
- package/build/screens/search/components/search_blank_states.d.ts.map +1 -0
- package/build/screens/search/components/search_blank_states.js +72 -0
- package/build/screens/search/components/search_blank_states.js.map +1 -0
- package/build/screens/search/components/search_field.d.ts +7 -0
- package/build/screens/search/components/search_field.d.ts.map +1 -0
- package/build/screens/search/components/search_field.js +152 -0
- package/build/screens/search/components/search_field.js.map +1 -0
- package/build/screens/search/components/snippet.d.ts +8 -0
- package/build/screens/search/components/snippet.d.ts.map +1 -0
- package/build/screens/search/components/snippet.js +68 -0
- package/build/screens/search/components/snippet.js.map +1 -0
- package/build/screens/search/search_screen.d.ts +5 -0
- package/build/screens/search/search_screen.d.ts.map +1 -0
- package/build/screens/search/search_screen.js +59 -0
- package/build/screens/search/search_screen.js.map +1 -0
- package/build/types/api_primitives.d.ts +1 -0
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/types/resources/conversation.d.ts +1 -0
- package/build/types/resources/conversation.d.ts.map +1 -1
- package/build/types/resources/conversation.js.map +1 -1
- package/build/types/resources/index.d.ts +1 -0
- package/build/types/resources/index.d.ts.map +1 -1
- package/build/types/resources/index.js +1 -0
- package/build/types/resources/index.js.map +1 -1
- package/build/types/resources/search_result.d.ts +29 -0
- package/build/types/resources/search_result.d.ts.map +1 -0
- package/build/types/resources/search_result.js +2 -0
- package/build/types/resources/search_result.js.map +1 -0
- package/build/utils/cache/messages_cache.d.ts +1 -0
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +37 -1
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/cache/messages_window.d.ts +11 -0
- package/build/utils/cache/messages_window.d.ts.map +1 -0
- package/build/utils/cache/messages_window.js +51 -0
- package/build/utils/cache/messages_window.js.map +1 -0
- package/build/utils/client/types.d.ts +1 -0
- package/build/utils/client/types.d.ts.map +1 -1
- package/build/utils/client/types.js.map +1 -1
- package/build/utils/request/get_search_results.d.ts +13 -0
- package/build/utils/request/get_search_results.d.ts.map +1 -0
- package/build/utils/request/get_search_results.js +20 -0
- package/build/utils/request/get_search_results.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/hooks/use_features.test.ts +10 -2
- package/src/__utils__/query_client.ts +3 -0
- package/src/components/conversation/message_form.tsx +31 -3
- package/src/components/conversation/message_list.tsx +88 -4
- package/src/components/conversation/missing_message.tsx +66 -0
- package/src/components/display/conversation_avatar.tsx +1 -10
- package/src/hooks/__tests__/use_conversation_messages.test.tsx +333 -0
- package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +87 -0
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +33 -0
- package/src/hooks/__tests__/use_message_create_or_update.test.tsx +2 -7
- package/src/hooks/__tests__/use_search_results.test.tsx +76 -0
- package/src/hooks/use_conversation_messages.ts +103 -17
- package/src/hooks/use_conversation_messages_jolt_events.ts +12 -2
- package/src/hooks/use_features.ts +3 -2
- package/src/hooks/use_mark_latest_message_read.ts +4 -3
- package/src/hooks/use_search_results.ts +77 -0
- package/src/hooks/use_suspense_api.ts +14 -6
- package/src/navigation/index.tsx +5 -0
- package/src/screens/conversation_screen.tsx +62 -13
- package/src/screens/conversation_select_recipients/components/view_more_link_row.tsx +12 -3
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +62 -0
- package/src/screens/conversations/components/search_list_header_component.tsx +11 -0
- package/src/screens/message_actions_screen.tsx +12 -1
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +55 -0
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +65 -0
- package/src/screens/search/components/__tests__/result_row.test.tsx +33 -0
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +20 -0
- package/src/screens/search/components/__tests__/search_field.test.tsx +29 -0
- package/src/screens/search/components/conversation_result_row.tsx +36 -0
- package/src/screens/search/components/conversation_results.tsx +39 -0
- package/src/screens/search/components/message_result_row.tsx +48 -0
- package/src/screens/search/components/result_row.tsx +58 -0
- package/src/screens/search/components/results_section.tsx +34 -0
- package/src/screens/search/components/search_blank_states.tsx +34 -0
- package/src/screens/search/components/search_field.tsx +81 -0
- package/src/screens/search/components/snippet.tsx +37 -0
- package/src/screens/search/search_screen.tsx +41 -0
- package/src/types/api_primitives.ts +1 -0
- package/src/types/resources/conversation.ts +9 -0
- package/src/types/resources/index.ts +1 -0
- package/src/types/resources/search_result.ts +32 -0
- package/src/utils/__tests__/get_search_results.test.ts +24 -0
- package/src/utils/cache/__tests__/messages_cache.test.ts +2 -1
- package/src/utils/cache/__tests__/messages_cache_deletion.test.ts +97 -0
- package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +3 -2
- package/src/utils/cache/__tests__/messages_window.test.ts +78 -0
- package/src/utils/cache/messages_cache.ts +45 -1
- package/src/utils/cache/messages_window.ts +55 -0
- package/src/utils/client/types.ts +1 -0
- package/src/utils/request/get_search_results.ts +23 -0
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
updateCacheReplyRoots,
|
|
15
15
|
getThreadedMessagesQueryKey,
|
|
16
16
|
} from '../utils/cache/messages_cache'
|
|
17
|
+
import { isBehindLiveEdge, MessagesWindow } from '../utils/cache/messages_window'
|
|
17
18
|
import { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'
|
|
18
19
|
import { completeMessageCreationTracking } from '../utils/performance_tracking'
|
|
19
20
|
import { getMessageQueryKey } from '../utils/request/get_message'
|
|
@@ -39,12 +40,17 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
|
|
|
39
40
|
const { addTypingEvent, removeTypingEventById, removeAllTypingEventsByAuthorId } =
|
|
40
41
|
useTypingStatusCache(conversationId)
|
|
41
42
|
|
|
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
|
+
|
|
42
47
|
const handleMessageUpdateOrCreate = async (e: MessageCreatedEvent | MessageUpdatedEvent) => {
|
|
43
48
|
const { data } = e.data
|
|
44
49
|
const message = transformMessageEventDataToMessageResource({
|
|
45
50
|
data,
|
|
46
51
|
currentPersonId: currentPerson.id,
|
|
47
52
|
})
|
|
53
|
+
const isCreate = e.event === 'message.created'
|
|
48
54
|
const isReplyRootUpdate = e.event === 'message.updated' && data.reply_root_id === data.sort_key
|
|
49
55
|
|
|
50
56
|
if (e.event === 'message.created' && data.author_id) {
|
|
@@ -55,7 +61,9 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
// Update the main conversation cache
|
|
58
|
-
|
|
64
|
+
if (!isCreate || acceptsCreates(messagesQueryKey)) {
|
|
65
|
+
updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)
|
|
66
|
+
}
|
|
59
67
|
|
|
60
68
|
// If message has a reply_root_id, also update the threaded cache
|
|
61
69
|
if (data.reply_root_id) {
|
|
@@ -63,7 +71,9 @@ export function useConversationMessagesJoltEvents({ conversationId }: Props) {
|
|
|
63
71
|
conversationId,
|
|
64
72
|
data.reply_root_id
|
|
65
73
|
)
|
|
66
|
-
|
|
74
|
+
if (!isCreate || acceptsCreates(threadedMessagesQueryKey)) {
|
|
75
|
+
updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)
|
|
76
|
+
}
|
|
67
77
|
|
|
68
78
|
if (isReplyRootUpdate) {
|
|
69
79
|
updateCacheReplyRoots(queryClient, messagesQueryKey, message)
|
|
@@ -55,8 +55,9 @@ 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: '
|
|
59
|
-
|
|
58
|
+
search: 'QA_MOBILE_search',
|
|
59
|
+
search_rollout: 'ROLLOUT_MOBILE_search',
|
|
60
|
+
} as const satisfies Record<string, `${'QA' | 'ROLLOUT'}_${string}`>
|
|
60
61
|
|
|
61
62
|
const stableEmptyFeatures: ApiCollection<FeatureResource> = {
|
|
62
63
|
data: [],
|
|
@@ -7,9 +7,10 @@ import { useConversationsMarkRead } from './use_conversations_actions'
|
|
|
7
7
|
interface Props {
|
|
8
8
|
conversation: ConversationResource
|
|
9
9
|
messages: MessageResource[]
|
|
10
|
+
enabled?: boolean
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export function useMarkLatestMessageRead({ conversation }: Props) {
|
|
13
|
+
export function useMarkLatestMessageRead({ conversation, enabled = true }: Props) {
|
|
13
14
|
const firedOnce = useRef<boolean>(false)
|
|
14
15
|
const { markRead } = useConversationsMarkRead({ conversation })
|
|
15
16
|
const debouncedMarkRead = useMemo(
|
|
@@ -24,10 +25,10 @@ export function useMarkLatestMessageRead({ conversation }: Props) {
|
|
|
24
25
|
const isActive = appState === 'active'
|
|
25
26
|
|
|
26
27
|
useEffect(() => {
|
|
27
|
-
if (!isActive || !shouldMarkRead) return
|
|
28
|
+
if (!enabled || !isActive || !shouldMarkRead) return
|
|
28
29
|
|
|
29
30
|
firedOnce.current = true
|
|
30
31
|
|
|
31
32
|
debouncedMarkRead(true)
|
|
32
|
-
}, [debouncedMarkRead, isActive, shouldMarkRead, unreadReaction])
|
|
33
|
+
}, [debouncedMarkRead, enabled, isActive, shouldMarkRead, unreadReaction])
|
|
33
34
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
2
|
+
import { useCallback, useMemo } from 'react'
|
|
3
|
+
import type { ApiCollection } from '../types'
|
|
4
|
+
import type { SearchResultResource } from '../types/resources/search_result'
|
|
5
|
+
import {
|
|
6
|
+
getSearchResultsQueryKey,
|
|
7
|
+
getSearchResultsRequestArgs,
|
|
8
|
+
} from '../utils/request/get_search_results'
|
|
9
|
+
import { ONE_MINUTE } from '../utils/time'
|
|
10
|
+
import { useApiClient } from './use_api_client'
|
|
11
|
+
|
|
12
|
+
export type SearchResultsCollection = ApiCollection<SearchResultResource> & {
|
|
13
|
+
meta: { failedTypes?: SearchResultResource['type'][] }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type SearchResultsPageParam = { offset?: number }
|
|
17
|
+
|
|
18
|
+
export const NO_FAILED_TYPES: SearchResultResource['type'][] = []
|
|
19
|
+
|
|
20
|
+
export function useSearchResults(term: string) {
|
|
21
|
+
const apiClient = useApiClient()
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
data,
|
|
25
|
+
isPending,
|
|
26
|
+
isError,
|
|
27
|
+
isFetchNextPageError,
|
|
28
|
+
fetchNextPage,
|
|
29
|
+
hasNextPage,
|
|
30
|
+
isFetchingNextPage,
|
|
31
|
+
} = useInfiniteQuery({
|
|
32
|
+
queryKey: getSearchResultsQueryKey(term),
|
|
33
|
+
queryFn: ({ pageParam }) => {
|
|
34
|
+
const requestArgs = getSearchResultsRequestArgs(term)
|
|
35
|
+
return apiClient.chat.get<SearchResultsCollection>({
|
|
36
|
+
url: requestArgs.url,
|
|
37
|
+
data: { ...requestArgs.data, ...pageParam },
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
initialPageParam: {} as SearchResultsPageParam,
|
|
41
|
+
getNextPageParam: lastPage => nextPageParam(lastPage.meta.next?.offset),
|
|
42
|
+
enabled: term.length >= 1,
|
|
43
|
+
staleTime: ONE_MINUTE,
|
|
44
|
+
refetchOnWindowFocus: false,
|
|
45
|
+
refetchOnMount: false,
|
|
46
|
+
retry: 1,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const results = useMemo(() => uniqueResults(data?.pages.flatMap(page => page.data) ?? []), [data])
|
|
50
|
+
const failedTypes = data?.pages[0]?.meta.failedTypes ?? NO_FAILED_TYPES
|
|
51
|
+
const loadMore = useCallback(() => fetchNextPage({ cancelRefetch: false }), [fetchNextPage])
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
results,
|
|
55
|
+
failedTypes,
|
|
56
|
+
isPending,
|
|
57
|
+
isError: isError && !isFetchNextPageError,
|
|
58
|
+
isFetchNextPageError,
|
|
59
|
+
loadMore,
|
|
60
|
+
hasNextPage,
|
|
61
|
+
isFetchingNextPage,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function nextPageParam(offset?: string): SearchResultsPageParam | undefined {
|
|
66
|
+
return offset ? { offset: Number(offset) } : undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function uniqueResults(results: SearchResultResource[]) {
|
|
70
|
+
const seen = new Set<string>()
|
|
71
|
+
return results.filter(result => {
|
|
72
|
+
const key = `${result.type}:${result.id}`
|
|
73
|
+
if (seen.has(key)) return false
|
|
74
|
+
seen.add(key)
|
|
75
|
+
return true
|
|
76
|
+
})
|
|
77
|
+
}
|
|
@@ -47,17 +47,23 @@ export const useSuspenseGet = <T extends ResourceObject | ResourceObject[]>(
|
|
|
47
47
|
export type SuspensePaginatorOptions = Omit<
|
|
48
48
|
AnyUseSuspenseInfiniteQueryOptions,
|
|
49
49
|
'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'
|
|
50
|
-
>
|
|
50
|
+
> & {
|
|
51
|
+
initialPageParam?: Partial<RequestData>
|
|
52
|
+
transformPage?(
|
|
53
|
+
page: ApiCollection<ResourceObject>,
|
|
54
|
+
pageParam: Partial<RequestData> | undefined
|
|
55
|
+
): ApiCollection<ResourceObject>
|
|
56
|
+
}
|
|
51
57
|
|
|
52
58
|
export const useSuspensePaginator = <T extends ResourceObject>(
|
|
53
59
|
args: SuspenseGetOptions,
|
|
54
|
-
opts
|
|
60
|
+
{ transformPage, ...opts }: SuspensePaginatorOptions = {}
|
|
55
61
|
) => {
|
|
56
62
|
const apiClient = useApiClient()
|
|
57
63
|
const query = useSuspenseInfiniteQuery<
|
|
58
64
|
ApiCollection<T>,
|
|
59
65
|
Response,
|
|
60
|
-
InfiniteData<ApiCollection<T
|
|
66
|
+
InfiniteData<ApiCollection<T>, Partial<RequestData> | undefined>,
|
|
61
67
|
any,
|
|
62
68
|
Partial<RequestData> | undefined
|
|
63
69
|
>({
|
|
@@ -70,7 +76,8 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
70
76
|
const where = { ...argsWhere, ...pageParmWhere }
|
|
71
77
|
const app = args.app || 'chat'
|
|
72
78
|
const offset = pageParam?.offset || args.data.offset
|
|
73
|
-
const
|
|
79
|
+
const order = pageParam?.order || args.data.order
|
|
80
|
+
const data = { ...args.data, where, offset, ...(order && { order }) }
|
|
74
81
|
|
|
75
82
|
return apiClient[app]
|
|
76
83
|
.get<ApiCollection<T>>({
|
|
@@ -78,16 +85,17 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
78
85
|
data,
|
|
79
86
|
})
|
|
80
87
|
.catch(throwResponseError)
|
|
88
|
+
.then(page => (transformPage ? (transformPage(page, pageParam) as ApiCollection<T>) : page))
|
|
81
89
|
},
|
|
82
90
|
initialPageParam: {} as Partial<RequestData>,
|
|
83
91
|
getNextPageParam: lastPage => getNextPageParamFromMeta(lastPage.meta?.next),
|
|
84
|
-
...
|
|
92
|
+
...opts,
|
|
85
93
|
})
|
|
86
94
|
|
|
87
95
|
const data: T[] = query.data?.pages.flatMap(page => page.data) || []
|
|
88
96
|
const totalCount = query.data?.pages[0]?.meta?.totalCount || data.length
|
|
89
97
|
|
|
90
|
-
return { ...query, data, totalCount }
|
|
98
|
+
return { ...query, data, totalCount, infiniteData: query.data }
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
export type RequestQueryKey = [
|
package/src/navigation/index.tsx
CHANGED
|
@@ -72,6 +72,7 @@ import { NotFound } from '../screens/not_found'
|
|
|
72
72
|
import { NotificationSettingsScreen } from '../screens/notification_settings_screen'
|
|
73
73
|
import { PreferredAppSelectionScreen } from '../screens/preferred_app_selection_screen'
|
|
74
74
|
import { ReactionsScreen, ReactionsScreenOptions } from '../screens/reactions_screen'
|
|
75
|
+
import { SearchScreen, SearchScreenOptions } from '../screens/search/search_screen'
|
|
75
76
|
import { SendGiphyScreen, SendGiphyScreenOptions } from '../screens/send_giphy_screen'
|
|
76
77
|
import { SettingsScreen } from '../screens/settings_screen'
|
|
77
78
|
import {
|
|
@@ -186,6 +187,10 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
186
187
|
screen: ConversationFiltersScreen,
|
|
187
188
|
options: ConversationFiltersScreenOptions,
|
|
188
189
|
},
|
|
190
|
+
Search: {
|
|
191
|
+
screen: SearchScreen,
|
|
192
|
+
options: SearchScreenOptions,
|
|
193
|
+
},
|
|
189
194
|
Conversation: {
|
|
190
195
|
screen: ConversationScreen,
|
|
191
196
|
options: ({ route, navigation }) =>
|
|
@@ -28,7 +28,10 @@ import { ConversationContextProvider } from '../contexts/conversation_context'
|
|
|
28
28
|
import { useMessageAvailableMembersAction } from '../hooks/direct_messages/use_message_available_members_action'
|
|
29
29
|
import { useConversation } from '../hooks/use_conversation'
|
|
30
30
|
import { useConversationJoltEvents } from '../hooks/use_conversation_jolt_events'
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
dropMessagesWindowIfBehind,
|
|
33
|
+
useConversationMessages,
|
|
34
|
+
} from '../hooks/use_conversation_messages'
|
|
32
35
|
import { useConversationMessagesJoltEvents } from '../hooks/use_conversation_messages_jolt_events'
|
|
33
36
|
import { useMarkLatestMessageRead } from '../hooks/use_mark_latest_message_read'
|
|
34
37
|
import {
|
|
@@ -41,10 +44,12 @@ import { useVideoModerationJoltEvents } from '../hooks/use_video_moderation_jolt
|
|
|
41
44
|
import { ConversationResource } from '../types/resources/conversation'
|
|
42
45
|
import { ConversationBadgeResource } from '../types/resources/conversation_badge'
|
|
43
46
|
import { MessageResource } from '../types/resources/message'
|
|
47
|
+
import { Log } from '../utils'
|
|
44
48
|
|
|
45
49
|
export type ConversationRouteProps = {
|
|
46
50
|
conversation_id: number
|
|
47
51
|
reply_root_id?: string | null
|
|
52
|
+
initial_message_id?: string | null
|
|
48
53
|
reply_root_author_name?: string
|
|
49
54
|
chat_group_graph_id?: string
|
|
50
55
|
clear_input?: boolean
|
|
@@ -81,18 +86,25 @@ export function ConversationScreen({ route }: ConversationScreenProps) {
|
|
|
81
86
|
function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
82
87
|
const styles = useStyles()
|
|
83
88
|
const navigation = useNavigation()
|
|
84
|
-
const {
|
|
85
|
-
route.params
|
|
86
|
-
const { data: conversation } = useConversation(route.params)
|
|
87
|
-
const { messages, fetchNextPage, hasNextPage } = useConversationMessages({
|
|
89
|
+
const {
|
|
88
90
|
conversation_id,
|
|
91
|
+
editing_message_id,
|
|
89
92
|
reply_root_id,
|
|
90
|
-
|
|
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
|
+
})
|
|
91
103
|
useConversationJoltEvents({ conversationId: conversation_id })
|
|
92
104
|
useConversationMessagesJoltEvents({ conversationId: conversation_id })
|
|
93
105
|
const { markHandledByMessageForm } = useVideoModerationJoltEvents()
|
|
94
106
|
useEnsureConversationsRouteExists()
|
|
95
|
-
useMarkLatestMessageRead({ conversation, messages })
|
|
107
|
+
useMarkLatestMessageRead({ conversation, messages, enabled: !behind })
|
|
96
108
|
const noMessages = messages.length === 0
|
|
97
109
|
|
|
98
110
|
const { repliesDisabled, memberAbility, badges, title } = conversation
|
|
@@ -120,11 +132,24 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
120
132
|
enabled: Platform.OS === 'ios',
|
|
121
133
|
})
|
|
122
134
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
const [anchorMessageId, setAnchorMessageId] = useState(initial_message_id)
|
|
136
|
+
const releaseAnchor = useCallback(() => setAnchorMessageId(null), [])
|
|
137
|
+
|
|
138
|
+
const handleReturnToBottom = useCallback(
|
|
139
|
+
(animated = true) => {
|
|
140
|
+
releaseAnchor()
|
|
141
|
+
listRef.current?.scrollToOffset({ offset: restOffset, animated })
|
|
142
|
+
},
|
|
143
|
+
[releaseAnchor, restOffset]
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
const logWindowFetchFailure = (error: unknown) =>
|
|
147
|
+
Log.error('conversation window fetch failed', error)
|
|
148
|
+
|
|
149
|
+
const returnToLatest = async () => {
|
|
150
|
+
if (behind) await fetchLiveWindow()
|
|
151
|
+
handleReturnToBottom(false)
|
|
152
|
+
}
|
|
128
153
|
|
|
129
154
|
useEffect(() => {
|
|
130
155
|
if (reply_root_id) {
|
|
@@ -141,6 +166,18 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
141
166
|
}
|
|
142
167
|
}, [navigation, title, badges, conversation?.deleted, reply_root_id, replyHeaderTitle, muted])
|
|
143
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
|
+
|
|
144
181
|
if (!conversation || conversation.deleted) {
|
|
145
182
|
return (
|
|
146
183
|
<View style={styles.container}>
|
|
@@ -174,8 +211,11 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
174
211
|
conversationId={conversation_id}
|
|
175
212
|
messages={messages}
|
|
176
213
|
replyRootId={reply_root_id}
|
|
214
|
+
anchorMessageId={anchorMessageId}
|
|
215
|
+
behind={behind}
|
|
177
216
|
hasNextPage={hasNextPage}
|
|
178
217
|
onEndReached={() => fetchNextPage()}
|
|
218
|
+
onStartReached={() => fetchNewer().catch(logWindowFetchFailure)}
|
|
179
219
|
onScroll={trackScroll}
|
|
180
220
|
onLayout={onLayout}
|
|
181
221
|
onContentSizeChange={onContentSizeChange}
|
|
@@ -183,7 +223,12 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
183
223
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
184
224
|
/>
|
|
185
225
|
)}
|
|
186
|
-
<JumpToBottomButton
|
|
226
|
+
<JumpToBottomButton
|
|
227
|
+
onPress={() =>
|
|
228
|
+
behind ? returnToLatest().catch(logWindowFetchFailure) : handleReturnToBottom()
|
|
229
|
+
}
|
|
230
|
+
visible={showJumpToBottomButton || behind}
|
|
231
|
+
/>
|
|
187
232
|
{!noMessages && <TypingIndicator />}
|
|
188
233
|
{showLeaderDisabledReplyBanner && <LeaderMessagesDisabledBanner />}
|
|
189
234
|
<ConversationBottomBar
|
|
@@ -193,6 +238,7 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
193
238
|
replyRootId={reply_root_id}
|
|
194
239
|
currentlyEditingMessage={currentlyEditingMessage}
|
|
195
240
|
onFlaggedInMessageForm={markHandledByMessageForm}
|
|
241
|
+
onBeforeSubmit={returnToLatest}
|
|
196
242
|
/>
|
|
197
243
|
</KeyboardView>
|
|
198
244
|
</View>
|
|
@@ -206,6 +252,7 @@ interface ConversationBottomBarProps {
|
|
|
206
252
|
replyRootId: string | null | undefined
|
|
207
253
|
currentlyEditingMessage: MessageResource | undefined
|
|
208
254
|
onFlaggedInMessageForm?: (id: string) => void
|
|
255
|
+
onBeforeSubmit?: () => void
|
|
209
256
|
}
|
|
210
257
|
|
|
211
258
|
function ConversationBottomBar({
|
|
@@ -215,6 +262,7 @@ function ConversationBottomBar({
|
|
|
215
262
|
replyRootId,
|
|
216
263
|
currentlyEditingMessage,
|
|
217
264
|
onFlaggedInMessageForm,
|
|
265
|
+
onBeforeSubmit,
|
|
218
266
|
}: ConversationBottomBarProps) {
|
|
219
267
|
const messageLink = useMessageAvailableMembersAction(conversation)
|
|
220
268
|
|
|
@@ -233,6 +281,7 @@ function ConversationBottomBar({
|
|
|
233
281
|
replyRootId={replyRootId}
|
|
234
282
|
currentlyEditingMessage={currentlyEditingMessage}
|
|
235
283
|
onFlaggedInMessageForm={onFlaggedInMessageForm}
|
|
284
|
+
onBeforeSubmit={onBeforeSubmit}
|
|
236
285
|
key={
|
|
237
286
|
currentlyEditingMessage
|
|
238
287
|
? `edit-message-form-${currentlyEditingMessage.id}`
|
|
@@ -4,15 +4,24 @@ import { TextButton } from '../../../components'
|
|
|
4
4
|
interface ViewMoreLinkRowProps {
|
|
5
5
|
onPress: () => void
|
|
6
6
|
accessibilityHint: string
|
|
7
|
+
expanded?: boolean
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const ViewMoreLinkRow = ({
|
|
10
|
+
export const ViewMoreLinkRow = ({
|
|
11
|
+
accessibilityHint,
|
|
12
|
+
expanded = false,
|
|
13
|
+
onPress,
|
|
14
|
+
}: ViewMoreLinkRowProps) => {
|
|
10
15
|
const styles = useRowStyles()
|
|
11
16
|
|
|
12
17
|
return (
|
|
13
18
|
<View style={[styles.row]}>
|
|
14
|
-
<TextButton
|
|
15
|
-
|
|
19
|
+
<TextButton
|
|
20
|
+
onPress={onPress}
|
|
21
|
+
accessibilityHint={accessibilityHint}
|
|
22
|
+
accessibilityState={{ expanded }}
|
|
23
|
+
>
|
|
24
|
+
{expanded ? 'View less' : 'View more'}
|
|
16
25
|
</TextButton>
|
|
17
26
|
</View>
|
|
18
27
|
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SearchListHeaderComponent } from '../search_list_header_component'
|
|
4
|
+
|
|
5
|
+
const mockNavigate = jest.fn()
|
|
6
|
+
|
|
7
|
+
jest.mock('@react-navigation/native', () => ({
|
|
8
|
+
...jest.requireActual('@react-navigation/native'),
|
|
9
|
+
useNavigation: () => ({ setParams: jest.fn(), navigate: mockNavigate }),
|
|
10
|
+
useRoute: () => ({ params: {} }),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
jest.mock('../../../../hooks/use_groups', () => ({
|
|
14
|
+
useCanDisplayGroups: () => true,
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../../../hooks/use_direct_messages_eligible', () => ({
|
|
17
|
+
useDirectMessagesEligible: () => true,
|
|
18
|
+
}))
|
|
19
|
+
jest.mock('../../../../hooks/use_has_direct_messages', () => ({
|
|
20
|
+
useHasDirectMessages: () => true,
|
|
21
|
+
}))
|
|
22
|
+
jest.mock('../../../../hooks/use_chat_permissions', () => ({
|
|
23
|
+
useCanCreateConversations: () => true,
|
|
24
|
+
}))
|
|
25
|
+
jest.mock('../../../../hooks/use_new_conversation_entry', () => ({
|
|
26
|
+
useNewConversationEntry: () => 'select_type',
|
|
27
|
+
}))
|
|
28
|
+
jest.mock('../../../../hooks/use_current_person', () => ({
|
|
29
|
+
useCurrentPersonCache: () => ({ update: jest.fn() }),
|
|
30
|
+
}))
|
|
31
|
+
jest.mock('../../../../hooks/use_conversations_actions', () => ({
|
|
32
|
+
useMarkAllRead: () => ({ markAllRead: jest.fn(), isPending: false }),
|
|
33
|
+
}))
|
|
34
|
+
jest.mock('../../../../hooks/use_new_conversation_from_filter', () => ({
|
|
35
|
+
useNewConversationFromFilter: () => undefined,
|
|
36
|
+
}))
|
|
37
|
+
jest.mock('../../../../hooks/use_api', () => ({
|
|
38
|
+
useApiGet: () => ({ data: undefined }),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
describe('SearchListHeaderComponent search button', () => {
|
|
42
|
+
beforeEach(() => mockNavigate.mockClear())
|
|
43
|
+
|
|
44
|
+
it('navigates to Search on press', () => {
|
|
45
|
+
const view = render(<SearchListHeaderComponent />)
|
|
46
|
+
|
|
47
|
+
fireEvent.press(view.getByTestId('conversations-search-button'))
|
|
48
|
+
|
|
49
|
+
expect(mockNavigate).toHaveBeenCalledTimes(1)
|
|
50
|
+
expect(mockNavigate).toHaveBeenCalledWith('Search')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('renders the search button after the other actions', () => {
|
|
54
|
+
const view = render(<SearchListHeaderComponent />)
|
|
55
|
+
|
|
56
|
+
const buttons = view.getAllByRole('button').map(button => button.props.accessibilityLabel)
|
|
57
|
+
|
|
58
|
+
expect(buttons.indexOf('Search')).toBeGreaterThanOrEqual(0)
|
|
59
|
+
expect(buttons.indexOf('Search')).toBeGreaterThan(buttons.indexOf('Chat settings'))
|
|
60
|
+
expect(buttons.indexOf('Search')).toBeGreaterThan(buttons.indexOf('New conversation'))
|
|
61
|
+
})
|
|
62
|
+
})
|
|
@@ -110,6 +110,10 @@ export const SearchListHeaderComponent = () => {
|
|
|
110
110
|
[navigation]
|
|
111
111
|
)
|
|
112
112
|
|
|
113
|
+
const handleSearch = useCallback(() => {
|
|
114
|
+
navigation.navigate('Search')
|
|
115
|
+
}, [navigation])
|
|
116
|
+
|
|
113
117
|
const handleChatSettings = useCallback(() => {
|
|
114
118
|
navigation.navigate('ChatSettings', {})
|
|
115
119
|
}, [navigation])
|
|
@@ -188,6 +192,13 @@ export const SearchListHeaderComponent = () => {
|
|
|
188
192
|
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
189
193
|
/>
|
|
190
194
|
)}
|
|
195
|
+
<ListHeaderActionButton
|
|
196
|
+
name="general.search"
|
|
197
|
+
onPress={handleSearch}
|
|
198
|
+
accessibilityLabel="Search"
|
|
199
|
+
testID="conversations-search-button"
|
|
200
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
201
|
+
/>
|
|
191
202
|
{shouldShowHeaderFiltersButton && <ToggleButton {...moreFiltersButtonProps} />}
|
|
192
203
|
</View>
|
|
193
204
|
</View>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import { StackActions, StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
3
|
-
import { useMutation } from '@tanstack/react-query'
|
|
3
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
4
4
|
import { isNil, omitBy } from 'lodash'
|
|
5
5
|
import React, { useCallback } from 'react'
|
|
6
6
|
import { Alert, Platform, StyleSheet, View } from 'react-native'
|
|
@@ -15,6 +15,10 @@ import { useMessageReactionToggle } from '../hooks/use_message_reaction_toggle'
|
|
|
15
15
|
import { MessageResource } from '../types'
|
|
16
16
|
import { ReactionCountResource } from '../types/resources/reaction'
|
|
17
17
|
import { REACTION_EMOJIS } from '../utils'
|
|
18
|
+
import {
|
|
19
|
+
applyMessageDeletionToCaches,
|
|
20
|
+
getThreadedMessagesQueryKey,
|
|
21
|
+
} from '../utils/cache/messages_cache'
|
|
18
22
|
import { Clipboard, Haptic } from '../utils/native_adapters'
|
|
19
23
|
|
|
20
24
|
export const MessageActionsScreenOptions = getFormSheetScreenOptions({
|
|
@@ -81,6 +85,7 @@ function MessageActionsScreenContent({
|
|
|
81
85
|
}) {
|
|
82
86
|
const navigation = useNavigation()
|
|
83
87
|
const apiClient = useApiClient()
|
|
88
|
+
const queryClient = useQueryClient()
|
|
84
89
|
const styles = useStyles()
|
|
85
90
|
const { featureEnabled } = useFeatures()
|
|
86
91
|
const expandedLink = message.attachments.find(attachment => attachment.type === 'ExpandedLink')
|
|
@@ -147,6 +152,12 @@ function MessageActionsScreenContent({
|
|
|
147
152
|
mutationFn: deleteMessage,
|
|
148
153
|
mutationKey: ['deleteMessage', message.id],
|
|
149
154
|
onSuccess: () => {
|
|
155
|
+
applyMessageDeletionToCaches(queryClient, conversation_id, message)
|
|
156
|
+
if (message.replyRootId) {
|
|
157
|
+
queryClient.invalidateQueries({
|
|
158
|
+
queryKey: getThreadedMessagesQueryKey(conversation_id, message.replyRootId),
|
|
159
|
+
})
|
|
160
|
+
}
|
|
150
161
|
refetchMessages()
|
|
151
162
|
Haptic.notificationSuccess()
|
|
152
163
|
},
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import type { ConversationSearchResultResource } from '../../../../types'
|
|
4
|
+
import { ConversationResults } from '../conversation_results'
|
|
5
|
+
|
|
6
|
+
const buildResults = (count: number, prefix = 'Conversation') =>
|
|
7
|
+
Array.from({ length: count }, (_, index) => ({
|
|
8
|
+
type: 'conversation' as const,
|
|
9
|
+
id: `${prefix}-${index + 1}`,
|
|
10
|
+
title: `${prefix} ${index + 1}`,
|
|
11
|
+
url: `/conversations/${index + 1}`,
|
|
12
|
+
extra: { avatar: { previewAvatarUrls: [] } },
|
|
13
|
+
})) satisfies ConversationSearchResultResource[]
|
|
14
|
+
|
|
15
|
+
describe('ConversationResults', () => {
|
|
16
|
+
it('caps at five rows until View more is pressed, then offers View less', () => {
|
|
17
|
+
const view = render(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
18
|
+
|
|
19
|
+
expect(view.getByText('Conversation 5')).toBeTruthy()
|
|
20
|
+
expect(view.queryByText('Conversation 6')).toBeNull()
|
|
21
|
+
|
|
22
|
+
fireEvent.press(view.getByText('View more'))
|
|
23
|
+
|
|
24
|
+
expect(view.getByText('Conversation 6')).toBeTruthy()
|
|
25
|
+
expect(view.getByText('View less')).toBeTruthy()
|
|
26
|
+
expect(view.queryByText('View more')).toBeNull()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('renders no footer for five or fewer results', () => {
|
|
30
|
+
const view = render(<ConversationResults results={buildResults(4)} onSelect={jest.fn()} />)
|
|
31
|
+
|
|
32
|
+
expect(view.getByText('Conversation 4')).toBeTruthy()
|
|
33
|
+
expect(view.queryByText('View more')).toBeNull()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('stays expanded when the parent re-renders with a new results array', () => {
|
|
37
|
+
const view = render(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
38
|
+
fireEvent.press(view.getByText('View more'))
|
|
39
|
+
|
|
40
|
+
view.rerender(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
41
|
+
|
|
42
|
+
expect(view.getByText('Conversation 6')).toBeTruthy()
|
|
43
|
+
expect(view.getByText('View less')).toBeTruthy()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('passes the pressed result to onSelect', () => {
|
|
47
|
+
const onSelect = jest.fn()
|
|
48
|
+
const results = buildResults(2)
|
|
49
|
+
const view = render(<ConversationResults results={results} onSelect={onSelect} />)
|
|
50
|
+
|
|
51
|
+
fireEvent.press(view.getByText('Conversation 2'))
|
|
52
|
+
|
|
53
|
+
expect(onSelect).toHaveBeenCalledWith(results[1])
|
|
54
|
+
})
|
|
55
|
+
})
|