@planningcenter/chat-react-native 4.8.0-rc.1 → 4.8.0-rc.11
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/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/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 +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 +176 -33
- package/build/screens/conversations/conversations_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/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/theme.js +20 -21
- package/build/utils/theme.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/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__/app_update_banner.test.tsx +27 -0
- 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/app_update_banner.tsx +36 -0
- 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/components/primitive/banner_primitive.tsx +5 -1
- 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 +37 -12
- 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 +76 -4
- 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/configuration.ts +5 -0
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/updates.ts +16 -0
- package/src/utils/product_analytics_token.ts +120 -0
- package/src/utils/theme.ts +20 -21
- 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
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { StaticScreenProps } from '@react-navigation/native'
|
|
2
|
-
import React from 'react'
|
|
1
|
+
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
|
+
import React, { useEffect, useLayoutEffect, useRef } from 'react'
|
|
3
3
|
import { StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Conversations } from '../../components'
|
|
5
|
+
import { AppUpdateBanner } from '../../components/conversations/app_update_banner'
|
|
6
|
+
import { BulkConversationActionsBar } from '../../components/conversations/bulk_conversation_actions_bar'
|
|
7
|
+
import {
|
|
8
|
+
composeOptions,
|
|
9
|
+
withRightClose,
|
|
10
|
+
withRightText,
|
|
11
|
+
} from '../../components/display/platform_modal_header_buttons'
|
|
5
12
|
import { Toast } from '../../components/display/toast'
|
|
6
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
ConversationsContextProvider,
|
|
15
|
+
useConversationsContext,
|
|
16
|
+
} from '../../contexts/conversations_context'
|
|
7
17
|
import { useFilterDropdownEnabled } from '../../hooks/use_filter_dropdown_enabled'
|
|
8
18
|
import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/use_product_analytics'
|
|
9
19
|
import { useSearchEnabled } from '../../hooks/use_search_enabled'
|
|
@@ -21,8 +31,21 @@ export type ConversationsScreenProps = StaticScreenProps<{
|
|
|
21
31
|
show_archived?: boolean
|
|
22
32
|
show_hidden?: boolean
|
|
23
33
|
show_unread?: boolean
|
|
34
|
+
select_conversation_id?: number
|
|
24
35
|
}>
|
|
25
36
|
|
|
37
|
+
export const conversationsScreenOptions = ({
|
|
38
|
+
title,
|
|
39
|
+
onClose,
|
|
40
|
+
}: {
|
|
41
|
+
title?: string
|
|
42
|
+
onClose: () => void
|
|
43
|
+
}) =>
|
|
44
|
+
composeOptions(
|
|
45
|
+
{ headerTitle: title ?? 'Chat', headerBackVisible: false },
|
|
46
|
+
withRightClose({ onPress: onClose })
|
|
47
|
+
)
|
|
48
|
+
|
|
26
49
|
export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
27
50
|
const styles = useStyles()
|
|
28
51
|
const Header = useListHeaderComponent()
|
|
@@ -32,13 +55,62 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
|
32
55
|
return (
|
|
33
56
|
<View style={styles.container}>
|
|
34
57
|
<ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
|
|
35
|
-
<
|
|
58
|
+
<SelectModeHeader title={route.params?.title} />
|
|
59
|
+
<SelectModeRequest conversationId={route.params?.select_conversation_id} />
|
|
60
|
+
<Conversations
|
|
61
|
+
ListHeaderComponent={
|
|
62
|
+
<>
|
|
63
|
+
<Header />
|
|
64
|
+
<AppUpdateBanner />
|
|
65
|
+
</>
|
|
66
|
+
}
|
|
67
|
+
/>
|
|
68
|
+
<BulkConversationActionsBar />
|
|
36
69
|
</ConversationsContextProvider>
|
|
37
70
|
<Toast />
|
|
38
71
|
</View>
|
|
39
72
|
)
|
|
40
73
|
}
|
|
41
74
|
|
|
75
|
+
function SelectModeHeader({ title }: { title?: string }) {
|
|
76
|
+
const navigation = useNavigation()
|
|
77
|
+
const { selectMode, selectedIds, clearSelection } = useConversationsContext()
|
|
78
|
+
const hasEnteredSelectMode = useRef(false)
|
|
79
|
+
const selectedCount = selectedIds.length
|
|
80
|
+
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
if (selectMode) hasEnteredSelectMode.current = true
|
|
83
|
+
if (!hasEnteredSelectMode.current) return
|
|
84
|
+
|
|
85
|
+
navigation.setOptions(
|
|
86
|
+
selectMode
|
|
87
|
+
? composeOptions(
|
|
88
|
+
{
|
|
89
|
+
headerTitle: selectedCount > 0 ? `${selectedCount} selected` : 'Select conversations',
|
|
90
|
+
},
|
|
91
|
+
withRightText({ text: 'Cancel', onPress: clearSelection })
|
|
92
|
+
)
|
|
93
|
+
: conversationsScreenOptions({ title, onClose: navigation.goBack })
|
|
94
|
+
)
|
|
95
|
+
}, [navigation, selectMode, selectedCount, clearSelection, title])
|
|
96
|
+
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function SelectModeRequest({ conversationId }: { conversationId?: number }) {
|
|
101
|
+
const navigation = useNavigation()
|
|
102
|
+
const { enterSelectMode } = useConversationsContext()
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (conversationId === undefined) return
|
|
106
|
+
|
|
107
|
+
enterSelectMode(conversationId)
|
|
108
|
+
navigation.setParams({ select_conversation_id: undefined })
|
|
109
|
+
}, [conversationId, enterSelectMode, navigation])
|
|
110
|
+
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
113
|
+
|
|
42
114
|
const useListHeaderComponent = () => {
|
|
43
115
|
const filterDropdownEnabled = useFilterDropdownEnabled()
|
|
44
116
|
const searchEnabled = useSearchEnabled()
|
|
@@ -81,6 +81,7 @@ describe('SearchResultsList', () => {
|
|
|
81
81
|
it('shows the no-results state with the term when nothing matches', () => {
|
|
82
82
|
const view = renderList({})
|
|
83
83
|
|
|
84
|
+
expect(view.getByText('No results')).toBeTruthy()
|
|
84
85
|
expect(view.getByText(/Nothing matches “potluck\.”/)).toBeTruthy()
|
|
85
86
|
})
|
|
86
87
|
|
|
@@ -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
|
+
}
|
|
@@ -4,12 +4,8 @@ describe('pickAttachmentPreviewKind', () => {
|
|
|
4
4
|
describe('with a usable MIME type', () => {
|
|
5
5
|
it.each([
|
|
6
6
|
['image/png', 'image'],
|
|
7
|
-
['image/jpeg', 'image'],
|
|
8
7
|
['video/mp4', 'video'],
|
|
9
|
-
['video/quicktime', 'video'],
|
|
10
8
|
['application/pdf', 'file'],
|
|
11
|
-
['text/plain', 'file'],
|
|
12
|
-
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'file'],
|
|
13
9
|
['', 'file'],
|
|
14
10
|
[undefined, 'file'],
|
|
15
11
|
])('classifies %p as %p', (input, expected) => {
|
|
@@ -144,32 +144,4 @@ describe('convertAttachmentsForCreate', () => {
|
|
|
144
144
|
expect(result).toHaveLength(1)
|
|
145
145
|
expect(result[0]).toEqual(expandedLinkAttachment)
|
|
146
146
|
})
|
|
147
|
-
|
|
148
|
-
it('converts mixed attachment types correctly', () => {
|
|
149
|
-
const messageAttachment: DenormalizedMessageAttachmentResourceForCreate = {
|
|
150
|
-
type: 'MessageAttachment',
|
|
151
|
-
id: 'msg-id',
|
|
152
|
-
file: {
|
|
153
|
-
uri: 'file://test.jpg',
|
|
154
|
-
name: 'test.jpg',
|
|
155
|
-
type: 'image/jpeg',
|
|
156
|
-
size: 1024,
|
|
157
|
-
},
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const expandedLinkAttachment: DenormalizedExpandedLinkAttachmentResource = {
|
|
161
|
-
type: 'ExpandedLink',
|
|
162
|
-
attributes: {
|
|
163
|
-
url: 'https://example.com',
|
|
164
|
-
title: 'Example Link',
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const result = convertAttachmentsForCreate([messageAttachment, expandedLinkAttachment])
|
|
169
|
-
|
|
170
|
-
expect(result).toHaveLength(2)
|
|
171
|
-
expect(result[0].type).toBe('MessageAttachment')
|
|
172
|
-
expect(result[1].type).toBe('ExpandedLink')
|
|
173
|
-
expect(result[1]).toEqual(expandedLinkAttachment)
|
|
174
|
-
})
|
|
175
147
|
})
|
|
@@ -7,8 +7,7 @@ const base = {
|
|
|
7
7
|
|
|
8
8
|
describe('isInputEditable', () => {
|
|
9
9
|
it.each([
|
|
10
|
-
['active conversation
|
|
11
|
-
['active conversation with text', base, true],
|
|
10
|
+
['active conversation', base, true],
|
|
12
11
|
['pending request locks input', { ...base, isPending: true }, false],
|
|
13
12
|
['disabled conversation locks input', { ...base, conversationDisabled: true }, false],
|
|
14
13
|
])('%s', (_label, args, expected) => {
|
|
@@ -37,9 +37,4 @@ describe('hasMessageText', () => {
|
|
|
37
37
|
])('%s -> %s', (_name, input, expected) => {
|
|
38
38
|
expect(hasMessageText(input)).toBe(expected)
|
|
39
39
|
})
|
|
40
|
-
|
|
41
|
-
it('is not fooled by trim alone, which does not treat the character as whitespace', () => {
|
|
42
|
-
expect(EMPTY.trim()).toBe(EMPTY)
|
|
43
|
-
expect(hasMessageText(EMPTY)).toBe(false)
|
|
44
|
-
})
|
|
45
40
|
})
|
|
@@ -35,30 +35,9 @@ describe('SessionManager', () => {
|
|
|
35
35
|
expect(manager.sessions).toEqual({})
|
|
36
36
|
expect(manager.currentSession.isAuthenticated).toBe(false)
|
|
37
37
|
})
|
|
38
|
-
|
|
39
|
-
it('should return a default SessionManager when given empty string', () => {
|
|
40
|
-
const manager = SessionManager.hydrate('')
|
|
41
|
-
|
|
42
|
-
expect(manager.currentSessionId).toBe(UNAUTHENTICATED_SESSION_ID)
|
|
43
|
-
expect(manager.sessions).toEqual({})
|
|
44
|
-
})
|
|
45
38
|
})
|
|
46
39
|
|
|
47
40
|
describe('currentSession', () => {
|
|
48
|
-
it('should return the current session when it exists', () => {
|
|
49
|
-
const session = new Session({ token: createToken('token-12345678') })
|
|
50
|
-
const managerString = JSON.stringify({
|
|
51
|
-
sessions: { '12345678': session.toString() },
|
|
52
|
-
currentSessionId: '12345678',
|
|
53
|
-
})
|
|
54
|
-
const manager = SessionManager.hydrate(managerString)
|
|
55
|
-
|
|
56
|
-
const currentSession = manager.currentSession
|
|
57
|
-
|
|
58
|
-
expect(currentSession.isAuthenticated).toBe(true)
|
|
59
|
-
expect(currentSession.token?.access_token).toBe('token-12345678')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
41
|
it('should return an unauthenticated session when currentSessionId does not exist', () => {
|
|
63
42
|
const managerString = JSON.stringify({
|
|
64
43
|
sessions: {},
|
|
@@ -71,17 +50,6 @@ describe('SessionManager', () => {
|
|
|
71
50
|
expect(currentSession.isAuthenticated).toBe(false)
|
|
72
51
|
expect(currentSession.id).toBe(UNAUTHENTICATED_SESSION_ID)
|
|
73
52
|
})
|
|
74
|
-
|
|
75
|
-
it('should return an unauthenticated session when currentSessionId is unauthenticated', () => {
|
|
76
|
-
const manager = SessionManager.hydrate(
|
|
77
|
-
JSON.stringify({ sessions: {}, currentSessionId: UNAUTHENTICATED_SESSION_ID })
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
const currentSession = manager.currentSession
|
|
81
|
-
|
|
82
|
-
expect(currentSession.isAuthenticated).toBe(false)
|
|
83
|
-
expect(currentSession.id).toBe(UNAUTHENTICATED_SESSION_ID)
|
|
84
|
-
})
|
|
85
53
|
})
|
|
86
54
|
|
|
87
55
|
describe('setEnv', () => {
|
|
@@ -153,17 +121,6 @@ describe('SessionManager', () => {
|
|
|
153
121
|
expect(manager.currentSession.env).toBe('staging')
|
|
154
122
|
expect(manager.currentSessionId).toBe('12345678')
|
|
155
123
|
})
|
|
156
|
-
|
|
157
|
-
it('should update currentSessionId to match the session ID', () => {
|
|
158
|
-
const manager = SessionManager.hydrate(
|
|
159
|
-
JSON.stringify({ sessions: {}, currentSessionId: UNAUTHENTICATED_SESSION_ID })
|
|
160
|
-
)
|
|
161
|
-
const session = new Session({ token: createToken('token-11111111') })
|
|
162
|
-
|
|
163
|
-
manager.upsertSession(session)
|
|
164
|
-
|
|
165
|
-
expect(manager.currentSessionId).toBe('11111111')
|
|
166
|
-
})
|
|
167
124
|
})
|
|
168
125
|
|
|
169
126
|
describe('removeSession', () => {
|
|
@@ -216,17 +173,6 @@ describe('SessionManager', () => {
|
|
|
216
173
|
expect(manager.currentSessionId).toBe('11111111')
|
|
217
174
|
expect(manager.sessions).not.toHaveProperty('22222222')
|
|
218
175
|
})
|
|
219
|
-
|
|
220
|
-
it('should handle removing unauthenticated session gracefully', () => {
|
|
221
|
-
const manager = SessionManager.hydrate(
|
|
222
|
-
JSON.stringify({ sessions: {}, currentSessionId: UNAUTHENTICATED_SESSION_ID })
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
manager.removeSession(UNAUTHENTICATED_SESSION_ID)
|
|
226
|
-
|
|
227
|
-
expect(manager.currentSessionId).toBe(UNAUTHENTICATED_SESSION_ID)
|
|
228
|
-
expect(manager.sessions).not.toHaveProperty(UNAUTHENTICATED_SESSION_ID)
|
|
229
|
-
})
|
|
230
176
|
})
|
|
231
177
|
|
|
232
178
|
describe('updateCurrentToken', () => {
|
|
@@ -244,20 +190,6 @@ describe('SessionManager', () => {
|
|
|
244
190
|
|
|
245
191
|
expect(manager.currentSession.token?.access_token).toBe('token-22222222')
|
|
246
192
|
expect(manager.currentSessionId).toBe('22222222')
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
it('should remove the old session when token changes', () => {
|
|
250
|
-
const oldToken = createToken('token-11111111')
|
|
251
|
-
const session = new Session({ token: oldToken })
|
|
252
|
-
const managerString = JSON.stringify({
|
|
253
|
-
sessions: { '11111111': session.toString() },
|
|
254
|
-
currentSessionId: '11111111',
|
|
255
|
-
})
|
|
256
|
-
const manager = SessionManager.hydrate(managerString)
|
|
257
|
-
const newToken = createToken('token-22222222')
|
|
258
|
-
|
|
259
|
-
manager.updateCurrentToken(newToken)
|
|
260
|
-
|
|
261
193
|
expect(manager.sessions).not.toHaveProperty('11111111')
|
|
262
194
|
expect(manager.sessions).toHaveProperty('22222222')
|
|
263
195
|
})
|
|
@@ -292,21 +224,6 @@ describe('SessionManager', () => {
|
|
|
292
224
|
})
|
|
293
225
|
|
|
294
226
|
describe('toString', () => {
|
|
295
|
-
it('should serialize the manager to a JSON string', () => {
|
|
296
|
-
const session = new Session({ token: createToken('token-12345678') })
|
|
297
|
-
const managerString = JSON.stringify({
|
|
298
|
-
sessions: { '12345678': session.toString() },
|
|
299
|
-
currentSessionId: '12345678',
|
|
300
|
-
})
|
|
301
|
-
const manager = SessionManager.hydrate(managerString)
|
|
302
|
-
|
|
303
|
-
const serialized = manager.toString()
|
|
304
|
-
const parsed = JSON.parse(serialized)
|
|
305
|
-
|
|
306
|
-
expect(parsed.currentSessionId).toBe('12345678')
|
|
307
|
-
expect(parsed.sessions).toHaveProperty('12345678')
|
|
308
|
-
})
|
|
309
|
-
|
|
310
227
|
it('should produce a string that can be hydrated back to the same state', () => {
|
|
311
228
|
const session1 = new Session({ token: createToken('token-11111111') })
|
|
312
229
|
const session2 = new Session({ token: createToken('token-22222222') })
|
|
@@ -11,11 +11,6 @@ describe('SHA256', () => {
|
|
|
11
11
|
expect(hash).toBe('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
it('computes correct hash for "The quick brown fox jumps over the lazy dog"', () => {
|
|
15
|
-
const hash = SHA256('The quick brown fox jumps over the lazy dog').toString(enc.Hex)
|
|
16
|
-
expect(hash).toBe('d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592')
|
|
17
|
-
})
|
|
18
|
-
|
|
19
14
|
it('computes correct hash for longer message', () => {
|
|
20
15
|
const message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
|
|
21
16
|
const hash = SHA256(message).toString(enc.Hex)
|
|
@@ -34,37 +29,8 @@ describe('SHA256', () => {
|
|
|
34
29
|
expect(hash).toBe('c15ee319b97bfd23fa98590baf0b47d1f7b7b81f9e5bf99d8275867e2e4a32a2')
|
|
35
30
|
})
|
|
36
31
|
|
|
37
|
-
it('computes correct hash for JSON payload', () => {
|
|
38
|
-
const payload = JSON.stringify({ events: [{ name: 'test', meta: { foo: 'bar' } }] })
|
|
39
|
-
const hash = SHA256(payload).toString(enc.Hex)
|
|
40
|
-
expect(hash).toBe('5e4043aadad336890b9795ee03675a9de1a6abbc4e84f9f95daaffb21569312e')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
32
|
it('toString without encoding parameter defaults to hex', () => {
|
|
44
33
|
const hash = SHA256('abc').toString()
|
|
45
34
|
expect(hash).toBe('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')
|
|
46
35
|
})
|
|
47
|
-
|
|
48
|
-
it('produces consistent results for the same input', () => {
|
|
49
|
-
const input = 'test message'
|
|
50
|
-
const hash1 = SHA256(input).toString(enc.Hex)
|
|
51
|
-
const hash2 = SHA256(input).toString(enc.Hex)
|
|
52
|
-
expect(hash1).toBe(hash2)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('produces different hashes for different inputs', () => {
|
|
56
|
-
const hash1 = SHA256('message 1').toString(enc.Hex)
|
|
57
|
-
const hash2 = SHA256('message 2').toString(enc.Hex)
|
|
58
|
-
expect(hash1).not.toBe(hash2)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('handles strings with special characters', () => {
|
|
62
|
-
const hash = SHA256('!@#$%^&*()_+-=[]{}|;:",.<>?/~`').toString(enc.Hex)
|
|
63
|
-
expect(hash).toBe('67764597efaadfd3a9d89032105c9fcde16c6f05d16214e42488af193abb280a')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('handles strings with newlines and tabs', () => {
|
|
67
|
-
const hash = SHA256('line1\nline2\tline3').toString(enc.Hex)
|
|
68
|
-
expect(hash).toBe('450c0302bb6c2b9d81f81c8c868f7e96e3a35bc83751a08b7da09e77c4f13eec')
|
|
69
|
-
})
|
|
70
36
|
})
|
|
@@ -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
|
+
}
|
|
@@ -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,
|