@planningcenter/chat-react-native 4.7.1-rc.0 → 4.8.0-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 +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/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +2 -0
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/chat_context.d.ts +0 -2
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +16 -93
- package/build/contexts/chat_context.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/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js +3 -0
- package/build/contexts/session_context.js.map +1 -1
- package/build/hooks/groups/use_group_chat_conversation_payload.d.ts +11 -1
- package/build/hooks/groups/use_group_chat_conversation_payload.d.ts.map +1 -1
- package/build/hooks/groups/use_group_chat_conversation_payload.js +92 -47
- package/build/hooks/groups/use_group_chat_conversation_payload.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +33 -25
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.js +125 -110
- package/build/hooks/groups/use_group_members_for_new_conversation.js.map +1 -1
- package/build/hooks/groups/use_groups_conversation_create.d.ts.map +1 -1
- package/build/hooks/groups/use_groups_conversation_create.js +39 -31
- package/build/hooks/groups/use_groups_conversation_create.js.map +1 -1
- package/build/hooks/groups/use_groups_proxy.d.ts +2 -0
- package/build/hooks/groups/use_groups_proxy.d.ts.map +1 -0
- package/build/hooks/groups/use_groups_proxy.js +18 -0
- package/build/hooks/groups/use_groups_proxy.js.map +1 -0
- 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_conversation_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_jolt_events.js +3 -2
- package/build/hooks/use_conversation_jolt_events.js.map +1 -1
- package/build/hooks/use_conversations_actions.d.ts +9 -9
- package/build/hooks/use_conversations_actions.d.ts.map +1 -1
- package/build/hooks/use_conversations_actions.js +12 -7
- package/build/hooks/use_conversations_actions.js.map +1 -1
- package/build/hooks/use_conversations_cache.d.ts +1 -3
- package/build/hooks/use_conversations_cache.d.ts.map +1 -1
- package/build/hooks/use_conversations_cache.js +79 -124
- package/build/hooks/use_conversations_cache.js.map +1 -1
- package/build/hooks/use_conversations_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversations_jolt_events.js +47 -20
- package/build/hooks/use_conversations_jolt_events.js.map +1 -1
- package/build/hooks/use_features.d.ts +2 -0
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +3 -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_groups_groups.js +25 -9
- package/build/hooks/use_groups_groups.js.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_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +5 -4
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_new_conversation_from_filter.d.ts.map +1 -1
- package/build/hooks/use_new_conversation_from_filter.js +11 -1
- package/build/hooks/use_new_conversation_from_filter.js.map +1 -1
- package/build/hooks/use_product_analytics.d.ts.map +1 -1
- package/build/hooks/use_product_analytics.js +93 -75
- package/build/hooks/use_product_analytics.js.map +1 -1
- 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/conversation_new/components/groups_form.d.ts.map +1 -1
- package/build/screens/conversation_new/components/groups_form.js +96 -93
- package/build/screens/conversation_new/components/groups_form.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/get_help_screen.d.ts.map +1 -1
- package/build/screens/get_help_screen.js +4 -20
- package/build/screens/get_help_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/jolt_events/index.d.ts +2 -0
- package/build/types/jolt_events/index.d.ts.map +1 -1
- package/build/types/jolt_events/index.js.map +1 -1
- package/build/types/jolt_events/person_events.d.ts +9 -0
- package/build/types/jolt_events/person_events.d.ts.map +1 -0
- package/build/types/jolt_events/person_events.js +2 -0
- package/build/types/jolt_events/person_events.js.map +1 -0
- 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/types/resources/groups/groups_group_resource.d.ts +1 -1
- package/build/types/resources/groups/groups_group_resource.d.ts.map +1 -1
- package/build/types/resources/groups/groups_group_resource.js.map +1 -1
- package/build/types/resources/groups/groups_membership_resource.d.ts +11 -0
- package/build/types/resources/groups/groups_membership_resource.d.ts.map +1 -0
- package/build/types/resources/groups/groups_membership_resource.js +2 -0
- package/build/types/resources/groups/groups_membership_resource.js.map +1 -0
- package/build/types/resources/groups/index.d.ts +1 -0
- package/build/types/resources/groups/index.d.ts.map +1 -1
- package/build/types/resources/groups/index.js +1 -0
- package/build/types/resources/groups/index.js.map +1 -1
- package/build/utils/jolt/parse_stream_user_event_type.d.ts +3 -0
- package/build/utils/jolt/parse_stream_user_event_type.d.ts.map +1 -0
- package/build/utils/jolt/parse_stream_user_event_type.js +9 -0
- package/build/utils/jolt/parse_stream_user_event_type.js.map +1 -0
- package/build/utils/native_adapters/linking.d.ts.map +1 -1
- package/build/utils/native_adapters/linking.js +48 -2
- package/build/utils/native_adapters/linking.js.map +1 -1
- package/build/utils/product_analytics_token.d.ts +12 -0
- package/build/utils/product_analytics_token.d.ts.map +1 -0
- package/build/utils/product_analytics_token.js +84 -0
- package/build/utils/product_analytics_token.js.map +1 -0
- 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/throttled_refresh.d.ts +7 -0
- package/build/utils/throttled_refresh.d.ts.map +1 -0
- package/build/utils/throttled_refresh.js +42 -0
- package/build/utils/throttled_refresh.js.map +1 -0
- 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__/hooks/use_group_chat_conversation_payload.test.tsx +31 -0
- 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/api_provider.tsx +2 -0
- package/src/contexts/chat_context.tsx +2 -58
- package/src/contexts/conversations_context.tsx +8 -1
- package/src/contexts/session_context.tsx +3 -0
- package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +229 -0
- package/src/hooks/__tests__/use_conversations_jolt_events.test.tsx +1 -0
- package/src/hooks/__tests__/use_conversations_mark_read.test.tsx +38 -12
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +189 -0
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +23 -2
- package/src/hooks/__tests__/use_product_analytics.test.tsx +304 -0
- package/src/hooks/groups/use_group_chat_conversation_payload.ts +30 -12
- package/src/hooks/groups/use_group_members_for_new_conversation.ts +49 -18
- package/src/hooks/groups/use_groups_conversation_create.ts +10 -14
- package/src/hooks/groups/use_groups_proxy.ts +6 -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_conversation_jolt_events.ts +2 -1
- package/src/hooks/use_conversations_actions.ts +7 -4
- package/src/hooks/use_conversations_cache.ts +1 -23
- package/src/hooks/use_conversations_jolt_events.ts +24 -10
- package/src/hooks/use_features.ts +2 -0
- package/src/hooks/use_groups_groups.ts +21 -16
- 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/hooks/use_mark_latest_message_read.ts +6 -5
- package/src/hooks/use_new_conversation_from_filter.ts +13 -5
- package/src/hooks/use_product_analytics.ts +74 -41
- 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/conversation_new/components/groups_form.tsx +11 -9
- 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/get_help_screen.tsx +4 -18
- package/src/screens/index.ts +1 -0
- package/src/types/jolt_events/index.ts +2 -0
- package/src/types/jolt_events/person_events.ts +16 -0
- package/src/types/resources/conversation_membership.ts +1 -0
- package/src/types/resources/groups/groups_group_resource.ts +1 -1
- package/src/types/resources/groups/groups_membership_resource.ts +10 -0
- package/src/types/resources/groups/index.ts +1 -0
- package/src/utils/__tests__/throttled_refresh.test.ts +101 -0
- package/src/utils/jolt/__tests__/parse_stream_user_event_type.test.ts +27 -0
- package/src/utils/jolt/parse_stream_user_event_type.ts +16 -0
- package/src/utils/native_adapters/__tests__/linking.test.ts +60 -4
- package/src/utils/native_adapters/linking.ts +50 -2
- package/src/utils/product_analytics_token.ts +120 -0
- package/src/utils/request/conversation.ts +6 -0
- package/src/utils/throttled_refresh.ts +62 -0
- package/src/utils/toast_store.ts +45 -0
- package/src/vendor/font_awesome_pro_solid_icons.ts +12 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query'
|
|
2
1
|
import { merge } from 'lodash'
|
|
3
2
|
import React, { createContext, useMemo } from 'react'
|
|
4
3
|
import { ColorSchemeName, useColorScheme } from 'react-native'
|
|
5
4
|
import { AgeCheckContactInfo } from '../screens/age_check/screen_props'
|
|
6
|
-
import {
|
|
5
|
+
import { DeepPartial } from '../types'
|
|
7
6
|
import { FailedResponse } from '../types'
|
|
8
|
-
import {
|
|
9
|
-
import { Client, ENV, OauthType, PartialToken, Session, Uri } from '../utils'
|
|
7
|
+
import { ENV, OauthType, PartialToken, Session } from '../utils'
|
|
10
8
|
import { setLiquidGlassCapability } from '../utils/liquid_glass'
|
|
11
9
|
import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
|
|
12
10
|
|
|
@@ -27,7 +25,6 @@ export interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {
|
|
|
27
25
|
session: Session
|
|
28
26
|
theme: ChatTheme
|
|
29
27
|
onAgeDisqualification: (params: AgeCheckContactInfo) => void
|
|
30
|
-
productAnalyticsConfig: ProductAnalyticsConfig | undefined
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
export const ChatContext = createContext<ChatContextValue>({
|
|
@@ -40,7 +37,6 @@ export const ChatContext = createContext<ChatContextValue>({
|
|
|
40
37
|
token: undefined,
|
|
41
38
|
edgeToEdge: true,
|
|
42
39
|
liquidGlassEnabled: false,
|
|
43
|
-
productAnalyticsConfig: undefined,
|
|
44
40
|
})
|
|
45
41
|
|
|
46
42
|
export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
|
|
@@ -64,7 +60,6 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
|
|
|
64
60
|
[env, prototypeName, token, tokenType]
|
|
65
61
|
)
|
|
66
62
|
|
|
67
|
-
const productAnalyticsConfig = useProductAnalyticsConfig(session)
|
|
68
63
|
const contextValue: ChatContextValue = {
|
|
69
64
|
...value,
|
|
70
65
|
edgeToEdge,
|
|
@@ -76,7 +71,6 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
|
|
|
76
71
|
session,
|
|
77
72
|
theme,
|
|
78
73
|
token,
|
|
79
|
-
productAnalyticsConfig,
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
return <ChatContext.Provider value={contextValue}>{children}</ChatContext.Provider>
|
|
@@ -107,53 +101,3 @@ export const useCreateChatTheme = ({
|
|
|
107
101
|
|
|
108
102
|
return theme
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
interface ProductAnalyticsTokenResponse {
|
|
112
|
-
type: 'ProductAnalyticsToken'
|
|
113
|
-
id: string
|
|
114
|
-
url: string
|
|
115
|
-
metadata: Record<string, unknown>
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// expiry time comes from here:
|
|
119
|
-
// https://github.com/planningcenter/pco-product-analytics/blob/e5bbc4c31b715b3c329c06a162829ee6967d3094/lib/pco/product/analytics/client_token_provider.rb#L24
|
|
120
|
-
const TOKEN_EXPIRY_TIME = 604800 * 1000 // 7 days in milliseconds
|
|
121
|
-
|
|
122
|
-
const useProductAnalyticsConfig = (session: Session): ProductAnalyticsConfig | undefined => {
|
|
123
|
-
const uri = useMemo(() => new Uri({ session }), [session])
|
|
124
|
-
const apiClient = useMemo(
|
|
125
|
-
() =>
|
|
126
|
-
new Client({
|
|
127
|
-
root: uri.api(`/chat/v2`),
|
|
128
|
-
defaultHeaders: uri.headers,
|
|
129
|
-
version: '2018-11-01',
|
|
130
|
-
}),
|
|
131
|
-
[uri]
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
const { data: config } = useQuery<ProductAnalyticsConfig>({
|
|
135
|
-
queryKey: ['product-analytics-token'],
|
|
136
|
-
queryFn: () =>
|
|
137
|
-
apiClient
|
|
138
|
-
.post<ApiResource<ProductAnalyticsTokenResponse>>({
|
|
139
|
-
url: '/me/product_analytics_authorize',
|
|
140
|
-
data: {
|
|
141
|
-
data: {
|
|
142
|
-
type: 'ProductAnalyticsToken',
|
|
143
|
-
attributes: {},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
.then(res => ({
|
|
148
|
-
token: res.data.id,
|
|
149
|
-
endpoint: res.data.url,
|
|
150
|
-
metadata: res.data.metadata,
|
|
151
|
-
})),
|
|
152
|
-
staleTime: TOKEN_EXPIRY_TIME,
|
|
153
|
-
gcTime: TOKEN_EXPIRY_TIME,
|
|
154
|
-
refetchInterval: TOKEN_EXPIRY_TIME,
|
|
155
|
-
enabled: process.env.NODE_ENV !== 'test',
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
return config
|
|
159
|
-
}
|
|
@@ -14,6 +14,7 @@ interface ConversationsContextValue extends UseConversationsValue {
|
|
|
14
14
|
activeConversationId?: number
|
|
15
15
|
setActiveConversationId: (_id: number) => void
|
|
16
16
|
args: ConversationFiltersParams
|
|
17
|
+
hideable: boolean
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const defaultQueryValue: UseConversationsValue = {
|
|
@@ -33,6 +34,7 @@ const ConversationsContext = createContext<ConversationsContextValue>({
|
|
|
33
34
|
args: {},
|
|
34
35
|
activeConversationId: undefined,
|
|
35
36
|
setActiveConversationId: () => {},
|
|
37
|
+
hideable: true,
|
|
36
38
|
...defaultQueryValue,
|
|
37
39
|
})
|
|
38
40
|
|
|
@@ -40,9 +42,11 @@ export const ConversationsContextProvider = ({
|
|
|
40
42
|
children,
|
|
41
43
|
args = {},
|
|
42
44
|
opts: paginatorOptions,
|
|
45
|
+
hideable = true,
|
|
43
46
|
}: PropsWithChildren<{
|
|
44
47
|
args: ConversationFiltersParams
|
|
45
48
|
opts?: ApiGetQueryOptions
|
|
49
|
+
hideable?: boolean
|
|
46
50
|
}>) => {
|
|
47
51
|
const [activeConversationId, setActiveConversationId] = useState<number | undefined>()
|
|
48
52
|
const {
|
|
@@ -50,6 +54,7 @@ export const ConversationsContextProvider = ({
|
|
|
50
54
|
group_source_app_name,
|
|
51
55
|
show_direct_messages,
|
|
52
56
|
show_archived,
|
|
57
|
+
show_hidden,
|
|
53
58
|
show_unread,
|
|
54
59
|
} = args
|
|
55
60
|
|
|
@@ -59,6 +64,7 @@ export const ConversationsContextProvider = ({
|
|
|
59
64
|
group_source_app_name,
|
|
60
65
|
show_direct_messages,
|
|
61
66
|
show_archived,
|
|
67
|
+
show_hidden,
|
|
62
68
|
show_unread,
|
|
63
69
|
},
|
|
64
70
|
paginatorOptions
|
|
@@ -69,9 +75,10 @@ export const ConversationsContextProvider = ({
|
|
|
69
75
|
args,
|
|
70
76
|
activeConversationId,
|
|
71
77
|
setActiveConversationId,
|
|
78
|
+
hideable,
|
|
72
79
|
...query,
|
|
73
80
|
}),
|
|
74
|
-
[args, activeConversationId, query]
|
|
81
|
+
[args, activeConversationId, hideable, query]
|
|
75
82
|
)
|
|
76
83
|
|
|
77
84
|
return <ConversationsContext.Provider value={value}>{children}</ConversationsContext.Provider>
|
|
@@ -17,6 +17,7 @@ import { ApiResource } from '../types/api_primitives'
|
|
|
17
17
|
import { ENV, PartialToken, Session, UNAUTHENTICATED_SESSION_ID } from '../utils'
|
|
18
18
|
import { StorageAdapter } from '../utils/native_adapters/storage_adapter'
|
|
19
19
|
import { SessionManager } from '../utils/session_manager'
|
|
20
|
+
import { cancelThrottledRefreshes } from '../utils/throttled_refresh'
|
|
20
21
|
import { chatQueryClient } from './api_provider'
|
|
21
22
|
|
|
22
23
|
type Sessions = Record<string, string> // Key is session ID
|
|
@@ -143,6 +144,8 @@ export function SessionContextProvider({
|
|
|
143
144
|
})
|
|
144
145
|
|
|
145
146
|
const handleClearQueryClient = useCallback(() => {
|
|
147
|
+
cancelThrottledRefreshes(chatQueryClient)
|
|
148
|
+
cancelThrottledRefreshes(queryClient)
|
|
146
149
|
chatQueryClient.clear()
|
|
147
150
|
queryClient.clear()
|
|
148
151
|
}, [queryClient])
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { act, render } from '@testing-library/react-native'
|
|
3
|
+
import React, { Suspense } from 'react'
|
|
4
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
|
+
import type { ApiResource, ConversationResource, CurrentPersonResource } from '../../types'
|
|
6
|
+
import { getConversationsRequestArgs } from '../../utils/request/conversation'
|
|
7
|
+
import { cancelThrottledRefreshes, REFRESH_THROTTLE_MS } from '../../utils/throttled_refresh'
|
|
8
|
+
import { getConversationRequestArgs } from '../use_conversation'
|
|
9
|
+
import { useConversationJoltEvents } from '../use_conversation_jolt_events'
|
|
10
|
+
import { useConversationsJoltEvents } from '../use_conversations_jolt_events'
|
|
11
|
+
import { currentPersonQueryKey } from '../use_current_person'
|
|
12
|
+
import { getRequestQueryKey } from '../use_suspense_api'
|
|
13
|
+
|
|
14
|
+
type Handler = (event: unknown) => void
|
|
15
|
+
const mockHandlers = new Map<string, Set<Handler>>()
|
|
16
|
+
|
|
17
|
+
jest.mock('../use_jolt', () => {
|
|
18
|
+
const { useEffect } = jest.requireActual<typeof import('react')>('react')
|
|
19
|
+
return {
|
|
20
|
+
useJoltChannel: (channelName: string) => channelName,
|
|
21
|
+
useJoltEvent: (channel: string, eventName: string, handler: Handler) => {
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const key = `${channel}:${eventName}`
|
|
24
|
+
const bound = mockHandlers.get(key) ?? new Set<Handler>()
|
|
25
|
+
mockHandlers.set(key, bound)
|
|
26
|
+
bound.add(handler)
|
|
27
|
+
return () => {
|
|
28
|
+
bound.delete(handler)
|
|
29
|
+
}
|
|
30
|
+
}, [channel, eventName, handler])
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
jest.mock('../use_api', () => ({ useApiGet: () => ({ data: { id: 1 } }) }))
|
|
35
|
+
jest.mock('../../contexts/conversations_context', () => ({
|
|
36
|
+
useConversationsContext: () => ({ args: {} }),
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
const mockGet = jest.fn()
|
|
40
|
+
jest.mock('../use_api_client', () => ({ useApiClient: () => ({ chat: { get: mockGet } }) }))
|
|
41
|
+
|
|
42
|
+
const personId = 1
|
|
43
|
+
const conversationId = 7
|
|
44
|
+
const peopleChannel = `chat.people.${personId}`
|
|
45
|
+
const conversationChannel = `chat.conversations.${conversationId}`
|
|
46
|
+
const listQueryKey = getRequestQueryKey(getConversationsRequestArgs({}))
|
|
47
|
+
const conversationQueryKey = getRequestQueryKey(
|
|
48
|
+
getConversationRequestArgs({ conversation_id: conversationId })
|
|
49
|
+
)
|
|
50
|
+
const listUrl = listQueryKey[0]
|
|
51
|
+
const conversationUrl = conversationQueryKey[0]
|
|
52
|
+
const meUrl = currentPersonQueryKey[0]
|
|
53
|
+
|
|
54
|
+
let queryClient: QueryClient
|
|
55
|
+
|
|
56
|
+
const ConversationsList = () => {
|
|
57
|
+
useConversationsJoltEvents()
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const ConversationScreen = () => {
|
|
62
|
+
useConversationJoltEvents({ conversationId })
|
|
63
|
+
useQuery({
|
|
64
|
+
queryKey: conversationQueryKey,
|
|
65
|
+
queryFn: () => mockGet({ url: conversationUrl }),
|
|
66
|
+
staleTime: Infinity,
|
|
67
|
+
})
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const fire = (channel: string, eventName: string, payload: Record<string, unknown>) => {
|
|
72
|
+
const message = { event: eventName, channel, ...payload }
|
|
73
|
+
mockHandlers.get(`${channel}:${eventName}`)?.forEach(handler => handler(message))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const conversationUpdated = () => {
|
|
77
|
+
const data = { data: { id: conversationId, last_message_author_id: 2 } }
|
|
78
|
+
fire(peopleChannel, 'conversation.updated', { data })
|
|
79
|
+
fire(conversationChannel, 'conversation.updated', { data })
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const conversationRead = () => {
|
|
83
|
+
const data = { data: { id: conversationId, latest_read_message_sort_key: 'z' } }
|
|
84
|
+
fire(peopleChannel, 'conversation.read', { data })
|
|
85
|
+
fire(conversationChannel, 'conversation.read', { data })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const streamUserUpdated = (payload: Record<string, unknown>) =>
|
|
89
|
+
fire(peopleChannel, 'STREAM_USER_UPDATED', { data: { data: JSON.stringify(payload) } })
|
|
90
|
+
|
|
91
|
+
const requestsFor = (url: string) =>
|
|
92
|
+
mockGet.mock.calls.filter(([request]) => request.url === url).length
|
|
93
|
+
|
|
94
|
+
const advance = (ms: number) => act(async () => jest.advanceTimersByTime(ms))
|
|
95
|
+
|
|
96
|
+
const seed = () => {
|
|
97
|
+
queryClient.setQueryData<ApiResource<CurrentPersonResource>>(currentPersonQueryKey, {
|
|
98
|
+
data: { type: 'Person', id: personId },
|
|
99
|
+
} as ApiResource<CurrentPersonResource>)
|
|
100
|
+
queryClient.setQueryData<ApiResource<ConversationResource>>(conversationQueryKey, {
|
|
101
|
+
data: { type: 'Conversation', id: conversationId },
|
|
102
|
+
} as ApiResource<ConversationResource>)
|
|
103
|
+
queryClient.setQueryData(listQueryKey, {
|
|
104
|
+
pages: [{ data: [{ type: 'Conversation', id: conversationId }], links: {}, meta: {} }],
|
|
105
|
+
pageParams: [undefined],
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const mountTwoListsAndTwoScreens = async () => {
|
|
110
|
+
seed()
|
|
111
|
+
render(
|
|
112
|
+
<QueryClientProvider client={queryClient}>
|
|
113
|
+
<Suspense fallback={null}>
|
|
114
|
+
<ConversationsList />
|
|
115
|
+
<ConversationsList />
|
|
116
|
+
<ConversationScreen />
|
|
117
|
+
<ConversationScreen />
|
|
118
|
+
</Suspense>
|
|
119
|
+
</QueryClientProvider>
|
|
120
|
+
)
|
|
121
|
+
await advance(1)
|
|
122
|
+
mockGet.mockClear()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
beforeEach(async () => {
|
|
126
|
+
jest.useFakeTimers()
|
|
127
|
+
mockHandlers.clear()
|
|
128
|
+
mockGet.mockReset()
|
|
129
|
+
mockGet.mockImplementation(({ url }: { url: string }) => {
|
|
130
|
+
if (url === meUrl) return Promise.resolve({ data: { type: 'Person', id: personId } })
|
|
131
|
+
if (url === conversationUrl) {
|
|
132
|
+
return Promise.resolve({ data: { type: 'Conversation', id: conversationId } })
|
|
133
|
+
}
|
|
134
|
+
return Promise.resolve({ data: [{ type: 'Conversation', id: conversationId }] })
|
|
135
|
+
})
|
|
136
|
+
queryClient = buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
137
|
+
await mountTwoListsAndTwoScreens()
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
afterEach(() => {
|
|
141
|
+
cancelThrottledRefreshes(queryClient)
|
|
142
|
+
jest.useRealTimers()
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('conversation.updated across two lists and two screens', () => {
|
|
146
|
+
it('collapses 50 events into one request now and one when the window ends', async () => {
|
|
147
|
+
for (let i = 0; i < 50; i++) conversationUpdated()
|
|
148
|
+
await advance(1)
|
|
149
|
+
|
|
150
|
+
expect(requestsFor(listUrl)).toBe(1)
|
|
151
|
+
expect(requestsFor(conversationUrl)).toBe(1)
|
|
152
|
+
|
|
153
|
+
await advance(REFRESH_THROTTLE_MS)
|
|
154
|
+
|
|
155
|
+
expect(requestsFor(listUrl)).toBe(2)
|
|
156
|
+
expect(requestsFor(conversationUrl)).toBe(2)
|
|
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
|
+
})
|
|
194
|
+
|
|
195
|
+
describe('/me refreshes', () => {
|
|
196
|
+
it('makes no /me request for message.created stream events or conversation.read events', async () => {
|
|
197
|
+
for (let i = 0; i < 50; i++) {
|
|
198
|
+
streamUserUpdated({ event_type: 'message.created' })
|
|
199
|
+
conversationRead()
|
|
200
|
+
}
|
|
201
|
+
await advance(REFRESH_THROTTLE_MS * 2)
|
|
202
|
+
|
|
203
|
+
expect(requestsFor(meUrl)).toBe(0)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('ignores the other read-state event types', async () => {
|
|
207
|
+
streamUserUpdated({ event_type: 'conversation.mark_read' })
|
|
208
|
+
streamUserUpdated({ event_type: 'conversation.mark_unread' })
|
|
209
|
+
streamUserUpdated({ event_type: 'person.mark_all_read' })
|
|
210
|
+
streamUserUpdated({ event_type: 'conversation.destroy' })
|
|
211
|
+
await advance(REFRESH_THROTTLE_MS * 2)
|
|
212
|
+
|
|
213
|
+
expect(requestsFor(meUrl)).toBe(0)
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it('refetches /me once for app_grant.synced', async () => {
|
|
217
|
+
streamUserUpdated({ event_type: 'app_grant.synced' })
|
|
218
|
+
await advance(REFRESH_THROTTLE_MS * 2)
|
|
219
|
+
|
|
220
|
+
expect(requestsFor(meUrl)).toBe(1)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('refetches /me once for an event with no event_type', async () => {
|
|
224
|
+
streamUserUpdated({})
|
|
225
|
+
await advance(REFRESH_THROTTLE_MS * 2)
|
|
226
|
+
|
|
227
|
+
expect(requestsFor(meUrl)).toBe(1)
|
|
228
|
+
})
|
|
229
|
+
})
|
|
@@ -18,6 +18,7 @@ jest.mock('../use_jolt', () => ({
|
|
|
18
18
|
jest.mock('../use_api', () => ({ useApiGet: () => ({ data: { id: 1 } }) }))
|
|
19
19
|
jest.mock('../use_current_person', () => ({
|
|
20
20
|
currentPersonRequestArgs: {},
|
|
21
|
+
currentPersonQueryKey: ['/me'],
|
|
21
22
|
useCurrentPersonCache: () => ({ invalidate: jest.fn() }),
|
|
22
23
|
}))
|
|
23
24
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryClientProvider } from '@tanstack/react-query'
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
2
|
import { act, renderHook } from '@testing-library/react-native'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
@@ -7,27 +7,53 @@ import { getConversationsRequestArgs } from '../../utils/request/conversation'
|
|
|
7
7
|
import { useConversationsMarkRead } from '../use_conversations_actions'
|
|
8
8
|
import { getRequestQueryKey } from '../use_suspense_api'
|
|
9
9
|
|
|
10
|
+
const mockPost = jest.fn()
|
|
11
|
+
const mockGet = jest.fn()
|
|
10
12
|
jest.mock('../use_api_client', () => ({
|
|
11
|
-
useApiClient: () => ({
|
|
12
|
-
chat: { post: jest.fn().mockResolvedValue({}), get: jest.fn().mockResolvedValue({ data: [] }) },
|
|
13
|
-
}),
|
|
13
|
+
useApiClient: () => ({ chat: { post: mockPost, get: mockGet } }),
|
|
14
14
|
}))
|
|
15
15
|
|
|
16
|
+
const conversation = { id: 7, unreadCount: 8 } as ConversationResource
|
|
17
|
+
const listKey = getRequestQueryKey(getConversationsRequestArgs())
|
|
18
|
+
const archivedListKey = getRequestQueryKey(getConversationsRequestArgs({ show_archived: true }))
|
|
19
|
+
let queryClient: QueryClient
|
|
20
|
+
|
|
21
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
22
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const listShows = (key: typeof listKey) => queryClient.getQueryData(key)
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
mockPost.mockReset()
|
|
29
|
+
mockGet.mockReset()
|
|
30
|
+
queryClient = buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
31
|
+
queryClient.setQueryData(listKey, { pages: [{ data: [conversation] }], pageParams: [] })
|
|
32
|
+
queryClient.setQueryData(archivedListKey, { pages: [{ data: [conversation] }], pageParams: [] })
|
|
33
|
+
})
|
|
34
|
+
|
|
16
35
|
describe('useConversationsMarkRead', () => {
|
|
17
36
|
it('marks the conversation read in a list outside the current conversations context', async () => {
|
|
18
|
-
|
|
19
|
-
const archivedListKey = getRequestQueryKey(getConversationsRequestArgs({ show_archived: true }))
|
|
20
|
-
const queryClient = buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
21
|
-
queryClient.setQueryData(archivedListKey, { pages: [{ data: [conversation] }], pageParams: [] })
|
|
22
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
23
|
-
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
24
|
-
)
|
|
37
|
+
mockPost.mockResolvedValue({ data: { type: 'Conversation', id: 7, unreadCount: 0 } })
|
|
25
38
|
const { result } = renderHook(() => useConversationsMarkRead({ conversation }), { wrapper })
|
|
26
39
|
|
|
27
40
|
await act(async () => result.current.markRead(true))
|
|
28
41
|
|
|
29
|
-
expect(
|
|
42
|
+
expect(listShows(archivedListKey)).toMatchObject({
|
|
30
43
|
pages: [{ data: [{ id: 7, unreadCount: 0 }] }],
|
|
31
44
|
})
|
|
32
45
|
})
|
|
46
|
+
|
|
47
|
+
it('shows the unread count from the response without refetching the conversation', async () => {
|
|
48
|
+
mockPost.mockResolvedValue({ data: { type: 'Conversation', id: 7, unreadCount: 3 } })
|
|
49
|
+
const { result } = renderHook(() => useConversationsMarkRead({ conversation }), { wrapper })
|
|
50
|
+
|
|
51
|
+
await act(async () => result.current.markRead(false))
|
|
52
|
+
|
|
53
|
+
expect(mockGet).not.toHaveBeenCalled()
|
|
54
|
+
expect(listShows(listKey)).toMatchObject({ pages: [{ data: [{ id: 7, unreadCount: 3 }] }] })
|
|
55
|
+
expect(listShows(archivedListKey)).toMatchObject({
|
|
56
|
+
pages: [{ data: [{ id: 7, unreadCount: 3 }] }],
|
|
57
|
+
})
|
|
58
|
+
})
|
|
33
59
|
})
|
|
@@ -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
|
+
})
|