@planningcenter/chat-react-native 4.6.0-rc.5 → 4.6.0-rc.7
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_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +155 -123
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +1 -0
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/conversation_avatar.d.ts +3 -1
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js +77 -66
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/components/display/keyboard_scroll_view.d.ts.map +1 -1
- package/build/components/display/keyboard_scroll_view.js +1 -0
- package/build/components/display/keyboard_scroll_view.js.map +1 -1
- package/build/hooks/use_conversation_avatar_update.d.ts +4 -3
- package/build/hooks/use_conversation_avatar_update.d.ts.map +1 -1
- package/build/hooks/use_conversation_avatar_update.js +146 -48
- package/build/hooks/use_conversation_avatar_update.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +3 -1
- package/build/navigation/index.js.map +1 -1
- package/build/screens/age_check/age_check_required_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_required_screen.js +1 -0
- package/build/screens/age_check/age_check_required_screen.js.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.d.ts.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.js +76 -66
- package/build/screens/avatar_picker/avatar_picker_screen.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +1 -0
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_new/components/form_list.d.ts.map +1 -1
- package/build/screens/conversation_new/components/form_list.js +1 -0
- package/build/screens/conversation_new/components/form_list.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js +68 -62
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js.map +1 -1
- package/build/screens/get_help_screen.js +56 -62
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/group_notification_settings_screen.js +3 -2
- package/build/screens/group_notification_settings_screen.js.map +1 -1
- package/build/screens/notification_settings_screen.d.ts.map +1 -1
- package/build/screens/notification_settings_screen.js +1 -0
- package/build/screens/notification_settings_screen.js.map +1 -1
- package/build/screens/preferred_app_selection_screen.js +45 -39
- package/build/screens/preferred_app_selection_screen.js.map +1 -1
- package/build/screens/search/components/search_results_list.d.ts.map +1 -1
- package/build/screens/search/components/search_results_list.js +1 -0
- package/build/screens/search/components/search_results_list.js.map +1 -1
- package/build/screens/settings_screen.d.ts.map +1 -1
- package/build/screens/settings_screen.js +7 -6
- package/build/screens/settings_screen.js.map +1 -1
- package/package.json +2 -2
- package/src/__utils__/render_with_query_client.tsx +13 -0
- package/src/components/conversation/__tests__/message_list.test.tsx +4 -0
- package/src/components/conversation/message_list.tsx +6 -0
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +2 -2
- package/src/components/conversations/conversations.tsx +1 -0
- package/src/components/display/__tests__/conversation_avatar.test.tsx +94 -0
- package/src/components/display/conversation_avatar.tsx +9 -2
- package/src/components/display/keyboard_scroll_view.tsx +1 -0
- package/src/hooks/__tests__/use_conversation_avatar_update.test.tsx +40 -0
- package/src/hooks/use_conversation_avatar_update.ts +67 -11
- package/src/navigation/index.tsx +6 -2
- package/src/screens/age_check/age_check_required_screen.tsx +5 -1
- package/src/screens/avatar_picker/__tests__/avatar_picker_screen.test.tsx +67 -0
- package/src/screens/avatar_picker/avatar_picker_screen.tsx +7 -1
- package/src/screens/conversation_details_screen.tsx +1 -0
- package/src/screens/conversation_new/components/form_list.tsx +1 -0
- package/src/screens/conversation_select_recipients/conversation_new_entry_screen.tsx +4 -1
- package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +1 -0
- package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx +1 -0
- package/src/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.tsx +1 -0
- package/src/screens/get_help_screen.tsx +4 -4
- package/src/screens/group_notification_settings_screen.tsx +3 -3
- package/src/screens/notification_settings_screen.tsx +1 -0
- package/src/screens/preferred_app_selection_screen.tsx +4 -4
- package/src/screens/search/__tests__/search_screen.test.tsx +6 -5
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +14 -5
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +5 -4
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +4 -3
- package/src/screens/search/components/search_results_list.tsx +1 -0
- package/src/screens/settings_screen.tsx +25 -25
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { render, type RenderOptions } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { buildTestQueryClient } from './query_client'
|
|
5
|
+
|
|
6
|
+
export const renderWithQueryClient = (ui: React.ReactElement, options: RenderOptions = {}) => {
|
|
7
|
+
const queryClient = buildTestQueryClient()
|
|
8
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
9
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
return render(ui, { wrapper, ...options })
|
|
13
|
+
}
|
|
@@ -27,6 +27,10 @@ import { addRecordInPagesData, deleteRecordInPagesData } from '../../../utils/ca
|
|
|
27
27
|
import { getMessagesQueryKey } from '../../../utils/request/get_messages'
|
|
28
28
|
import { MessageList } from '../message_list'
|
|
29
29
|
|
|
30
|
+
jest.mock('@react-navigation/elements', () => ({
|
|
31
|
+
...jest.requireActual('@react-navigation/elements'),
|
|
32
|
+
useHeaderHeight: () => 0,
|
|
33
|
+
}))
|
|
30
34
|
jest.mock('../../../hooks/use_api_client')
|
|
31
35
|
const mockFlash = jest.fn()
|
|
32
36
|
jest.mock('../../../hooks/use_animated_message_background_color', () => ({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { date as formatDate } from '@planningcenter/datetime-fmt'
|
|
2
|
+
import { useHeaderHeight } from '@react-navigation/elements'
|
|
2
3
|
import { noop } from 'lodash'
|
|
3
4
|
import React, { RefObject, useCallback, useEffect, useRef, useState } from 'react'
|
|
4
5
|
import { FlatList, FlatListProps, StyleSheet, View } from 'react-native'
|
|
@@ -7,6 +8,7 @@ import { ConversationResource } from '../../types/resources/conversation'
|
|
|
7
8
|
import { MessageResource } from '../../types/resources/message'
|
|
8
9
|
import { getRelativeDateStatus } from '../../utils/date'
|
|
9
10
|
import { groupMessages, type DateSeparator, type EnrichedMessage } from '../../utils/group_messages'
|
|
11
|
+
import { isLiquidGlassEnabled } from '../../utils/liquid_glass'
|
|
10
12
|
import { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles'
|
|
11
13
|
import { isSystemMessage } from '../../utils/system_messages'
|
|
12
14
|
import { Text } from '../display'
|
|
@@ -69,6 +71,8 @@ export function MessageList({
|
|
|
69
71
|
onMomentumScrollEnd,
|
|
70
72
|
}: MessageListProps) {
|
|
71
73
|
const styles = useStyles()
|
|
74
|
+
const headerHeight = useHeaderHeight()
|
|
75
|
+
const glassHeaderInset = isLiquidGlassEnabled() ? headerHeight : 0
|
|
72
76
|
const inReplyScreen = !!replyRootId
|
|
73
77
|
const canDeleteNonAuthoredMessages =
|
|
74
78
|
conversation.memberAbility?.canDeleteNonAuthoredMessages ?? false
|
|
@@ -155,6 +159,8 @@ export function MessageList({
|
|
|
155
159
|
inverted
|
|
156
160
|
ref={listRef}
|
|
157
161
|
contentContainerStyle={styles.listContainer}
|
|
162
|
+
contentInset={{ bottom: glassHeaderInset }}
|
|
163
|
+
scrollIndicatorInsets={{ bottom: glassHeaderInset }}
|
|
158
164
|
data={messagesWithSeparators}
|
|
159
165
|
keyExtractor={item => item.id}
|
|
160
166
|
onScroll={onScroll}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { render } from '@testing-library/react-native'
|
|
2
1
|
import React from 'react'
|
|
2
|
+
import { renderWithQueryClient } from '../../../__utils__/render_with_query_client'
|
|
3
3
|
import type { ConversationPreviewData, ConversationResource } from '../../../types'
|
|
4
4
|
import { formatDatePreview } from '../../../utils/date'
|
|
5
5
|
import { ConversationPreview } from '../conversation_preview'
|
|
@@ -49,7 +49,7 @@ const renderPreview = (
|
|
|
49
49
|
preview: ConversationPreviewData,
|
|
50
50
|
overrides: Partial<ConversationResource> = {}
|
|
51
51
|
) =>
|
|
52
|
-
|
|
52
|
+
renderWithQueryClient(
|
|
53
53
|
<ConversationPreview conversation={conversation(preview, overrides)} onPress={jest.fn()} />
|
|
54
54
|
)
|
|
55
55
|
|
|
@@ -79,6 +79,7 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
|
|
|
79
79
|
data={data}
|
|
80
80
|
keyExtractor={item => item.id.toString()}
|
|
81
81
|
contentContainerStyle={styles.contentContainer}
|
|
82
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
82
83
|
onRefresh={refetch}
|
|
83
84
|
refreshing={!isFetched && isRefetching}
|
|
84
85
|
ListHeaderComponent={ListHeaderComponent}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { render, waitFor } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Image } from 'react-native'
|
|
5
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
6
|
+
import type { AvatarUpdatePayload } from '../../../hooks/use_conversation_avatar_update'
|
|
7
|
+
import { ConversationAvatar } from '../conversation_avatar'
|
|
8
|
+
|
|
9
|
+
const conversation = {
|
|
10
|
+
id: 7,
|
|
11
|
+
customAvatarType: 'emoji' as const,
|
|
12
|
+
customAvatarKey: '🎉',
|
|
13
|
+
customAvatarColor: 'cosmic',
|
|
14
|
+
customAvatarImageUrl: null,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const imagePayload: AvatarUpdatePayload = {
|
|
18
|
+
kind: 'image',
|
|
19
|
+
color: 'cosmic',
|
|
20
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let queryClient: QueryClient
|
|
24
|
+
let inFlight: { settle: () => void; done: Promise<unknown> }[]
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
queryClient = buildTestQueryClient({ defaultOptions: { mutations: { gcTime: Infinity } } })
|
|
28
|
+
inFlight = []
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
afterEach(async () => {
|
|
32
|
+
inFlight.forEach(({ settle }) => settle())
|
|
33
|
+
await Promise.all(inFlight.map(({ done }) => done))
|
|
34
|
+
queryClient.clear()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
function startAvatarUpdate(conversationId: number) {
|
|
38
|
+
let settle = () => {}
|
|
39
|
+
const upload = new Promise<void>(resolve => (settle = resolve))
|
|
40
|
+
const mutation = queryClient.getMutationCache().build(queryClient, {
|
|
41
|
+
mutationKey: ['updateConversationAvatar', conversationId],
|
|
42
|
+
mutationFn: () => upload,
|
|
43
|
+
networkMode: 'always',
|
|
44
|
+
})
|
|
45
|
+
const done = mutation.execute(imagePayload)
|
|
46
|
+
inFlight.push({ settle, done })
|
|
47
|
+
return settle
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function renderAvatar() {
|
|
51
|
+
return render(
|
|
52
|
+
<QueryClientProvider client={queryClient}>
|
|
53
|
+
<ConversationAvatar conversation={conversation} />
|
|
54
|
+
</QueryClientProvider>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('ConversationAvatar', () => {
|
|
59
|
+
it('renders the pending avatar update over the cached conversation data', () => {
|
|
60
|
+
startAvatarUpdate(conversation.id)
|
|
61
|
+
|
|
62
|
+
const view = renderAvatar()
|
|
63
|
+
|
|
64
|
+
expect(view.UNSAFE_getByType(Image).props.source).toEqual({ uri: 'file:///photo.jpg' })
|
|
65
|
+
expect(view.queryByText('🎉')).toBeNull()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('ignores pending avatar updates for other conversations', () => {
|
|
69
|
+
startAvatarUpdate(conversation.id + 1)
|
|
70
|
+
|
|
71
|
+
const view = renderAvatar()
|
|
72
|
+
|
|
73
|
+
expect(view.getByText('🎉')).toBeTruthy()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('returns to the cached conversation data once the update settles', async () => {
|
|
77
|
+
const settle = startAvatarUpdate(conversation.id)
|
|
78
|
+
const view = renderAvatar()
|
|
79
|
+
|
|
80
|
+
settle()
|
|
81
|
+
|
|
82
|
+
await waitFor(() => expect(view.getByText('🎉')).toBeTruthy())
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('ignores an older pending update once a newer one has settled', async () => {
|
|
86
|
+
startAvatarUpdate(conversation.id)
|
|
87
|
+
const settleNewer = startAvatarUpdate(conversation.id)
|
|
88
|
+
const view = renderAvatar()
|
|
89
|
+
|
|
90
|
+
settleNewer()
|
|
91
|
+
|
|
92
|
+
await waitFor(() => expect(view.getByText('🎉')).toBeTruthy())
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { ViewStyle } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
applyAvatarUpdate,
|
|
5
|
+
usePendingConversationAvatarUpdate,
|
|
6
|
+
} from '../../hooks/use_conversation_avatar_update'
|
|
3
7
|
import type { ConversationAvatarData } from '../../types'
|
|
4
8
|
import AvatarPrimitive, { type AvatarRootProps } from '../primitive/avatar_primitive'
|
|
5
9
|
import { AvatarGroup } from './avatar_group'
|
|
@@ -38,7 +42,7 @@ function resolveAvatar(conversation: ConversationAvatarData): ResolvedAvatar {
|
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
interface ConversationAvatarProps {
|
|
41
|
-
conversation: ConversationAvatarData
|
|
45
|
+
conversation: ConversationAvatarData & { id?: number }
|
|
42
46
|
size?: AvatarRootProps['size']
|
|
43
47
|
showFallback?: boolean
|
|
44
48
|
fallbackIconName?: IconString
|
|
@@ -54,7 +58,10 @@ export function ConversationAvatar({
|
|
|
54
58
|
style,
|
|
55
59
|
maxFontSizeMultiplier,
|
|
56
60
|
}: ConversationAvatarProps) {
|
|
57
|
-
const
|
|
61
|
+
const pendingUpdate = usePendingConversationAvatarUpdate(conversation.id)
|
|
62
|
+
const avatar = resolveAvatar(
|
|
63
|
+
pendingUpdate ? applyAvatarUpdate(conversation, pendingUpdate) : conversation
|
|
64
|
+
)
|
|
58
65
|
const sizeProps = { size, maxFontSizeMultiplier, style }
|
|
59
66
|
|
|
60
67
|
switch (avatar.kind) {
|
|
@@ -43,6 +43,7 @@ export function KeyboardScrollView({ children, contentContainerStyle }: Keyboard
|
|
|
43
43
|
<KeyboardView>
|
|
44
44
|
<ScrollView
|
|
45
45
|
ref={scrollViewRef}
|
|
46
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
46
47
|
contentContainerStyle={contentContainerStyle}
|
|
47
48
|
onLayout={scrollFocusedInputIntoView}
|
|
48
49
|
onContentSizeChange={scrollFocusedInputIntoView}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
|
+
import { useConversationAvatarUpdate } from '../use_conversation_avatar_update'
|
|
6
|
+
|
|
7
|
+
const mockPatch = jest.fn().mockResolvedValue({ data: { id: 7 } })
|
|
8
|
+
let finishUpload = () => {}
|
|
9
|
+
jest.mock('../use_api_client', () => ({ useApiClient: () => ({ chat: { patch: mockPatch } }) }))
|
|
10
|
+
jest.mock('../use_upload_client', () => ({
|
|
11
|
+
useUploadClient: () => ({
|
|
12
|
+
uploadFile: () => new Promise(resolve => (finishUpload = () => resolve({ id: 'upload-1' }))),
|
|
13
|
+
}),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe('useConversationAvatarUpdate', () => {
|
|
17
|
+
it('saves only the newest pick when an icon is chosen during a photo upload', async () => {
|
|
18
|
+
const queryClient = buildTestQueryClient({
|
|
19
|
+
defaultOptions: { mutations: { gcTime: Infinity } },
|
|
20
|
+
})
|
|
21
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
22
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
23
|
+
)
|
|
24
|
+
const { result } = renderHook(() => useConversationAvatarUpdate({ conversationId: 7 }), {
|
|
25
|
+
wrapper,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const photoSave = result.current.mutateAsync({
|
|
29
|
+
kind: 'image',
|
|
30
|
+
color: 'cosmic',
|
|
31
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
32
|
+
})
|
|
33
|
+
await act(() => result.current.mutateAsync({ kind: 'icon', key: 'star', color: 'cosmic' }))
|
|
34
|
+
finishUpload()
|
|
35
|
+
await act(() => photoSave)
|
|
36
|
+
|
|
37
|
+
expect(mockPatch).toHaveBeenCalledTimes(1)
|
|
38
|
+
expect(mockPatch.mock.calls[0][0].data.data.attributes.custom_avatar_type).toBe('icon')
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
import { Alert } from 'react-native'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import { InfiniteData, useMutation, useMutationState, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { Alert, Image } from 'react-native'
|
|
3
|
+
import type {
|
|
4
|
+
ApiCollection,
|
|
5
|
+
ApiResource,
|
|
6
|
+
ConversationAvatarData,
|
|
7
|
+
ConversationResource,
|
|
8
|
+
} from '../types'
|
|
9
|
+
import { updateAllRecordsInPagesData } from '../utils/cache/page_mutations'
|
|
5
10
|
import { transformGetToPost } from '../utils/client/request_helpers'
|
|
6
11
|
import type { ImagePickerAsset } from '../utils/native_adapters/image_picker'
|
|
7
12
|
import { ApiClient, useApiClient } from './use_api_client'
|
|
@@ -16,6 +21,18 @@ export type AvatarUpdatePayload =
|
|
|
16
21
|
| { kind: Extract<AvatarType, 'image'>; imageAsset: ImagePickerAsset; color: string }
|
|
17
22
|
| { kind: 'clear' }
|
|
18
23
|
|
|
24
|
+
const MUTATION_KEY = 'updateConversationAvatar'
|
|
25
|
+
|
|
26
|
+
export const usePendingConversationAvatarUpdate = (conversationId: number | undefined) => {
|
|
27
|
+
const newest = useMutationState({
|
|
28
|
+
filters: { mutationKey: [MUTATION_KEY, conversationId], exact: true },
|
|
29
|
+
select: mutation => mutation.state,
|
|
30
|
+
}).at(-1)
|
|
31
|
+
|
|
32
|
+
if (conversationId === undefined || newest?.status !== 'pending') return undefined
|
|
33
|
+
return newest.variables as AvatarUpdatePayload
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
export const useConversationAvatarUpdate = ({ conversationId }: { conversationId: number }) => {
|
|
20
37
|
const apiClient = useApiClient()
|
|
21
38
|
const uploadClient = useUploadClient()
|
|
@@ -23,11 +40,18 @@ export const useConversationAvatarUpdate = ({ conversationId }: { conversationId
|
|
|
23
40
|
const requestArgs = getConversationRequestArgs({ conversation_id: conversationId })
|
|
24
41
|
const queryKey = getRequestQueryKey(requestArgs)
|
|
25
42
|
|
|
43
|
+
const isSuperseded = (payload: AvatarUpdatePayload) =>
|
|
44
|
+
queryClient
|
|
45
|
+
.getMutationCache()
|
|
46
|
+
.findAll({ mutationKey: [MUTATION_KEY, conversationId], exact: true })
|
|
47
|
+
.at(-1)?.state.variables !== payload
|
|
48
|
+
|
|
26
49
|
return useMutation({
|
|
27
|
-
mutationKey: [
|
|
50
|
+
mutationKey: [MUTATION_KEY, conversationId],
|
|
28
51
|
mutationFn: async (payload: AvatarUpdatePayload) => {
|
|
29
52
|
const postArgs = transformGetToPost(requestArgs).data
|
|
30
53
|
const attributes = await buildAttributes(payload, uploadClient)
|
|
54
|
+
if (isSuperseded(payload)) return null
|
|
31
55
|
|
|
32
56
|
return apiClient.chat.patch<ApiResource<ConversationResource>>({
|
|
33
57
|
url: `/me/conversations/${conversationId}/`,
|
|
@@ -41,16 +65,35 @@ export const useConversationAvatarUpdate = ({ conversationId }: { conversationId
|
|
|
41
65
|
|
|
42
66
|
queryClient.setQueryData<ApiResource<ConversationResource>>(queryKey, prev => {
|
|
43
67
|
if (!prev?.data) return prev
|
|
44
|
-
return { ...prev, data:
|
|
68
|
+
return { ...prev, data: applyAvatarUpdate(prev.data, payload) }
|
|
45
69
|
})
|
|
46
70
|
|
|
47
71
|
return { previous }
|
|
48
72
|
},
|
|
49
|
-
onSuccess: (response, _payload, _context) => {
|
|
73
|
+
onSuccess: async (response, _payload, _context) => {
|
|
74
|
+
if (!response) return
|
|
75
|
+
|
|
50
76
|
queryClient.setQueryData<ApiResource<ConversationResource>>(queryKey, () => response)
|
|
77
|
+
queryClient.setQueriesData<InfiniteData<ApiCollection<ConversationResource>>>(
|
|
78
|
+
{ queryKey: ['/me/conversations'] },
|
|
79
|
+
prev => {
|
|
80
|
+
if (!prev?.pages) return prev
|
|
81
|
+
|
|
82
|
+
return updateAllRecordsInPagesData({
|
|
83
|
+
data: prev,
|
|
84
|
+
processRecord: record =>
|
|
85
|
+
record.id === conversationId ? applySavedAvatar(record, response.data) : record,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
)
|
|
51
89
|
queryClient.invalidateQueries({ queryKey: ['/me/conversations'] })
|
|
90
|
+
|
|
91
|
+
const imageUrl = response.data.customAvatarImageUrl
|
|
92
|
+
if (imageUrl) await Image.prefetch(imageUrl).catch(() => false)
|
|
52
93
|
},
|
|
53
|
-
onError: (_error,
|
|
94
|
+
onError: (_error, payload, context) => {
|
|
95
|
+
if (isSuperseded(payload)) return
|
|
96
|
+
|
|
54
97
|
if (context?.previous) {
|
|
55
98
|
queryClient.setQueryData(queryKey, context.previous)
|
|
56
99
|
}
|
|
@@ -83,10 +126,23 @@ export async function patchConversationAvatar(
|
|
|
83
126
|
}
|
|
84
127
|
}
|
|
85
128
|
|
|
86
|
-
function
|
|
87
|
-
data:
|
|
129
|
+
function applySavedAvatar<T extends ConversationAvatarData>(
|
|
130
|
+
data: T,
|
|
131
|
+
saved: ConversationAvatarData
|
|
132
|
+
): T {
|
|
133
|
+
return {
|
|
134
|
+
...data,
|
|
135
|
+
customAvatarType: saved.customAvatarType,
|
|
136
|
+
customAvatarKey: saved.customAvatarKey,
|
|
137
|
+
customAvatarColor: saved.customAvatarColor,
|
|
138
|
+
customAvatarImageUrl: saved.customAvatarImageUrl,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function applyAvatarUpdate<T extends ConversationAvatarData>(
|
|
143
|
+
data: T,
|
|
88
144
|
payload: AvatarUpdatePayload
|
|
89
|
-
):
|
|
145
|
+
): T {
|
|
90
146
|
switch (payload.kind) {
|
|
91
147
|
case 'icon':
|
|
92
148
|
return {
|
package/src/navigation/index.tsx
CHANGED
|
@@ -85,7 +85,9 @@ import { ScreenLayoutWithChatAccessGate } from './screenLayout'
|
|
|
85
85
|
|
|
86
86
|
const globalScreenOptions: () => NativeStackNavigationOptions = () => ({
|
|
87
87
|
headerBackButtonDisplayMode: 'minimal',
|
|
88
|
-
...(isLiquidGlassEnabled()
|
|
88
|
+
...(isLiquidGlassEnabled()
|
|
89
|
+
? { headerShadowVisible: false, headerTransparent: true, headerBlurEffect: 'regular' }
|
|
90
|
+
: {}),
|
|
89
91
|
})
|
|
90
92
|
|
|
91
93
|
export const NewConversationStack = createNativeStackNavigator({
|
|
@@ -232,7 +234,9 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
232
234
|
screen: ConversationScreen,
|
|
233
235
|
options: ({ route, navigation }) =>
|
|
234
236
|
composeOptions(
|
|
235
|
-
{
|
|
237
|
+
{
|
|
238
|
+
title: (route.params as ConversationRouteProps)?.title ?? 'Reply',
|
|
239
|
+
},
|
|
236
240
|
withMinimalBack({ onPress: navigation.goBack })
|
|
237
241
|
),
|
|
238
242
|
},
|
|
@@ -58,7 +58,11 @@ export function AgeCheckRequiredScreen() {
|
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<>
|
|
61
|
-
<ScrollView
|
|
61
|
+
<ScrollView
|
|
62
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
63
|
+
style={styles.scrollView}
|
|
64
|
+
contentContainerStyle={styles.container}
|
|
65
|
+
>
|
|
62
66
|
<View style={styles.header}>
|
|
63
67
|
<View style={styles.heading}>
|
|
64
68
|
<Icon name="general.exclamationTriangle" size={20} style={styles.warningIcon} />
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { HeaderHeightContext } from '@react-navigation/elements'
|
|
2
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
3
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
+
import { render } from '@testing-library/react-native'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { Image } from 'react-native'
|
|
7
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
8
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
9
|
+
import type { AvatarUpdatePayload } from '../../../hooks/use_conversation_avatar_update'
|
|
10
|
+
import { AvatarPickerScreen } from '../avatar_picker_screen'
|
|
11
|
+
|
|
12
|
+
jest.mock('@react-navigation/native', () => ({
|
|
13
|
+
...jest.requireActual('@react-navigation/native'),
|
|
14
|
+
useNavigation: () => ({ goBack: jest.fn(), dispatch: jest.fn() }),
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../../hooks/use_api_client', () => ({ useApiClient: () => ({}) }))
|
|
17
|
+
jest.mock('../../../hooks/use_upload_client', () => ({ useUploadClient: () => ({}) }))
|
|
18
|
+
jest.mock('../../../hooks/use_conversation', () => ({
|
|
19
|
+
...jest.requireActual('../../../hooks/use_conversation'),
|
|
20
|
+
useConversation: () => ({
|
|
21
|
+
data: { id: 7, customAvatarType: 'icon', customAvatarKey: 'star', customAvatarColor: 'cosmic' },
|
|
22
|
+
}),
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
const safeAreaMetrics = {
|
|
26
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
27
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('AvatarPickerScreen', () => {
|
|
31
|
+
it('opens on a photo that is still uploading instead of the cached avatar', async () => {
|
|
32
|
+
const queryClient = buildTestQueryClient()
|
|
33
|
+
const photo: AvatarUpdatePayload = {
|
|
34
|
+
kind: 'image',
|
|
35
|
+
color: 'cosmic',
|
|
36
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
37
|
+
}
|
|
38
|
+
let finishUpload = () => {}
|
|
39
|
+
const uploading = new Promise<void>(resolve => (finishUpload = resolve))
|
|
40
|
+
const upload = queryClient
|
|
41
|
+
.getMutationCache()
|
|
42
|
+
.build(queryClient, {
|
|
43
|
+
mutationKey: ['updateConversationAvatar', 7],
|
|
44
|
+
mutationFn: () => uploading,
|
|
45
|
+
networkMode: 'always',
|
|
46
|
+
})
|
|
47
|
+
.execute(photo)
|
|
48
|
+
|
|
49
|
+
const view = render(
|
|
50
|
+
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
51
|
+
<ThemeProvider value={DefaultTheme}>
|
|
52
|
+
<HeaderHeightContext.Provider value={0}>
|
|
53
|
+
<QueryClientProvider client={queryClient}>
|
|
54
|
+
<AvatarPickerScreen route={{ params: { conversation_id: 7 } } as never} />
|
|
55
|
+
</QueryClientProvider>
|
|
56
|
+
</HeaderHeightContext.Provider>
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
</SafeAreaProvider>
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const sources = view.UNSAFE_getAllByType(Image).map(image => image.props.source)
|
|
62
|
+
expect(sources).toContainEqual({ uri: 'file:///photo.jpg' })
|
|
63
|
+
|
|
64
|
+
finishUpload()
|
|
65
|
+
await upload
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -11,6 +11,7 @@ import { useTheme } from '../../hooks'
|
|
|
11
11
|
import { useConversation } from '../../hooks/use_conversation'
|
|
12
12
|
import {
|
|
13
13
|
useConversationAvatarUpdate,
|
|
14
|
+
usePendingConversationAvatarUpdate,
|
|
14
15
|
type AvatarUpdatePayload,
|
|
15
16
|
} from '../../hooks/use_conversation_avatar_update'
|
|
16
17
|
import { useFontScale } from '../../hooks/use_font_scale'
|
|
@@ -79,9 +80,14 @@ function EditModeContent({ conversationId }: { conversationId: number }) {
|
|
|
79
80
|
const navigation = useNavigation()
|
|
80
81
|
const { data: conversation } = useConversation({ conversation_id: conversationId })
|
|
81
82
|
const mutation = useConversationAvatarUpdate({ conversationId })
|
|
83
|
+
const pendingUpdate = usePendingConversationAvatarUpdate(conversationId)
|
|
82
84
|
const previewDiameter = usePreviewAvatarDiameter()
|
|
83
85
|
|
|
84
|
-
const [state, dispatch] = useReducer(avatarPickerReducer,
|
|
86
|
+
const [state, dispatch] = useReducer(avatarPickerReducer, undefined, () =>
|
|
87
|
+
pendingUpdate
|
|
88
|
+
? initAvatarPickerStateFromPayload(pendingUpdate)
|
|
89
|
+
: initAvatarPickerState(conversation)
|
|
90
|
+
)
|
|
85
91
|
|
|
86
92
|
const hasAvatar = state.selectedType !== null
|
|
87
93
|
|
|
@@ -427,6 +427,7 @@ export function ConversationDetailsScreen({ route }: ConversationDetailsScreenPr
|
|
|
427
427
|
return (
|
|
428
428
|
<View style={styles.listContainer}>
|
|
429
429
|
<FlatList
|
|
430
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
430
431
|
data={listData as SectionListData}
|
|
431
432
|
contentContainerStyle={styles.contentContainer}
|
|
432
433
|
renderItem={({ item, index }) => {
|
|
@@ -59,7 +59,10 @@ export const ConversationNewEntryScreen = ({ route }: ConversationSelectRecipien
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
|
-
<ScrollView
|
|
62
|
+
<ScrollView
|
|
63
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
64
|
+
contentContainerStyle={styles.contentContainer}
|
|
65
|
+
>
|
|
63
66
|
<View style={styles.header}>
|
|
64
67
|
<Heading variant="h2">Start a conversation by</Heading>
|
|
65
68
|
</View>
|
|
@@ -333,6 +333,7 @@ function CandidateList({
|
|
|
333
333
|
return (
|
|
334
334
|
<FlatList<DirectMessageCandidateResource>
|
|
335
335
|
data={available}
|
|
336
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
336
337
|
keyboardShouldPersistTaps="handled"
|
|
337
338
|
keyExtractor={item => item.id}
|
|
338
339
|
renderItem={({ item }) => (
|
package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx
CHANGED
|
@@ -60,6 +60,7 @@ export const ConversationSelectGroupRecipientsScreen = ({
|
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
62
|
<SectionList<GroupsGroupResource, GroupsSection>
|
|
63
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
63
64
|
sections={sections}
|
|
64
65
|
keyExtractor={item => item.id.toString()}
|
|
65
66
|
stickySectionHeadersEnabled={false}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import { useCallback, useMemo } from 'react'
|
|
3
|
-
import { Alert, StyleSheet, View } from 'react-native'
|
|
3
|
+
import { Alert, ScrollView, StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Heading, PressableRow, Text, TextInlineButton } from '../components'
|
|
5
5
|
import { useApiGet, useTheme } from '../hooks'
|
|
6
6
|
import { useAppName } from '../hooks/use_app_name'
|
|
@@ -56,7 +56,7 @@ export const GetHelpScreen = ({ route }: GetHelpScreenProps) => {
|
|
|
56
56
|
}, [navigation])
|
|
57
57
|
|
|
58
58
|
return (
|
|
59
|
-
<
|
|
59
|
+
<ScrollView contentInsetAdjustmentBehavior="automatic" contentContainerStyle={styles.container}>
|
|
60
60
|
{appSpecificHelpUrls.length > 0 && (
|
|
61
61
|
<Heading variant="h2" style={[styles.heading, styles.headingBottomBorder]}>
|
|
62
62
|
How-to articles
|
|
@@ -90,7 +90,7 @@ export const GetHelpScreen = ({ route }: GetHelpScreenProps) => {
|
|
|
90
90
|
to the development team.
|
|
91
91
|
</Text>
|
|
92
92
|
</View>
|
|
93
|
-
</
|
|
93
|
+
</ScrollView>
|
|
94
94
|
)
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -145,7 +145,7 @@ const useStyles = () => {
|
|
|
145
145
|
|
|
146
146
|
return StyleSheet.create({
|
|
147
147
|
container: {
|
|
148
|
-
|
|
148
|
+
flexGrow: 1,
|
|
149
149
|
},
|
|
150
150
|
text: {
|
|
151
151
|
paddingVertical: 4,
|
|
@@ -2,7 +2,7 @@ import { PlatformPressable } from '@react-navigation/elements'
|
|
|
2
2
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
3
3
|
import type { NativeStackNavigationProp } from '@react-navigation/native-stack'
|
|
4
4
|
import React, { useEffect } from 'react'
|
|
5
|
-
import { Platform, StyleSheet, View } from 'react-native'
|
|
5
|
+
import { Platform, ScrollView, StyleSheet, View } from 'react-native'
|
|
6
6
|
import { Heading, Icon, Text } from '../components'
|
|
7
7
|
import { useTheme } from '../hooks'
|
|
8
8
|
import { platformFontWeightBold } from '../utils/styles'
|
|
@@ -38,7 +38,7 @@ export function GroupNotificationSettingsScreen({ route }: GroupNotificationSett
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
|
-
<
|
|
41
|
+
<ScrollView contentInsetAdjustmentBehavior="automatic" style={styles.container}>
|
|
42
42
|
<View style={styles.sectionOuter}>
|
|
43
43
|
<View style={styles.sectionInner}>
|
|
44
44
|
<Heading variant="h2" style={styles.sectionHeading}>
|
|
@@ -76,7 +76,7 @@ export function GroupNotificationSettingsScreen({ route }: GroupNotificationSett
|
|
|
76
76
|
)}
|
|
77
77
|
</View>
|
|
78
78
|
</PlatformPressable>
|
|
79
|
-
</
|
|
79
|
+
</ScrollView>
|
|
80
80
|
)
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -123,6 +123,7 @@ export function NotificationSettingsScreen({}: NotificationSettingsScreenProps)
|
|
|
123
123
|
return (
|
|
124
124
|
<View style={styles.listContainer}>
|
|
125
125
|
<FlatList
|
|
126
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
126
127
|
data={listData as SectionListData}
|
|
127
128
|
contentContainerStyle={styles.contentContainer}
|
|
128
129
|
renderItem={({ item, index }) => {
|