@planningcenter/chat-react-native 4.7.1-rc.0 → 4.8.0-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/app_update_banner.d.ts +2 -0
- package/build/components/conversations/app_update_banner.d.ts.map +1 -0
- package/build/components/conversations/app_update_banner.js +52 -0
- package/build/components/conversations/app_update_banner.js.map +1 -0
- 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/components/primitive/banner_primitive.js +7 -3
- package/build/components/primitive/banner_primitive.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 +47 -21
- 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/configuration.d.ts +3 -0
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +3 -0
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/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/native_adapters/updates.d.ts +11 -0
- package/build/utils/native_adapters/updates.d.ts.map +1 -0
- package/build/utils/native_adapters/updates.js +8 -0
- package/build/utils/native_adapters/updates.js.map +1 -0
- package/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__/app_update_banner.test.tsx +27 -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/app_update_banner.tsx +36 -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/components/primitive/banner_primitive.tsx +5 -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 +3 -3
- 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 +12 -1
- 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/configuration.ts +5 -0
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/linking.ts +50 -2
- package/src/utils/native_adapters/updates.ts +16 -0
- 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
|
@@ -2,7 +2,6 @@ import { InfiniteData, useQueryClient } from '@tanstack/react-query'
|
|
|
2
2
|
import { ApiCollection, ConversationResource } from '../types'
|
|
3
3
|
import {
|
|
4
4
|
deleteRecordInPagesData,
|
|
5
|
-
updateRecordInPagesData,
|
|
6
5
|
updateAllRecordsInPagesData,
|
|
7
6
|
updateOrCreateRecordInPagesData,
|
|
8
7
|
} from '../utils'
|
|
@@ -44,20 +43,6 @@ export function useConversationsCache(args?: Partial<ConversationRequestArgs>) {
|
|
|
44
43
|
)
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
const updateOnly = async (conversation: ConversationResource) => {
|
|
48
|
-
if (!conversation.id) return
|
|
49
|
-
|
|
50
|
-
queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>
|
|
51
|
-
updateRecordInPagesData({
|
|
52
|
-
data: prev,
|
|
53
|
-
record: conversation,
|
|
54
|
-
processRecord: (record, current) => {
|
|
55
|
-
return { ...current, ...record }
|
|
56
|
-
},
|
|
57
|
-
})
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
46
|
const updateAll = async (update: Partial<ConversationResource>) => {
|
|
62
47
|
queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>
|
|
63
48
|
updateAllRecordsInPagesData({
|
|
@@ -92,13 +77,6 @@ export function useConversationsCache(args?: Partial<ConversationRequestArgs>) {
|
|
|
92
77
|
)
|
|
93
78
|
}
|
|
94
79
|
|
|
95
|
-
const fetchAndUpdate = async ({ id }: { id: number }) => {
|
|
96
|
-
const conversation = await fetchConversation(id).catch(() => undefined)
|
|
97
|
-
if (!conversation) return
|
|
98
|
-
|
|
99
|
-
updateOnly(conversation)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
80
|
const fetchAndSync = async ({ id }: { id: number }) => {
|
|
103
81
|
let conversation: ConversationResource | undefined
|
|
104
82
|
try {
|
|
@@ -115,10 +93,10 @@ export function useConversationsCache(args?: Partial<ConversationRequestArgs>) {
|
|
|
115
93
|
}
|
|
116
94
|
|
|
117
95
|
return {
|
|
96
|
+
queryKey: conversationQueryKey,
|
|
118
97
|
create: updateOrCreate,
|
|
119
98
|
destroy: handleConversationDestroy,
|
|
120
99
|
fetchSync: fetchAndSync,
|
|
121
|
-
fetchUpdate: fetchAndUpdate,
|
|
122
100
|
invalidate: () => queryClient.invalidateQueries({ queryKey: conversationQueryKey }),
|
|
123
101
|
invalidateAllLists,
|
|
124
102
|
update: updateOrCreate,
|
|
@@ -1,37 +1,48 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
1
2
|
import { useConversationsContext } from '../contexts/conversations_context'
|
|
2
3
|
import { CurrentPersonResource } from '../types'
|
|
3
|
-
import { JoltConversationEvent } from '../types/jolt_events'
|
|
4
|
+
import { JoltConversationEvent, StreamUserUpdatedEvent } from '../types/jolt_events'
|
|
5
|
+
import { parseStreamUserEventType } from '../utils/jolt/parse_stream_user_event_type'
|
|
4
6
|
import { completeMessageCreationConversationTracking } from '../utils/performance_tracking'
|
|
7
|
+
import { throttledRefresh } from '../utils/throttled_refresh'
|
|
5
8
|
import { useApiGet } from './use_api'
|
|
6
9
|
import { useApiClient } from './use_api_client'
|
|
7
10
|
import { useConversationsCache } from './use_conversations_cache'
|
|
8
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
currentPersonQueryKey,
|
|
13
|
+
currentPersonRequestArgs,
|
|
14
|
+
useCurrentPersonCache,
|
|
15
|
+
} from './use_current_person'
|
|
9
16
|
import { useJoltChannel, useJoltEvent } from './use_jolt'
|
|
10
17
|
|
|
11
18
|
const useCurrentPerson = () => {
|
|
12
19
|
return useApiGet<CurrentPersonResource>(currentPersonRequestArgs)
|
|
13
20
|
}
|
|
14
21
|
|
|
22
|
+
const refreshesCurrentPerson = (event: StreamUserUpdatedEvent) => {
|
|
23
|
+
const eventType = parseStreamUserEventType(event)
|
|
24
|
+
return eventType === undefined || eventType === 'app_grant.synced'
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
export function useConversationsJoltEvents() {
|
|
16
28
|
const { data: currentPerson } = useCurrentPerson()
|
|
17
29
|
const { args } = useConversationsContext()
|
|
18
30
|
const cache = useConversationsCache(args)
|
|
19
31
|
const currentPersonCache = useCurrentPersonCache()
|
|
20
32
|
const apiClient = useApiClient()
|
|
33
|
+
const queryClient = useQueryClient()
|
|
21
34
|
const enabled = currentPerson?.id ? true : false
|
|
22
35
|
const joltChannel = useJoltChannel(`chat.people.${currentPerson?.id}`, enabled)
|
|
23
36
|
|
|
24
37
|
useJoltEvent(joltChannel, 'conversation.updated', (e: JoltConversationEvent) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
e.data.data.last_message_author_id === currentPerson?.id
|
|
28
|
-
) {
|
|
38
|
+
const { id, last_message_idempotent_key, last_message_author_id } = e.data.data
|
|
39
|
+
if (last_message_idempotent_key && last_message_author_id === currentPerson?.id) {
|
|
29
40
|
completeMessageCreationConversationTracking({
|
|
30
41
|
apiClient,
|
|
31
|
-
idempotentKey:
|
|
42
|
+
idempotentKey: last_message_idempotent_key,
|
|
32
43
|
})
|
|
33
44
|
}
|
|
34
|
-
cache.
|
|
45
|
+
throttledRefresh(queryClient, [...cache.queryKey, id], e, () => cache.fetchSync({ id }))
|
|
35
46
|
})
|
|
36
47
|
useJoltEvent(joltChannel, 'conversation.created', (e: JoltConversationEvent) =>
|
|
37
48
|
cache.fetchSync({ id: e.data.data.id })
|
|
@@ -40,6 +51,9 @@ export function useConversationsJoltEvents() {
|
|
|
40
51
|
cache.destroy({ id: e.data.data.id })
|
|
41
52
|
)
|
|
42
53
|
|
|
43
|
-
useJoltEvent(joltChannel, 'STREAM_USER_UPDATED',
|
|
44
|
-
|
|
54
|
+
useJoltEvent(joltChannel, 'STREAM_USER_UPDATED', (e: StreamUserUpdatedEvent) => {
|
|
55
|
+
if (!refreshesCurrentPerson(e)) return
|
|
56
|
+
|
|
57
|
+
throttledRefresh(queryClient, currentPersonQueryKey, e, currentPersonCache.invalidate)
|
|
58
|
+
})
|
|
45
59
|
}
|
|
@@ -61,6 +61,8 @@ 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
|
+
groups_proxy: 'ROLLOUT_groups_proxy',
|
|
65
|
+
hide_conversations: 'ROLLOUT_hide_conversations',
|
|
64
66
|
} as const satisfies Record<string, `${'QA' | 'ROLLOUT'}_${string}`>
|
|
65
67
|
|
|
66
68
|
const featureNames = Object.values(availableFeatures)
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import { GroupsGroupResource } from '../types'
|
|
2
2
|
import { FIVE_MINUTES } from '../utils/time'
|
|
3
|
+
import { useGroupsProxy } from './groups/use_groups_proxy'
|
|
3
4
|
import { useApiPaginator } from './use_api'
|
|
4
5
|
|
|
6
|
+
const GROUP_FIELDS = [
|
|
7
|
+
'can_create_conversation',
|
|
8
|
+
'can_create_conversation_reason_code',
|
|
9
|
+
'name',
|
|
10
|
+
'header_image',
|
|
11
|
+
'memberships_count',
|
|
12
|
+
]
|
|
13
|
+
|
|
5
14
|
export const useGroupsGroups = () => {
|
|
15
|
+
const proxied = useGroupsProxy()
|
|
16
|
+
|
|
6
17
|
return useApiPaginator<GroupsGroupResource>(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'memberships_count',
|
|
18
|
-
],
|
|
18
|
+
proxied
|
|
19
|
+
? {
|
|
20
|
+
url: '/me/groups_groups',
|
|
21
|
+
data: { perPage: 100, fields: { GroupsGroup: GROUP_FIELDS } },
|
|
22
|
+
app: 'chat',
|
|
23
|
+
}
|
|
24
|
+
: {
|
|
25
|
+
url: '/me/groups',
|
|
26
|
+
data: { perPage: 100, fields: { Group: GROUP_FIELDS }, order: 'name' },
|
|
27
|
+
app: 'groups',
|
|
19
28
|
},
|
|
20
|
-
order: 'name',
|
|
21
|
-
},
|
|
22
|
-
app: 'groups',
|
|
23
|
-
},
|
|
24
29
|
{ staleTime: FIVE_MINUTES }
|
|
25
30
|
)
|
|
26
31
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { throttle } from 'lodash'
|
|
2
2
|
import { useEffect, useMemo, useRef } from 'react'
|
|
3
3
|
import { ConversationResource, MessageResource } from '../types'
|
|
4
|
+
import { REFRESH_THROTTLE_MS } from '../utils/throttled_refresh'
|
|
4
5
|
import { useAppState } from './use_app_state'
|
|
5
6
|
import { useConversationsMarkRead } from './use_conversations_actions'
|
|
6
7
|
|
|
@@ -13,8 +14,8 @@ interface Props {
|
|
|
13
14
|
export function useMarkLatestMessageRead({ conversation, enabled = true }: Props) {
|
|
14
15
|
const firedOnce = useRef<boolean>(false)
|
|
15
16
|
const { markRead } = useConversationsMarkRead({ conversation })
|
|
16
|
-
const
|
|
17
|
-
() =>
|
|
17
|
+
const throttledMarkRead = useMemo(
|
|
18
|
+
() => throttle(markRead, REFRESH_THROTTLE_MS, { leading: true, trailing: true }),
|
|
18
19
|
[markRead]
|
|
19
20
|
)
|
|
20
21
|
const unreadCount = conversation.unreadCount
|
|
@@ -30,6 +31,6 @@ export function useMarkLatestMessageRead({ conversation, enabled = true }: Props
|
|
|
30
31
|
|
|
31
32
|
firedOnce.current = true
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
}, [
|
|
34
|
+
throttledMarkRead(true)
|
|
35
|
+
}, [throttledMarkRead, isActive, shouldMarkRead, unreadReaction])
|
|
35
36
|
}
|
|
@@ -2,6 +2,7 @@ import { useMemo } from 'react'
|
|
|
2
2
|
import { GroupResource, GraphId } from '../types/resources/group_resource'
|
|
3
3
|
import { GroupsGroupResource } from '../types/resources/groups/groups_group_resource'
|
|
4
4
|
import { destructureChatGroupGraphId } from '../utils'
|
|
5
|
+
import { useGroupsProxy } from './groups/use_groups_proxy'
|
|
5
6
|
import { useApiGet } from './use_api'
|
|
6
7
|
import { useNewConversationEntry } from './use_new_conversation_entry'
|
|
7
8
|
|
|
@@ -22,6 +23,7 @@ export function useNewConversationFromFilter(
|
|
|
22
23
|
): NewConversationFromFilter | undefined {
|
|
23
24
|
const { sourceAppName, sourceType, sourceId } = destructureChatGroupGraphId(chatGroupGraphId)
|
|
24
25
|
const entryMode = useNewConversationEntry()
|
|
26
|
+
const proxied = useGroupsProxy()
|
|
25
27
|
const isGroupsGroup = sourceAppName === 'Groups' && sourceType === 'Group'
|
|
26
28
|
const isServicesTeam = sourceAppName === 'Services' && sourceType === 'Team'
|
|
27
29
|
|
|
@@ -31,11 +33,17 @@ export function useNewConversationFromFilter(
|
|
|
31
33
|
)
|
|
32
34
|
|
|
33
35
|
const { data: groupsGroup } = useApiGet<GroupsGroupResource>(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
proxied
|
|
37
|
+
? {
|
|
38
|
+
url: `/me/groups_groups/${sourceId}`,
|
|
39
|
+
data: { fields: { GroupsGroup: ['can_create_conversation'] } },
|
|
40
|
+
app: 'chat',
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
url: `/me/groups/${sourceId}`,
|
|
44
|
+
data: { fields: { Group: ['can_create_conversation'] } },
|
|
45
|
+
app: 'groups',
|
|
46
|
+
},
|
|
39
47
|
{ enabled: isGroupsGroup && !!sourceId }
|
|
40
48
|
)
|
|
41
49
|
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isCancelledError, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
2
3
|
import { useChatContext } from '../contexts/chat_context'
|
|
3
4
|
import { ProductAnalyticsConfig } from '../types/product_analytics'
|
|
4
5
|
import { AnalyticsMetadataResource } from '../types/resources/analytics_metadata'
|
|
5
6
|
import { keysToSnakeCase } from '../utils/client/utils'
|
|
7
|
+
import { Log } from '../utils/native_adapters/configuration'
|
|
8
|
+
import { fetchProductAnalyticsConfig } from '../utils/product_analytics_token'
|
|
9
|
+
import { isResponseLike, ResponseError } from '../utils/response_error'
|
|
6
10
|
import { SHA256, enc } from '../utils/sha_256'
|
|
7
11
|
|
|
8
12
|
export interface EventMetadata {
|
|
@@ -27,6 +31,46 @@ function contentSha256(payload: string): string {
|
|
|
27
31
|
return SHA256(payload).toString(enc.Hex)
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
type AnalyticsStage = 'prepare' | 'send'
|
|
35
|
+
|
|
36
|
+
const REPORT_TAGS = {
|
|
37
|
+
team: 'chat',
|
|
38
|
+
package: 'chat-react-native',
|
|
39
|
+
feature: 'product-analytics',
|
|
40
|
+
} as const
|
|
41
|
+
|
|
42
|
+
const isNetworkFailure = (error: unknown) =>
|
|
43
|
+
error instanceof TypeError && /network/i.test(error.message)
|
|
44
|
+
|
|
45
|
+
// HTTP failures from the API client are already reported by instrumentedFetch,
|
|
46
|
+
// network failures are expected on flaky connections, and queries are cancelled
|
|
47
|
+
// whenever the session changes. Anything else is a bug worth seeing in Sentry.
|
|
48
|
+
const isExpectedFailure = (error: unknown) =>
|
|
49
|
+
isResponseLike(error) ||
|
|
50
|
+
error instanceof ResponseError ||
|
|
51
|
+
isCancelledError(error) ||
|
|
52
|
+
isNetworkFailure(error)
|
|
53
|
+
|
|
54
|
+
function reportAnalyticsError(error: unknown, stage: AnalyticsStage) {
|
|
55
|
+
if (__DEV__) {
|
|
56
|
+
console.warn(`Product Analytics ${stage} failed:`, error)
|
|
57
|
+
}
|
|
58
|
+
if (isExpectedFailure(error)) return
|
|
59
|
+
|
|
60
|
+
const reported = error instanceof Error ? error : new Error(String(error))
|
|
61
|
+
Log.reportError(reported, { tags: { ...REPORT_TAGS, 'analytics.stage': stage } })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The events endpoint is outside the chat API, so it isn't instrumented.
|
|
65
|
+
// A rejected batch here usually means the stored token is no longer accepted.
|
|
66
|
+
function reportRejectedEvents(response: Response) {
|
|
67
|
+
const error = new Error(`HTTP ${response.status} POST product analytics events`)
|
|
68
|
+
error.name = `HTTPError${response.status}`
|
|
69
|
+
Log.reportError(error, {
|
|
70
|
+
tags: { ...REPORT_TAGS, 'analytics.stage': 'send', 'http.status': String(response.status) },
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
30
74
|
function sendEvents(events: AnalyticsEvent[], config: ProductAnalyticsConfig): Promise<Response[]> {
|
|
31
75
|
// Split into chunks of 10 and make parallel requests
|
|
32
76
|
const chunks: AnalyticsEvent[][] = []
|
|
@@ -37,7 +81,7 @@ function sendEvents(events: AnalyticsEvent[], config: ProductAnalyticsConfig): P
|
|
|
37
81
|
return Promise.all(
|
|
38
82
|
chunks.map(async chunk => {
|
|
39
83
|
const payload = JSON.stringify({ events: chunk })
|
|
40
|
-
|
|
84
|
+
const response = await fetch(config.endpoint, {
|
|
41
85
|
method: 'POST',
|
|
42
86
|
headers: {
|
|
43
87
|
'Content-Type': 'application/json; charset=utf-8',
|
|
@@ -46,56 +90,45 @@ function sendEvents(events: AnalyticsEvent[], config: ProductAnalyticsConfig): P
|
|
|
46
90
|
},
|
|
47
91
|
body: payload,
|
|
48
92
|
})
|
|
93
|
+
if (!response.ok) reportRejectedEvents(response)
|
|
94
|
+
return response
|
|
49
95
|
})
|
|
50
96
|
).catch(error => {
|
|
51
|
-
|
|
52
|
-
console.warn('Product Analytics request failed:', error)
|
|
53
|
-
}
|
|
97
|
+
reportAnalyticsError(error, 'send')
|
|
54
98
|
return [] as Response[]
|
|
55
99
|
})
|
|
56
100
|
}
|
|
57
101
|
|
|
58
102
|
export const useProductAnalytics = () => {
|
|
59
|
-
const {
|
|
60
|
-
|
|
61
|
-
const snakeCasedBaseMeta = useMemo(
|
|
62
|
-
() => keysToSnakeCase(productAnalyticsConfig?.metadata || {}),
|
|
63
|
-
[productAnalyticsConfig?.metadata]
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
const publishEvent = useCallback(
|
|
67
|
-
(name: AnalyticsEventName, meta: EventMetadata = {}): Promise<Response[]> => {
|
|
68
|
-
if (!productAnalyticsConfig) {
|
|
69
|
-
if (__DEV__) {
|
|
70
|
-
console.warn('Product Analytics not available')
|
|
71
|
-
}
|
|
72
|
-
return Promise.resolve([])
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const mergedMeta = { ...snakeCasedBaseMeta, ...meta } as EventMetadata
|
|
76
|
-
|
|
77
|
-
return sendEvents([{ name, meta: mergedMeta }], productAnalyticsConfig)
|
|
78
|
-
},
|
|
79
|
-
[productAnalyticsConfig, snakeCasedBaseMeta]
|
|
80
|
-
)
|
|
103
|
+
const { session } = useChatContext()
|
|
104
|
+
const queryClient = useQueryClient()
|
|
81
105
|
|
|
82
106
|
const publishEvents = useCallback(
|
|
83
107
|
(events: Array<{ name: AnalyticsEventName; meta?: EventMetadata }>): Promise<Response[]> => {
|
|
84
|
-
if (!
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
if (!session.isAuthenticated) return Promise.resolve([])
|
|
109
|
+
|
|
110
|
+
return fetchProductAnalyticsConfig(queryClient, session)
|
|
111
|
+
.then(config => {
|
|
112
|
+
const baseMeta = keysToSnakeCase(config.metadata || {})
|
|
113
|
+
const eventsWithMeta = events.map(event => ({
|
|
114
|
+
name: event.name,
|
|
115
|
+
meta: { ...baseMeta, ...event.meta } as EventMetadata,
|
|
116
|
+
}))
|
|
117
|
+
|
|
118
|
+
return sendEvents(eventsWithMeta, config)
|
|
119
|
+
})
|
|
120
|
+
.catch(error => {
|
|
121
|
+
reportAnalyticsError(error, 'prepare')
|
|
122
|
+
return [] as Response[]
|
|
123
|
+
})
|
|
97
124
|
},
|
|
98
|
-
[
|
|
125
|
+
[queryClient, session]
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
const publishEvent = useCallback(
|
|
129
|
+
(name: AnalyticsEventName, meta: EventMetadata = {}): Promise<Response[]> =>
|
|
130
|
+
publishEvents([{ name, meta }]),
|
|
131
|
+
[publishEvents]
|
|
99
132
|
)
|
|
100
133
|
|
|
101
134
|
return { publishEvent, publishEvents }
|
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
|
+
})
|