@planningcenter/chat-react-native 4.3.0-rc.1 → 4.3.0-rc.10
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/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/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/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/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__/search_blank_states.test.tsx +20 -0
- package/src/screens/search/components/__tests__/search_field.test.tsx +29 -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/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
|
@@ -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,20 @@
|
|
|
1
|
+
import { render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { NoResultsBlankState, SearchPromptBlankState } from '../search_blank_states'
|
|
4
|
+
|
|
5
|
+
describe('SearchPromptBlankState', () => {
|
|
6
|
+
it('renders the prompt heading', () => {
|
|
7
|
+
const view = render(<SearchPromptBlankState />)
|
|
8
|
+
|
|
9
|
+
expect(view.getByText('Search chat')).toBeTruthy()
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('NoResultsBlankState', () => {
|
|
14
|
+
it('renders the heading and the searched term', () => {
|
|
15
|
+
const view = render(<NoResultsBlankState term="budget" />)
|
|
16
|
+
|
|
17
|
+
expect(view.getByText('No results')).toBeTruthy()
|
|
18
|
+
expect(view.getByText(/Nothing matches “budget\.”/)).toBeTruthy()
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SearchField } from '../search_field'
|
|
4
|
+
|
|
5
|
+
const inputLabel = 'Search titles and messages'
|
|
6
|
+
const clearLabel = 'Clear search'
|
|
7
|
+
|
|
8
|
+
describe('SearchField', () => {
|
|
9
|
+
it('reports typed text through onChange', () => {
|
|
10
|
+
const onChange = jest.fn()
|
|
11
|
+
const view = render(<SearchField term="" onChange={onChange} />)
|
|
12
|
+
|
|
13
|
+
fireEvent.changeText(view.getByLabelText(inputLabel), 'budget')
|
|
14
|
+
|
|
15
|
+
expect(onChange).toHaveBeenCalledWith('budget')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('shows the clear button only for a non-empty term and clears on press', () => {
|
|
19
|
+
const onChange = jest.fn()
|
|
20
|
+
const view = render(<SearchField term="" onChange={onChange} />)
|
|
21
|
+
|
|
22
|
+
expect(view.queryByLabelText(clearLabel)).toBeNull()
|
|
23
|
+
|
|
24
|
+
view.rerender(<SearchField term="budget" onChange={onChange} />)
|
|
25
|
+
fireEvent.press(view.getByLabelText(clearLabel))
|
|
26
|
+
|
|
27
|
+
expect(onChange).toHaveBeenCalledWith('')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import BlankState from '../../../components/primitive/blank_state_primitive'
|
|
3
|
+
|
|
4
|
+
export function SearchPromptBlankState() {
|
|
5
|
+
return (
|
|
6
|
+
<BlankState.Root>
|
|
7
|
+
<BlankState.Imagery name="general.search" />
|
|
8
|
+
<BlankState.Content>
|
|
9
|
+
<BlankState.Heading>Search chat</BlankState.Heading>
|
|
10
|
+
<BlankState.Text>
|
|
11
|
+
Find conversations by title, or search for words from a message.
|
|
12
|
+
</BlankState.Text>
|
|
13
|
+
</BlankState.Content>
|
|
14
|
+
</BlankState.Root>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface NoResultsBlankStateProps {
|
|
19
|
+
term: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function NoResultsBlankState({ term }: NoResultsBlankStateProps) {
|
|
23
|
+
return (
|
|
24
|
+
<BlankState.Root>
|
|
25
|
+
<BlankState.Imagery name="general.search" />
|
|
26
|
+
<BlankState.Content>
|
|
27
|
+
<BlankState.Heading>No results</BlankState.Heading>
|
|
28
|
+
<BlankState.Text>
|
|
29
|
+
Nothing matches “{term}.” Try a conversation title, or a word from a message.
|
|
30
|
+
</BlankState.Text>
|
|
31
|
+
</BlankState.Content>
|
|
32
|
+
</BlankState.Root>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useRef } from 'react'
|
|
2
|
+
import { Pressable, StyleSheet, TextInput, View } from 'react-native'
|
|
3
|
+
import { Icon } from '../../../components'
|
|
4
|
+
import { AutoFocusAwareTextInput } from '../../../components/display/text_input'
|
|
5
|
+
import { useTheme } from '../../../hooks'
|
|
6
|
+
|
|
7
|
+
const PLACEHOLDER = 'Search titles and messages'
|
|
8
|
+
|
|
9
|
+
interface SearchFieldProps {
|
|
10
|
+
term: string
|
|
11
|
+
onChange: (term: string) => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function SearchField({ term, onChange }: SearchFieldProps) {
|
|
15
|
+
const styles = useStyles()
|
|
16
|
+
const { colors } = useTheme()
|
|
17
|
+
const inputRef = useRef<TextInput>(null)
|
|
18
|
+
|
|
19
|
+
const clear = () => {
|
|
20
|
+
onChange('')
|
|
21
|
+
inputRef.current?.clear()
|
|
22
|
+
inputRef.current?.focus()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<View style={styles.container}>
|
|
27
|
+
<View style={styles.field}>
|
|
28
|
+
<Icon name="general.search" size={16} color={colors.iconColorDefaultSecondary} />
|
|
29
|
+
<AutoFocusAwareTextInput
|
|
30
|
+
autoFocus
|
|
31
|
+
autoCorrect={false}
|
|
32
|
+
inputRef={inputRef}
|
|
33
|
+
placeholder={PLACEHOLDER}
|
|
34
|
+
placeholderTextColor={colors.textColorDefaultPlaceholder}
|
|
35
|
+
accessibilityLabel={PLACEHOLDER}
|
|
36
|
+
value={term}
|
|
37
|
+
onChangeText={onChange}
|
|
38
|
+
returnKeyType="search"
|
|
39
|
+
style={styles.input}
|
|
40
|
+
/>
|
|
41
|
+
{term.length > 0 && (
|
|
42
|
+
<Pressable
|
|
43
|
+
onPress={clear}
|
|
44
|
+
hitSlop={8}
|
|
45
|
+
accessibilityRole="button"
|
|
46
|
+
accessibilityLabel="Clear search"
|
|
47
|
+
>
|
|
48
|
+
<Icon name="general.x" size={12} color={colors.iconColorDefaultSecondary} />
|
|
49
|
+
</Pressable>
|
|
50
|
+
)}
|
|
51
|
+
</View>
|
|
52
|
+
</View>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const useStyles = () => {
|
|
57
|
+
const { colors } = useTheme()
|
|
58
|
+
|
|
59
|
+
return StyleSheet.create({
|
|
60
|
+
container: {
|
|
61
|
+
paddingHorizontal: 16,
|
|
62
|
+
paddingVertical: 8,
|
|
63
|
+
},
|
|
64
|
+
field: {
|
|
65
|
+
flexDirection: 'row',
|
|
66
|
+
alignItems: 'center',
|
|
67
|
+
gap: 8,
|
|
68
|
+
borderWidth: 1,
|
|
69
|
+
borderColor: colors.borderColorDefaultBase,
|
|
70
|
+
borderRadius: 8,
|
|
71
|
+
paddingHorizontal: 12,
|
|
72
|
+
paddingVertical: 8,
|
|
73
|
+
},
|
|
74
|
+
input: {
|
|
75
|
+
flex: 1,
|
|
76
|
+
color: colors.textColorDefaultPrimary,
|
|
77
|
+
fontSize: 16,
|
|
78
|
+
paddingVertical: 2,
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ParamListBase } from '@react-navigation/native'
|
|
2
|
+
import {
|
|
3
|
+
NativeStackNavigationOptions,
|
|
4
|
+
NativeStackScreenProps,
|
|
5
|
+
} from '@react-navigation/native-stack'
|
|
6
|
+
import React, { useState } from 'react'
|
|
7
|
+
import { StyleSheet, View } from 'react-native'
|
|
8
|
+
import { KeyboardView } from '../../components'
|
|
9
|
+
import {
|
|
10
|
+
composeOptions,
|
|
11
|
+
withMinimalBack,
|
|
12
|
+
} from '../../components/display/platform_modal_header_buttons'
|
|
13
|
+
import { SearchPromptBlankState } from './components/search_blank_states'
|
|
14
|
+
import { SearchField } from './components/search_field'
|
|
15
|
+
|
|
16
|
+
export const SearchScreenOptions = ({
|
|
17
|
+
navigation,
|
|
18
|
+
}: NativeStackScreenProps<ParamListBase>): NativeStackNavigationOptions =>
|
|
19
|
+
composeOptions(
|
|
20
|
+
{ title: 'Search', animation: 'fade' },
|
|
21
|
+
withMinimalBack({ onPress: () => navigation.goBack() })
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export function SearchScreen() {
|
|
25
|
+
const [term, setTerm] = useState('')
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<KeyboardView>
|
|
29
|
+
<View style={styles.container} testID="search-screen">
|
|
30
|
+
<SearchField term={term} onChange={setTerm} />
|
|
31
|
+
<SearchPromptBlankState />
|
|
32
|
+
</View>
|
|
33
|
+
</KeyboardView>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
|
+
container: {
|
|
39
|
+
flex: 1,
|
|
40
|
+
},
|
|
41
|
+
})
|
|
@@ -46,3 +46,12 @@ export interface ConversationResource {
|
|
|
46
46
|
unreadReaction: boolean
|
|
47
47
|
updatedAt: string
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
export type ConversationAvatarData = Pick<
|
|
51
|
+
ConversationResource,
|
|
52
|
+
| 'customAvatarType'
|
|
53
|
+
| 'customAvatarKey'
|
|
54
|
+
| 'customAvatarColor'
|
|
55
|
+
| 'customAvatarImageUrl'
|
|
56
|
+
| 'previewAvatarUrls'
|
|
57
|
+
>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ConversationAvatarData } from './conversation'
|
|
2
|
+
|
|
3
|
+
interface BaseSearchResultResource {
|
|
4
|
+
id: string
|
|
5
|
+
title: string
|
|
6
|
+
url: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SnippetSegment {
|
|
10
|
+
text: string
|
|
11
|
+
match: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ConversationSearchResultResource extends BaseSearchResultResource {
|
|
15
|
+
type: 'conversation'
|
|
16
|
+
extra: {
|
|
17
|
+
avatar: ConversationAvatarData
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface MessageSearchResultResource extends BaseSearchResultResource {
|
|
22
|
+
type: 'message'
|
|
23
|
+
extra: {
|
|
24
|
+
conversationId: number
|
|
25
|
+
authorName: string
|
|
26
|
+
snippet: SnippetSegment[]
|
|
27
|
+
createdAt: string
|
|
28
|
+
avatar: ConversationAvatarData
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type SearchResultResource = ConversationSearchResultResource | MessageSearchResultResource
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSearchResultsQueryKey,
|
|
3
|
+
getSearchResultsRequestArgs,
|
|
4
|
+
} from '../request/get_search_results'
|
|
5
|
+
|
|
6
|
+
describe('getSearchResultsRequestArgs', () => {
|
|
7
|
+
it('requests the first page of search results for the term', () => {
|
|
8
|
+
expect(getSearchResultsRequestArgs('potluck')).toEqual({
|
|
9
|
+
url: '/search_results',
|
|
10
|
+
data: {
|
|
11
|
+
q: 'potluck',
|
|
12
|
+
perPage: 20,
|
|
13
|
+
fields: { SearchResult: ['type', 'title', 'url', 'extra'] },
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe('getSearchResultsQueryKey', () => {
|
|
20
|
+
it('changes with the term', () => {
|
|
21
|
+
expect(getSearchResultsQueryKey('potluck')).not.toEqual(getSearchResultsQueryKey('picnic'))
|
|
22
|
+
expect(getSearchResultsQueryKey('potluck')).toEqual(getSearchResultsQueryKey('potluck'))
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InfiniteData, QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
2
3
|
import type { ApiCollection, MessageResource } from '../../../types'
|
|
3
4
|
import type { PersonResource } from '../../../types/resources/person'
|
|
4
5
|
import { updateCacheWithMessage } from '../messages_cache'
|
|
@@ -44,7 +45,7 @@ describe('updateCacheWithMessage on message.created', () => {
|
|
|
44
45
|
let queryClient: QueryClient
|
|
45
46
|
|
|
46
47
|
beforeEach(() => {
|
|
47
|
-
queryClient =
|
|
48
|
+
queryClient = buildTestQueryClient()
|
|
48
49
|
seed(
|
|
49
50
|
queryClient,
|
|
50
51
|
message({ id: '01B-temp', idempotentKey: 'key-b', pending: true }),
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { InfiniteData, QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
3
|
+
import type { ApiCollection, ApiResource, MessageResource } from '../../../types'
|
|
4
|
+
import type { PersonResource } from '../../../types/resources/person'
|
|
5
|
+
import { getMessageQueryKey } from '../../request/get_message'
|
|
6
|
+
import { getMessagesQueryKey } from '../../request/get_messages'
|
|
7
|
+
import { applyMessageDeletionToCaches, getThreadedMessagesQueryKey } from '../messages_cache'
|
|
8
|
+
|
|
9
|
+
type MessagesQueryData = InfiniteData<ApiCollection<MessageResource>>
|
|
10
|
+
|
|
11
|
+
const conversation_id = 7
|
|
12
|
+
const author = { id: 1, type: 'Person', name: 'Gina', avatar: null } as unknown as PersonResource
|
|
13
|
+
|
|
14
|
+
const message = (id: string, overrides: Partial<MessageResource> = {}): MessageResource =>
|
|
15
|
+
({
|
|
16
|
+
type: 'Message',
|
|
17
|
+
id,
|
|
18
|
+
text: `msg ${id}`,
|
|
19
|
+
html: '',
|
|
20
|
+
createdAt: '2026-01-01T00:00:00Z',
|
|
21
|
+
deletedAt: null,
|
|
22
|
+
textEditedAt: null,
|
|
23
|
+
mine: true,
|
|
24
|
+
attachments: [],
|
|
25
|
+
author,
|
|
26
|
+
reactionCounts: [],
|
|
27
|
+
replyCount: 0,
|
|
28
|
+
replyRootId: null,
|
|
29
|
+
messageType: 'message',
|
|
30
|
+
...overrides,
|
|
31
|
+
}) as MessageResource
|
|
32
|
+
|
|
33
|
+
const mainKey = getMessagesQueryKey({ conversation_id })
|
|
34
|
+
const threadKey = getThreadedMessagesQueryKey(conversation_id, 'root')
|
|
35
|
+
const rootKey = getMessageQueryKey({ conversation_id, messageId: 'root' })
|
|
36
|
+
|
|
37
|
+
const seedPages = (queryClient: QueryClient, queryKey: unknown[], messages: MessageResource[]) =>
|
|
38
|
+
queryClient.setQueryData<MessagesQueryData>(queryKey, {
|
|
39
|
+
pageParams: [{}],
|
|
40
|
+
pages: [{ data: messages, links: {}, meta: { count: messages.length, totalCount: 1 } }],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const pageMessages = (queryClient: QueryClient, queryKey: unknown[]) =>
|
|
44
|
+
queryClient.getQueryData<MessagesQueryData>(queryKey)!.pages[0].data
|
|
45
|
+
|
|
46
|
+
describe('applyMessageDeletionToCaches', () => {
|
|
47
|
+
let queryClient: QueryClient
|
|
48
|
+
const root = message('root', {
|
|
49
|
+
replyRootId: 'root',
|
|
50
|
+
replyCount: 1,
|
|
51
|
+
text: 'What are our prayer requests?',
|
|
52
|
+
})
|
|
53
|
+
const reply = message('reply', { replyRootId: 'root', replyRoot: root, text: 'Smith family' })
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
queryClient = buildTestQueryClient()
|
|
57
|
+
seedPages(queryClient, mainKey, [reply, message('other'), root])
|
|
58
|
+
seedPages(queryClient, threadKey, [reply, root])
|
|
59
|
+
queryClient.setQueryData<ApiResource<MessageResource>>(rootKey, {
|
|
60
|
+
data: root,
|
|
61
|
+
links: {},
|
|
62
|
+
meta: {},
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('marks a deleted reply root as deleted everywhere it is cached and keeps its replies', () => {
|
|
67
|
+
applyMessageDeletionToCaches(queryClient, conversation_id, root)
|
|
68
|
+
|
|
69
|
+
const [threadReply, threadRoot] = pageMessages(queryClient, threadKey)
|
|
70
|
+
expect(threadRoot.deletedAt).toEqual(expect.any(String))
|
|
71
|
+
expect(threadReply).toMatchObject({ id: 'reply', text: 'Smith family' })
|
|
72
|
+
expect(threadReply.replyRoot?.deletedAt).toEqual(expect.any(String))
|
|
73
|
+
|
|
74
|
+
const [mainReply, , mainRoot] = pageMessages(queryClient, mainKey)
|
|
75
|
+
expect(mainRoot.deletedAt).toEqual(expect.any(String))
|
|
76
|
+
expect(mainReply.replyRoot?.deletedAt).toEqual(expect.any(String))
|
|
77
|
+
|
|
78
|
+
expect(queryClient.getQueryData<ApiResource<MessageResource>>(rootKey)!.data.deletedAt).toEqual(
|
|
79
|
+
expect.any(String)
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('removes a deleted reply from the thread and conversation caches but leaves the root', () => {
|
|
84
|
+
applyMessageDeletionToCaches(queryClient, conversation_id, reply)
|
|
85
|
+
|
|
86
|
+
expect(pageMessages(queryClient, threadKey).map(m => m.id)).toEqual(['root'])
|
|
87
|
+
expect(pageMessages(queryClient, mainKey).map(m => m.id)).toEqual(['other', 'root'])
|
|
88
|
+
expect(pageMessages(queryClient, threadKey)[0].deletedAt).toBeNull()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('removes a plain message from the conversation cache without touching thread caches', () => {
|
|
92
|
+
applyMessageDeletionToCaches(queryClient, conversation_id, message('other'))
|
|
93
|
+
|
|
94
|
+
expect(pageMessages(queryClient, mainKey).map(m => m.id)).toEqual(['reply', 'root'])
|
|
95
|
+
expect(pageMessages(queryClient, threadKey).map(m => m.id)).toEqual(['reply', 'root'])
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InfiniteData, QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
2
3
|
import type { ApiCollection } from '../../../types'
|
|
3
4
|
import type { MessageResource } from '../../../types/resources/message'
|
|
4
5
|
import type { PersonResource } from '../../../types/resources/person'
|
|
@@ -39,7 +40,7 @@ const pageMessages = (queryClient: QueryClient) =>
|
|
|
39
40
|
|
|
40
41
|
describe('updateCacheReplyRoots', () => {
|
|
41
42
|
it('merges a root update into every reply carrying that root', () => {
|
|
42
|
-
const queryClient =
|
|
43
|
+
const queryClient = buildTestQueryClient()
|
|
43
44
|
const root = message('rootA', { replyRootId: 'rootA', text: 'before' })
|
|
44
45
|
seedPages(queryClient, [
|
|
45
46
|
message('03', { replyRootId: 'rootA', replyRoot: root }),
|
|
@@ -60,7 +61,7 @@ describe('updateCacheReplyRoots', () => {
|
|
|
60
61
|
})
|
|
61
62
|
|
|
62
63
|
it('ignores replies without an inline root', () => {
|
|
63
|
-
const queryClient =
|
|
64
|
+
const queryClient = buildTestQueryClient()
|
|
64
65
|
seedPages(queryClient, [message('01', { replyRootId: 'rootA' })])
|
|
65
66
|
|
|
66
67
|
updateCacheReplyRoots(queryClient, queryKey, message('rootA', { replyRootId: 'rootA' }))
|
|
@@ -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
|
+
})
|