@planningcenter/chat-react-native 4.2.2 → 4.2.3-qa-staging.0
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/attachments/giphy_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.js +2 -2
- package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
- 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 +168 -371
- 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/conversation/system_message.js +3 -3
- package/build/components/conversation/system_message.js.map +1 -1
- 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/index.d.ts +1 -0
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.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_debounced_search_term.d.ts +2 -0
- package/build/hooks/use_debounced_search_term.d.ts.map +1 -0
- package/build/hooks/use_debounced_search_term.js +40 -0
- package/build/hooks/use_debounced_search_term.js.map +1 -0
- package/build/hooks/use_direct_message_eligibility.d.ts +14 -0
- package/build/hooks/use_direct_message_eligibility.d.ts.map +1 -0
- package/build/hooks/use_direct_message_eligibility.js +87 -0
- package/build/hooks/use_direct_message_eligibility.js.map +1 -0
- 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 +153 -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/age_check/age_check_underage_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.js +3 -2
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/bug_report_screen.d.ts.map +1 -1
- package/build/screens/bug_report_screen.js +2 -2
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/conversation_new/components/services_form.js +9 -8
- package/build/screens/conversation_new/components/services_form.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/conversation_select_recipients/conversation_select_direct_message_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js +142 -158
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.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/get_help_screen.js +4 -4
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +109 -94
- 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/search_results_list.d.ts +8 -0
- package/build/screens/search/components/search_results_list.d.ts.map +1 -0
- package/build/screens/search/components/search_results_list.js +314 -0
- package/build/screens/search/components/search_results_list.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 +68 -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/member.d.ts +1 -0
- package/build/types/resources/member.d.ts.map +1 -1
- package/build/types/resources/member.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/request_helpers.js +1 -1
- package/build/utils/client/request_helpers.js.map +1 -1
- 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/group_messages.js +4 -1
- package/build/utils/group_messages.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 +3 -3
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
- package/src/__tests__/hooks/use_direct_message_eligibility.test.tsx +83 -0
- package/src/__tests__/hooks/use_features.test.ts +10 -2
- package/src/__tests__/screens/conversation_new/components/services_form.test.tsx +91 -0
- package/src/__tests__/screens/get_help_screen.test.ts +40 -0
- package/src/__tests__/screens/message_actions_screen.test.tsx +136 -0
- package/src/__tests__/utils/client.ts +3 -4
- package/src/__utils__/query_client.ts +3 -0
- package/src/components/conversation/__tests__/message_form.test.tsx +78 -0
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
- 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/conversation/system_message.tsx +3 -3
- 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_debounced_search_term.test.tsx +38 -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 +88 -0
- package/src/hooks/index.ts +1 -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_debounced_search_term.ts +20 -0
- package/src/hooks/use_direct_message_eligibility.ts +40 -0
- 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 +78 -0
- package/src/hooks/use_suspense_api.ts +14 -6
- package/src/navigation/index.tsx +5 -0
- package/src/screens/age_check/age_check_underage_screen.tsx +3 -2
- package/src/screens/bug_report_screen.tsx +2 -10
- package/src/screens/conversation_new/components/services_form.tsx +5 -5
- 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/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +3 -8
- 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/get_help_screen.tsx +4 -4
- package/src/screens/message_actions_screen.tsx +18 -3
- package/src/screens/search/__tests__/search_screen.test.tsx +64 -0
- 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/__tests__/search_results_list.test.tsx +135 -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/search_results_list.tsx +147 -0
- package/src/screens/search/components/snippet.tsx +37 -0
- package/src/screens/search/search_screen.tsx +49 -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/member.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/__tests__/group_messages.test.ts +29 -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/__tests__/request_helpers.test.ts +40 -0
- package/src/utils/client/request_helpers.ts +1 -1
- package/src/utils/client/types.ts +1 -0
- package/src/utils/group_messages.ts +4 -1
- package/src/utils/request/get_search_results.ts +23 -0
|
@@ -1,33 +1,119 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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'
|
|
3
14
|
import { replaceEqualById } from '../utils/replace_equal_by_id'
|
|
4
15
|
import { getMessagesQueryKey, getMessagesRequestArgs } from '../utils/request/get_messages'
|
|
16
|
+
import { useApiClient } from './use_api_client'
|
|
5
17
|
import { SuspensePaginatorOptions, useSuspensePaginator } from './use_suspense_api'
|
|
6
18
|
|
|
19
|
+
type WindowOptions = { conversation_id: number; reply_root_id?: string | null }
|
|
20
|
+
type Options = WindowOptions & { anchor?: string | null }
|
|
21
|
+
|
|
7
22
|
export const useConversationMessages = (
|
|
8
|
-
{ conversation_id, reply_root_id }:
|
|
23
|
+
{ conversation_id, reply_root_id, anchor }: Options,
|
|
9
24
|
opts?: SuspensePaginatorOptions
|
|
10
25
|
) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
getMessagesRequestArgs({ conversation_id, reply_root_id }),
|
|
14
|
-
{
|
|
15
|
-
structuralSharing: replaceEqualById,
|
|
16
|
-
...opts,
|
|
17
|
-
}
|
|
18
|
-
)
|
|
26
|
+
const queryClient = useQueryClient()
|
|
27
|
+
const apiClient = useApiClient()
|
|
19
28
|
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
|
+
|
|
20
67
|
const messages = useMemo(
|
|
21
68
|
() =>
|
|
22
69
|
data
|
|
23
|
-
.filter(
|
|
24
|
-
message =>
|
|
25
|
-
(!message.deletedAt || message.replyRootId) &&
|
|
26
|
-
(message.attachments?.length || message.text?.length)
|
|
27
|
-
)
|
|
70
|
+
.filter(message => message.deletedAt || message.attachments?.length || message.text?.length)
|
|
28
71
|
.sort((a, b) => -a.id.localeCompare(b.id)),
|
|
29
72
|
[data]
|
|
30
73
|
)
|
|
31
74
|
|
|
32
|
-
|
|
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 })
|
|
33
119
|
}
|
|
@@ -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)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const DEFAULT_DELAY_MS = 200
|
|
4
|
+
|
|
5
|
+
export function useDebouncedSearchTerm(term: string, delayMs = DEFAULT_DELAY_MS) {
|
|
6
|
+
const [debouncedTerm, setDebouncedTerm] = useState('')
|
|
7
|
+
const trimmedTerm = term.trim()
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (trimmedTerm.length === 0) {
|
|
11
|
+
setDebouncedTerm('')
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const timer = setTimeout(() => setDebouncedTerm(trimmedTerm), delayMs)
|
|
16
|
+
return () => clearTimeout(timer)
|
|
17
|
+
}, [trimmedTerm, delayMs])
|
|
18
|
+
|
|
19
|
+
return debouncedTerm
|
|
20
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { ApiResource, MemberResource } from '../types'
|
|
3
|
+
import { useApiClient } from './use_api_client'
|
|
4
|
+
|
|
5
|
+
export interface DirectMessageEligibility {
|
|
6
|
+
canDirectMessage: boolean
|
|
7
|
+
directMessagesDisabled: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useDirectMessageEligibility({
|
|
11
|
+
groupId,
|
|
12
|
+
personId,
|
|
13
|
+
enabled = true,
|
|
14
|
+
}: {
|
|
15
|
+
groupId: string
|
|
16
|
+
personId: number
|
|
17
|
+
enabled?: boolean
|
|
18
|
+
}) {
|
|
19
|
+
const apiClient = useApiClient()
|
|
20
|
+
const url = `/me/groups/${groupId}/members/${personId}`
|
|
21
|
+
|
|
22
|
+
const { data, isLoading, isError } = useQuery({
|
|
23
|
+
queryKey: ['chat', url, 'direct_message_eligibility'],
|
|
24
|
+
queryFn: () =>
|
|
25
|
+
apiClient.chat.get({
|
|
26
|
+
url,
|
|
27
|
+
data: { fields: { Member: ['can_direct_message', 'direct_messages_disabled'] } },
|
|
28
|
+
}) as Promise<ApiResource<MemberResource>>,
|
|
29
|
+
enabled,
|
|
30
|
+
retry: false,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const member = data?.data
|
|
34
|
+
const eligibility: DirectMessageEligibility | undefined = member && {
|
|
35
|
+
canDirectMessage: member.canDirectMessage ?? false,
|
|
36
|
+
directMessagesDisabled: member.directMessagesDisabled ?? false,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { eligibility, isLoading, isError }
|
|
40
|
+
}
|
|
@@ -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,78 @@
|
|
|
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
|
+
const trimmedTerm = term.trim()
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
data,
|
|
26
|
+
isPending,
|
|
27
|
+
isError,
|
|
28
|
+
isFetchNextPageError,
|
|
29
|
+
fetchNextPage,
|
|
30
|
+
hasNextPage,
|
|
31
|
+
isFetchingNextPage,
|
|
32
|
+
} = useInfiniteQuery({
|
|
33
|
+
queryKey: getSearchResultsQueryKey(trimmedTerm),
|
|
34
|
+
queryFn: ({ pageParam }) => {
|
|
35
|
+
const requestArgs = getSearchResultsRequestArgs(trimmedTerm)
|
|
36
|
+
return apiClient.chat.get<SearchResultsCollection>({
|
|
37
|
+
url: requestArgs.url,
|
|
38
|
+
data: { ...requestArgs.data, ...pageParam },
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
initialPageParam: {} as SearchResultsPageParam,
|
|
42
|
+
getNextPageParam: lastPage => nextPageParam(lastPage.meta.next?.offset),
|
|
43
|
+
enabled: trimmedTerm.length >= 1,
|
|
44
|
+
staleTime: ONE_MINUTE,
|
|
45
|
+
refetchOnWindowFocus: false,
|
|
46
|
+
refetchOnMount: false,
|
|
47
|
+
retry: 1,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const results = useMemo(() => uniqueResults(data?.pages.flatMap(page => page.data) ?? []), [data])
|
|
51
|
+
const failedTypes = data?.pages[0]?.meta.failedTypes ?? NO_FAILED_TYPES
|
|
52
|
+
const loadMore = useCallback(() => fetchNextPage({ cancelRefetch: false }), [fetchNextPage])
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
results,
|
|
56
|
+
failedTypes,
|
|
57
|
+
isPending,
|
|
58
|
+
isError: isError && !isFetchNextPageError,
|
|
59
|
+
isFetchNextPageError,
|
|
60
|
+
loadMore,
|
|
61
|
+
hasNextPage,
|
|
62
|
+
isFetchingNextPage,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function nextPageParam(offset?: string): SearchResultsPageParam | undefined {
|
|
67
|
+
return offset ? { offset: Number(offset) } : undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function uniqueResults(results: SearchResultResource[]) {
|
|
71
|
+
const seen = new Set<string>()
|
|
72
|
+
return results.filter(result => {
|
|
73
|
+
const key = `${result.type}:${result.id}`
|
|
74
|
+
if (seen.has(key)) return false
|
|
75
|
+
seen.add(key)
|
|
76
|
+
return true
|
|
77
|
+
})
|
|
78
|
+
}
|
|
@@ -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 }) =>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useRoute, RouteProp } from '@react-navigation/native'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Linking, StyleSheet, View, ScrollView } from 'react-native'
|
|
3
|
+
import { Linking as RNLinking, StyleSheet, View, ScrollView } from 'react-native'
|
|
4
4
|
import { Heading } from '../../components'
|
|
5
5
|
import { Icon, Text, TextInlineButton } from '../../components/display'
|
|
6
6
|
import { useTheme } from '../../hooks'
|
|
7
|
+
import { Linking } from '../../utils'
|
|
7
8
|
import type { AgeCheckParams } from './screen_props'
|
|
8
9
|
|
|
9
10
|
export interface AgeCheckUnderageScreenProps {
|
|
@@ -18,7 +19,7 @@ export function AgeCheckUnderageScreen({ contactEmail }: AgeCheckUnderageScreenP
|
|
|
18
19
|
|
|
19
20
|
const openChurchAdminHelp = () => {
|
|
20
21
|
if (!email) return
|
|
21
|
-
|
|
22
|
+
RNLinking.openURL(`mailto:${email}`)
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const openTerms = () => {
|
|
@@ -5,15 +5,7 @@ import type {
|
|
|
5
5
|
} from '@react-navigation/native-stack'
|
|
6
6
|
import { startsWith } from 'lodash'
|
|
7
7
|
import React, { useCallback, useState } from 'react'
|
|
8
|
-
import {
|
|
9
|
-
View,
|
|
10
|
-
StyleSheet,
|
|
11
|
-
TextInput,
|
|
12
|
-
Linking,
|
|
13
|
-
ScrollView,
|
|
14
|
-
TouchableOpacity,
|
|
15
|
-
Platform,
|
|
16
|
-
} from 'react-native'
|
|
8
|
+
import { View, StyleSheet, TextInput, ScrollView, TouchableOpacity, Platform } from 'react-native'
|
|
17
9
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
18
10
|
import {
|
|
19
11
|
Button,
|
|
@@ -38,7 +30,7 @@ import { useTheme } from '../hooks'
|
|
|
38
30
|
import { useAppName } from '../hooks/use_app_name'
|
|
39
31
|
import { useReportBugAction } from '../hooks/use_report_bug_action'
|
|
40
32
|
import { useUploadClient } from '../hooks/use_upload_client'
|
|
41
|
-
import { ImagePicker, ImagePickerResult, platformFontWeightBold } from '../utils'
|
|
33
|
+
import { ImagePicker, ImagePickerResult, Linking, platformFontWeightBold } from '../utils'
|
|
42
34
|
|
|
43
35
|
const MAX_DESCRIPTION_LENGTH = 2000
|
|
44
36
|
|
|
@@ -45,6 +45,7 @@ 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)
|
|
48
49
|
const initialState = useMemo(() => uniq(initialTeamIds) || [], [initialTeamIds]) // Uniq here because services can send duplicates in the teams_i_lead response.
|
|
49
50
|
const [selectedTeamIds, setSelectedTeamIds] = useState<number[]>(initialState)
|
|
50
51
|
|
|
@@ -52,6 +53,7 @@ export const ServicesForm = ({
|
|
|
52
53
|
useEffect(() => {
|
|
53
54
|
setSelectedTeamIds(initialState)
|
|
54
55
|
setSelectedPlanId(initialPlanId)
|
|
56
|
+
setFilterByPlan(!!initialPlanId)
|
|
55
57
|
}, [initialState, initialPlanId])
|
|
56
58
|
|
|
57
59
|
const removeSelection = useCallback(
|
|
@@ -61,9 +63,7 @@ export const ServicesForm = ({
|
|
|
61
63
|
[selectedTeamIds]
|
|
62
64
|
)
|
|
63
65
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
const activePlanId = filerByPlan ? selectedPlanId : undefined
|
|
66
|
+
const activePlanId = filterByPlan ? 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:
|
|
82
|
+
planId: activePlanId,
|
|
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={
|
|
121
|
+
filterByPlan={filterByPlan}
|
|
122
122
|
setFilterByPlan={setFilterByPlan}
|
|
123
123
|
members={members}
|
|
124
124
|
isMemberError={isMemberError}
|