@planningcenter/chat-react-native 4.8.0-rc.0 → 4.8.0-rc.10
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/bulk_conversation_actions_bar.d.ts +2 -0
- package/build/components/conversations/bulk_conversation_actions_bar.d.ts.map +1 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js +215 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
- package/build/components/conversations/conversation_actions.d.ts +2 -1
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +173 -130
- 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 +168 -110
- 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 +50 -48
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/checkbox.d.ts +8 -0
- package/build/components/display/checkbox.d.ts.map +1 -0
- package/build/components/display/checkbox.js +87 -0
- package/build/components/display/checkbox.js.map +1 -0
- package/build/components/display/icon.d.ts +3 -1
- package/build/components/display/icon.d.ts.map +1 -1
- package/build/components/display/icon.js +2 -0
- package/build/components/display/icon.js.map +1 -1
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.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 +5 -0
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +121 -32
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/contexts/session_context.d.ts +0 -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 +27 -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_bulk_conversation_actions.d.ts +8 -0
- package/build/hooks/use_bulk_conversation_actions.d.ts.map +1 -0
- package/build/hooks/use_bulk_conversation_actions.js +309 -0
- package/build/hooks/use_bulk_conversation_actions.js.map +1 -0
- 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 +15 -5
- package/build/hooks/use_conversations_cache.d.ts.map +1 -1
- package/build/hooks/use_conversations_cache.js +170 -122
- 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 +1 -0
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -0
- package/build/hooks/use_features.js.map +1 -1
- 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_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/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -7
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_actions_screen.d.ts +2 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -1
- package/build/screens/conversation_actions_screen.js +380 -46
- package/build/screens/conversation_actions_screen.js.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
- package/build/screens/conversation_filter_recipients/components/checkbox_row.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/conversations_screen.d.ts +5 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +156 -31
- 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/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/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/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/package.json +2 -2
- package/src/__tests__/contexts/session_context.tsx +19 -39
- package/src/__tests__/hooks/useTheme.tsx +0 -7
- package/src/__tests__/hooks/use_async_storage.test.tsx +1 -87
- package/src/__tests__/hooks/use_attachment_uploader.test.tsx +0 -11
- package/src/__tests__/hooks/use_font_scale.test.ts +0 -25
- package/src/__tests__/hooks/use_group_chat_conversation_payload.test.tsx +31 -0
- package/src/__tests__/utils/cache/page_mutations.ts +3 -68
- package/src/__tests__/utils/client.ts +6 -15
- package/src/__tests__/utils/native_adapters/configuration.ts +15 -50
- package/src/__tests__/utils/parse_simple_markdown.ts +0 -6
- package/src/__tests__/utils/session.ts +0 -11
- package/src/__tests__/utils/theme.ts +0 -17
- package/src/components/conversations/__tests__/bulk_conversation_actions_bar.test.tsx +95 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +35 -3
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
- package/src/components/conversations/__tests__/conversations.test.tsx +4 -1
- package/src/components/conversations/bulk_conversation_actions_bar.tsx +140 -0
- package/src/components/conversations/conversation_actions.tsx +17 -9
- package/src/components/conversations/conversation_preview.tsx +20 -2
- package/src/components/conversations/conversations.tsx +2 -1
- package/src/components/display/__tests__/filter_dropdown.test.tsx +1 -19
- package/src/components/display/__tests__/icon_tile.test.tsx +24 -7
- package/src/components/display/checkbox.tsx +47 -0
- package/src/components/display/icon.tsx +3 -0
- package/src/components/display/index.ts +1 -0
- package/src/components/page/__tests__/component_error_boundary.test.tsx +0 -12
- package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
- package/src/contexts/api_provider.tsx +2 -0
- package/src/contexts/chat_context.tsx +2 -58
- package/src/contexts/conversations_context.tsx +69 -2
- package/src/contexts/session_context.tsx +3 -1
- package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +194 -0
- package/src/hooks/__tests__/use_bulk_conversation_actions.test.tsx +119 -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 +15 -3
- 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_bulk_conversation_actions.ts +173 -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 +33 -26
- package/src/hooks/use_conversations_jolt_events.ts +24 -10
- package/src/hooks/use_features.ts +1 -0
- package/src/hooks/use_groups_groups.ts +21 -16
- 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 -8
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +48 -6
- package/src/screens/__tests__/conversation_details_screen.test.tsx +0 -19
- package/src/screens/avatar_picker/__tests__/avatar_picker_state.test.ts +0 -14
- package/src/screens/conversation_actions_screen.tsx +145 -12
- package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
- package/src/screens/conversation_new/components/groups_form.tsx +11 -9
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +35 -9
- package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -8
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +0 -10
- package/src/screens/conversations/conversations_screen.tsx +67 -3
- package/src/screens/get_help_screen.tsx +4 -18
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +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/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__/attachment_kind.test.ts +0 -4
- package/src/utils/__tests__/convert_attachments_for_create.test.ts +0 -28
- package/src/utils/__tests__/is_input_editable.test.ts +1 -2
- package/src/utils/__tests__/message_text.test.ts +0 -5
- package/src/utils/__tests__/session_manager.test.ts +0 -83
- package/src/utils/__tests__/sha_256.test.ts +0 -34
- package/src/utils/__tests__/throttled_refresh.test.ts +101 -0
- package/src/utils/__tests__/uri.test.ts +51 -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/throttled_refresh.ts +62 -0
- package/src/__tests__/event-polyfill.test.ts +0 -313
- package/src/__tests__/index.tsx +0 -5
- package/src/__tests__/jest.ts +0 -11
- package/src/__tests__/utils/uri.ts +0 -65
- package/src/components/display/__tests__/version_footer.test.tsx +0 -48
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +0 -20
- package/src/utils/__tests__/membership_sync_info_text.test.ts +0 -15
|
@@ -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
|
+
})
|
|
@@ -24,3 +24,54 @@ describe('on a Protonova environment', () => {
|
|
|
24
24
|
)
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
|
+
|
|
28
|
+
describe('baseUrl', () => {
|
|
29
|
+
describe('planning center', () => {
|
|
30
|
+
it('should return the correct base URL for production', () => {
|
|
31
|
+
const uri = new Uri({
|
|
32
|
+
session: new Session({ env: 'production', type: 'OAuth' }),
|
|
33
|
+
})
|
|
34
|
+
expect(uri.baseUrl).toBe('https://api.planningcenteronline.com')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should return the correct base URL for staging', () => {
|
|
38
|
+
const uri = new Uri({
|
|
39
|
+
session: new Session({ env: 'staging', type: 'OAuth' }),
|
|
40
|
+
})
|
|
41
|
+
expect(uri.baseUrl).toBe('https://api-staging.planningcenteronline.com')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should return the correct base URL for development', () => {
|
|
45
|
+
const uri = new Uri({
|
|
46
|
+
session: new Session({ env: 'development', type: 'OAuth' }),
|
|
47
|
+
})
|
|
48
|
+
expect(uri.baseUrl).toBe('https://api.pco.test')
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('church center', () => {
|
|
53
|
+
it('should return the correct base URL for production', () => {
|
|
54
|
+
const uri = new Uri({
|
|
55
|
+
session: new Session({ env: 'production', type: 'ChurchCenterOauth' }),
|
|
56
|
+
graph: 'churchcenter',
|
|
57
|
+
})
|
|
58
|
+
expect(uri.baseUrl).toBe('https://api.churchcenter.com')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should return the correct base URL for staging', () => {
|
|
62
|
+
const uri = new Uri({
|
|
63
|
+
session: new Session({ env: 'staging', type: 'ChurchCenterOauth' }),
|
|
64
|
+
graph: 'churchcenter',
|
|
65
|
+
})
|
|
66
|
+
expect(uri.baseUrl).toBe('https://api.staging.churchcenter.com')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('should return the correct base URL for development', () => {
|
|
70
|
+
const uri = new Uri({
|
|
71
|
+
session: new Session({ env: 'development', type: 'ChurchCenterOauth' }),
|
|
72
|
+
graph: 'churchcenter',
|
|
73
|
+
})
|
|
74
|
+
expect(uri.baseUrl).toBe('https://api.churchcenter.test')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -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
|
})
|
|
@@ -9,6 +9,7 @@ import { LinkingAdapter } from './linking'
|
|
|
9
9
|
import { LogAdapter } from './log'
|
|
10
10
|
import { MenuAdapter } from './menu'
|
|
11
11
|
import { StorageAdapter } from './storage_adapter'
|
|
12
|
+
import { UpdatesAdapter } from './updates'
|
|
12
13
|
import { VideoAdapter } from './video'
|
|
13
14
|
|
|
14
15
|
type ChatConfigurations = {
|
|
@@ -21,6 +22,7 @@ type ChatConfigurations = {
|
|
|
21
22
|
linking?: LinkingAdapter
|
|
22
23
|
haptic?: HapticAdapter
|
|
23
24
|
menu?: MenuAdapter
|
|
25
|
+
updates?: UpdatesAdapter
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export class ChatAdapters {
|
|
@@ -34,6 +36,7 @@ export class ChatAdapters {
|
|
|
34
36
|
Linking = configurations.linking || new LinkingAdapter(RNLinking)
|
|
35
37
|
Haptic = configurations.haptic || new HapticAdapter()
|
|
36
38
|
Menu = configurations.menu || new MenuAdapter()
|
|
39
|
+
Updates = configurations.updates || new UpdatesAdapter()
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -87,6 +90,8 @@ export let Haptic: HapticAdapter = new HapticAdapter()
|
|
|
87
90
|
|
|
88
91
|
export let Menu: MenuAdapter = new MenuAdapter()
|
|
89
92
|
|
|
93
|
+
export let Updates: UpdatesAdapter = new UpdatesAdapter()
|
|
94
|
+
|
|
90
95
|
export let Storage = new StorageAdapter({
|
|
91
96
|
getItem: AsyncStorage.getItem,
|
|
92
97
|
setItem: AsyncStorage.setItem,
|
|
@@ -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,16 @@
|
|
|
1
|
+
import { noop } from 'lodash'
|
|
2
|
+
|
|
3
|
+
interface Updates {
|
|
4
|
+
useDownloadedUpdateId: () => string | undefined
|
|
5
|
+
restart: () => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class UpdatesAdapter {
|
|
9
|
+
useDownloadedUpdateId: () => string | undefined
|
|
10
|
+
restart: () => void
|
|
11
|
+
|
|
12
|
+
constructor(methods?: Updates) {
|
|
13
|
+
this.useDownloadedUpdateId = methods?.useDownloadedUpdateId ?? (() => undefined)
|
|
14
|
+
this.restart = methods?.restart ?? noop
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { hashKey, QueryClient, QueryKey } from '@tanstack/react-query'
|
|
2
|
+
import { DebouncedFuncLeading, throttle } from 'lodash'
|
|
3
|
+
|
|
4
|
+
export const REFRESH_THROTTLE_MS = 3000
|
|
5
|
+
|
|
6
|
+
type Refresh = () => unknown
|
|
7
|
+
|
|
8
|
+
interface ThrottledRefresh {
|
|
9
|
+
run: DebouncedFuncLeading<(refresh: Refresh) => void>
|
|
10
|
+
lastEvent?: object
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const refreshesByClient = new WeakMap<QueryClient, Map<string, ThrottledRefresh>>()
|
|
14
|
+
|
|
15
|
+
const refreshesFor = (queryClient: QueryClient) => {
|
|
16
|
+
const existing = refreshesByClient.get(queryClient)
|
|
17
|
+
if (existing) return existing
|
|
18
|
+
|
|
19
|
+
const refreshes = new Map<string, ThrottledRefresh>()
|
|
20
|
+
refreshesByClient.set(queryClient, refreshes)
|
|
21
|
+
return refreshes
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const throttledRefreshFor = (queryClient: QueryClient, key: QueryKey) => {
|
|
25
|
+
const refreshes = refreshesFor(queryClient)
|
|
26
|
+
const hashedKey = hashKey(key)
|
|
27
|
+
const existing = refreshes.get(hashedKey)
|
|
28
|
+
if (existing) return existing
|
|
29
|
+
|
|
30
|
+
const created: ThrottledRefresh = {
|
|
31
|
+
run: throttle(
|
|
32
|
+
(refresh: Refresh) => {
|
|
33
|
+
refresh()
|
|
34
|
+
},
|
|
35
|
+
REFRESH_THROTTLE_MS,
|
|
36
|
+
{ leading: true, trailing: true }
|
|
37
|
+
),
|
|
38
|
+
}
|
|
39
|
+
refreshes.set(hashedKey, created)
|
|
40
|
+
return created
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const throttledRefresh = (
|
|
44
|
+
queryClient: QueryClient,
|
|
45
|
+
key: QueryKey,
|
|
46
|
+
event: object,
|
|
47
|
+
refresh: Refresh
|
|
48
|
+
) => {
|
|
49
|
+
const throttled = throttledRefreshFor(queryClient, key)
|
|
50
|
+
if (throttled.lastEvent === event) return
|
|
51
|
+
|
|
52
|
+
throttled.lastEvent = event
|
|
53
|
+
throttled.run(refresh)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const cancelThrottledRefreshes = (queryClient: QueryClient) => {
|
|
57
|
+
const refreshes = refreshesByClient.get(queryClient)
|
|
58
|
+
if (!refreshes) return
|
|
59
|
+
|
|
60
|
+
refreshes.forEach(({ run }) => run.cancel())
|
|
61
|
+
refreshesByClient.delete(queryClient)
|
|
62
|
+
}
|