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