@planningcenter/chat-react-native 4.7.1-qa-staging.9 → 4.7.1-qa-1119.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/conversations/bulk_conversation_actions_bar.d.ts +2 -0
- package/build/components/conversations/bulk_conversation_actions_bar.d.ts.map +1 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js +215 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
- package/build/components/conversations/conversation_actions.d.ts +2 -1
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +173 -130
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/conversations/conversation_preview.d.ts.map +1 -1
- package/build/components/conversations/conversation_preview.js +168 -110
- package/build/components/conversations/conversation_preview.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +50 -48
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/checkbox.d.ts +8 -0
- package/build/components/display/checkbox.d.ts.map +1 -0
- package/build/components/display/checkbox.js +87 -0
- package/build/components/display/checkbox.js.map +1 -0
- package/build/components/display/icon.d.ts +3 -1
- package/build/components/display/icon.d.ts.map +1 -1
- package/build/components/display/icon.js +2 -0
- package/build/components/display/icon.js.map +1 -1
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +5 -0
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +121 -32
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/contexts/session_context.d.ts +0 -1
- package/build/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js.map +1 -1
- package/build/hooks/use_bulk_conversation_actions.d.ts +8 -0
- package/build/hooks/use_bulk_conversation_actions.d.ts.map +1 -0
- package/build/hooks/use_bulk_conversation_actions.js +309 -0
- package/build/hooks/use_bulk_conversation_actions.js.map +1 -0
- package/build/hooks/use_conversations_cache.d.ts +14 -2
- package/build/hooks/use_conversations_cache.d.ts.map +1 -1
- package/build/hooks/use_conversations_cache.js +149 -56
- package/build/hooks/use_conversations_cache.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -7
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_actions_screen.d.ts +2 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -1
- package/build/screens/conversation_actions_screen.js +380 -46
- package/build/screens/conversation_actions_screen.js.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +5 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +156 -31
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/utils/native_adapters/configuration.d.ts +3 -0
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +3 -0
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/updates.d.ts +11 -0
- package/build/utils/native_adapters/updates.d.ts.map +1 -0
- package/build/utils/native_adapters/updates.js +8 -0
- package/build/utils/native_adapters/updates.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/contexts/session_context.tsx +19 -39
- package/src/__tests__/hooks/useTheme.tsx +0 -7
- package/src/__tests__/hooks/use_async_storage.test.tsx +1 -87
- package/src/__tests__/hooks/use_attachment_uploader.test.tsx +0 -11
- package/src/__tests__/hooks/use_font_scale.test.ts +0 -25
- package/src/__tests__/utils/cache/page_mutations.ts +3 -68
- package/src/__tests__/utils/client.ts +6 -15
- package/src/__tests__/utils/native_adapters/configuration.ts +15 -50
- package/src/__tests__/utils/parse_simple_markdown.ts +0 -6
- package/src/__tests__/utils/session.ts +0 -11
- package/src/__tests__/utils/theme.ts +0 -17
- package/src/components/conversations/__tests__/bulk_conversation_actions_bar.test.tsx +95 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +35 -3
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
- package/src/components/conversations/__tests__/conversations.test.tsx +4 -1
- package/src/components/conversations/bulk_conversation_actions_bar.tsx +140 -0
- package/src/components/conversations/conversation_actions.tsx +17 -9
- package/src/components/conversations/conversation_preview.tsx +20 -2
- package/src/components/conversations/conversations.tsx +2 -1
- package/src/components/display/__tests__/filter_dropdown.test.tsx +1 -19
- package/src/components/display/__tests__/icon_tile.test.tsx +24 -7
- package/src/components/display/checkbox.tsx +47 -0
- package/src/components/display/icon.tsx +3 -0
- package/src/components/display/index.ts +1 -0
- package/src/components/page/__tests__/component_error_boundary.test.tsx +0 -12
- package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
- package/src/contexts/conversations_context.tsx +69 -2
- package/src/contexts/session_context.tsx +0 -1
- package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +0 -35
- package/src/hooks/__tests__/use_bulk_conversation_actions.test.tsx +119 -0
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +15 -3
- package/src/hooks/use_bulk_conversation_actions.ts +173 -0
- package/src/hooks/use_conversations_cache.ts +32 -3
- package/src/navigation/index.tsx +8 -8
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +48 -6
- package/src/screens/__tests__/conversation_details_screen.test.tsx +0 -19
- package/src/screens/avatar_picker/__tests__/avatar_picker_state.test.ts +0 -14
- package/src/screens/conversation_actions_screen.tsx +145 -12
- package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +35 -9
- package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -8
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +0 -10
- package/src/screens/conversations/conversations_screen.tsx +67 -3
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +1 -0
- package/src/utils/__tests__/attachment_kind.test.ts +0 -4
- package/src/utils/__tests__/convert_attachments_for_create.test.ts +0 -28
- package/src/utils/__tests__/is_input_editable.test.ts +1 -2
- package/src/utils/__tests__/message_text.test.ts +0 -5
- package/src/utils/__tests__/session_manager.test.ts +0 -83
- package/src/utils/__tests__/sha_256.test.ts +0 -34
- package/src/utils/__tests__/uri.test.ts +51 -0
- package/src/utils/native_adapters/configuration.ts +5 -0
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/updates.ts +16 -0
- package/src/__tests__/event-polyfill.test.ts +0 -313
- package/src/__tests__/index.tsx +0 -5
- package/src/__tests__/jest.ts +0 -11
- package/src/__tests__/utils/uri.ts +0 -65
- package/src/components/display/__tests__/version_footer.test.tsx +0 -48
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +0 -20
- package/src/utils/__tests__/membership_sync_info_text.test.ts +0 -15
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
|
|
3
|
+
import { useTheme } from '../../hooks'
|
|
4
|
+
import { tokens } from '../../vendor/tapestry/tokens'
|
|
5
|
+
import { Icon } from './icon'
|
|
6
|
+
|
|
7
|
+
interface CheckboxProps {
|
|
8
|
+
checked: boolean
|
|
9
|
+
style?: StyleProp<ViewStyle>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Checkbox({ checked, style }: CheckboxProps) {
|
|
13
|
+
const styles = useStyles()
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<View style={[checked ? styles.checkedContainer : styles.uncheckedContainer, style]}>
|
|
17
|
+
{checked && <Icon name="general.thickCheckmark" style={styles.checkedIcon} />}
|
|
18
|
+
</View>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const useStyles = () => {
|
|
23
|
+
const { colors } = useTheme()
|
|
24
|
+
|
|
25
|
+
const baseCheckboxStyles: ViewStyle = {
|
|
26
|
+
width: 20,
|
|
27
|
+
height: 20,
|
|
28
|
+
borderRadius: 40,
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return StyleSheet.create({
|
|
34
|
+
checkedContainer: {
|
|
35
|
+
...baseCheckboxStyles,
|
|
36
|
+
backgroundColor: colors.statusSuccessIcon,
|
|
37
|
+
},
|
|
38
|
+
uncheckedContainer: {
|
|
39
|
+
...baseCheckboxStyles,
|
|
40
|
+
borderWidth: 2,
|
|
41
|
+
borderColor: colors.borderColorDefaultDarker,
|
|
42
|
+
},
|
|
43
|
+
checkedIcon: {
|
|
44
|
+
color: tokens.colorNeutral100White,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -3,6 +3,7 @@ import * as api from '@planningcenter/icons/paths/api'
|
|
|
3
3
|
import * as brand from '@planningcenter/icons/paths/brand'
|
|
4
4
|
import * as calendar from '@planningcenter/icons/paths/calendar'
|
|
5
5
|
import * as chat from '@planningcenter/icons/paths/chat'
|
|
6
|
+
import * as checkIns from '@planningcenter/icons/paths/check-ins'
|
|
6
7
|
import * as churchCenter from '@planningcenter/icons/paths/church-center'
|
|
7
8
|
import * as general from '@planningcenter/icons/paths/general'
|
|
8
9
|
import * as groups from '@planningcenter/icons/paths/groups'
|
|
@@ -30,6 +31,7 @@ const ICONS = {
|
|
|
30
31
|
brand,
|
|
31
32
|
calendar,
|
|
32
33
|
chat,
|
|
34
|
+
checkIns,
|
|
33
35
|
churchCenter,
|
|
34
36
|
general,
|
|
35
37
|
groups,
|
|
@@ -55,6 +57,7 @@ export type IconString =
|
|
|
55
57
|
| `brand.${IconName<'brand'>}`
|
|
56
58
|
| `calendar.${IconName<'calendar'>}`
|
|
57
59
|
| `chat.${IconName<'chat'>}`
|
|
60
|
+
| `checkIns.${IconName<'checkIns'>}`
|
|
58
61
|
| `churchCenter.${IconName<'churchCenter'>}`
|
|
59
62
|
| `general.${IconName<'general'>}`
|
|
60
63
|
| `groups.${IconName<'groups'>}`
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { render } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Text } from 'react-native'
|
|
4
3
|
import { Log } from '../../../utils/native_adapters/configuration'
|
|
5
4
|
import { ComponentErrorBoundary } from '../component_error_boundary'
|
|
6
5
|
|
|
@@ -32,15 +31,4 @@ describe('ComponentErrorBoundary', () => {
|
|
|
32
31
|
expect(toJSON()).toBeNull()
|
|
33
32
|
expect(reportError.mock.calls[0][1]).toMatchObject({ scope: 'component' })
|
|
34
33
|
})
|
|
35
|
-
|
|
36
|
-
it('lets callers override the defaults', () => {
|
|
37
|
-
const { getByText } = render(
|
|
38
|
-
<ComponentErrorBoundary scope="screen" fallback={<Text>overridden</Text>}>
|
|
39
|
-
<Boom thrown={new Error('boom')} />
|
|
40
|
-
</ComponentErrorBoundary>
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
expect(getByText('overridden')).toBeTruthy()
|
|
44
|
-
expect(reportError.mock.calls[0][1]).toMatchObject({ scope: 'screen' })
|
|
45
|
-
})
|
|
46
34
|
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { ConversationFiltersParams } from '../../screens/conversation_filters/screen_props'
|
|
4
|
+
import { ConversationsContextProvider, useConversationsContext } from '../conversations_context'
|
|
5
|
+
|
|
6
|
+
let mockHideEnabled = true
|
|
7
|
+
jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
|
|
8
|
+
useHideConversationsEnabled: () => mockHideEnabled,
|
|
9
|
+
}))
|
|
10
|
+
jest.mock('../../hooks/use_conversations', () => ({
|
|
11
|
+
useConversations: () => ({ conversations: [] }),
|
|
12
|
+
}))
|
|
13
|
+
|
|
14
|
+
let mockArgs: ConversationFiltersParams = {}
|
|
15
|
+
|
|
16
|
+
const renderContext = () =>
|
|
17
|
+
renderHook(() => useConversationsContext(), {
|
|
18
|
+
wrapper: ({ children }: { children: React.ReactNode }) => (
|
|
19
|
+
<ConversationsContextProvider args={mockArgs}>{children}</ConversationsContextProvider>
|
|
20
|
+
),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('ConversationsContextProvider selection', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
mockHideEnabled = true
|
|
26
|
+
mockArgs = {}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('toggles conversations in and out of the selection', () => {
|
|
30
|
+
const { result } = renderContext()
|
|
31
|
+
|
|
32
|
+
act(() => result.current.enterSelectMode(1))
|
|
33
|
+
act(() => result.current.toggleSelected(2))
|
|
34
|
+
|
|
35
|
+
expect(result.current.selectMode).toBe(true)
|
|
36
|
+
expect(result.current.selectedIds).toEqual([1, 2])
|
|
37
|
+
|
|
38
|
+
act(() => result.current.toggleSelected(1))
|
|
39
|
+
|
|
40
|
+
expect(result.current.selectedIds).toEqual([2])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('leaves select mode on clear', () => {
|
|
44
|
+
const { result } = renderContext()
|
|
45
|
+
|
|
46
|
+
act(() => result.current.enterSelectMode(1))
|
|
47
|
+
act(() => result.current.clearSelection())
|
|
48
|
+
|
|
49
|
+
expect(result.current.selectMode).toBe(false)
|
|
50
|
+
expect(result.current.selectedIds).toEqual([])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('clears the selection when the filter changes', () => {
|
|
54
|
+
const { result, rerender } = renderContext()
|
|
55
|
+
|
|
56
|
+
act(() => result.current.enterSelectMode(1))
|
|
57
|
+
mockArgs = { show_unread: true }
|
|
58
|
+
rerender({})
|
|
59
|
+
|
|
60
|
+
expect(result.current.selectMode).toBe(false)
|
|
61
|
+
expect(result.current.selectedIds).toEqual([])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('stays out of select mode when the flag is off', () => {
|
|
65
|
+
mockHideEnabled = false
|
|
66
|
+
const { result } = renderContext()
|
|
67
|
+
|
|
68
|
+
act(() => result.current.enterSelectMode(1))
|
|
69
|
+
|
|
70
|
+
expect(result.current.selectMode).toBe(false)
|
|
71
|
+
expect(result.current.selectedIds).toEqual([])
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('does not revive the selection when the flag flips off and back on', () => {
|
|
75
|
+
const { result, rerender } = renderContext()
|
|
76
|
+
|
|
77
|
+
act(() => result.current.enterSelectMode(1))
|
|
78
|
+
mockHideEnabled = false
|
|
79
|
+
rerender({})
|
|
80
|
+
mockHideEnabled = true
|
|
81
|
+
rerender({})
|
|
82
|
+
|
|
83
|
+
expect(result.current.selectMode).toBe(false)
|
|
84
|
+
expect(result.current.selectedIds).toEqual([])
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -3,9 +3,18 @@ import {
|
|
|
3
3
|
InfiniteQueryObserverResult,
|
|
4
4
|
InfiniteData,
|
|
5
5
|
} from '@tanstack/react-query'
|
|
6
|
-
import React, {
|
|
6
|
+
import React, {
|
|
7
|
+
createContext,
|
|
8
|
+
PropsWithChildren,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react'
|
|
7
15
|
import { ApiGetQueryOptions } from '../hooks'
|
|
8
16
|
import { useConversations, UseConversationsValue } from '../hooks/use_conversations'
|
|
17
|
+
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
|
|
9
18
|
import { ConversationFiltersParams } from '../screens/conversation_filters/screen_props'
|
|
10
19
|
import { ApiCollection, ConversationResource } from '../types'
|
|
11
20
|
import { ResponseError } from '../utils/response_error'
|
|
@@ -15,6 +24,11 @@ interface ConversationsContextValue extends UseConversationsValue {
|
|
|
15
24
|
setActiveConversationId: (_id: number) => void
|
|
16
25
|
args: ConversationFiltersParams
|
|
17
26
|
hideable: boolean
|
|
27
|
+
selectMode: boolean
|
|
28
|
+
selectedIds: number[]
|
|
29
|
+
enterSelectMode: (_id?: number) => void
|
|
30
|
+
toggleSelected: (_id: number) => void
|
|
31
|
+
clearSelection: () => void
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
const defaultQueryValue: UseConversationsValue = {
|
|
@@ -35,6 +49,11 @@ const ConversationsContext = createContext<ConversationsContextValue>({
|
|
|
35
49
|
activeConversationId: undefined,
|
|
36
50
|
setActiveConversationId: () => {},
|
|
37
51
|
hideable: true,
|
|
52
|
+
selectMode: false,
|
|
53
|
+
selectedIds: [],
|
|
54
|
+
enterSelectMode: () => {},
|
|
55
|
+
toggleSelected: () => {},
|
|
56
|
+
clearSelection: () => {},
|
|
38
57
|
...defaultQueryValue,
|
|
39
58
|
})
|
|
40
59
|
|
|
@@ -49,6 +68,10 @@ export const ConversationsContextProvider = ({
|
|
|
49
68
|
hideable?: boolean
|
|
50
69
|
}>) => {
|
|
51
70
|
const [activeConversationId, setActiveConversationId] = useState<number | undefined>()
|
|
71
|
+
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
72
|
+
const [selecting, setSelecting] = useState(false)
|
|
73
|
+
const [selectedIds, setSelectedIds] = useState<number[]>([])
|
|
74
|
+
const selectMode = hideConversationsEnabled && selecting
|
|
52
75
|
const {
|
|
53
76
|
chat_group_graph_id,
|
|
54
77
|
group_source_app_name,
|
|
@@ -70,15 +93,59 @@ export const ConversationsContextProvider = ({
|
|
|
70
93
|
paginatorOptions
|
|
71
94
|
)
|
|
72
95
|
|
|
96
|
+
const enterSelectMode = useCallback((id?: number) => {
|
|
97
|
+
setSelecting(true)
|
|
98
|
+
setSelectedIds(id === undefined ? [] : [id])
|
|
99
|
+
}, [])
|
|
100
|
+
|
|
101
|
+
const toggleSelected = useCallback((id: number) => {
|
|
102
|
+
setSelectedIds(ids =>
|
|
103
|
+
ids.includes(id) ? ids.filter(selectedId => selectedId !== id) : [...ids, id]
|
|
104
|
+
)
|
|
105
|
+
}, [])
|
|
106
|
+
|
|
107
|
+
const clearSelection = useCallback(() => {
|
|
108
|
+
setSelecting(false)
|
|
109
|
+
setSelectedIds([])
|
|
110
|
+
}, [])
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
clearSelection()
|
|
114
|
+
}, [
|
|
115
|
+
clearSelection,
|
|
116
|
+
hideConversationsEnabled,
|
|
117
|
+
chat_group_graph_id,
|
|
118
|
+
group_source_app_name,
|
|
119
|
+
show_direct_messages,
|
|
120
|
+
show_archived,
|
|
121
|
+
show_hidden,
|
|
122
|
+
show_unread,
|
|
123
|
+
])
|
|
124
|
+
|
|
73
125
|
const value = useMemo(
|
|
74
126
|
() => ({
|
|
75
127
|
args,
|
|
76
128
|
activeConversationId,
|
|
77
129
|
setActiveConversationId,
|
|
78
130
|
hideable,
|
|
131
|
+
selectMode,
|
|
132
|
+
selectedIds: selectMode ? selectedIds : [],
|
|
133
|
+
enterSelectMode,
|
|
134
|
+
toggleSelected,
|
|
135
|
+
clearSelection,
|
|
79
136
|
...query,
|
|
80
137
|
}),
|
|
81
|
-
[
|
|
138
|
+
[
|
|
139
|
+
args,
|
|
140
|
+
activeConversationId,
|
|
141
|
+
hideable,
|
|
142
|
+
selectMode,
|
|
143
|
+
selectedIds,
|
|
144
|
+
enterSelectMode,
|
|
145
|
+
toggleSelected,
|
|
146
|
+
clearSelection,
|
|
147
|
+
query,
|
|
148
|
+
]
|
|
82
149
|
)
|
|
83
150
|
|
|
84
151
|
return <ConversationsContext.Provider value={value}>{children}</ConversationsContext.Provider>
|
|
@@ -155,41 +155,6 @@ describe('conversation.updated across two lists and two screens', () => {
|
|
|
155
155
|
expect(requestsFor(listUrl)).toBe(2)
|
|
156
156
|
expect(requestsFor(conversationUrl)).toBe(2)
|
|
157
157
|
})
|
|
158
|
-
|
|
159
|
-
it('refreshes immediately for a lone event and makes no second request', async () => {
|
|
160
|
-
conversationUpdated()
|
|
161
|
-
await advance(1)
|
|
162
|
-
|
|
163
|
-
expect(requestsFor(listUrl)).toBe(1)
|
|
164
|
-
expect(requestsFor(conversationUrl)).toBe(1)
|
|
165
|
-
|
|
166
|
-
await advance(REFRESH_THROTTLE_MS * 2)
|
|
167
|
-
|
|
168
|
-
expect(requestsFor(listUrl)).toBe(1)
|
|
169
|
-
expect(requestsFor(conversationUrl)).toBe(1)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('gives an event inside the window a trailing refresh opened its own trailing refresh', async () => {
|
|
173
|
-
conversationUpdated()
|
|
174
|
-
await advance(1000)
|
|
175
|
-
conversationUpdated()
|
|
176
|
-
await advance(REFRESH_THROTTLE_MS - 1000)
|
|
177
|
-
|
|
178
|
-
expect(requestsFor(listUrl)).toBe(2)
|
|
179
|
-
expect(requestsFor(conversationUrl)).toBe(2)
|
|
180
|
-
|
|
181
|
-
await advance(500)
|
|
182
|
-
conversationUpdated()
|
|
183
|
-
await advance(1)
|
|
184
|
-
|
|
185
|
-
expect(requestsFor(listUrl)).toBe(2)
|
|
186
|
-
expect(requestsFor(conversationUrl)).toBe(2)
|
|
187
|
-
|
|
188
|
-
await advance(REFRESH_THROTTLE_MS)
|
|
189
|
-
|
|
190
|
-
expect(requestsFor(listUrl)).toBe(3)
|
|
191
|
-
expect(requestsFor(conversationUrl)).toBe(3)
|
|
192
|
-
})
|
|
193
158
|
})
|
|
194
159
|
|
|
195
160
|
describe('/me refreshes', () => {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Alert } from 'react-native'
|
|
5
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
6
|
+
import type { ConversationResource } from '../../types'
|
|
7
|
+
import { getConversationsRequestArgs } from '../../utils/request/conversation'
|
|
8
|
+
import { dismissToast, toastStore } from '../../utils/toast_store'
|
|
9
|
+
import { useBulkConversationActions } from '../use_bulk_conversation_actions'
|
|
10
|
+
import { currentPersonQueryKey } from '../use_current_person'
|
|
11
|
+
import { getRequestQueryKey } from '../use_suspense_api'
|
|
12
|
+
|
|
13
|
+
const mockPatch = jest.fn()
|
|
14
|
+
const mockPost = jest.fn()
|
|
15
|
+
jest.mock('../use_api_client', () => ({
|
|
16
|
+
useApiClient: () => ({ chat: { patch: mockPatch, post: mockPost } }),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
const conversations = [
|
|
20
|
+
{ id: 7, muted: false, unreadCount: 2, unreadReaction: false },
|
|
21
|
+
{ id: 8, muted: false, unreadCount: 3, unreadReaction: true },
|
|
22
|
+
{ id: 9, muted: false, unreadCount: 0, unreadReaction: false },
|
|
23
|
+
] as ConversationResource[]
|
|
24
|
+
const allKey = getRequestQueryKey(getConversationsRequestArgs({ gids: 'all' }))
|
|
25
|
+
const hiddenKey = getRequestQueryKey(getConversationsRequestArgs({ show_hidden: true }))
|
|
26
|
+
|
|
27
|
+
const listData = (records: ConversationResource[]) => ({
|
|
28
|
+
pages: [{ data: records, links: {}, meta: { count: records.length } }],
|
|
29
|
+
pageParams: [{}],
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const listRecords = () =>
|
|
33
|
+
(queryClient.getQueryData(allKey) as ReturnType<typeof listData>).pages[0].data
|
|
34
|
+
|
|
35
|
+
const listIds = () => listRecords().map(({ id }) => id)
|
|
36
|
+
|
|
37
|
+
let queryClient = buildTestQueryClient()
|
|
38
|
+
|
|
39
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
40
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const renderBulk = () => renderHook(() => useBulkConversationActions(), { wrapper })
|
|
44
|
+
|
|
45
|
+
describe('useBulkConversationActions', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
queryClient = buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
48
|
+
queryClient.setQueryData(allKey, listData(conversations))
|
|
49
|
+
queryClient.setQueryData(currentPersonQueryKey, { data: { unreadCount: 10 } })
|
|
50
|
+
mockPatch.mockReset().mockResolvedValue({ data: {} })
|
|
51
|
+
mockPost.mockReset().mockResolvedValue({ data: {} })
|
|
52
|
+
dismissToast()
|
|
53
|
+
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
jest.restoreAllMocks()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it.each([
|
|
61
|
+
['hide', mockPatch, '/me/conversations/7/conversation_membership', { hidden: true }],
|
|
62
|
+
['unhide', mockPatch, '/me/conversations/7/conversation_membership', { hidden: false }],
|
|
63
|
+
['silence', mockPatch, '/me/conversations/7/conversation_membership', { muted: true }],
|
|
64
|
+
['markRead', mockPost, '/me/conversations/7/mark_read', {}],
|
|
65
|
+
] as const)(
|
|
66
|
+
'%s sends one request per conversation',
|
|
67
|
+
async (action, request, firstUrl, attributes) => {
|
|
68
|
+
const { result } = renderBulk()
|
|
69
|
+
|
|
70
|
+
await act(() => result.current[action](conversations))
|
|
71
|
+
|
|
72
|
+
expect(request.mock.calls.map(([{ url, data }]) => [url, data.data.attributes])).toEqual([
|
|
73
|
+
[firstUrl, attributes],
|
|
74
|
+
[firstUrl.replace('/7/', '/8/'), attributes],
|
|
75
|
+
[firstUrl.replace('/7/', '/9/'), attributes],
|
|
76
|
+
])
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
it('rolls back only the failed rows and alerts once', async () => {
|
|
81
|
+
mockPost.mockImplementation(({ url }) =>
|
|
82
|
+
url.includes('/8/') ? Promise.reject(new Error('nope')) : Promise.resolve({ data: {} })
|
|
83
|
+
)
|
|
84
|
+
const { result } = renderBulk()
|
|
85
|
+
|
|
86
|
+
await act(() => result.current.markRead(conversations))
|
|
87
|
+
|
|
88
|
+
expect(listRecords().map(({ unreadCount }) => unreadCount)).toEqual([0, 3, 0])
|
|
89
|
+
expect(queryClient.getQueryData(currentPersonQueryKey)).toEqual({ data: { unreadCount: 8 } })
|
|
90
|
+
expect(Alert.alert).toHaveBeenCalledTimes(1)
|
|
91
|
+
expect(Alert.alert).toHaveBeenCalledWith(
|
|
92
|
+
'Oops',
|
|
93
|
+
"Couldn't mark read 1 conversation. Please try again."
|
|
94
|
+
)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('restores every hidden row on undo and unhides the ones that succeeded', async () => {
|
|
98
|
+
mockPatch.mockImplementation(({ url }) =>
|
|
99
|
+
url.includes('/9/') ? Promise.reject(new Error('nope')) : Promise.resolve({ data: {} })
|
|
100
|
+
)
|
|
101
|
+
queryClient.setQueryData(hiddenKey, listData([]))
|
|
102
|
+
const { result } = renderBulk()
|
|
103
|
+
|
|
104
|
+
await act(() => result.current.hide(conversations))
|
|
105
|
+
|
|
106
|
+
expect(listIds()).toEqual([9])
|
|
107
|
+
expect(queryClient.getQueryState(hiddenKey)?.isInvalidated).toBe(true)
|
|
108
|
+
expect(toastStore.getSnapshot()).toMatchObject({ title: '2 conversations hidden' })
|
|
109
|
+
|
|
110
|
+
mockPatch.mockClear()
|
|
111
|
+
await act(async () => toastStore.getSnapshot()?.action?.onPress())
|
|
112
|
+
|
|
113
|
+
expect(listIds()).toEqual([7, 8, 9])
|
|
114
|
+
expect(mockPatch.mock.calls.map(([{ url, data }]) => [url, data.data.attributes])).toEqual([
|
|
115
|
+
['/me/conversations/7/conversation_membership', { hidden: false }],
|
|
116
|
+
['/me/conversations/8/conversation_membership', { hidden: false }],
|
|
117
|
+
])
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -47,6 +47,16 @@ const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
|
47
47
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
48
48
|
)
|
|
49
49
|
|
|
50
|
+
// A mutation left pending keeps Jest alive: with no observers, TanStack Query
|
|
51
|
+
// re-arms its gc timer until the mutation settles.
|
|
52
|
+
let settlePatch: (() => void) | undefined
|
|
53
|
+
const mockPendingPatch = () =>
|
|
54
|
+
mockPatch.mockReturnValue(
|
|
55
|
+
new Promise(resolve => {
|
|
56
|
+
settlePatch = () => resolve({ data: {} })
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
|
|
50
60
|
const renderHide = (target: ConversationResource = conversation, hidden?: boolean) =>
|
|
51
61
|
renderHook(() => useHideConversation({ conversation: target, hidden }), { wrapper })
|
|
52
62
|
|
|
@@ -63,12 +73,14 @@ describe('useHideConversation', () => {
|
|
|
63
73
|
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
64
74
|
})
|
|
65
75
|
|
|
66
|
-
afterEach(() => {
|
|
76
|
+
afterEach(async () => {
|
|
77
|
+
await act(async () => settlePatch?.())
|
|
78
|
+
settlePatch = undefined
|
|
67
79
|
jest.restoreAllMocks()
|
|
68
80
|
})
|
|
69
81
|
|
|
70
82
|
it('removes the conversation from every list before the request resolves', async () => {
|
|
71
|
-
|
|
83
|
+
mockPendingPatch()
|
|
72
84
|
const { result } = renderHide()
|
|
73
85
|
|
|
74
86
|
await act(async () => result.current.setHidden(true))
|
|
@@ -152,7 +164,7 @@ describe('useHideConversation', () => {
|
|
|
152
164
|
})
|
|
153
165
|
|
|
154
166
|
it('removes the conversation from the hidden list before the request resolves', async () => {
|
|
155
|
-
|
|
167
|
+
mockPendingPatch()
|
|
156
168
|
const { result } = renderHide(conversation, true)
|
|
157
169
|
|
|
158
170
|
expect(result.current.hidden).toBe(true)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { Alert } from 'react-native'
|
|
3
|
+
import { useConversationsContext } from '../contexts/conversations_context'
|
|
4
|
+
import { ApiResource, ConversationResource } from '../types'
|
|
5
|
+
import { pluralize } from '../utils/pluralize'
|
|
6
|
+
import { HIDDEN_CONVERSATIONS_FILTER } from '../utils/request/conversation'
|
|
7
|
+
import { showToast } from '../utils/toast_store'
|
|
8
|
+
import { useApiClient } from './use_api_client'
|
|
9
|
+
import { getConversationRequestArgs } from './use_conversation'
|
|
10
|
+
import { useConversationsCache } from './use_conversations_cache'
|
|
11
|
+
import { useCurrentPersonCache } from './use_current_person'
|
|
12
|
+
import { getRequestQueryKey } from './use_suspense_api'
|
|
13
|
+
|
|
14
|
+
const settle = async (
|
|
15
|
+
conversations: ConversationResource[],
|
|
16
|
+
request: (conversation: ConversationResource) => Promise<unknown>
|
|
17
|
+
) => {
|
|
18
|
+
const results = await Promise.allSettled(conversations.map(request))
|
|
19
|
+
const succeeded = conversations.filter((_, i) => results[i].status === 'fulfilled')
|
|
20
|
+
const failed = conversations.filter((_, i) => results[i].status === 'rejected')
|
|
21
|
+
|
|
22
|
+
return { succeeded, failed }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const alertFailures = (verb: string, failed: ConversationResource[]) => {
|
|
26
|
+
if (failed.length === 0) return
|
|
27
|
+
|
|
28
|
+
Alert.alert(
|
|
29
|
+
'Oops',
|
|
30
|
+
`Couldn't ${verb} ${pluralize(failed.length, 'conversation')}. Please try again.`
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const sumUnread = (conversations: ConversationResource[]) =>
|
|
35
|
+
conversations.reduce((sum, { unreadCount }) => sum + (unreadCount || 0), 0)
|
|
36
|
+
|
|
37
|
+
export const useBulkConversationActions = () => {
|
|
38
|
+
const apiClient = useApiClient()
|
|
39
|
+
const queryClient = useQueryClient()
|
|
40
|
+
const { args } = useConversationsContext()
|
|
41
|
+
const currentPersonCache = useCurrentPersonCache()
|
|
42
|
+
const {
|
|
43
|
+
cancelAllLists,
|
|
44
|
+
invalidateAllLists,
|
|
45
|
+
removeFromAllLists,
|
|
46
|
+
restoreLists,
|
|
47
|
+
snapshotAllLists,
|
|
48
|
+
updateInAllLists,
|
|
49
|
+
} = useConversationsCache(args)
|
|
50
|
+
|
|
51
|
+
const setMembershipHidden = (conversations: ConversationResource[], hidden: boolean) =>
|
|
52
|
+
conversations.forEach(({ id }) =>
|
|
53
|
+
queryClient.setQueryData<ApiResource<ConversationResource>>(
|
|
54
|
+
getRequestQueryKey(getConversationRequestArgs({ conversation_id: id })),
|
|
55
|
+
prev => {
|
|
56
|
+
if (!prev?.data) return prev
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...prev,
|
|
60
|
+
data: {
|
|
61
|
+
...prev.data,
|
|
62
|
+
conversationMembership: { ...prev.data.conversationMembership, hidden },
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const patchMembership =
|
|
70
|
+
(attributes: { hidden?: boolean; muted?: boolean }) =>
|
|
71
|
+
({ id }: ConversationResource) =>
|
|
72
|
+
apiClient.chat.patch({
|
|
73
|
+
url: `/me/conversations/${id}/conversation_membership`,
|
|
74
|
+
data: {
|
|
75
|
+
data: { type: 'ConversationMembership', attributes },
|
|
76
|
+
fields: { ConversationMembership: Object.keys(attributes).join(',') },
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const applyHidden = async (conversations: ConversationResource[], hidden: boolean) => {
|
|
81
|
+
const filter = hidden ? undefined : HIDDEN_CONVERSATIONS_FILTER
|
|
82
|
+
await cancelAllLists()
|
|
83
|
+
const previousLists = snapshotAllLists()
|
|
84
|
+
|
|
85
|
+
removeFromAllLists(
|
|
86
|
+
conversations.map(({ id }) => id),
|
|
87
|
+
{ filter }
|
|
88
|
+
)
|
|
89
|
+
setMembershipHidden(conversations, hidden)
|
|
90
|
+
|
|
91
|
+
const result = await settle(conversations, patchMembership({ hidden }))
|
|
92
|
+
|
|
93
|
+
if (result.failed.length > 0) {
|
|
94
|
+
restoreLists(previousLists)
|
|
95
|
+
removeFromAllLists(
|
|
96
|
+
result.succeeded.map(({ id }) => id),
|
|
97
|
+
{ filter }
|
|
98
|
+
)
|
|
99
|
+
setMembershipHidden(result.failed, !hidden)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { ...result, previousLists }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const unhide = async (conversations: ConversationResource[]) => {
|
|
106
|
+
const { failed } = await applyHidden(conversations, false)
|
|
107
|
+
|
|
108
|
+
invalidateAllLists()
|
|
109
|
+
alertFailures('unhide', failed)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const hide = async (conversations: ConversationResource[]) => {
|
|
113
|
+
const { succeeded, failed, previousLists } = await applyHidden(conversations, true)
|
|
114
|
+
|
|
115
|
+
alertFailures('hide', failed)
|
|
116
|
+
if (succeeded.length === 0) return
|
|
117
|
+
|
|
118
|
+
invalidateAllLists({ filter: HIDDEN_CONVERSATIONS_FILTER })
|
|
119
|
+
showToast({
|
|
120
|
+
title: `${pluralize(succeeded.length, 'conversation')} hidden`,
|
|
121
|
+
action: {
|
|
122
|
+
label: 'Undo',
|
|
123
|
+
onPress: () => {
|
|
124
|
+
restoreLists(previousLists)
|
|
125
|
+
unhide(succeeded)
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const silence = async (conversations: ConversationResource[]) => {
|
|
132
|
+
const setMuted = (conversation: ConversationResource, muted: boolean) =>
|
|
133
|
+
updateInAllLists(conversation.id, {
|
|
134
|
+
muted,
|
|
135
|
+
conversationMembership: { ...conversation.conversationMembership, muted },
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
conversations.forEach(conversation => setMuted(conversation, true))
|
|
139
|
+
|
|
140
|
+
const { failed } = await settle(conversations, patchMembership({ muted: true }))
|
|
141
|
+
|
|
142
|
+
failed.forEach(conversation => setMuted(conversation, conversation.muted))
|
|
143
|
+
alertFailures('silence', failed)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const adjustPersonUnread = (delta: number) =>
|
|
147
|
+
currentPersonCache.update({}, person => ({
|
|
148
|
+
...person,
|
|
149
|
+
unreadCount: Math.max(person.unreadCount + delta, 0),
|
|
150
|
+
}))
|
|
151
|
+
|
|
152
|
+
const markRead = async (conversations: ConversationResource[]) => {
|
|
153
|
+
conversations.forEach(({ id }) =>
|
|
154
|
+
updateInAllLists(id, { unreadCount: 0, unreadReaction: false })
|
|
155
|
+
)
|
|
156
|
+
adjustPersonUnread(-sumUnread(conversations))
|
|
157
|
+
|
|
158
|
+
const { failed } = await settle(conversations, ({ id }) =>
|
|
159
|
+
apiClient.chat.post({
|
|
160
|
+
url: `/me/conversations/${id}/mark_read`,
|
|
161
|
+
data: { data: { type: '', attributes: {} }, fields: { Conversation: 'unread_count,id' } },
|
|
162
|
+
})
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
failed.forEach(({ id, unreadCount, unreadReaction }) =>
|
|
166
|
+
updateInAllLists(id, { unreadCount, unreadReaction })
|
|
167
|
+
)
|
|
168
|
+
adjustPersonUnread(sumUnread(failed))
|
|
169
|
+
alertFailures('mark read', failed)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { hide, unhide, silence, markRead }
|
|
173
|
+
}
|