@planningcenter/chat-react-native 4.2.1 → 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
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
beforeEach(() => {
|
|
53
|
+
chatQueryClient.clear()
|
|
54
|
+
// Never resolves, so the send stays in flight for the assertion.
|
|
55
|
+
mockPost.mockReset().mockReturnValue(new Promise(() => {}))
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('keeps the input editable while a sent message is in flight', async () => {
|
|
59
|
+
render(
|
|
60
|
+
<QueryClientProvider client={chatQueryClient}>
|
|
61
|
+
<ThemeProvider value={DefaultTheme}>
|
|
62
|
+
<MessageForm.Root conversation={conversation}>
|
|
63
|
+
<MessageForm.TextInput />
|
|
64
|
+
<MessageForm.SubmitButton />
|
|
65
|
+
</MessageForm.Root>
|
|
66
|
+
</ThemeProvider>
|
|
67
|
+
</QueryClientProvider>
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
fireEvent.changeText(screen.getByTestId('message-composer-input'), 'hello')
|
|
71
|
+
await act(async () => {
|
|
72
|
+
fireEvent.press(screen.getByLabelText('Send message'))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
expect(mockPost).toHaveBeenCalled()
|
|
76
|
+
expect(screen.getByTestId('message-composer-input').props.editable).toBe(true)
|
|
77
|
+
})
|
|
78
|
+
})
|
|
@@ -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
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'
|
|
2
|
-
import React, { useCallback, useContext, useEffect, useState } from 'react'
|
|
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,8 @@ import {
|
|
|
34
33
|
FileAttachment,
|
|
35
34
|
} from '../../types/resources/denormalized_attachment_resource_for_create'
|
|
36
35
|
import {
|
|
36
|
+
Linking,
|
|
37
|
+
Log,
|
|
37
38
|
MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
|
|
38
39
|
platformFontWeightMedium,
|
|
39
40
|
platformPressedOpacityStyle,
|
|
@@ -71,6 +72,7 @@ interface MessagesFormRootProps extends ViewProps {
|
|
|
71
72
|
replyRootId?: string | null
|
|
72
73
|
replyRootAuthorFirstName?: string | null
|
|
73
74
|
onFlaggedInMessageForm?: (id: string) => void
|
|
75
|
+
onBeforeSubmit?: () => void | Promise<void>
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
const MessageFormContext = React.createContext<{
|
|
@@ -113,6 +115,7 @@ function MessageFormRoot({
|
|
|
113
115
|
replyRootId,
|
|
114
116
|
replyRootAuthorFirstName,
|
|
115
117
|
onFlaggedInMessageForm,
|
|
118
|
+
onBeforeSubmit,
|
|
116
119
|
}: MessagesFormRootProps) {
|
|
117
120
|
const { giphyApiKey } = useContext(ChatContext)
|
|
118
121
|
const canGiphy = !!giphyApiKey && !currentlyEditingMessage
|
|
@@ -224,10 +227,31 @@ function MessageFormRoot({
|
|
|
224
227
|
}
|
|
225
228
|
}, [conversation.id, navigation, text])
|
|
226
229
|
|
|
227
|
-
const
|
|
230
|
+
const catchingUp = useRef(false)
|
|
231
|
+
|
|
232
|
+
// A send from a window behind the live edge would leave a gap above it, so a failed
|
|
233
|
+
// catch-up stops the send and keeps what was typed.
|
|
234
|
+
const catchUpBeforeSend = async () => {
|
|
235
|
+
if (catchingUp.current) return false
|
|
236
|
+
|
|
237
|
+
catchingUp.current = true
|
|
238
|
+
try {
|
|
239
|
+
await onBeforeSubmit?.()
|
|
240
|
+
return true
|
|
241
|
+
} catch (error) {
|
|
242
|
+
Log.error('send stopped: live window fetch failed', error)
|
|
243
|
+
return false
|
|
244
|
+
} finally {
|
|
245
|
+
catchingUp.current = false
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const handleSubmit = async () => {
|
|
228
250
|
if (!canSubmit) return
|
|
229
251
|
|
|
230
252
|
if (canGiphy && usingGiphy) {
|
|
253
|
+
if (!(await catchUpBeforeSend())) return
|
|
254
|
+
|
|
231
255
|
TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput())
|
|
232
256
|
Haptic.impactLight()
|
|
233
257
|
navigateToSendGiphyAfterKeyboardHides()
|
|
@@ -248,6 +272,10 @@ function MessageFormRoot({
|
|
|
248
272
|
mutateAsync({ text: messageText })
|
|
249
273
|
reset()
|
|
250
274
|
} else {
|
|
275
|
+
// The live-window fetch replaces the cache, which would wipe an optimistic row
|
|
276
|
+
// added earlier.
|
|
277
|
+
if (!(await catchUpBeforeSend())) return
|
|
278
|
+
|
|
251
279
|
mutateAsync({ text: messageText, attachments: attachmentsForSubmit })
|
|
252
280
|
reset()
|
|
253
281
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { date as formatDate } from '@planningcenter/datetime-fmt'
|
|
2
|
-
import
|
|
2
|
+
import { noop } from 'lodash'
|
|
3
|
+
import React, { RefObject, useRef } from 'react'
|
|
3
4
|
import { FlatList, FlatListProps, StyleSheet, View } from 'react-native'
|
|
4
5
|
import { useTheme } from '../../hooks'
|
|
5
6
|
import { ConversationResource } from '../../types/resources/conversation'
|
|
@@ -11,12 +12,23 @@ import { isSystemMessage } from '../../utils/system_messages'
|
|
|
11
12
|
import { Text } from '../display'
|
|
12
13
|
import { ConversationStartBanner } from './conversation_start_banner'
|
|
13
14
|
import { Message } from './message'
|
|
15
|
+
import { MissingMessage } from './missing_message'
|
|
14
16
|
import { ReplyShadowMessage } from './reply_shadow_message'
|
|
15
17
|
import { SystemMessage } from './system_message'
|
|
16
18
|
|
|
19
|
+
// While behind, the bottom of the window isn't the live edge. Following there pulls
|
|
20
|
+
// each newly paged-in page into view and chains the next fetch.
|
|
21
|
+
const HOLD_AND_FOLLOW = { minIndexForVisible: 0, autoscrollToTopThreshold: 100 }
|
|
22
|
+
const HOLD_ONLY = { minIndexForVisible: 0 }
|
|
23
|
+
|
|
17
24
|
type ScrollHandlers = Pick<
|
|
18
25
|
FlatListProps<EnrichedMessage>,
|
|
19
|
-
|
|
26
|
+
| 'onScroll'
|
|
27
|
+
| 'onLayout'
|
|
28
|
+
| 'onContentSizeChange'
|
|
29
|
+
| 'onScrollBeginDrag'
|
|
30
|
+
| 'onScrollEndDrag'
|
|
31
|
+
| 'onMomentumScrollEnd'
|
|
20
32
|
>
|
|
21
33
|
|
|
22
34
|
interface MessageListProps extends ScrollHandlers {
|
|
@@ -25,10 +37,15 @@ interface MessageListProps extends ScrollHandlers {
|
|
|
25
37
|
conversationId: number
|
|
26
38
|
messages: MessageResource[]
|
|
27
39
|
replyRootId?: string | null
|
|
40
|
+
anchorMessageId?: string | null
|
|
41
|
+
behind?: boolean
|
|
28
42
|
hasNextPage: boolean
|
|
29
43
|
onEndReached: () => void
|
|
44
|
+
onStartReached?: () => void
|
|
30
45
|
}
|
|
31
46
|
|
|
47
|
+
const ANCHOR_CLEARS_JUMP_BUTTON = 56
|
|
48
|
+
|
|
32
49
|
/** MessageList
|
|
33
50
|
* The inverted list of messages, reply previews, and date separators for a conversation
|
|
34
51
|
*/
|
|
@@ -38,11 +55,15 @@ export function MessageList({
|
|
|
38
55
|
conversationId,
|
|
39
56
|
messages,
|
|
40
57
|
replyRootId,
|
|
58
|
+
anchorMessageId,
|
|
59
|
+
behind = false,
|
|
41
60
|
hasNextPage,
|
|
42
61
|
onEndReached,
|
|
62
|
+
onStartReached,
|
|
43
63
|
onScroll,
|
|
44
64
|
onLayout,
|
|
45
65
|
onContentSizeChange,
|
|
66
|
+
onScrollBeginDrag,
|
|
46
67
|
onScrollEndDrag,
|
|
47
68
|
onMomentumScrollEnd,
|
|
48
69
|
}: MessageListProps) {
|
|
@@ -52,6 +73,60 @@ export function MessageList({
|
|
|
52
73
|
conversation.memberAbility?.canDeleteNonAuthoredMessages ?? false
|
|
53
74
|
const latestRead = conversation.latestReadMessageSortKey
|
|
54
75
|
const messagesWithSeparators = groupMessages({ ms: messages, inReplyScreen })
|
|
76
|
+
const anchorIndex = anchorMessageId
|
|
77
|
+
? messagesWithSeparators.findIndex(item => item.id === anchorMessageId)
|
|
78
|
+
: -1
|
|
79
|
+
const layoutHeight = useRef(0)
|
|
80
|
+
const contentHeight = useRef(0)
|
|
81
|
+
const userHasScrolled = useRef(false)
|
|
82
|
+
const draggedSinceStartReached = useRef(false)
|
|
83
|
+
|
|
84
|
+
// Row heights keep settling after the first layout (images, attachments), so we
|
|
85
|
+
// re-pin on every layout pass until the reader takes over with a drag.
|
|
86
|
+
const pinAnchorToBottomEdge = () => {
|
|
87
|
+
const anchorIsLoaded = anchorIndex >= 0
|
|
88
|
+
if (!anchorIsLoaded || userHasScrolled.current) return
|
|
89
|
+
|
|
90
|
+
const scrollable = layoutHeight.current > 0 && contentHeight.current > layoutHeight.current
|
|
91
|
+
if (!scrollable) return
|
|
92
|
+
|
|
93
|
+
listRef.current?.scrollToIndex({
|
|
94
|
+
index: anchorIndex,
|
|
95
|
+
viewPosition: 0,
|
|
96
|
+
viewOffset: ANCHOR_CLEARS_JUMP_BUTTON,
|
|
97
|
+
animated: false,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const handleLayout: FlatListProps<EnrichedMessage>['onLayout'] = event => {
|
|
102
|
+
onLayout?.(event)
|
|
103
|
+
layoutHeight.current = event.nativeEvent.layout.height
|
|
104
|
+
pinAnchorToBottomEdge()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const handleContentSizeChange: FlatListProps<EnrichedMessage>['onContentSizeChange'] = (
|
|
108
|
+
width,
|
|
109
|
+
height
|
|
110
|
+
) => {
|
|
111
|
+
onContentSizeChange?.(width, height)
|
|
112
|
+
contentHeight.current = height
|
|
113
|
+
pinAnchorToBottomEdge()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const handleScrollBeginDrag: FlatListProps<EnrichedMessage>['onScrollBeginDrag'] = event => {
|
|
117
|
+
userHasScrolled.current = true
|
|
118
|
+
draggedSinceStartReached.current = true
|
|
119
|
+
onScrollBeginDrag?.(event)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// VirtualizedList re-checks its edges on every content size change using a JS offset
|
|
123
|
+
// the native hold never updates, so without this each merged page re-fires it.
|
|
124
|
+
const handleStartReached = () => {
|
|
125
|
+
if (!draggedSinceStartReached.current) return
|
|
126
|
+
|
|
127
|
+
draggedSinceStartReached.current = false
|
|
128
|
+
onStartReached?.()
|
|
129
|
+
}
|
|
55
130
|
|
|
56
131
|
return (
|
|
57
132
|
<FlatList
|
|
@@ -61,11 +136,15 @@ export function MessageList({
|
|
|
61
136
|
data={messagesWithSeparators}
|
|
62
137
|
keyExtractor={item => item.id}
|
|
63
138
|
onScroll={onScroll}
|
|
64
|
-
onLayout={
|
|
65
|
-
onContentSizeChange={
|
|
139
|
+
onLayout={handleLayout}
|
|
140
|
+
onContentSizeChange={handleContentSizeChange}
|
|
141
|
+
onScrollBeginDrag={handleScrollBeginDrag}
|
|
142
|
+
// Expected while rows are still measuring; the next layout pass pins again.
|
|
143
|
+
onScrollToIndexFailed={noop}
|
|
66
144
|
onScrollEndDrag={onScrollEndDrag}
|
|
67
145
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
68
146
|
scrollEventThrottle={10}
|
|
147
|
+
maintainVisibleContentPosition={behind ? HOLD_ONLY : HOLD_AND_FOLLOW}
|
|
69
148
|
ListFooterComponent={
|
|
70
149
|
hasNextPage ? null : (
|
|
71
150
|
<ConversationStartBanner conversation={conversation} hasMessages={true} />
|
|
@@ -76,6 +155,10 @@ export function MessageList({
|
|
|
76
155
|
return <InlineDateSeparator {...item} />
|
|
77
156
|
}
|
|
78
157
|
|
|
158
|
+
if (item.type === 'Message' && item.deletedAt && !item.replyRootId) {
|
|
159
|
+
return <MissingMessage />
|
|
160
|
+
}
|
|
161
|
+
|
|
79
162
|
if (item.type === 'ReplyShadowMessage') {
|
|
80
163
|
return (
|
|
81
164
|
<ReplyShadowMessage
|
|
@@ -102,6 +185,7 @@ export function MessageList({
|
|
|
102
185
|
)
|
|
103
186
|
}}
|
|
104
187
|
onEndReached={onEndReached}
|
|
188
|
+
onStartReached={handleStartReached}
|
|
105
189
|
ListHeaderComponent={<View style={styles.listHeader} />}
|
|
106
190
|
/>
|
|
107
191
|
)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleSheet, useWindowDimensions, View } from 'react-native'
|
|
3
|
+
import { useTheme } from '../../hooks'
|
|
4
|
+
import { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles'
|
|
5
|
+
import { Avatar, Text } from '../display'
|
|
6
|
+
import { AVATAR_CONNECTOR_SPACING } from './reply_connectors'
|
|
7
|
+
|
|
8
|
+
export function MissingMessage() {
|
|
9
|
+
const styles = useStyles()
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<View style={styles.message} accessibilityLabel="Message deleted">
|
|
13
|
+
<Avatar
|
|
14
|
+
size="md"
|
|
15
|
+
sourceUri=""
|
|
16
|
+
style={styles.avatar}
|
|
17
|
+
maxFontSizeMultiplier={1}
|
|
18
|
+
minFontSizeMultiplier={1}
|
|
19
|
+
fallbackIconName="publishing.trash"
|
|
20
|
+
showFallback
|
|
21
|
+
/>
|
|
22
|
+
<View style={styles.messageContent}>
|
|
23
|
+
<View style={styles.messageBubble}>
|
|
24
|
+
<View style={styles.messageText}>
|
|
25
|
+
<Text style={styles.deletedText}>Message deleted</Text>
|
|
26
|
+
</View>
|
|
27
|
+
</View>
|
|
28
|
+
</View>
|
|
29
|
+
</View>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const useStyles = () => {
|
|
34
|
+
const { colors } = useTheme()
|
|
35
|
+
const { width } = useWindowDimensions()
|
|
36
|
+
const tabletWidth = width >= 744
|
|
37
|
+
|
|
38
|
+
return StyleSheet.create({
|
|
39
|
+
message: {
|
|
40
|
+
gap: 8,
|
|
41
|
+
flexDirection: 'row',
|
|
42
|
+
paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,
|
|
43
|
+
},
|
|
44
|
+
avatar: {
|
|
45
|
+
marginBottom: AVATAR_CONNECTOR_SPACING,
|
|
46
|
+
},
|
|
47
|
+
messageContent: {
|
|
48
|
+
flex: 1,
|
|
49
|
+
marginBottom: 16,
|
|
50
|
+
},
|
|
51
|
+
messageBubble: {
|
|
52
|
+
backgroundColor: colors.fillColorNeutral070,
|
|
53
|
+
borderRadius: 8,
|
|
54
|
+
maxWidth: tabletWidth ? 360 : '80%',
|
|
55
|
+
alignSelf: 'flex-start',
|
|
56
|
+
},
|
|
57
|
+
messageText: {
|
|
58
|
+
paddingVertical: 6,
|
|
59
|
+
paddingHorizontal: 8,
|
|
60
|
+
},
|
|
61
|
+
deletedText: {
|
|
62
|
+
color: colors.textColorDefaultSecondary,
|
|
63
|
+
fontStyle: 'italic',
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
}
|
|
@@ -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
|
}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { ViewStyle } from 'react-native'
|
|
3
|
-
import type {
|
|
3
|
+
import type { ConversationAvatarData } from '../../types'
|
|
4
4
|
import AvatarPrimitive, { type AvatarRootProps } from '../primitive/avatar_primitive'
|
|
5
5
|
import { AvatarGroup } from './avatar_group'
|
|
6
6
|
import { EmojiAvatar } from './emoji_avatar'
|
|
7
7
|
import { type IconString } from './icon'
|
|
8
8
|
import { IconAvatar } from './icon_avatar'
|
|
9
9
|
|
|
10
|
-
type ConversationAvatarData = Pick<
|
|
11
|
-
ConversationResource,
|
|
12
|
-
| 'customAvatarType'
|
|
13
|
-
| 'customAvatarKey'
|
|
14
|
-
| 'customAvatarColor'
|
|
15
|
-
| 'customAvatarImageUrl'
|
|
16
|
-
| 'previewAvatarUrls'
|
|
17
|
-
>
|
|
18
|
-
|
|
19
10
|
type ResolvedAvatar =
|
|
20
11
|
| { kind: 'image'; url: string }
|
|
21
12
|
| { kind: 'icon'; iconKey: string; color: string | null }
|