@planningcenter/chat-react-native 4.3.0-rc.9 → 4.3.1-qa-989.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/attachments/image_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +5 -3
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/conversation/message.d.ts +3 -1
- package/build/components/conversation/message.d.ts.map +1 -1
- package/build/components/conversation/message.js +183 -158
- package/build/components/conversation/message.js.map +1 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +3 -3
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +143 -88
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/system_message.js +3 -3
- package/build/components/conversation/system_message.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +0 -6
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/contexts/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +28 -25
- package/build/contexts/api_provider.js.map +1 -1
- package/build/hooks/use_animated_message_background_color.d.ts +1 -0
- package/build/hooks/use_animated_message_background_color.d.ts.map +1 -1
- package/build/hooks/use_animated_message_background_color.js +26 -9
- package/build/hooks/use_animated_message_background_color.js.map +1 -1
- package/build/hooks/use_chat_permissions.d.ts +10 -2
- package/build/hooks/use_chat_permissions.d.ts.map +1 -1
- package/build/hooks/use_chat_permissions.js +8 -0
- package/build/hooks/use_chat_permissions.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_features.d.ts +2 -0
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +3 -1
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_jolt.d.ts.map +1 -1
- package/build/hooks/use_jolt.js +2 -1
- package/build/hooks/use_jolt.js.map +1 -1
- package/build/hooks/use_product_analytics.d.ts +9 -0
- package/build/hooks/use_product_analytics.d.ts.map +1 -1
- package/build/hooks/use_product_analytics.js +4 -2
- package/build/hooks/use_product_analytics.js.map +1 -1
- package/build/hooks/use_search_enabled.d.ts +2 -0
- package/build/hooks/use_search_enabled.d.ts.map +1 -0
- package/build/hooks/use_search_enabled.js +18 -0
- package/build/hooks/use_search_enabled.js.map +1 -0
- 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/screens/age_check/age_check_underage_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.js +2 -1
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.js +5 -2
- package/build/screens/attachment_actions/attachment_actions_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_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.js +3 -3
- package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +2 -5
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/get_help_screen.js +2 -2
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/message_actions_screen.js +6 -2
- package/build/screens/message_actions_screen.js.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_results_list.d.ts +13 -0
- package/build/screens/search/components/search_results_list.d.ts.map +1 -0
- package/build/screens/search/components/search_results_list.js +344 -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.map +1 -1
- package/build/screens/search/search_screen.js +92 -20
- package/build/screens/search/search_screen.js.map +1 -1
- package/build/utils/client/request_helpers.js +1 -1
- package/build/utils/client/request_helpers.js.map +1 -1
- package/build/utils/native_adapters/linking.d.ts +11 -3
- package/build/utils/native_adapters/linking.d.ts.map +1 -1
- package/build/utils/native_adapters/linking.js.map +1 -1
- package/build/utils/response_error.d.ts +1 -1
- package/build/utils/response_error.d.ts.map +1 -1
- package/build/utils/response_error.js +1 -1
- package/build/utils/response_error.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
- package/src/__tests__/contexts/api_provider.test.tsx +50 -0
- package/src/__tests__/screens/attachment_actions_screen.test.tsx +81 -0
- package/src/__tests__/screens/get_help_screen.test.ts +36 -0
- package/src/__tests__/screens/message_actions_screen.test.tsx +136 -0
- package/src/__tests__/utils/client.ts +3 -4
- package/src/components/conversation/__tests__/message_form.test.tsx +83 -0
- package/src/components/conversation/__tests__/message_list.test.tsx +71 -3
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
- package/src/components/conversation/attachments/image_attachment.tsx +2 -3
- package/src/components/conversation/message.tsx +12 -1
- package/src/components/conversation/message_form.tsx +2 -2
- package/src/components/conversation/message_list.tsx +26 -1
- package/src/components/conversation/system_message.tsx +3 -3
- package/src/components/conversations/conversations.tsx +0 -7
- package/src/contexts/__tests__/api_provider.test.tsx +106 -0
- package/src/contexts/api_provider.tsx +6 -9
- package/src/hooks/__tests__/use_debounced_search_term.test.tsx +38 -0
- package/src/hooks/__tests__/use_jolt.test.tsx +70 -0
- package/src/hooks/__tests__/use_search_results.test.tsx +88 -0
- package/src/hooks/use_animated_message_background_color.ts +37 -12
- package/src/hooks/use_chat_permissions.ts +15 -2
- package/src/hooks/use_debounced_search_term.ts +20 -0
- package/src/hooks/use_features.ts +2 -0
- package/src/hooks/use_jolt.ts +10 -7
- package/src/hooks/use_product_analytics.ts +3 -1
- package/src/hooks/use_search_enabled.ts +9 -0
- package/src/hooks/use_search_results.ts +78 -0
- package/src/screens/age_check/age_check_underage_screen.tsx +2 -1
- package/src/screens/attachment_actions/attachment_actions_screen.tsx +3 -2
- package/src/screens/bug_report_screen.tsx +2 -10
- 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/__tests__/conversations_screen.test.tsx +71 -0
- package/src/screens/conversations/components/search_list_header_component.tsx +1 -1
- package/src/screens/conversations/conversations_screen.tsx +2 -3
- package/src/screens/get_help_screen.tsx +2 -2
- package/src/screens/message_actions_screen.tsx +6 -2
- package/src/screens/search/__tests__/search_screen.test.tsx +194 -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_results_list.test.tsx +180 -0
- package/src/screens/search/components/conversation_result_row.tsx +36 -0
- package/src/screens/search/components/conversation_results.tsx +43 -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_results_list.tsx +168 -0
- package/src/screens/search/components/snippet.tsx +37 -0
- package/src/screens/search/search_screen.tsx +50 -4
- package/src/utils/__tests__/response_error.test.ts +7 -2
- package/src/utils/client/__tests__/request_helpers.test.ts +40 -0
- package/src/utils/client/request_helpers.ts +1 -1
- package/src/utils/native_adapters/__tests__/linking.test.ts +12 -0
- package/src/utils/native_adapters/linking.ts +12 -3
- package/src/utils/response_error.ts +2 -2
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { HeaderHeightContext } from '@react-navigation/elements'
|
|
2
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
3
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
+
import { fireEvent, render, waitFor } from '@testing-library/react-native'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
7
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
8
|
+
import {
|
|
9
|
+
MessageActionsScreen,
|
|
10
|
+
MessageActionsScreenProps,
|
|
11
|
+
} from '../../screens/message_actions_screen'
|
|
12
|
+
import { MessageResource } from '../../types'
|
|
13
|
+
import {
|
|
14
|
+
AudioAdapter,
|
|
15
|
+
ChatAdapters,
|
|
16
|
+
ClipboardAdapter,
|
|
17
|
+
HapticAdapter,
|
|
18
|
+
ImagePickerAdapter,
|
|
19
|
+
VideoAdapter,
|
|
20
|
+
} from '../../utils/native_adapters'
|
|
21
|
+
|
|
22
|
+
const mockMessage: MessageResource = {
|
|
23
|
+
type: 'Message',
|
|
24
|
+
id: '1',
|
|
25
|
+
text: 'Copy me',
|
|
26
|
+
html: '<p>Copy me</p>',
|
|
27
|
+
createdAt: '2026-01-01T00:00:00Z',
|
|
28
|
+
deletedAt: null,
|
|
29
|
+
textEditedAt: null,
|
|
30
|
+
mine: false,
|
|
31
|
+
attachments: [],
|
|
32
|
+
author: { id: 1, type: 'Person', name: 'Author', avatar: '' },
|
|
33
|
+
reactionCounts: [],
|
|
34
|
+
replyCount: 0,
|
|
35
|
+
replyRootId: null,
|
|
36
|
+
messageType: 'user',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let mockCurrentMessage = mockMessage
|
|
40
|
+
|
|
41
|
+
const mockGoBack = jest.fn()
|
|
42
|
+
jest.mock('@react-navigation/native', () => ({
|
|
43
|
+
...jest.requireActual('@react-navigation/native'),
|
|
44
|
+
useNavigation: () => ({ navigate: jest.fn(), dispatch: jest.fn(), goBack: mockGoBack }),
|
|
45
|
+
}))
|
|
46
|
+
jest.mock('../../hooks/use_api_client', () => ({ useApiClient: () => ({}) }))
|
|
47
|
+
jest.mock('../../hooks/use_features', () => ({
|
|
48
|
+
...jest.requireActual('../../hooks/use_features'),
|
|
49
|
+
useFeatures: () => ({ features: [], featureEnabled: () => false }),
|
|
50
|
+
}))
|
|
51
|
+
jest.mock('../../hooks/use_message_reaction_toggle', () => ({
|
|
52
|
+
useMessageReactionToggle: () => ({ handleReactionToggle: jest.fn(), isPending: false }),
|
|
53
|
+
}))
|
|
54
|
+
jest.mock('../../hooks/use_conversation_messages', () => ({
|
|
55
|
+
useConversationMessages: () => ({ messages: [mockCurrentMessage], refetch: jest.fn() }),
|
|
56
|
+
}))
|
|
57
|
+
|
|
58
|
+
const setStringAsync = jest.fn(async (_: string) => {})
|
|
59
|
+
const notificationSuccess = jest.fn()
|
|
60
|
+
|
|
61
|
+
const safeAreaMetrics = {
|
|
62
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
63
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const route = {
|
|
67
|
+
key: 'MessageActions',
|
|
68
|
+
name: 'MessageActions',
|
|
69
|
+
params: { conversation_id: 1, message_id: mockMessage.id },
|
|
70
|
+
} as MessageActionsScreenProps['route']
|
|
71
|
+
|
|
72
|
+
const renderScreen = () =>
|
|
73
|
+
render(
|
|
74
|
+
<QueryClientProvider client={buildTestQueryClient()}>
|
|
75
|
+
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
76
|
+
<ThemeProvider value={DefaultTheme}>
|
|
77
|
+
<HeaderHeightContext.Provider value={0}>
|
|
78
|
+
<MessageActionsScreen route={route} />
|
|
79
|
+
</HeaderHeightContext.Provider>
|
|
80
|
+
</ThemeProvider>
|
|
81
|
+
</SafeAreaProvider>
|
|
82
|
+
</QueryClientProvider>
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
describe('MessageActionsScreen', () => {
|
|
86
|
+
beforeAll(() => {
|
|
87
|
+
ChatAdapters.configure({
|
|
88
|
+
clipboard: new ClipboardAdapter({ getStringAsync: async () => '', setStringAsync }),
|
|
89
|
+
audio: new AudioAdapter({ useAudio: () => ({}) as any }),
|
|
90
|
+
video: new VideoAdapter({ Player: React.forwardRef(() => null) }),
|
|
91
|
+
imagePicker: new ImagePickerAdapter({
|
|
92
|
+
openCameraAsync: async () => ({ canceled: true, assets: null }),
|
|
93
|
+
openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
|
|
94
|
+
}),
|
|
95
|
+
haptic: new HapticAdapter({
|
|
96
|
+
impactLight: jest.fn(),
|
|
97
|
+
impactMedium: jest.fn(),
|
|
98
|
+
impactHeavy: jest.fn(),
|
|
99
|
+
rigid: jest.fn(),
|
|
100
|
+
soft: jest.fn(),
|
|
101
|
+
notificationSuccess,
|
|
102
|
+
notificationWarning: jest.fn(),
|
|
103
|
+
notificationError: jest.fn(),
|
|
104
|
+
}),
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
jest.clearAllMocks()
|
|
110
|
+
mockCurrentMessage = mockMessage
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('copies the message text and gives success haptic feedback before closing', async () => {
|
|
114
|
+
const { getByText } = renderScreen()
|
|
115
|
+
|
|
116
|
+
fireEvent.press(getByText('Copy text'))
|
|
117
|
+
|
|
118
|
+
expect(setStringAsync).toHaveBeenCalledWith('Copy me')
|
|
119
|
+
await waitFor(() => expect(mockGoBack).toHaveBeenCalledTimes(1))
|
|
120
|
+
expect(notificationSuccess).toHaveBeenCalledTimes(1)
|
|
121
|
+
expect(notificationSuccess.mock.invocationCallOrder[0]).toBeLessThan(
|
|
122
|
+
mockGoBack.mock.invocationCallOrder[0]
|
|
123
|
+
)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('leaves the clipboard alone and gives no haptic when there is nothing to copy', async () => {
|
|
127
|
+
mockCurrentMessage = { ...mockMessage, text: null }
|
|
128
|
+
const { getByText } = renderScreen()
|
|
129
|
+
|
|
130
|
+
fireEvent.press(getByText('Copy text'))
|
|
131
|
+
|
|
132
|
+
await waitFor(() => expect(mockGoBack).toHaveBeenCalledTimes(1))
|
|
133
|
+
expect(setStringAsync).not.toHaveBeenCalled()
|
|
134
|
+
expect(notificationSuccess).not.toHaveBeenCalled()
|
|
135
|
+
})
|
|
136
|
+
})
|
|
@@ -59,8 +59,7 @@ describe('get', () => {
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
expect(fetchSpy).toHaveBeenCalledWith(
|
|
62
|
-
|
|
63
|
-
APP_BASE_URL + '/records?fields[Record]=id&per_page=100&where[id]=1',
|
|
62
|
+
APP_BASE_URL + '/records?fields%5BRecord%5D=id&per_page=100&where%5Bid%5D=1',
|
|
64
63
|
expect.any(Object)
|
|
65
64
|
)
|
|
66
65
|
})
|
|
@@ -75,7 +74,7 @@ describe('get', () => {
|
|
|
75
74
|
})
|
|
76
75
|
|
|
77
76
|
it('walks pagination when walk = true', async () => {
|
|
78
|
-
const expectUrl = APP_BASE_URL + '/records?fields
|
|
77
|
+
const expectUrl = APP_BASE_URL + '/records?fields%5BRecord%5D=id&per_page=1'
|
|
79
78
|
const nextUrl = expectUrl + '&offset=1'
|
|
80
79
|
|
|
81
80
|
MockServer.get(url, { ...DefaultFixtures.records(), links: { next: nextUrl } }, 200, {
|
|
@@ -92,7 +91,7 @@ describe('get', () => {
|
|
|
92
91
|
})
|
|
93
92
|
|
|
94
93
|
it('does not overwrite params in `url` when walking', async () => {
|
|
95
|
-
const expectUrl = APP_BASE_URL + '/records?fields
|
|
94
|
+
const expectUrl = APP_BASE_URL + '/records?fields%5BRecord%5D=id'
|
|
96
95
|
const nextUrl = expectUrl + '&offset=1&per_page=1'
|
|
97
96
|
MockServer.get(url, { ...DefaultFixtures.records(), links: { next: nextUrl } }, 200, {
|
|
98
97
|
once: true,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
2
|
+
import { QueryClientProvider, notifyManager } from '@tanstack/react-query'
|
|
3
|
+
import { act, fireEvent, render, screen } from '@testing-library/react-native'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import { chatQueryClient } from '../../../contexts/api_provider'
|
|
6
|
+
import type { ConversationResource } from '../../../types'
|
|
7
|
+
import { MessageForm } from '../message_form'
|
|
8
|
+
|
|
9
|
+
jest.mock('../../../contexts/api_provider', () => {
|
|
10
|
+
const { buildTestQueryClient } = require('../../../__utils__/query_client')
|
|
11
|
+
return { chatQueryClient: buildTestQueryClient() }
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const mockPost = jest.fn()
|
|
15
|
+
jest.mock('../../../hooks/use_api_client', () => ({
|
|
16
|
+
useApiClient: () => ({ chat: { post: mockPost, patch: jest.fn() } }),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
jest.mock('../../../hooks/use_current_person', () => ({
|
|
20
|
+
useCurrentPerson: () => ({ type: 'Person', id: 1, name: 'Me', avatar: null }),
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
jest.mock('../../../hooks/use_message_draft', () => ({
|
|
24
|
+
useMessageDraft: () => ({ draft: null, saveDraft: jest.fn(), clearDraft: jest.fn() }),
|
|
25
|
+
}))
|
|
26
|
+
|
|
27
|
+
jest.mock('../../../hooks/use_attachment_uploader', () => ({
|
|
28
|
+
useAttachmentUploader: () => ({
|
|
29
|
+
attachments: [],
|
|
30
|
+
attachmentIds: [],
|
|
31
|
+
pendingUploads: false,
|
|
32
|
+
flaggedAttachmentCount: 0,
|
|
33
|
+
reset: jest.fn(),
|
|
34
|
+
}),
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
jest.mock('../../../hooks/use_broadcast_typing_status', () => ({
|
|
38
|
+
useBroadcastTypingStatus: () => jest.fn(),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
jest.mock('@react-navigation/native', () => ({
|
|
42
|
+
...jest.requireActual('@react-navigation/native'),
|
|
43
|
+
useNavigation: () => ({ navigate: jest.fn(), setParams: jest.fn() }),
|
|
44
|
+
useRoute: () => ({ params: { conversation_id: 7 } }),
|
|
45
|
+
}))
|
|
46
|
+
|
|
47
|
+
notifyManager.setNotifyFunction(fn => act(fn))
|
|
48
|
+
|
|
49
|
+
const conversation = { id: 7, disabled: false } as unknown as ConversationResource
|
|
50
|
+
|
|
51
|
+
describe('MessageForm', () => {
|
|
52
|
+
let finishSend: (value: unknown) => void
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
chatQueryClient.clear()
|
|
56
|
+
mockPost.mockReset().mockReturnValue(new Promise(resolve => (finishSend = resolve)))
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
afterEach(async () => {
|
|
60
|
+
await act(async () => finishSend({ data: { type: 'Message', id: 'sent', mine: true } }))
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('keeps the input editable while a sent message is in flight', async () => {
|
|
64
|
+
render(
|
|
65
|
+
<QueryClientProvider client={chatQueryClient}>
|
|
66
|
+
<ThemeProvider value={DefaultTheme}>
|
|
67
|
+
<MessageForm.Root conversation={conversation}>
|
|
68
|
+
<MessageForm.TextInput />
|
|
69
|
+
<MessageForm.SubmitButton />
|
|
70
|
+
</MessageForm.Root>
|
|
71
|
+
</ThemeProvider>
|
|
72
|
+
</QueryClientProvider>
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
fireEvent.changeText(screen.getByTestId('message-composer-input'), 'hello')
|
|
76
|
+
await act(async () => {
|
|
77
|
+
fireEvent.press(screen.getByLabelText('Send message'))
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
expect(mockPost).toHaveBeenCalled()
|
|
81
|
+
expect(screen.getByTestId('message-composer-input').props.editable).toBe(true)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
@@ -28,6 +28,15 @@ import { getMessagesQueryKey } from '../../../utils/request/get_messages'
|
|
|
28
28
|
import { MessageList } from '../message_list'
|
|
29
29
|
|
|
30
30
|
jest.mock('../../../hooks/use_api_client')
|
|
31
|
+
const mockFlash = jest.fn()
|
|
32
|
+
jest.mock('../../../hooks/use_animated_message_background_color', () => ({
|
|
33
|
+
useAnimatedMessageBackgroundColor: () => ({
|
|
34
|
+
animatedBackgroundColor: {},
|
|
35
|
+
flash: mockFlash,
|
|
36
|
+
handleMessagePressIn: jest.fn(),
|
|
37
|
+
handleMessagePressOut: jest.fn(),
|
|
38
|
+
}),
|
|
39
|
+
}))
|
|
31
40
|
jest.mock('@react-navigation/native', () => ({
|
|
32
41
|
...jest.requireActual('@react-navigation/native'),
|
|
33
42
|
useNavigation: () => ({ navigate: jest.fn() }),
|
|
@@ -105,7 +114,7 @@ let queryClient: QueryClient
|
|
|
105
114
|
// A top-level rerender would rebuild the wrapper context and redraw every row.
|
|
106
115
|
let setHarnessConversation: (next: ConversationResource) => void = () => {}
|
|
107
116
|
|
|
108
|
-
function Harness() {
|
|
117
|
+
function Harness({ anchorMessageId }: { anchorMessageId?: string }) {
|
|
109
118
|
const [current, setCurrent] = React.useState(conversation)
|
|
110
119
|
React.useEffect(() => {
|
|
111
120
|
setHarnessConversation = setCurrent
|
|
@@ -117,6 +126,7 @@ function Harness() {
|
|
|
117
126
|
conversation={current}
|
|
118
127
|
conversationId={CONVERSATION_ID}
|
|
119
128
|
messages={loaded}
|
|
129
|
+
anchorMessageId={anchorMessageId}
|
|
120
130
|
hasNextPage
|
|
121
131
|
onEndReached={() => {}}
|
|
122
132
|
/>
|
|
@@ -151,16 +161,24 @@ const renderedRowIds = () => {
|
|
|
151
161
|
return Array.from(new Set(ids)).sort()
|
|
152
162
|
}
|
|
153
163
|
|
|
154
|
-
const renderList = (seed: MessageResource[] = messages) => {
|
|
164
|
+
const renderList = (seed: MessageResource[] = messages, anchorMessageId?: string) => {
|
|
155
165
|
queryClient.setQueryData<MessagesQueryData>(messagesQueryKey, {
|
|
156
166
|
pages: [{ data: seed, links: {}, meta: { count: seed.length, totalCount: seed.length } }],
|
|
157
167
|
pageParams: [{}],
|
|
158
168
|
})
|
|
159
|
-
render(<Harness />, { wrapper: Wrapper })
|
|
169
|
+
render(<Harness anchorMessageId={anchorMessageId} />, { wrapper: Wrapper })
|
|
160
170
|
seed.forEach(m => screen.getByTestId(`message-${m.id}`))
|
|
161
171
|
renderSpy.mockClear()
|
|
162
172
|
}
|
|
163
173
|
|
|
174
|
+
const reportViewable = (items: MessageResource[]) =>
|
|
175
|
+
act(() =>
|
|
176
|
+
screen.UNSAFE_getByType(FlatList).props.onViewableItemsChanged({
|
|
177
|
+
viewableItems: items.map(item => ({ item, key: item.id, index: null, isViewable: true })),
|
|
178
|
+
changed: [],
|
|
179
|
+
})
|
|
180
|
+
)
|
|
181
|
+
|
|
164
182
|
// TanStack notifies observers on a setTimeout; deliver inline so one write is one act().
|
|
165
183
|
beforeAll(() => notifyManager.setScheduler(callback => callback()))
|
|
166
184
|
afterAll(() => notifyManager.setScheduler(callback => setTimeout(callback, 0)))
|
|
@@ -274,4 +292,54 @@ describe('MessageList', () => {
|
|
|
274
292
|
expect(screen.queryByTestId(`message-${target.id}`)).toBeNull()
|
|
275
293
|
expect(renderedRowIds()).toEqual([])
|
|
276
294
|
})
|
|
295
|
+
|
|
296
|
+
describe('opened at an anchor message', () => {
|
|
297
|
+
const anchor = messages[4]
|
|
298
|
+
|
|
299
|
+
it('flashes the anchor row once it comes into view, redrawing only that row', () => {
|
|
300
|
+
renderList(messages, anchor.id)
|
|
301
|
+
|
|
302
|
+
reportViewable([messages[1], messages[2]])
|
|
303
|
+
expect(mockFlash).not.toHaveBeenCalled()
|
|
304
|
+
expect(renderedRowIds()).toEqual([])
|
|
305
|
+
|
|
306
|
+
reportViewable([messages[3], anchor])
|
|
307
|
+
expect(mockFlash).toHaveBeenCalledTimes(1)
|
|
308
|
+
expect(renderedRowIds()).toEqual([anchor.id])
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
it('flashes only once, through later viewability changes, redraws, and a remount', () => {
|
|
312
|
+
renderList(messages, anchor.id)
|
|
313
|
+
reportViewable([anchor])
|
|
314
|
+
expect(mockFlash).toHaveBeenCalledTimes(1)
|
|
315
|
+
|
|
316
|
+
reportViewable([anchor, messages[5]])
|
|
317
|
+
act(() => updateCacheWithReaction(queryClient, messagesQueryKey, reactionEvent(anchor), ME))
|
|
318
|
+
expect(screen.getByTestId(`reaction-${anchor.id}-heart`)).toBeTruthy()
|
|
319
|
+
|
|
320
|
+
act(() =>
|
|
321
|
+
queryClient.setQueryData<MessagesQueryData>(messagesQueryKey, prev =>
|
|
322
|
+
deleteRecordInPagesData({ data: prev, record: anchor })
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
expect(screen.queryByTestId(`message-${anchor.id}`)).toBeNull()
|
|
326
|
+
act(() =>
|
|
327
|
+
queryClient.setQueryData<MessagesQueryData>(messagesQueryKey, prev =>
|
|
328
|
+
addRecordInPagesData({ data: prev, record: anchor })
|
|
329
|
+
)
|
|
330
|
+
)
|
|
331
|
+
expect(screen.getByTestId(`message-${anchor.id}`)).toBeTruthy()
|
|
332
|
+
reportViewable([anchor])
|
|
333
|
+
|
|
334
|
+
expect(mockFlash).toHaveBeenCalledTimes(1)
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
it('never flashes when there is no anchor', () => {
|
|
338
|
+
renderList()
|
|
339
|
+
|
|
340
|
+
reportViewable([messages[0], messages[1]])
|
|
341
|
+
|
|
342
|
+
expect(mockFlash).not.toHaveBeenCalled()
|
|
343
|
+
})
|
|
344
|
+
})
|
|
277
345
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Text, StyleSheet
|
|
3
|
+
import { Text, StyleSheet } from 'react-native'
|
|
4
4
|
import { useTheme } from '../../../hooks'
|
|
5
5
|
import { DenormalizedGiphyAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
6
|
-
import { assertKeysAreNumbers } from '../../../utils'
|
|
6
|
+
import { assertKeysAreNumbers, Linking } from '../../../utils'
|
|
7
7
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
8
8
|
import { Image } from '../../display'
|
|
9
9
|
|
|
@@ -22,7 +22,6 @@ export function GiphyAttachment({
|
|
|
22
22
|
|
|
23
23
|
function handlePress() {
|
|
24
24
|
if (titleLink) {
|
|
25
|
-
// Open Giphy link in the default web browser
|
|
26
25
|
Linking.openURL(titleLink)
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
StyleSheet,
|
|
7
7
|
Modal,
|
|
8
8
|
View,
|
|
9
|
-
Linking,
|
|
10
9
|
Dimensions,
|
|
11
10
|
NativeSyntheticEvent,
|
|
12
11
|
NativeScrollEvent,
|
|
@@ -30,7 +29,7 @@ import Animated, {
|
|
|
30
29
|
import { useSafeAreaInsets, SafeAreaProvider } from 'react-native-safe-area-context'
|
|
31
30
|
import { useTheme } from '../../../hooks'
|
|
32
31
|
import { DenormalizedMessageAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
33
|
-
import { Haptic, platformFontWeightMedium } from '../../../utils'
|
|
32
|
+
import { Haptic, Linking, platformFontWeightMedium } from '../../../utils'
|
|
34
33
|
import { formatDatePreview } from '../../../utils/date'
|
|
35
34
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
36
35
|
import { IconButton, Image, Heading, Text } from '../../display'
|
|
@@ -212,7 +211,7 @@ const LightboxGallery = ({
|
|
|
212
211
|
HANDLERS
|
|
213
212
|
============================ */
|
|
214
213
|
const handleOpenInBrowser = useCallback(() => {
|
|
215
|
-
Linking.openURL(urlMedium || url)
|
|
214
|
+
Linking.openURL(urlMedium || url, { forceOpenInBrowser: true })
|
|
216
215
|
}, [urlMedium, url])
|
|
217
216
|
|
|
218
217
|
// Helper to enable or disable FlatList scroll state after gestures have ended
|
|
@@ -46,6 +46,8 @@ interface MessageProps extends MessageResource {
|
|
|
46
46
|
conversation_id: number
|
|
47
47
|
readByOthers?: boolean
|
|
48
48
|
inReplyScreen?: boolean
|
|
49
|
+
highlighted?: boolean
|
|
50
|
+
onHighlightShown?: () => void
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export const Message = memo(function MessageRow({
|
|
@@ -53,6 +55,8 @@ export const Message = memo(function MessageRow({
|
|
|
53
55
|
conversation_id,
|
|
54
56
|
readByOthers,
|
|
55
57
|
inReplyScreen,
|
|
58
|
+
highlighted = false,
|
|
59
|
+
onHighlightShown,
|
|
56
60
|
...message
|
|
57
61
|
}: MessageProps) {
|
|
58
62
|
const { reactionCounts, pending, error, attachments, author } = message
|
|
@@ -71,7 +75,7 @@ export const Message = memo(function MessageRow({
|
|
|
71
75
|
const isPersisted = !isNewMessage(message)
|
|
72
76
|
const [temporarilyHidePendingState, setTemporarilyHidePendingState] = React.useState(true)
|
|
73
77
|
const [messageBubbleHeight, setMessageBubbleHeight] = React.useState(0)
|
|
74
|
-
const { animatedBackgroundColor, handleMessagePressIn, handleMessagePressOut } =
|
|
78
|
+
const { animatedBackgroundColor, flash, handleMessagePressIn, handleMessagePressOut } =
|
|
75
79
|
useAnimatedMessageBackgroundColor()
|
|
76
80
|
const isReplyRootMessage = message.replyRootId === message.id
|
|
77
81
|
const isDeletedReplyRootMessage = isReplyRootMessage && !!message.deletedAt
|
|
@@ -116,6 +120,13 @@ export const Message = memo(function MessageRow({
|
|
|
116
120
|
messageText || ''
|
|
117
121
|
} ${saveStatusLabel} ${timestamp} ${replyCountLabel}`
|
|
118
122
|
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!highlighted) return
|
|
125
|
+
|
|
126
|
+
flash()
|
|
127
|
+
onHighlightShown?.()
|
|
128
|
+
}, [highlighted, flash, onHighlightShown])
|
|
129
|
+
|
|
119
130
|
useEffect(() => {
|
|
120
131
|
if (pending) {
|
|
121
132
|
const timer = setTimeout(() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'
|
|
2
2
|
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
|
|
3
3
|
import {
|
|
4
|
-
Linking,
|
|
5
4
|
Platform,
|
|
6
5
|
Pressable,
|
|
7
6
|
ScrollView,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
FileAttachment,
|
|
35
34
|
} from '../../types/resources/denormalized_attachment_resource_for_create'
|
|
36
35
|
import {
|
|
36
|
+
Linking,
|
|
37
37
|
Log,
|
|
38
38
|
MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
|
|
39
39
|
platformFontWeightMedium,
|
|
@@ -276,8 +276,8 @@ function MessageFormRoot({
|
|
|
276
276
|
// added earlier.
|
|
277
277
|
if (!(await catchUpBeforeSend())) return
|
|
278
278
|
|
|
279
|
-
reset()
|
|
280
279
|
mutateAsync({ text: messageText, attachments: attachmentsForSubmit })
|
|
280
|
+
reset()
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { date as formatDate } from '@planningcenter/datetime-fmt'
|
|
2
2
|
import { noop } from 'lodash'
|
|
3
|
-
import React, { RefObject, useRef } from 'react'
|
|
3
|
+
import React, { RefObject, useCallback, useEffect, useRef, useState } from 'react'
|
|
4
4
|
import { FlatList, FlatListProps, StyleSheet, View } from 'react-native'
|
|
5
5
|
import { useTheme } from '../../hooks'
|
|
6
6
|
import { ConversationResource } from '../../types/resources/conversation'
|
|
@@ -45,6 +45,7 @@ interface MessageListProps extends ScrollHandlers {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const ANCHOR_CLEARS_JUMP_BUTTON = 56
|
|
48
|
+
const ANCHOR_VIEWABILITY = { itemVisiblePercentThreshold: 50 }
|
|
48
49
|
|
|
49
50
|
/** MessageList
|
|
50
51
|
* The inverted list of messages, reply previews, and date separators for a conversation
|
|
@@ -80,6 +81,13 @@ export function MessageList({
|
|
|
80
81
|
const contentHeight = useRef(0)
|
|
81
82
|
const userHasScrolled = useRef(false)
|
|
82
83
|
const draggedSinceStartReached = useRef(false)
|
|
84
|
+
const latestAnchorMessageId = useRef(anchorMessageId)
|
|
85
|
+
const flashedAnchorId = useRef<string | null>(null)
|
|
86
|
+
const [highlightedMessageId, setHighlightedMessageId] = useState<string | null>(null)
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
latestAnchorMessageId.current = anchorMessageId
|
|
90
|
+
}, [anchorMessageId])
|
|
83
91
|
|
|
84
92
|
// Row heights keep settling after the first layout (images, attachments), so we
|
|
85
93
|
// re-pin on every layout pass until the reader takes over with a drag.
|
|
@@ -119,6 +127,19 @@ export function MessageList({
|
|
|
119
127
|
onScrollBeginDrag?.(event)
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
const flashAnchorOnceViewable: FlatListProps<EnrichedMessage>['onViewableItemsChanged'] = ({
|
|
131
|
+
viewableItems,
|
|
132
|
+
}) => {
|
|
133
|
+
const anchorId = latestAnchorMessageId.current
|
|
134
|
+
if (!anchorId || anchorId === flashedAnchorId.current) return
|
|
135
|
+
if (!viewableItems.some(token => token.item.id === anchorId)) return
|
|
136
|
+
|
|
137
|
+
flashedAnchorId.current = anchorId
|
|
138
|
+
setHighlightedMessageId(anchorId)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const clearHighlight = useCallback(() => setHighlightedMessageId(null), [])
|
|
142
|
+
|
|
122
143
|
// VirtualizedList re-checks its edges on every content size change using a JS offset
|
|
123
144
|
// the native hold never updates, so without this each merged page re-fires it.
|
|
124
145
|
const handleStartReached = () => {
|
|
@@ -143,6 +164,8 @@ export function MessageList({
|
|
|
143
164
|
onScrollToIndexFailed={noop}
|
|
144
165
|
onScrollEndDrag={onScrollEndDrag}
|
|
145
166
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
167
|
+
onViewableItemsChanged={flashAnchorOnceViewable}
|
|
168
|
+
viewabilityConfig={ANCHOR_VIEWABILITY}
|
|
146
169
|
scrollEventThrottle={10}
|
|
147
170
|
maintainVisibleContentPosition={behind ? HOLD_ONLY : HOLD_AND_FOLLOW}
|
|
148
171
|
ListFooterComponent={
|
|
@@ -181,6 +204,8 @@ export function MessageList({
|
|
|
181
204
|
conversation_id={conversationId}
|
|
182
205
|
readByOthers={readByOthers}
|
|
183
206
|
inReplyScreen={inReplyScreen}
|
|
207
|
+
highlighted={item.id === highlightedMessageId}
|
|
208
|
+
onHighlightShown={clearHighlight}
|
|
184
209
|
/>
|
|
185
210
|
)
|
|
186
211
|
}}
|
|
@@ -21,7 +21,7 @@ export function SystemMessage({ message, conversationId }: SystemMessageProps) {
|
|
|
21
21
|
const navigation = useNavigation()
|
|
22
22
|
const { colors } = useTheme()
|
|
23
23
|
const text = systemMessageText(names, overflowCount, action)
|
|
24
|
-
const
|
|
24
|
+
const isTruncated = overflowCount > 0
|
|
25
25
|
const hasReactions = reactionCounts.length > 0
|
|
26
26
|
const { animatedBackgroundColor, handleMessagePressIn, handleMessagePressOut } =
|
|
27
27
|
useAnimatedMessageBackgroundColor()
|
|
@@ -53,14 +53,14 @@ export function SystemMessage({ message, conversationId }: SystemMessageProps) {
|
|
|
53
53
|
|
|
54
54
|
return (
|
|
55
55
|
<Pressable
|
|
56
|
-
onPress={
|
|
56
|
+
onPress={isTruncated ? handlePress : undefined}
|
|
57
57
|
onLongPress={handleLongPress}
|
|
58
58
|
onPressIn={handleMessagePressIn}
|
|
59
59
|
onPressOut={handleMessagePressOut}
|
|
60
60
|
android_ripple={{ color: colors.androidRippleNeutral, borderless: false, foreground: true }}
|
|
61
61
|
accessibilityRole="button"
|
|
62
62
|
accessibilityHint={
|
|
63
|
-
|
|
63
|
+
isTruncated
|
|
64
64
|
? 'Tap to see people. Long press for message actions.'
|
|
65
65
|
: 'Long press for message actions.'
|
|
66
66
|
}
|
|
@@ -6,7 +6,6 @@ import { useTheme } from '../../hooks'
|
|
|
6
6
|
import { useCanCreateConversations } from '../../hooks/use_chat_permissions'
|
|
7
7
|
import { useConversationsJoltEvents } from '../../hooks/use_conversations_jolt_events'
|
|
8
8
|
import { ConversationResource } from '../../types'
|
|
9
|
-
import { throwResponseError } from '../../utils/response_error'
|
|
10
9
|
import { ConversationPreview, ConversationPreviewSkeleton } from './conversation_preview'
|
|
11
10
|
import { ConversationsBlankState } from './conversations_blank_state'
|
|
12
11
|
|
|
@@ -27,8 +26,6 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
|
|
|
27
26
|
refetch,
|
|
28
27
|
isRefetching,
|
|
29
28
|
isFetched,
|
|
30
|
-
isError,
|
|
31
|
-
error,
|
|
32
29
|
args: { chat_group_graph_id, group_source_app_name },
|
|
33
30
|
} = useConversationsContext()
|
|
34
31
|
const navigation = useNavigation()
|
|
@@ -48,10 +45,6 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
|
|
|
48
45
|
}))
|
|
49
46
|
}, [conversations, isLoading])
|
|
50
47
|
|
|
51
|
-
if (isError) {
|
|
52
|
-
throwResponseError(error)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
48
|
useConversationsJoltEvents()
|
|
56
49
|
|
|
57
50
|
return (
|