@planningcenter/chat-react-native 4.7.0 → 4.7.1-qa-staging.1
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 +333 -193
- 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 +106 -91
- 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 +63 -56
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/conversations/conversations_blank_state.d.ts +2 -1
- package/build/components/conversations/conversations_blank_state.d.ts.map +1 -1
- package/build/components/conversations/conversations_blank_state.js +71 -39
- package/build/components/conversations/conversations_blank_state.js.map +1 -1
- package/build/components/conversations/hidden_indicator.d.ts +4 -0
- package/build/components/conversations/hidden_indicator.d.ts.map +1 -0
- package/build/components/conversations/hidden_indicator.js +52 -0
- package/build/components/conversations/hidden_indicator.js.map +1 -0
- package/build/components/conversations/hidden_results_footer.d.ts +2 -0
- package/build/components/conversations/hidden_results_footer.d.ts.map +1 -0
- package/build/components/conversations/hidden_results_footer.js +34 -0
- package/build/components/conversations/hidden_results_footer.js.map +1 -0
- 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 +39 -31
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +6 -0
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/use_api.d.ts +6 -0
- package/build/hooks/use_api.d.ts.map +1 -1
- package/build/hooks/use_api.js +8 -5
- package/build/hooks/use_api.js.map +1 -1
- package/build/hooks/use_clear_conversation_filters.d.ts.map +1 -1
- package/build/hooks/use_clear_conversation_filters.js +1 -0
- package/build/hooks/use_clear_conversation_filters.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_groups.d.ts +6 -0
- package/build/hooks/use_groups.d.ts.map +1 -1
- package/build/hooks/use_groups_groups.d.ts +6 -0
- package/build/hooks/use_groups_groups.d.ts.map +1 -1
- package/build/hooks/use_hidden_conversations_count.d.ts +2 -0
- package/build/hooks/use_hidden_conversations_count.d.ts.map +1 -0
- package/build/hooks/use_hidden_conversations_count.js +32 -0
- package/build/hooks/use_hidden_conversations_count.js.map +1 -0
- package/build/hooks/use_hide_conversation.d.ts +108 -0
- package/build/hooks/use_hide_conversation.d.ts.map +1 -0
- package/build/hooks/use_hide_conversation.js +243 -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/hooks/use_teams.d.ts +6 -0
- package/build/hooks/use_teams.d.ts.map +1 -1
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/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/conversation_filters/components/conversation_filters.d.ts.map +1 -1
- package/build/screens/conversation_filters/components/conversation_filters.js +53 -12
- package/build/screens/conversation_filters/components/conversation_filters.js.map +1 -1
- package/build/screens/conversation_filters/components/rows.d.ts +6 -3
- package/build/screens/conversation_filters/components/rows.d.ts.map +1 -1
- package/build/screens/conversation_filters/components/rows.js +99 -62
- package/build/screens/conversation_filters/components/rows.js.map +1 -1
- package/build/screens/conversation_filters/context/conversation_filter_context.d.ts.map +1 -1
- package/build/screens/conversation_filters/context/conversation_filter_context.js +4 -0
- package/build/screens/conversation_filters/context/conversation_filter_context.js.map +1 -1
- package/build/screens/conversation_filters/filter_types.d.ts +1 -0
- package/build/screens/conversation_filters/filter_types.d.ts.map +1 -1
- package/build/screens/conversation_filters/filter_types.js +1 -0
- package/build/screens/conversation_filters/filter_types.js.map +1 -1
- package/build/screens/conversation_filters/hooks/filters.d.ts +12 -0
- package/build/screens/conversation_filters/hooks/filters.d.ts.map +1 -1
- package/build/screens/conversation_filters/screen_props.d.ts +1 -0
- package/build/screens/conversation_filters/screen_props.d.ts.map +1 -1
- package/build/screens/conversation_filters/screen_props.js.map +1 -1
- package/build/screens/conversations/components/filter_dropdown_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/filter_dropdown_list_header_component.js +138 -126
- package/build/screens/conversations/components/filter_dropdown_list_header_component.js.map +1 -1
- package/build/screens/conversations/components/list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/list_header_component.js +95 -90
- package/build/screens/conversations/components/list_header_component.js.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.js +100 -95
- package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +1 -0
- 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/request/conversation.d.ts +3 -1
- package/build/utils/request/conversation.d.ts.map +1 -1
- package/build/utils/request/conversation.js +4 -0
- package/build/utils/request/conversation.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/build/vendor/font_awesome_pro_solid_icons.d.ts +1 -0
- package/build/vendor/font_awesome_pro_solid_icons.d.ts.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.js +5 -0
- package/build/vendor/font_awesome_pro_solid_icons.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/screens/conversation_filters/components/conversation_filters.test.tsx +6 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +77 -2
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +29 -0
- package/src/components/conversations/__tests__/conversations.test.tsx +26 -0
- package/src/components/conversations/__tests__/conversations_blank_state.test.tsx +17 -0
- package/src/components/conversations/conversation_actions.tsx +73 -4
- package/src/components/conversations/conversation_preview.tsx +12 -1
- package/src/components/conversations/conversations.tsx +9 -0
- package/src/components/conversations/conversations_blank_state.tsx +18 -0
- package/src/components/conversations/hidden_indicator.tsx +30 -0
- package/src/components/conversations/hidden_results_footer.tsx +25 -0
- 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 +8 -1
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +189 -0
- package/src/hooks/use_api.ts +2 -1
- package/src/hooks/use_clear_conversation_filters.ts +1 -0
- package/src/hooks/use_conversation.ts +1 -0
- package/src/hooks/use_features.ts +1 -0
- package/src/hooks/use_hidden_conversations_count.ts +14 -0
- package/src/hooks/use_hide_conversation.ts +128 -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/conversation_filters/__tests__/conversation_filters.test.tsx +42 -0
- package/src/screens/conversation_filters/components/conversation_filters.tsx +22 -3
- package/src/screens/conversation_filters/components/rows.tsx +44 -10
- package/src/screens/conversation_filters/context/conversation_filter_context.tsx +4 -0
- package/src/screens/conversation_filters/filter_types.ts +1 -0
- package/src/screens/conversation_filters/screen_props.ts +1 -0
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +1 -0
- package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +42 -0
- package/src/screens/conversations/components/__tests__/list_header_component.test.tsx +1 -0
- package/src/screens/conversations/components/filter_dropdown_list_header_component.tsx +21 -5
- package/src/screens/conversations/components/list_header_component.tsx +14 -4
- package/src/screens/conversations/components/search_list_header_component.tsx +14 -4
- package/src/screens/conversations/conversations_screen.tsx +3 -0
- package/src/screens/index.ts +1 -0
- package/src/types/resources/conversation_membership.ts +1 -0
- package/src/utils/request/conversation.ts +6 -0
- package/src/utils/toast_store.ts +45 -0
- package/src/vendor/font_awesome_pro_solid_icons.ts +12 -0
|
@@ -0,0 +1,189 @@
|
|
|
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 { getConversationRequestArgs } from '../use_conversation'
|
|
10
|
+
import {
|
|
11
|
+
HIDDEN_AND_SILENCED_TOAST_SUBTITLE,
|
|
12
|
+
HIDDEN_TOAST_SUBTITLE,
|
|
13
|
+
useHideConversation,
|
|
14
|
+
} from '../use_hide_conversation'
|
|
15
|
+
import { getRequestQueryKey } from '../use_suspense_api'
|
|
16
|
+
|
|
17
|
+
const mockPatch = jest.fn()
|
|
18
|
+
jest.mock('../use_api_client', () => ({
|
|
19
|
+
useApiClient: () => ({ chat: { patch: mockPatch } }),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
const conversation = { id: 7, muted: false } as ConversationResource
|
|
23
|
+
const otherConversation = { id: 8, muted: false } as ConversationResource
|
|
24
|
+
const conversationKey = getRequestQueryKey(getConversationRequestArgs({ conversation_id: 7 }))
|
|
25
|
+
const allKey = getRequestQueryKey(getConversationsRequestArgs({ gids: 'all' }))
|
|
26
|
+
const unreadKey = getRequestQueryKey(
|
|
27
|
+
getConversationsRequestArgs({ gids: 'all', show_unread: true })
|
|
28
|
+
)
|
|
29
|
+
const hiddenKey = getRequestQueryKey(getConversationsRequestArgs({ show_hidden: true }))
|
|
30
|
+
|
|
31
|
+
const listData = (conversations: ConversationResource[]) => ({
|
|
32
|
+
pages: [{ data: conversations, links: {}, meta: { count: conversations.length } }],
|
|
33
|
+
pageParams: [{}],
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const listIds = (queryKey: unknown[]) =>
|
|
37
|
+
(
|
|
38
|
+
queryClient.getQueryData(queryKey) as ReturnType<typeof listData> | undefined
|
|
39
|
+
)?.pages[0].data.map(({ id }) => id)
|
|
40
|
+
|
|
41
|
+
const buildQueryClient = () =>
|
|
42
|
+
buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
43
|
+
|
|
44
|
+
let queryClient = buildQueryClient()
|
|
45
|
+
|
|
46
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
47
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const renderHide = (target: ConversationResource = conversation, hidden?: boolean) =>
|
|
51
|
+
renderHook(() => useHideConversation({ conversation: target, hidden }), { wrapper })
|
|
52
|
+
|
|
53
|
+
describe('useHideConversation', () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
queryClient = buildQueryClient()
|
|
56
|
+
queryClient.setQueryData(allKey, listData([conversation, otherConversation]))
|
|
57
|
+
queryClient.setQueryData(unreadKey, listData([conversation]))
|
|
58
|
+
queryClient.setQueryData(conversationKey, {
|
|
59
|
+
data: { id: 7, conversationMembership: { muted: false } },
|
|
60
|
+
})
|
|
61
|
+
mockPatch.mockReset()
|
|
62
|
+
dismissToast()
|
|
63
|
+
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
jest.restoreAllMocks()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('removes the conversation from every list before the request resolves', async () => {
|
|
71
|
+
mockPatch.mockReturnValue(new Promise(() => {}))
|
|
72
|
+
const { result } = renderHide()
|
|
73
|
+
|
|
74
|
+
await act(async () => result.current.setHidden(true))
|
|
75
|
+
|
|
76
|
+
expect(listIds(allKey)).toEqual([8])
|
|
77
|
+
expect(listIds(unreadKey)).toEqual([])
|
|
78
|
+
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
79
|
+
data: { id: 7, conversationMembership: { muted: false, hidden: true } },
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('patches hidden on the membership', async () => {
|
|
84
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
85
|
+
const { result } = renderHide()
|
|
86
|
+
|
|
87
|
+
await act(() => result.current.mutateAsync(true))
|
|
88
|
+
|
|
89
|
+
expect(mockPatch).toHaveBeenCalledWith({
|
|
90
|
+
url: '/me/conversations/7/conversation_membership',
|
|
91
|
+
data: {
|
|
92
|
+
data: { type: 'ConversationMembership', attributes: { hidden: true } },
|
|
93
|
+
fields: { ConversationMembership: 'hidden' },
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it.each([
|
|
99
|
+
[false, HIDDEN_TOAST_SUBTITLE],
|
|
100
|
+
[true, HIDDEN_AND_SILENCED_TOAST_SUBTITLE],
|
|
101
|
+
])('shows an undo toast for muted=%s', async (muted, subtitle) => {
|
|
102
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
103
|
+
const { result } = renderHide({ ...conversation, muted })
|
|
104
|
+
|
|
105
|
+
await act(() => result.current.mutateAsync(true))
|
|
106
|
+
|
|
107
|
+
expect(toastStore.getSnapshot()).toMatchObject({
|
|
108
|
+
title: 'Conversation hidden',
|
|
109
|
+
subtitle,
|
|
110
|
+
action: { label: 'Undo' },
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('restores the lists and unhides on undo', async () => {
|
|
115
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
116
|
+
const { result } = renderHide()
|
|
117
|
+
await act(() => result.current.mutateAsync(true))
|
|
118
|
+
|
|
119
|
+
await act(async () => toastStore.getSnapshot()?.action?.onPress())
|
|
120
|
+
|
|
121
|
+
expect(listIds(allKey)).toEqual([7, 8])
|
|
122
|
+
expect(listIds(unreadKey)).toEqual([7])
|
|
123
|
+
expect(mockPatch).toHaveBeenLastCalledWith(
|
|
124
|
+
expect.objectContaining({
|
|
125
|
+
data: expect.objectContaining({
|
|
126
|
+
data: { type: 'ConversationMembership', attributes: { hidden: false } },
|
|
127
|
+
}),
|
|
128
|
+
})
|
|
129
|
+
)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('puts the conversation back and alerts when hiding fails', async () => {
|
|
133
|
+
mockPatch.mockRejectedValue(new Error('nope'))
|
|
134
|
+
const { result } = renderHide()
|
|
135
|
+
|
|
136
|
+
await act(() => result.current.mutateAsync(true).catch(() => {}))
|
|
137
|
+
|
|
138
|
+
expect(listIds(allKey)).toEqual([7, 8])
|
|
139
|
+
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
140
|
+
data: { id: 7, conversationMembership: { muted: false, hidden: false } },
|
|
141
|
+
})
|
|
142
|
+
expect(toastStore.getSnapshot()).toBeNull()
|
|
143
|
+
expect(Alert.alert).toHaveBeenCalledWith(
|
|
144
|
+
'Oops',
|
|
145
|
+
"Couldn't hide this conversation. Please try again."
|
|
146
|
+
)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('from the hidden list', () => {
|
|
150
|
+
beforeEach(() => {
|
|
151
|
+
queryClient.setQueryData(hiddenKey, listData([conversation, otherConversation]))
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('removes the conversation from the hidden list before the request resolves', async () => {
|
|
155
|
+
mockPatch.mockReturnValue(new Promise(() => {}))
|
|
156
|
+
const { result } = renderHide(conversation, true)
|
|
157
|
+
|
|
158
|
+
expect(result.current.hidden).toBe(true)
|
|
159
|
+
|
|
160
|
+
await act(async () => result.current.setHidden(false))
|
|
161
|
+
|
|
162
|
+
expect(listIds(hiddenKey)).toEqual([8])
|
|
163
|
+
expect(listIds(allKey)).toEqual([7, 8])
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('puts the conversation back in the hidden list when unhiding fails', async () => {
|
|
167
|
+
mockPatch.mockRejectedValue(new Error('nope'))
|
|
168
|
+
const { result } = renderHide(conversation, true)
|
|
169
|
+
|
|
170
|
+
await act(() => result.current.mutateAsync(false).catch(() => {}))
|
|
171
|
+
|
|
172
|
+
expect(listIds(hiddenKey)).toEqual([7, 8])
|
|
173
|
+
expect(Alert.alert).toHaveBeenCalledWith(
|
|
174
|
+
'Oops',
|
|
175
|
+
"Couldn't unhide this conversation. Please try again."
|
|
176
|
+
)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('refreshes the hidden list after hiding elsewhere', async () => {
|
|
180
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
181
|
+
const { result } = renderHide(otherConversation)
|
|
182
|
+
|
|
183
|
+
await act(() => result.current.mutateAsync(true))
|
|
184
|
+
|
|
185
|
+
expect(queryClient.getQueryState(hiddenKey)?.isInvalidated).toBe(true)
|
|
186
|
+
expect(queryClient.getQueryState(unreadKey)?.isInvalidated).toBe(false)
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
})
|
package/src/hooks/use_api.ts
CHANGED
|
@@ -84,6 +84,7 @@ export const useApiPaginator = <T extends ResourceObject>(
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
const data: T[] = query.data?.pages?.flatMap(page => page.data) || []
|
|
87
|
+
const totalCount = query.data?.pages?.[0]?.meta?.totalCount ?? data.length
|
|
87
88
|
|
|
88
|
-
return { ...query, data }
|
|
89
|
+
return { ...query, data, totalCount }
|
|
89
90
|
}
|
|
@@ -61,6 +61,7 @@ export const availableFeatures = {
|
|
|
61
61
|
filter_dropdown_rollout: 'ROLLOUT_MOBILE_filter_dropdown',
|
|
62
62
|
manual_archiving: 'QA_MOBILE_manual_archiving',
|
|
63
63
|
manual_archiving_rollout: 'ROLLOUT_MOBILE_manual_archiving',
|
|
64
|
+
hide_conversations: 'ROLLOUT_hide_conversations',
|
|
64
65
|
} as const satisfies Record<string, `${'QA' | 'ROLLOUT'}_${string}`>
|
|
65
66
|
|
|
66
67
|
const featureNames = Object.values(availableFeatures)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConversationResource } from '../types'
|
|
2
|
+
import { getConversationsRequestArgs } from '../utils/request/conversation'
|
|
3
|
+
import { useApiPaginator } from './use_api'
|
|
4
|
+
import { useHideConversationsEnabled } from './use_hide_conversations_enabled'
|
|
5
|
+
|
|
6
|
+
export function useHiddenConversationsCount() {
|
|
7
|
+
const enabled = useHideConversationsEnabled()
|
|
8
|
+
const { totalCount } = useApiPaginator<ConversationResource>(
|
|
9
|
+
getConversationsRequestArgs({ show_hidden: true }),
|
|
10
|
+
{ enabled }
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
return enabled ? totalCount : 0
|
|
14
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 {
|
|
12
|
+
getConversationsRequestArgs,
|
|
13
|
+
HIDDEN_CONVERSATIONS_FILTER,
|
|
14
|
+
} from '../utils/request/conversation'
|
|
15
|
+
import { showToast } from '../utils/toast_store'
|
|
16
|
+
import { useApiClient } from './use_api_client'
|
|
17
|
+
import { getConversationRequestArgs } from './use_conversation'
|
|
18
|
+
import { getRequestQueryKey } from './use_suspense_api'
|
|
19
|
+
|
|
20
|
+
type ConversationsData = InfiniteData<ApiCollection<ConversationResource>>
|
|
21
|
+
type ListsSnapshot = Array<[QueryKey, ConversationsData | undefined]>
|
|
22
|
+
|
|
23
|
+
export const HIDDEN_TOAST_TITLE = 'Conversation hidden'
|
|
24
|
+
export const HIDDEN_TOAST_SUBTITLE = "It'll come back if someone sends a new message."
|
|
25
|
+
export const HIDDEN_AND_SILENCED_TOAST_SUBTITLE =
|
|
26
|
+
"It's silenced too, so it stays hidden until you unhide it."
|
|
27
|
+
|
|
28
|
+
export const useHideConversation = ({
|
|
29
|
+
conversation,
|
|
30
|
+
hidden: knownHidden,
|
|
31
|
+
}: {
|
|
32
|
+
conversation: ConversationResource
|
|
33
|
+
hidden?: boolean
|
|
34
|
+
}) => {
|
|
35
|
+
const apiClient = useApiClient()
|
|
36
|
+
const queryClient = useQueryClient()
|
|
37
|
+
const listsQueryKey = [getConversationsRequestArgs().url]
|
|
38
|
+
const hiddenListsQueryKey = [...listsQueryKey, { filter: HIDDEN_CONVERSATIONS_FILTER }]
|
|
39
|
+
const conversationQueryKey = getRequestQueryKey(
|
|
40
|
+
getConversationRequestArgs({ conversation_id: conversation.id })
|
|
41
|
+
)
|
|
42
|
+
const hidden = knownHidden ?? !!conversation.conversationMembership?.hidden
|
|
43
|
+
|
|
44
|
+
const setMembershipHidden = (value: boolean) =>
|
|
45
|
+
queryClient.setQueryData<ApiResource<ConversationResource>>(conversationQueryKey, prev => {
|
|
46
|
+
if (!prev?.data) return prev
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
...prev,
|
|
50
|
+
data: {
|
|
51
|
+
...prev.data,
|
|
52
|
+
conversationMembership: { ...prev.data.conversationMembership, hidden: value },
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const removeFromLists = (queryKey: QueryKey) =>
|
|
58
|
+
queryClient.setQueriesData<ConversationsData>({ queryKey }, prev => {
|
|
59
|
+
if (!prev?.pages) return prev
|
|
60
|
+
|
|
61
|
+
return deleteRecordInPagesData({ data: prev, record: { id: conversation.id } })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const restoreLists = (lists: ListsSnapshot) => {
|
|
65
|
+
lists.forEach(([queryKey, data]) => {
|
|
66
|
+
queryClient.setQueryData<ConversationsData>(queryKey, data)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { mutate: setHidden, ...mutation } = useMutation({
|
|
71
|
+
mutationKey: ['hideConversation', conversation.id],
|
|
72
|
+
scope: { id: `hideConversation-${conversation.id}` },
|
|
73
|
+
onMutate: async (value: boolean) => {
|
|
74
|
+
await queryClient.cancelQueries({ queryKey: listsQueryKey })
|
|
75
|
+
const previousLists = queryClient.getQueriesData<ConversationsData>({
|
|
76
|
+
queryKey: listsQueryKey,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
removeFromLists(value ? listsQueryKey : hiddenListsQueryKey)
|
|
80
|
+
setMembershipHidden(value)
|
|
81
|
+
|
|
82
|
+
return { previousLists }
|
|
83
|
+
},
|
|
84
|
+
mutationFn: (value: boolean) =>
|
|
85
|
+
apiClient.chat.patch<ApiResource<ConversationMembershipResource>>({
|
|
86
|
+
url: `/me/conversations/${conversation.id}/conversation_membership`,
|
|
87
|
+
data: {
|
|
88
|
+
data: { type: 'ConversationMembership', attributes: { hidden: value } },
|
|
89
|
+
fields: { ConversationMembership: 'hidden' },
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
onSuccess: (_response, value, { previousLists }) => {
|
|
93
|
+
Haptic.notificationSuccess()
|
|
94
|
+
|
|
95
|
+
if (!value) {
|
|
96
|
+
queryClient.invalidateQueries({ queryKey: listsQueryKey })
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
queryClient.invalidateQueries({ queryKey: hiddenListsQueryKey })
|
|
101
|
+
showToast({
|
|
102
|
+
title: HIDDEN_TOAST_TITLE,
|
|
103
|
+
subtitle: conversation.muted ? HIDDEN_AND_SILENCED_TOAST_SUBTITLE : HIDDEN_TOAST_SUBTITLE,
|
|
104
|
+
action: {
|
|
105
|
+
label: 'Undo',
|
|
106
|
+
onPress: () => {
|
|
107
|
+
restoreLists(previousLists)
|
|
108
|
+
setHidden(false)
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
onError: (_error, value, context) => {
|
|
114
|
+
if (context) restoreLists(context.previousLists)
|
|
115
|
+
setMembershipHidden(!value)
|
|
116
|
+
Alert.alert(
|
|
117
|
+
'Oops',
|
|
118
|
+
`Couldn't ${value ? 'hide' : 'unhide'} this conversation. Please try again.`
|
|
119
|
+
)
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
hidden,
|
|
125
|
+
setHidden,
|
|
126
|
+
...mutation,
|
|
127
|
+
}
|
|
128
|
+
}
|
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: {
|