@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
|
@@ -45,6 +45,7 @@ export const ListHeaderComponent = () => {
|
|
|
45
45
|
group_source_app_name = '',
|
|
46
46
|
show_direct_messages,
|
|
47
47
|
show_archived,
|
|
48
|
+
show_hidden,
|
|
48
49
|
} = route.params || {}
|
|
49
50
|
const currentPersonCache = useCurrentPersonCache()
|
|
50
51
|
const { markAllRead, isPending } = useMarkAllRead()
|
|
@@ -55,7 +56,7 @@ export const ListHeaderComponent = () => {
|
|
|
55
56
|
)
|
|
56
57
|
|
|
57
58
|
const active: FilterTypes = useMemo(() => {
|
|
58
|
-
if (chat_group_graph_id || show_archived) {
|
|
59
|
+
if (chat_group_graph_id || show_archived || show_hidden) {
|
|
59
60
|
return FilterTypes.More
|
|
60
61
|
} else if (/groups/i.test(group_source_app_name)) {
|
|
61
62
|
return FilterTypes.Groups
|
|
@@ -66,7 +67,7 @@ export const ListHeaderComponent = () => {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
return FilterTypes.All
|
|
69
|
-
}, [chat_group_graph_id, group_source_app_name, show_direct_messages, show_archived])
|
|
70
|
+
}, [chat_group_graph_id, group_source_app_name, show_direct_messages, show_archived, show_hidden])
|
|
70
71
|
|
|
71
72
|
const handleNewConversationNavigation = useCallback(() => {
|
|
72
73
|
if (newConversationFromFilter || entryMode === 'select_type') {
|
|
@@ -106,6 +107,7 @@ export const ListHeaderComponent = () => {
|
|
|
106
107
|
group_source_app_name: undefined,
|
|
107
108
|
show_direct_messages: undefined,
|
|
108
109
|
show_archived: undefined,
|
|
110
|
+
show_hidden: undefined,
|
|
109
111
|
...params,
|
|
110
112
|
})
|
|
111
113
|
},
|
|
@@ -122,8 +124,16 @@ export const ListHeaderComponent = () => {
|
|
|
122
124
|
group_source_app_name,
|
|
123
125
|
show_direct_messages,
|
|
124
126
|
show_archived,
|
|
127
|
+
show_hidden,
|
|
125
128
|
})
|
|
126
|
-
}, [
|
|
129
|
+
}, [
|
|
130
|
+
navigation,
|
|
131
|
+
chat_group_graph_id,
|
|
132
|
+
group_source_app_name,
|
|
133
|
+
show_direct_messages,
|
|
134
|
+
show_archived,
|
|
135
|
+
show_hidden,
|
|
136
|
+
])
|
|
127
137
|
|
|
128
138
|
const handleMarkAllRead = useCallback(() => {
|
|
129
139
|
currentPersonCache.update({ unreadCount: 0 })
|
|
@@ -164,7 +174,7 @@ export const ListHeaderComponent = () => {
|
|
|
164
174
|
<Heading numberOfLines={1} variant="h2">
|
|
165
175
|
Conversations
|
|
166
176
|
</Heading>
|
|
167
|
-
{!show_archived && (
|
|
177
|
+
{!show_archived && !show_hidden && (
|
|
168
178
|
<TextButton
|
|
169
179
|
onPress={alertMarkAllRead}
|
|
170
180
|
disabled={isPending}
|
|
@@ -45,6 +45,7 @@ export const SearchListHeaderComponent = () => {
|
|
|
45
45
|
group_source_app_name = '',
|
|
46
46
|
show_direct_messages,
|
|
47
47
|
show_archived,
|
|
48
|
+
show_hidden,
|
|
48
49
|
} = route.params || {}
|
|
49
50
|
const currentPersonCache = useCurrentPersonCache()
|
|
50
51
|
const { markAllRead, isPending } = useMarkAllRead()
|
|
@@ -55,7 +56,7 @@ export const SearchListHeaderComponent = () => {
|
|
|
55
56
|
)
|
|
56
57
|
|
|
57
58
|
const active: FilterTypes = useMemo(() => {
|
|
58
|
-
if (chat_group_graph_id || show_archived) {
|
|
59
|
+
if (chat_group_graph_id || show_archived || show_hidden) {
|
|
59
60
|
return FilterTypes.More
|
|
60
61
|
} else if (/groups/i.test(group_source_app_name)) {
|
|
61
62
|
return FilterTypes.Groups
|
|
@@ -66,7 +67,7 @@ export const SearchListHeaderComponent = () => {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
return FilterTypes.All
|
|
69
|
-
}, [chat_group_graph_id, group_source_app_name, show_direct_messages, show_archived])
|
|
70
|
+
}, [chat_group_graph_id, group_source_app_name, show_direct_messages, show_archived, show_hidden])
|
|
70
71
|
|
|
71
72
|
const handleNewConversationNavigation = useCallback(() => {
|
|
72
73
|
if (newConversationFromFilter || entryMode === 'select_type') {
|
|
@@ -106,6 +107,7 @@ export const SearchListHeaderComponent = () => {
|
|
|
106
107
|
group_source_app_name: undefined,
|
|
107
108
|
show_direct_messages: undefined,
|
|
108
109
|
show_archived: undefined,
|
|
110
|
+
show_hidden: undefined,
|
|
109
111
|
...params,
|
|
110
112
|
})
|
|
111
113
|
},
|
|
@@ -126,8 +128,16 @@ export const SearchListHeaderComponent = () => {
|
|
|
126
128
|
group_source_app_name,
|
|
127
129
|
show_direct_messages,
|
|
128
130
|
show_archived,
|
|
131
|
+
show_hidden,
|
|
129
132
|
})
|
|
130
|
-
}, [
|
|
133
|
+
}, [
|
|
134
|
+
navigation,
|
|
135
|
+
chat_group_graph_id,
|
|
136
|
+
group_source_app_name,
|
|
137
|
+
show_direct_messages,
|
|
138
|
+
show_archived,
|
|
139
|
+
show_hidden,
|
|
140
|
+
])
|
|
131
141
|
|
|
132
142
|
const handleMarkAllRead = useCallback(() => {
|
|
133
143
|
currentPersonCache.update({ unreadCount: 0 })
|
|
@@ -168,7 +178,7 @@ export const SearchListHeaderComponent = () => {
|
|
|
168
178
|
<Heading numberOfLines={1} variant="h2">
|
|
169
179
|
Conversations
|
|
170
180
|
</Heading>
|
|
171
|
-
{!show_archived && (
|
|
181
|
+
{!show_archived && !show_hidden && (
|
|
172
182
|
<TextButton
|
|
173
183
|
onPress={alertMarkAllRead}
|
|
174
184
|
disabled={isPending}
|
|
@@ -2,6 +2,7 @@ import { StaticScreenProps } from '@react-navigation/native'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Conversations } from '../../components'
|
|
5
|
+
import { Toast } from '../../components/display/toast'
|
|
5
6
|
import { ConversationsContextProvider } from '../../contexts/conversations_context'
|
|
6
7
|
import { useFilterDropdownEnabled } from '../../hooks/use_filter_dropdown_enabled'
|
|
7
8
|
import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/use_product_analytics'
|
|
@@ -18,6 +19,7 @@ export type ConversationsScreenProps = StaticScreenProps<{
|
|
|
18
19
|
group_source_app_name?: AppName
|
|
19
20
|
show_direct_messages?: boolean
|
|
20
21
|
show_archived?: boolean
|
|
22
|
+
show_hidden?: boolean
|
|
21
23
|
show_unread?: boolean
|
|
22
24
|
}>
|
|
23
25
|
|
|
@@ -32,6 +34,7 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
|
32
34
|
<ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
|
|
33
35
|
<Conversations ListHeaderComponent={Header} />
|
|
34
36
|
</ConversationsContextProvider>
|
|
37
|
+
<Toast />
|
|
35
38
|
</View>
|
|
36
39
|
)
|
|
37
40
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import { useCallback, useMemo } from 'react'
|
|
3
|
-
import {
|
|
3
|
+
import { ScrollView, StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Heading, PressableRow, Text, TextInlineButton } from '../components'
|
|
5
5
|
import { useApiGet, useTheme } from '../hooks'
|
|
6
6
|
import { useAppName } from '../hooks/use_app_name'
|
|
7
7
|
import { useOrganization } from '../hooks/use_organization'
|
|
8
8
|
import { ResourceObject } from '../types'
|
|
9
|
-
import {
|
|
9
|
+
import { Linking } from '../utils'
|
|
10
10
|
|
|
11
11
|
type GetHelpScreenRouteProps = {
|
|
12
12
|
type?: 'chat' | 'general'
|
|
@@ -117,27 +117,13 @@ const ContactRow = ({ email, phone }: { email?: string; phone?: string }) => {
|
|
|
117
117
|
export function sendEmail(email: string) {
|
|
118
118
|
if (!email) return
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Linking.openURL(url).catch(() => {
|
|
123
|
-
Alert.alert('Oops', `Unable to open: ${email}`, [
|
|
124
|
-
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(email) },
|
|
125
|
-
{ text: 'OK' },
|
|
126
|
-
])
|
|
127
|
-
})
|
|
120
|
+
Linking.openURL(encodeURI(`mailto:${email}`))
|
|
128
121
|
}
|
|
129
122
|
|
|
130
123
|
export function placePhoneCall(phoneNumber: string) {
|
|
131
124
|
if (!phoneNumber) return
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
Linking.openURL(url).catch(() => {
|
|
136
|
-
Alert.alert('Oops', `Unable to open: ${phoneNumber}`, [
|
|
137
|
-
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(phoneNumber) },
|
|
138
|
-
{ text: 'OK' },
|
|
139
|
-
])
|
|
140
|
-
})
|
|
126
|
+
Linking.openURL(encodeURI(`tel:${phoneNumber}`))
|
|
141
127
|
}
|
|
142
128
|
|
|
143
129
|
const useStyles = () => {
|
package/src/screens/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './preferred_app_selection_screen'
|
|
|
8
8
|
export * from './group_notification_settings_screen'
|
|
9
9
|
export * from './conversation_filter_recipients/conversation_filter_recipients_screen'
|
|
10
10
|
export * from './message_actions_screen'
|
|
11
|
+
export * from './conversation_actions_screen'
|
|
11
12
|
export * from './message_report_screen'
|
|
12
13
|
export * from './send_giphy_screen'
|
|
13
14
|
export * from './not_found'
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
MessageDeletedEvent,
|
|
11
11
|
MessageUpdatedEvent,
|
|
12
12
|
} from './message_events'
|
|
13
|
+
import type { StreamUserEventType, StreamUserUpdatedEvent } from './person_events'
|
|
13
14
|
import type { ReactionCreatedEvent, ReactionDeletedEvent } from './reaction_events'
|
|
14
15
|
import type { TypingBroadcastEvent } from './typing_events'
|
|
15
16
|
|
|
@@ -22,6 +23,7 @@ export type JoltMessageEvent = MessageCreatedEvent | MessageUpdatedEvent | Messa
|
|
|
22
23
|
export type JoltReactionEvent = ReactionCreatedEvent | ReactionDeletedEvent
|
|
23
24
|
export type JoltTypingEvent = TypingBroadcastEvent
|
|
24
25
|
export type JoltAttachmentEvent = AttachmentFlaggedEvent
|
|
26
|
+
export type { StreamUserEventType, StreamUserUpdatedEvent }
|
|
25
27
|
|
|
26
28
|
export type CustomJoltEvent =
|
|
27
29
|
| JoltConversationEvent
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
|
|
2
|
+
|
|
3
|
+
export type StreamUserEventType =
|
|
4
|
+
| 'message.created'
|
|
5
|
+
| 'conversation.mark_read'
|
|
6
|
+
| 'conversation.mark_unread'
|
|
7
|
+
| 'conversation.destroy'
|
|
8
|
+
| 'person.mark_all_read'
|
|
9
|
+
| 'app_grant.synced'
|
|
10
|
+
|
|
11
|
+
export interface StreamUserUpdatedEvent extends CustomMessage {
|
|
12
|
+
event: 'STREAM_USER_UPDATED'
|
|
13
|
+
data: {
|
|
14
|
+
data: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -5,6 +5,7 @@ export type NotificationLevelDescription = string
|
|
|
5
5
|
|
|
6
6
|
export interface ConversationMembershipResource extends ResourceObject {
|
|
7
7
|
type: 'ConversationMembership'
|
|
8
|
+
hidden?: boolean
|
|
8
9
|
lastReadMessageSortKey: string
|
|
9
10
|
muted: boolean
|
|
10
11
|
notificationLevel: NotificationLevelValue
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
3
|
+
import {
|
|
4
|
+
cancelThrottledRefreshes,
|
|
5
|
+
REFRESH_THROTTLE_MS,
|
|
6
|
+
throttledRefresh,
|
|
7
|
+
} from '../throttled_refresh'
|
|
8
|
+
|
|
9
|
+
const key = ['/me/conversations/7']
|
|
10
|
+
let queryClient: QueryClient
|
|
11
|
+
let refresh: jest.Mock
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.useFakeTimers()
|
|
15
|
+
queryClient = buildTestQueryClient()
|
|
16
|
+
refresh = jest.fn()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
cancelThrottledRefreshes(queryClient)
|
|
21
|
+
jest.useRealTimers()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const fire = (events = 1) => {
|
|
25
|
+
for (let i = 0; i < events; i++) throttledRefresh(queryClient, key, {}, refresh)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('throttledRefresh', () => {
|
|
29
|
+
it('runs a lone event immediately and never again', () => {
|
|
30
|
+
fire()
|
|
31
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
32
|
+
|
|
33
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS * 3)
|
|
34
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('collapses a burst into one immediate run and one when the window ends', () => {
|
|
38
|
+
fire(50)
|
|
39
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
40
|
+
|
|
41
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS - 1)
|
|
42
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
43
|
+
|
|
44
|
+
jest.advanceTimersByTime(1)
|
|
45
|
+
expect(refresh).toHaveBeenCalledTimes(2)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('gives an event inside the window opened by a trailing run its own trailing run', () => {
|
|
49
|
+
fire()
|
|
50
|
+
jest.advanceTimersByTime(1000)
|
|
51
|
+
fire()
|
|
52
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS - 1000)
|
|
53
|
+
expect(refresh).toHaveBeenCalledTimes(2)
|
|
54
|
+
|
|
55
|
+
jest.advanceTimersByTime(500)
|
|
56
|
+
fire()
|
|
57
|
+
expect(refresh).toHaveBeenCalledTimes(2)
|
|
58
|
+
|
|
59
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS)
|
|
60
|
+
expect(refresh).toHaveBeenCalledTimes(3)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('counts the same event delivered to several consumers once', () => {
|
|
64
|
+
const event = {}
|
|
65
|
+
const other = jest.fn()
|
|
66
|
+
throttledRefresh(queryClient, key, event, refresh)
|
|
67
|
+
throttledRefresh(queryClient, [...key], event, other)
|
|
68
|
+
|
|
69
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS * 2)
|
|
70
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
71
|
+
expect(other).not.toHaveBeenCalled()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('shares one window across consumers using the same client and key', () => {
|
|
75
|
+
const other = jest.fn()
|
|
76
|
+
throttledRefresh(queryClient, key, {}, refresh)
|
|
77
|
+
throttledRefresh(queryClient, [...key], {}, other)
|
|
78
|
+
|
|
79
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
80
|
+
expect(other).not.toHaveBeenCalled()
|
|
81
|
+
|
|
82
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS)
|
|
83
|
+
expect(other).toHaveBeenCalledTimes(1)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('keeps separate windows per key and per query client', () => {
|
|
87
|
+
throttledRefresh(queryClient, key, {}, refresh)
|
|
88
|
+
throttledRefresh(queryClient, ['/me'], {}, refresh)
|
|
89
|
+
throttledRefresh(buildTestQueryClient(), key, {}, refresh)
|
|
90
|
+
|
|
91
|
+
expect(refresh).toHaveBeenCalledTimes(3)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('drops pending trailing runs when cancelled', () => {
|
|
95
|
+
fire(2)
|
|
96
|
+
cancelThrottledRefreshes(queryClient)
|
|
97
|
+
|
|
98
|
+
jest.advanceTimersByTime(REFRESH_THROTTLE_MS)
|
|
99
|
+
expect(refresh).toHaveBeenCalledTimes(1)
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { StreamUserUpdatedEvent } from '../../../types/jolt_events'
|
|
2
|
+
import { parseStreamUserEventType } from '../parse_stream_user_event_type'
|
|
3
|
+
|
|
4
|
+
const event = (data: unknown) =>
|
|
5
|
+
({
|
|
6
|
+
event: 'STREAM_USER_UPDATED',
|
|
7
|
+
channel: 'chat.people.1',
|
|
8
|
+
data: { data },
|
|
9
|
+
}) as StreamUserUpdatedEvent
|
|
10
|
+
|
|
11
|
+
describe('parseStreamUserEventType', () => {
|
|
12
|
+
it('reads the event type out of the JSON payload', () => {
|
|
13
|
+
expect(parseStreamUserEventType(event('{"event_type":"message.created"}'))).toBe(
|
|
14
|
+
'message.created'
|
|
15
|
+
)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('treats an empty payload as missing', () => {
|
|
19
|
+
expect(parseStreamUserEventType(event('{}'))).toBeUndefined()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('treats a payload that fails to parse as missing', () => {
|
|
23
|
+
expect(parseStreamUserEventType(event('not json'))).toBeUndefined()
|
|
24
|
+
expect(parseStreamUserEventType(event(undefined))).toBeUndefined()
|
|
25
|
+
expect(parseStreamUserEventType(event('null'))).toBeUndefined()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StreamUserEventType, StreamUserUpdatedEvent } from '../../types/jolt_events'
|
|
2
|
+
|
|
3
|
+
interface StreamUserEventData {
|
|
4
|
+
event_type?: StreamUserEventType
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const parseStreamUserEventType = (
|
|
8
|
+
event: StreamUserUpdatedEvent
|
|
9
|
+
): StreamUserEventType | undefined => {
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(event.data.data) as StreamUserEventData | null
|
|
12
|
+
return parsed?.event_type
|
|
13
|
+
} catch {
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,12 +1,68 @@
|
|
|
1
|
+
import { Alert } from 'react-native'
|
|
2
|
+
import { Clipboard, Log } from '../configuration'
|
|
1
3
|
import { LinkingAdapter } from '../linking'
|
|
2
4
|
|
|
5
|
+
type AlertButton = { text?: string; onPress?: () => void }
|
|
6
|
+
|
|
7
|
+
const pressButton = (text: string) => {
|
|
8
|
+
const buttons = (Alert.alert as jest.Mock).mock.calls[0][2] as AlertButton[]
|
|
9
|
+
buttons.find(button => button.text === text)?.onPress?.()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const buildAdapter = (openURL: jest.Mock) =>
|
|
13
|
+
new LinkingAdapter({ openURL, canOpenURL: async () => true })
|
|
14
|
+
|
|
3
15
|
describe('LinkingAdapter', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const adapter = new LinkingAdapter({ openURL, canOpenURL: async () => true })
|
|
16
|
+
let setStringAsync: jest.SpyInstance
|
|
17
|
+
let reportError: jest.SpyInstance
|
|
7
18
|
|
|
8
|
-
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
21
|
+
setStringAsync = jest.spyOn(Clipboard, 'setStringAsync').mockResolvedValue()
|
|
22
|
+
reportError = jest.spyOn(Log, 'reportError').mockImplementation(() => {})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
jest.restoreAllMocks()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('forwards the url and options to the host', async () => {
|
|
30
|
+
const openURL = jest.fn().mockResolvedValue(true)
|
|
31
|
+
|
|
32
|
+
await buildAdapter(openURL).openURL('https://example.com', { forceOpenInBrowser: true })
|
|
9
33
|
|
|
10
34
|
expect(openURL).toHaveBeenCalledWith('https://example.com', { forceOpenInBrowser: true })
|
|
35
|
+
expect(Alert.alert).not.toHaveBeenCalled()
|
|
36
|
+
expect(reportError).not.toHaveBeenCalled()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('reports a failed web link instead of alerting', async () => {
|
|
40
|
+
const error = new Error('Unable to open URL')
|
|
41
|
+
const openURL = jest.fn().mockRejectedValue(error)
|
|
42
|
+
|
|
43
|
+
await buildAdapter(openURL).openURL('https://youtu.be/abc')
|
|
44
|
+
|
|
45
|
+
expect(reportError).toHaveBeenCalledWith(error, { extra: { url: 'https://youtu.be/abc' } })
|
|
46
|
+
expect(Alert.alert).not.toHaveBeenCalled()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it.each([
|
|
50
|
+
['mailto', 'mailto:admin@example.com', 'admin@example.com'],
|
|
51
|
+
['encoded mailto', encodeURI('mailto:first last@example.com'), 'first last@example.com'],
|
|
52
|
+
['tel', 'tel:+1 (555) 555-0100', '+1 (555) 555-0100'],
|
|
53
|
+
])('alerts and offers to copy the bare address for a %s link', async (_name, url, address) => {
|
|
54
|
+
const openURL = jest.fn().mockRejectedValue(new Error('No Activity found'))
|
|
55
|
+
|
|
56
|
+
await buildAdapter(openURL).openURL(url)
|
|
57
|
+
|
|
58
|
+
expect(Alert.alert).toHaveBeenCalledWith(
|
|
59
|
+
'Oops',
|
|
60
|
+
`Unable to open: ${address}`,
|
|
61
|
+
expect.arrayContaining([expect.objectContaining({ text: 'Copy to clipboard' })])
|
|
62
|
+
)
|
|
63
|
+
expect(reportError).not.toHaveBeenCalled()
|
|
64
|
+
|
|
65
|
+
pressButton('Copy to clipboard')
|
|
66
|
+
expect(setStringAsync).toHaveBeenCalledWith(address)
|
|
11
67
|
})
|
|
12
68
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Linking } from 'react-native'
|
|
1
|
+
import { Alert, Linking } from 'react-native'
|
|
2
|
+
import { Clipboard, Log } from './configuration'
|
|
2
3
|
|
|
3
4
|
export type LinkingOpenURLOptions = {
|
|
4
5
|
forceOpenInBrowser?: boolean
|
|
@@ -9,12 +10,59 @@ type LinkingMethods = {
|
|
|
9
10
|
canOpenURL: Linking['canOpenURL']
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
const CONTACT_SCHEME = /^(mailto|tel):/i
|
|
14
|
+
|
|
12
15
|
export class LinkingAdapter {
|
|
13
16
|
openURL: LinkingMethods['openURL']
|
|
14
17
|
canOpenURL: LinkingMethods['canOpenURL']
|
|
15
18
|
|
|
16
19
|
constructor(methods: LinkingMethods) {
|
|
17
|
-
|
|
20
|
+
const openURL = methods.openURL.bind(Linking)
|
|
21
|
+
|
|
22
|
+
this.openURL = async (...args) => {
|
|
23
|
+
try {
|
|
24
|
+
await openURL(...args)
|
|
25
|
+
} catch (error) {
|
|
26
|
+
handleOpenFailure(args[0], error)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
this.canOpenURL = methods.canOpenURL.bind(Linking)
|
|
19
30
|
}
|
|
20
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* mailto: and tel: links fail for ordinary reasons (no mail app, no phone),
|
|
35
|
+
* so the user gets an alert offering to copy the address. Any other failure
|
|
36
|
+
* is reported through the Log adapter so it stays visible as a handled error.
|
|
37
|
+
*/
|
|
38
|
+
function handleOpenFailure(url: string, error: unknown) {
|
|
39
|
+
if (CONTACT_SCHEME.test(url)) {
|
|
40
|
+
alertUnableToOpen(url)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Log.reportError(toError(error, url), { extra: { url } })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function alertUnableToOpen(url: string) {
|
|
48
|
+
const address = readableAddress(url)
|
|
49
|
+
|
|
50
|
+
Alert.alert('Oops', `Unable to open: ${address}`, [
|
|
51
|
+
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(address) },
|
|
52
|
+
{ text: 'OK' },
|
|
53
|
+
])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readableAddress(url: string) {
|
|
57
|
+
const address = url.replace(CONTACT_SCHEME, '')
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
return decodeURIComponent(address)
|
|
61
|
+
} catch {
|
|
62
|
+
return address
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function toError(error: unknown, url: string) {
|
|
67
|
+
return error instanceof Error ? error : new Error(`Unable to open URL: ${url}`)
|
|
68
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { currentPersonQueryKey } from '../hooks/use_current_person'
|
|
3
|
+
import { ApiResource, CurrentPersonResource } from '../types'
|
|
4
|
+
import { ProductAnalyticsConfig } from '../types/product_analytics'
|
|
5
|
+
import { Client } from './client'
|
|
6
|
+
import { Storage } from './native_adapters'
|
|
7
|
+
import { Session } from './session'
|
|
8
|
+
import { ONE_HOUR, toMs } from './time'
|
|
9
|
+
import { Uri } from './uri'
|
|
10
|
+
|
|
11
|
+
interface ProductAnalyticsTokenResponse {
|
|
12
|
+
type: 'ProductAnalyticsToken'
|
|
13
|
+
id: string
|
|
14
|
+
url: string
|
|
15
|
+
metadata: Record<string, unknown>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface StoredProductAnalyticsConfig extends ProductAnalyticsConfig {
|
|
19
|
+
expiresAt: number
|
|
20
|
+
personId: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const TOKEN_EXPIRY_TIME = toMs(7 * 24, 'hours')
|
|
24
|
+
const EXPIRY_MARGIN = ONE_HOUR
|
|
25
|
+
|
|
26
|
+
// One slot per environment, tagged with the person it belongs to. Keying on
|
|
27
|
+
// session.id would miss on every access-token refresh and leave orphaned entries.
|
|
28
|
+
export const productAnalyticsStorageKey = (session: Session) =>
|
|
29
|
+
`product-analytics-token:${session.env}`
|
|
30
|
+
|
|
31
|
+
export const productAnalyticsQueryKey = (session: Session) => [
|
|
32
|
+
'product-analytics-token',
|
|
33
|
+
session.env,
|
|
34
|
+
session.id,
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
const renewalTime = (config: StoredProductAnalyticsConfig) => config.expiresAt - EXPIRY_MARGIN
|
|
38
|
+
|
|
39
|
+
const isStoredConfig = (value: unknown): value is StoredProductAnalyticsConfig =>
|
|
40
|
+
typeof value === 'object' &&
|
|
41
|
+
value !== null &&
|
|
42
|
+
typeof (value as StoredProductAnalyticsConfig).token === 'string' &&
|
|
43
|
+
typeof (value as StoredProductAnalyticsConfig).endpoint === 'string' &&
|
|
44
|
+
typeof (value as StoredProductAnalyticsConfig).expiresAt === 'number' &&
|
|
45
|
+
typeof (value as StoredProductAnalyticsConfig).personId === 'string'
|
|
46
|
+
|
|
47
|
+
async function readStoredConfig(key: string): Promise<StoredProductAnalyticsConfig | undefined> {
|
|
48
|
+
try {
|
|
49
|
+
const raw = await Storage.getItem(key)
|
|
50
|
+
if (!raw) return undefined
|
|
51
|
+
|
|
52
|
+
const parsed: unknown = JSON.parse(raw)
|
|
53
|
+
return isStoredConfig(parsed) ? parsed : undefined
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function writeStoredConfig(key: string, config: StoredProductAnalyticsConfig): Promise<void> {
|
|
60
|
+
return Storage.setItem(key, JSON.stringify(config)).catch(() => {})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function requestConfig(session: Session, personId: string): Promise<StoredProductAnalyticsConfig> {
|
|
64
|
+
const uri = new Uri({ session })
|
|
65
|
+
const client = new Client({
|
|
66
|
+
root: uri.api('/chat/v2'),
|
|
67
|
+
defaultHeaders: uri.headers,
|
|
68
|
+
version: '2018-11-01',
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return client
|
|
72
|
+
.post<ApiResource<ProductAnalyticsTokenResponse>>({
|
|
73
|
+
url: '/me/product_analytics_authorize',
|
|
74
|
+
data: { data: { type: 'ProductAnalyticsToken', attributes: {} } },
|
|
75
|
+
})
|
|
76
|
+
.then(res => ({
|
|
77
|
+
token: res.data.id,
|
|
78
|
+
endpoint: res.data.url,
|
|
79
|
+
metadata: res.data.metadata,
|
|
80
|
+
expiresAt: Date.now() + TOKEN_EXPIRY_TIME,
|
|
81
|
+
personId,
|
|
82
|
+
}))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The chat screens that publish events already load /me, and the package's query
|
|
86
|
+
// client is cleared whenever the access token changes, so this is normally a cache hit.
|
|
87
|
+
async function currentPersonId(queryClient: QueryClient): Promise<string> {
|
|
88
|
+
const { data } = await queryClient.ensureQueryData<ApiResource<CurrentPersonResource>>({
|
|
89
|
+
queryKey: currentPersonQueryKey,
|
|
90
|
+
})
|
|
91
|
+
return String(data.id)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function loadConfig(
|
|
95
|
+
queryClient: QueryClient,
|
|
96
|
+
session: Session
|
|
97
|
+
): Promise<StoredProductAnalyticsConfig> {
|
|
98
|
+
const personId = await currentPersonId(queryClient)
|
|
99
|
+
const key = productAnalyticsStorageKey(session)
|
|
100
|
+
const stored = await readStoredConfig(key)
|
|
101
|
+
if (stored && stored.personId === personId && renewalTime(stored) > Date.now()) return stored
|
|
102
|
+
|
|
103
|
+
const config = await requestConfig(session, personId)
|
|
104
|
+
await writeStoredConfig(key, config)
|
|
105
|
+
return config
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function fetchProductAnalyticsConfig(
|
|
109
|
+
queryClient: QueryClient,
|
|
110
|
+
session: Session
|
|
111
|
+
): Promise<StoredProductAnalyticsConfig> {
|
|
112
|
+
return queryClient.fetchQuery({
|
|
113
|
+
queryKey: productAnalyticsQueryKey(session),
|
|
114
|
+
queryFn: () => loadConfig(queryClient, session),
|
|
115
|
+
staleTime: ({ state }) =>
|
|
116
|
+
state.data ? Math.max(0, renewalTime(state.data) - state.dataUpdatedAt) : 0,
|
|
117
|
+
gcTime: TOKEN_EXPIRY_TIME,
|
|
118
|
+
retry: false,
|
|
119
|
+
})
|
|
120
|
+
}
|