@planningcenter/chat-react-native 4.7.0 → 4.7.1-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/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +322 -186
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/display/toast.d.ts +3 -0
- package/build/components/display/toast.d.ts.map +1 -0
- package/build/components/display/toast.js +224 -0
- package/build/components/display/toast.js.map +1 -0
- package/build/components/group_conversation_list.d.ts.map +1 -1
- package/build/components/group_conversation_list.js +1 -0
- package/build/components/group_conversation_list.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +3 -1
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +32 -27
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +1 -1
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_features.d.ts +1 -0
- 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_hide_conversation.d.ts +107 -0
- package/build/hooks/use_hide_conversation.d.ts.map +1 -0
- package/build/hooks/use_hide_conversation.js +238 -0
- package/build/hooks/use_hide_conversation.js.map +1 -0
- package/build/hooks/use_hide_conversations_enabled.d.ts +2 -0
- package/build/hooks/use_hide_conversations_enabled.d.ts.map +1 -0
- package/build/hooks/use_hide_conversations_enabled.js +18 -0
- package/build/hooks/use_hide_conversations_enabled.js.map +1 -0
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_actions_screen.d.ts +7 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -0
- package/build/screens/conversation_actions_screen.js +89 -0
- package/build/screens/conversation_actions_screen.js.map +1 -0
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +460 -394
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +18 -10
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/index.d.ts +1 -0
- package/build/screens/index.d.ts.map +1 -1
- package/build/screens/index.js +1 -0
- package/build/screens/index.js.map +1 -1
- package/build/types/resources/conversation_membership.d.ts +1 -0
- package/build/types/resources/conversation_membership.d.ts.map +1 -1
- package/build/types/resources/conversation_membership.js.map +1 -1
- package/build/utils/toast_store.d.ts +21 -0
- package/build/utils/toast_store.d.ts.map +1 -0
- package/build/utils/toast_store.js +27 -0
- package/build/utils/toast_store.js.map +1 -0
- package/package.json +3 -3
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +76 -2
- package/src/components/conversations/conversation_actions.tsx +68 -4
- package/src/components/display/__tests__/toast.test.tsx +55 -0
- package/src/components/display/toast.tsx +115 -0
- package/src/components/group_conversation_list.tsx +4 -1
- package/src/contexts/conversations_context.tsx +6 -1
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +147 -0
- package/src/hooks/use_conversation.ts +1 -0
- package/src/hooks/use_features.ts +1 -0
- package/src/hooks/use_hide_conversation.ts +118 -0
- package/src/hooks/use_hide_conversations_enabled.ts +7 -0
- package/src/navigation/index.tsx +8 -0
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +79 -0
- package/src/screens/__tests__/conversation_details_screen.test.tsx +49 -1
- package/src/screens/conversation_actions_screen.tsx +53 -0
- package/src/screens/conversation_details_screen.tsx +19 -0
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +1 -0
- package/src/screens/conversations/conversations_screen.tsx +2 -0
- package/src/screens/index.ts +1 -0
- package/src/types/resources/conversation_membership.ts +1 -0
- package/src/utils/toast_store.ts +45 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { InfiniteData, QueryKey, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { Alert } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
ApiCollection,
|
|
5
|
+
ApiResource,
|
|
6
|
+
ConversationMembershipResource,
|
|
7
|
+
ConversationResource,
|
|
8
|
+
} from '../types'
|
|
9
|
+
import { deleteRecordInPagesData } from '../utils/cache/page_mutations'
|
|
10
|
+
import { Haptic } from '../utils/native_adapters'
|
|
11
|
+
import { getConversationsRequestArgs } from '../utils/request/conversation'
|
|
12
|
+
import { showToast } from '../utils/toast_store'
|
|
13
|
+
import { useApiClient } from './use_api_client'
|
|
14
|
+
import { getConversationRequestArgs } from './use_conversation'
|
|
15
|
+
import { getRequestQueryKey } from './use_suspense_api'
|
|
16
|
+
|
|
17
|
+
type ConversationsData = InfiniteData<ApiCollection<ConversationResource>>
|
|
18
|
+
type ListsSnapshot = Array<[QueryKey, ConversationsData | undefined]>
|
|
19
|
+
|
|
20
|
+
export const HIDDEN_TOAST_TITLE = 'Conversation hidden'
|
|
21
|
+
export const HIDDEN_TOAST_SUBTITLE = "It'll come back if someone sends a new message."
|
|
22
|
+
export const HIDDEN_AND_SILENCED_TOAST_SUBTITLE =
|
|
23
|
+
"It's silenced too, so it stays hidden until you unhide it."
|
|
24
|
+
|
|
25
|
+
export const useHideConversation = ({ conversation }: { conversation: ConversationResource }) => {
|
|
26
|
+
const apiClient = useApiClient()
|
|
27
|
+
const queryClient = useQueryClient()
|
|
28
|
+
const listsQueryKey = [getConversationsRequestArgs().url]
|
|
29
|
+
const conversationQueryKey = getRequestQueryKey(
|
|
30
|
+
getConversationRequestArgs({ conversation_id: conversation.id })
|
|
31
|
+
)
|
|
32
|
+
const hidden = !!conversation.conversationMembership?.hidden
|
|
33
|
+
|
|
34
|
+
const setMembershipHidden = (value: boolean) =>
|
|
35
|
+
queryClient.setQueryData<ApiResource<ConversationResource>>(conversationQueryKey, prev => {
|
|
36
|
+
if (!prev?.data) return prev
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
...prev,
|
|
40
|
+
data: {
|
|
41
|
+
...prev.data,
|
|
42
|
+
conversationMembership: { ...prev.data.conversationMembership, hidden: value },
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const removeFromLists = () =>
|
|
48
|
+
queryClient.setQueriesData<ConversationsData>({ queryKey: listsQueryKey }, prev => {
|
|
49
|
+
if (!prev?.pages) return prev
|
|
50
|
+
|
|
51
|
+
return deleteRecordInPagesData({ data: prev, record: { id: conversation.id } })
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const restoreLists = (lists: ListsSnapshot) => {
|
|
55
|
+
lists.forEach(([queryKey, data]) => {
|
|
56
|
+
queryClient.setQueryData<ConversationsData>(queryKey, data)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { mutate: setHidden, ...mutation } = useMutation({
|
|
61
|
+
mutationKey: ['hideConversation', conversation.id],
|
|
62
|
+
scope: { id: `hideConversation-${conversation.id}` },
|
|
63
|
+
onMutate: async (value: boolean) => {
|
|
64
|
+
await queryClient.cancelQueries({ queryKey: listsQueryKey })
|
|
65
|
+
const previousLists = queryClient.getQueriesData<ConversationsData>({
|
|
66
|
+
queryKey: listsQueryKey,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
if (value) removeFromLists()
|
|
70
|
+
setMembershipHidden(value)
|
|
71
|
+
|
|
72
|
+
return { previousLists }
|
|
73
|
+
},
|
|
74
|
+
mutationFn: (value: boolean) =>
|
|
75
|
+
apiClient.chat.patch<ApiResource<ConversationMembershipResource>>({
|
|
76
|
+
url: `/me/conversations/${conversation.id}/conversation_membership`,
|
|
77
|
+
data: {
|
|
78
|
+
data: { type: 'ConversationMembership', attributes: { hidden: value } },
|
|
79
|
+
fields: { ConversationMembership: 'hidden' },
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
onSuccess: (_response, value, { previousLists }) => {
|
|
83
|
+
Haptic.notificationSuccess()
|
|
84
|
+
|
|
85
|
+
if (!value) {
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: listsQueryKey })
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
showToast({
|
|
91
|
+
title: HIDDEN_TOAST_TITLE,
|
|
92
|
+
subtitle: conversation.muted ? HIDDEN_AND_SILENCED_TOAST_SUBTITLE : HIDDEN_TOAST_SUBTITLE,
|
|
93
|
+
action: {
|
|
94
|
+
label: 'Undo',
|
|
95
|
+
onPress: () => {
|
|
96
|
+
restoreLists(previousLists)
|
|
97
|
+
setHidden(false)
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
onError: (_error, value, context) => {
|
|
103
|
+
if (!value) queryClient.invalidateQueries({ queryKey: listsQueryKey })
|
|
104
|
+
else if (context) restoreLists(context.previousLists)
|
|
105
|
+
setMembershipHidden(!value)
|
|
106
|
+
Alert.alert(
|
|
107
|
+
'Oops',
|
|
108
|
+
`Couldn't ${value ? 'hide' : 'unhide'} this conversation. Please try again.`
|
|
109
|
+
)
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
hidden,
|
|
115
|
+
setHidden,
|
|
116
|
+
...mutation,
|
|
117
|
+
}
|
|
118
|
+
}
|
package/src/navigation/index.tsx
CHANGED
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
MessageReadReceiptsScreen,
|
|
28
28
|
MessageReadReceiptsScreenOptions,
|
|
29
29
|
} from '../screens/conversation/message_read_receipts_screen'
|
|
30
|
+
import {
|
|
31
|
+
ConversationActionsScreen,
|
|
32
|
+
ConversationActionsScreenOptions,
|
|
33
|
+
} from '../screens/conversation_actions_screen'
|
|
30
34
|
import { ConversationDetailsScreen } from '../screens/conversation_details_screen'
|
|
31
35
|
import {
|
|
32
36
|
ConversationFilterReceipientsScreenOptions,
|
|
@@ -342,6 +346,10 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
342
346
|
// Something about sheetAllowedDetents declared inline breaks TS
|
|
343
347
|
options: MessageActionsScreenOptions,
|
|
344
348
|
},
|
|
349
|
+
ConversationActions: {
|
|
350
|
+
screen: ConversationActionsScreen,
|
|
351
|
+
options: ConversationActionsScreenOptions,
|
|
352
|
+
},
|
|
345
353
|
MessageReport: {
|
|
346
354
|
screen: MessageReportScreen,
|
|
347
355
|
options: MessageReportScreenOptions,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
5
|
+
import type { ConversationResource } from '../../types'
|
|
6
|
+
import { ConversationActionsScreen } from '../conversation_actions_screen'
|
|
7
|
+
|
|
8
|
+
const mockNavigation = { goBack: jest.fn() }
|
|
9
|
+
jest.mock('@react-navigation/native', () => ({
|
|
10
|
+
...jest.requireActual('@react-navigation/native'),
|
|
11
|
+
useNavigation: () => mockNavigation,
|
|
12
|
+
}))
|
|
13
|
+
jest.mock('@react-navigation/elements', () => ({
|
|
14
|
+
...jest.requireActual('@react-navigation/elements'),
|
|
15
|
+
useHeaderHeight: () => 0,
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
const conversation = { type: 'Conversation', id: 7, title: 'Youth Group' } as ConversationResource
|
|
19
|
+
jest.mock('../../hooks/use_conversation', () => ({
|
|
20
|
+
useConversation: () => ({ data: conversation }),
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
let mockHidden = false
|
|
24
|
+
const mockSetHidden = jest.fn()
|
|
25
|
+
jest.mock('../../hooks/use_hide_conversation', () => ({
|
|
26
|
+
useHideConversation: () => ({ hidden: mockHidden, setHidden: mockSetHidden, isPending: false }),
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
let mockHideEnabled = true
|
|
30
|
+
jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
|
|
31
|
+
useHideConversationsEnabled: () => mockHideEnabled,
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
const safeAreaMetrics = {
|
|
35
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
36
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const renderScreen = () =>
|
|
40
|
+
render(
|
|
41
|
+
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
42
|
+
<ThemeProvider value={DefaultTheme}>
|
|
43
|
+
<ConversationActionsScreen route={{ params: { conversation_id: 7 } }} />
|
|
44
|
+
</ThemeProvider>
|
|
45
|
+
</SafeAreaProvider>
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
describe('ConversationActionsScreen', () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
mockHidden = false
|
|
51
|
+
mockHideEnabled = true
|
|
52
|
+
jest.clearAllMocks()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('offers nothing when the flag is off', () => {
|
|
56
|
+
mockHideEnabled = false
|
|
57
|
+
const { queryByText } = renderScreen()
|
|
58
|
+
|
|
59
|
+
expect(queryByText('Hide conversation')).toBeNull()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('hides the conversation and closes the sheet', () => {
|
|
63
|
+
const { getByText } = renderScreen()
|
|
64
|
+
|
|
65
|
+
fireEvent.press(getByText('Hide conversation'))
|
|
66
|
+
|
|
67
|
+
expect(mockSetHidden).toHaveBeenCalledWith(true)
|
|
68
|
+
expect(mockNavigation.goBack).toHaveBeenCalledTimes(1)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('unhides a hidden conversation', () => {
|
|
72
|
+
mockHidden = true
|
|
73
|
+
const { getByText } = renderScreen()
|
|
74
|
+
|
|
75
|
+
fireEvent.press(getByText('Unhide conversation'))
|
|
76
|
+
|
|
77
|
+
expect(mockSetHidden).toHaveBeenCalledWith(false)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
1
|
+
import { DefaultTheme, StackActions, ThemeProvider } from '@react-navigation/native'
|
|
2
2
|
import { QueryClientProvider } from '@tanstack/react-query'
|
|
3
3
|
import { fireEvent, render } from '@testing-library/react-native'
|
|
4
4
|
import React from 'react'
|
|
@@ -68,6 +68,12 @@ jest.mock('../../hooks/use_conversation', () => ({
|
|
|
68
68
|
useConversationUpdate: () => ({ mutate: mockSaveTitle }),
|
|
69
69
|
}))
|
|
70
70
|
|
|
71
|
+
let mockHidden = false
|
|
72
|
+
const mockSetHidden = jest.fn()
|
|
73
|
+
jest.mock('../../hooks/use_hide_conversation', () => ({
|
|
74
|
+
useHideConversation: () => ({ hidden: mockHidden, setHidden: mockSetHidden, isPending: false }),
|
|
75
|
+
}))
|
|
76
|
+
|
|
71
77
|
let mockEnabledFeatures: string[] = []
|
|
72
78
|
jest.mock('../../hooks/use_features', () => ({
|
|
73
79
|
...jest.requireActual('../../hooks/use_features'),
|
|
@@ -303,3 +309,45 @@ describe('ConversationDetailsScreen archive', () => {
|
|
|
303
309
|
expect(mockArchive).not.toHaveBeenCalled()
|
|
304
310
|
})
|
|
305
311
|
})
|
|
312
|
+
|
|
313
|
+
describe('ConversationDetailsScreen hide', () => {
|
|
314
|
+
beforeEach(() => {
|
|
315
|
+
mockConversation = baseConversation
|
|
316
|
+
mockEnabledFeatures = ['ROLLOUT_hide_conversations']
|
|
317
|
+
mockHidden = false
|
|
318
|
+
jest.clearAllMocks()
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
it('hides the row when the flag is off', () => {
|
|
322
|
+
mockEnabledFeatures = []
|
|
323
|
+
const { queryByText } = renderScreen()
|
|
324
|
+
|
|
325
|
+
expect(queryByText('Hide conversation')).toBeNull()
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('hides the row for an archived conversation', () => {
|
|
329
|
+
mockConversation = archivedConversation
|
|
330
|
+
const { queryByText } = renderScreen()
|
|
331
|
+
|
|
332
|
+
expect(queryByText('Hide conversation')).toBeNull()
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
it('hides the conversation and returns to the list', () => {
|
|
336
|
+
const { getByText } = renderScreen()
|
|
337
|
+
|
|
338
|
+
fireEvent.press(getByText('Hide conversation'))
|
|
339
|
+
|
|
340
|
+
expect(mockSetHidden).toHaveBeenCalledWith(true)
|
|
341
|
+
expect(mockNavigation.dispatch).toHaveBeenCalledWith(StackActions.popToTop())
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
it('unhides a hidden conversation and stays on the details', () => {
|
|
345
|
+
mockHidden = true
|
|
346
|
+
const { getByText } = renderScreen()
|
|
347
|
+
|
|
348
|
+
fireEvent.press(getByText('Unhide conversation'))
|
|
349
|
+
|
|
350
|
+
expect(mockSetHidden).toHaveBeenCalledWith(false)
|
|
351
|
+
expect(mockNavigation.dispatch).not.toHaveBeenCalled()
|
|
352
|
+
})
|
|
353
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { StyleSheet } from 'react-native'
|
|
4
|
+
import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
|
|
5
|
+
import { useConversation } from '../hooks/use_conversation'
|
|
6
|
+
import { useHideConversation } from '../hooks/use_hide_conversation'
|
|
7
|
+
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
|
|
8
|
+
|
|
9
|
+
export const ConversationActionsScreenOptions = getFormSheetScreenOptions({
|
|
10
|
+
headerTitle: 'Conversation actions',
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export type ConversationActionsScreenProps = StaticScreenProps<{
|
|
14
|
+
conversation_id: number
|
|
15
|
+
}>
|
|
16
|
+
|
|
17
|
+
export function ConversationActionsScreen({ route }: ConversationActionsScreenProps) {
|
|
18
|
+
const navigation = useNavigation()
|
|
19
|
+
const styles = useStyles()
|
|
20
|
+
const { data: conversation } = useConversation(route.params)
|
|
21
|
+
const { hidden, setHidden, isPending } = useHideConversation({ conversation })
|
|
22
|
+
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
23
|
+
|
|
24
|
+
const handleHidePress = () => {
|
|
25
|
+
setHidden(!hidden)
|
|
26
|
+
navigation.goBack()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<FormSheet.Root style={styles.formSheetContent}>
|
|
31
|
+
{hideConversationsEnabled && (
|
|
32
|
+
<FormSheet.Action
|
|
33
|
+
onPress={handleHidePress}
|
|
34
|
+
title={hidden ? 'Unhide conversation' : 'Hide conversation'}
|
|
35
|
+
iconName={hidden ? 'general.showEye' : 'general.hideEye'}
|
|
36
|
+
disabled={isPending}
|
|
37
|
+
accessibilityHint={
|
|
38
|
+
hidden
|
|
39
|
+
? 'Shows this conversation in your conversation list again.'
|
|
40
|
+
: 'Hides this conversation from your conversation list.'
|
|
41
|
+
}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
</FormSheet.Root>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const useStyles = () =>
|
|
49
|
+
StyleSheet.create({
|
|
50
|
+
formSheetContent: {
|
|
51
|
+
paddingTop: 16,
|
|
52
|
+
},
|
|
53
|
+
})
|
|
@@ -50,6 +50,8 @@ import {
|
|
|
50
50
|
useConversationUpdate,
|
|
51
51
|
} from '../hooks/use_conversation'
|
|
52
52
|
import { availableFeatures, useFeatures } from '../hooks/use_features'
|
|
53
|
+
import { useHideConversation } from '../hooks/use_hide_conversation'
|
|
54
|
+
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
|
|
53
55
|
import { useManualArchivingEnabled } from '../hooks/use_manual_archiving_enabled'
|
|
54
56
|
import { usePreviewAvatarDiameter } from '../hooks/use_preview_avatar_diameter'
|
|
55
57
|
import { useUnarchiveConversationAction } from '../hooks/use_unarchive_conversation_action'
|
|
@@ -115,6 +117,8 @@ export function ConversationDetailsScreen({ route }: ConversationDetailsScreenPr
|
|
|
115
117
|
const granularNotificationsEnabled = featureEnabled(availableFeatures.granular_notifications_ui)
|
|
116
118
|
const customAvatarsEnabled = featureEnabled(availableFeatures.custom_conversation_avatars)
|
|
117
119
|
const manualArchivingEnabled = useManualArchivingEnabled()
|
|
120
|
+
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
121
|
+
const { hidden, setHidden, isPending: isHidePending } = useHideConversation({ conversation })
|
|
118
122
|
const showGenderFilter =
|
|
119
123
|
featureEnabled(availableFeatures.gender_specific_conversations) && !!conversation.genderOption
|
|
120
124
|
const genderLabel = conversation.genderOption ? genderDisplayLabel(conversation.genderOption) : ''
|
|
@@ -130,6 +134,7 @@ export function ConversationDetailsScreen({ route }: ConversationDetailsScreenPr
|
|
|
130
134
|
const canSaveTitle = canUpdate && !emptyTitle
|
|
131
135
|
const canDelete = conversation.memberAbility?.canDelete || false
|
|
132
136
|
const canArchive = manualArchivingEnabled && (conversation.memberAbility?.canArchive || false)
|
|
137
|
+
const canHide = hideConversationsEnabled && !archived
|
|
133
138
|
const isLeader = conversation.memberAbility?.leader || false
|
|
134
139
|
const isDisabled = conversation.disabled ?? false
|
|
135
140
|
const showAdultRequirementNotice = isDisabled && conversation.disabledReason === 'safety_check'
|
|
@@ -231,6 +236,11 @@ export function ConversationDetailsScreen({ route }: ConversationDetailsScreenPr
|
|
|
231
236
|
)
|
|
232
237
|
}, [setArchived])
|
|
233
238
|
|
|
239
|
+
const handleHide = useCallback(() => {
|
|
240
|
+
setHidden(!hidden)
|
|
241
|
+
if (!hidden) navigation.dispatch(StackActions.popToTop())
|
|
242
|
+
}, [hidden, navigation, setHidden])
|
|
243
|
+
|
|
234
244
|
const HeaderTitle = useCallback(
|
|
235
245
|
(props: HeaderTitleProps) => {
|
|
236
246
|
return (
|
|
@@ -354,6 +364,15 @@ export function ConversationDetailsScreen({ route }: ConversationDetailsScreenPr
|
|
|
354
364
|
},
|
|
355
365
|
showBottomBorder: true,
|
|
356
366
|
},
|
|
367
|
+
{
|
|
368
|
+
type: canHide ? SectionTypes.setting : SectionTypes.hidden,
|
|
369
|
+
data: {
|
|
370
|
+
title: hidden ? 'Unhide conversation' : 'Hide conversation',
|
|
371
|
+
disabled: isHidePending,
|
|
372
|
+
onPress: handleHide,
|
|
373
|
+
},
|
|
374
|
+
showBottomBorder: canArchive || canDelete,
|
|
375
|
+
},
|
|
357
376
|
{
|
|
358
377
|
type: canArchive ? SectionTypes.setting : SectionTypes.hidden,
|
|
359
378
|
data: {
|
|
@@ -27,6 +27,7 @@ jest.mock('../../../components', () => ({
|
|
|
27
27
|
<ListHeaderComponent />
|
|
28
28
|
),
|
|
29
29
|
}))
|
|
30
|
+
jest.mock('../../../components/display/toast', () => ({ Toast: () => null }))
|
|
30
31
|
jest.mock('../components/list_header_component', () => {
|
|
31
32
|
const { Text } = require('react-native')
|
|
32
33
|
return { ListHeaderComponent: () => <Text>Default header</Text> }
|
|
@@ -2,6 +2,7 @@ import { StaticScreenProps } from '@react-navigation/native'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Conversations } from '../../components'
|
|
5
|
+
import { Toast } from '../../components/display/toast'
|
|
5
6
|
import { ConversationsContextProvider } from '../../contexts/conversations_context'
|
|
6
7
|
import { useFilterDropdownEnabled } from '../../hooks/use_filter_dropdown_enabled'
|
|
7
8
|
import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/use_product_analytics'
|
|
@@ -32,6 +33,7 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
|
32
33
|
<ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
|
|
33
34
|
<Conversations ListHeaderComponent={Header} />
|
|
34
35
|
</ConversationsContextProvider>
|
|
36
|
+
<Toast />
|
|
35
37
|
</View>
|
|
36
38
|
)
|
|
37
39
|
}
|
package/src/screens/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './preferred_app_selection_screen'
|
|
|
8
8
|
export * from './group_notification_settings_screen'
|
|
9
9
|
export * from './conversation_filter_recipients/conversation_filter_recipients_screen'
|
|
10
10
|
export * from './message_actions_screen'
|
|
11
|
+
export * from './conversation_actions_screen'
|
|
11
12
|
export * from './message_report_screen'
|
|
12
13
|
export * from './send_giphy_screen'
|
|
13
14
|
export * from './not_found'
|
|
@@ -5,6 +5,7 @@ export type NotificationLevelDescription = string
|
|
|
5
5
|
|
|
6
6
|
export interface ConversationMembershipResource extends ResourceObject {
|
|
7
7
|
type: 'ConversationMembership'
|
|
8
|
+
hidden?: boolean
|
|
8
9
|
lastReadMessageSortKey: string
|
|
9
10
|
muted: boolean
|
|
10
11
|
notificationLevel: NotificationLevelValue
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface ToastAction {
|
|
2
|
+
label: string
|
|
3
|
+
onPress: () => void
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface ToastOptions {
|
|
7
|
+
title: string
|
|
8
|
+
subtitle?: string
|
|
9
|
+
action?: ToastAction
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ToastState extends ToastOptions {
|
|
13
|
+
id: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Listener = () => void
|
|
17
|
+
|
|
18
|
+
let currentToast: ToastState | null = null
|
|
19
|
+
let nextId = 1
|
|
20
|
+
const listeners = new Set<Listener>()
|
|
21
|
+
|
|
22
|
+
const emit = () => listeners.forEach(listener => listener())
|
|
23
|
+
|
|
24
|
+
export const toastStore = {
|
|
25
|
+
getSnapshot: () => currentToast,
|
|
26
|
+
subscribe: (listener: Listener) => {
|
|
27
|
+
listeners.add(listener)
|
|
28
|
+
return () => {
|
|
29
|
+
listeners.delete(listener)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function showToast(options: ToastOptions) {
|
|
35
|
+
currentToast = { ...options, id: nextId++ }
|
|
36
|
+
emit()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function dismissToast(id?: number) {
|
|
40
|
+
if (!currentToast) return
|
|
41
|
+
if (id !== undefined && currentToast.id !== id) return
|
|
42
|
+
|
|
43
|
+
currentToast = null
|
|
44
|
+
emit()
|
|
45
|
+
}
|