@planningcenter/chat-react-native 3.37.1-qa-736.0 → 3.37.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/components/conversation/jump_to_bottom_button.d.ts +1 -2
- package/build/components/conversation/jump_to_bottom_button.d.ts.map +1 -1
- package/build/components/conversation/jump_to_bottom_button.js +7 -39
- package/build/components/conversation/jump_to_bottom_button.js.map +1 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +7 -19
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/reply_shadow_message.d.ts +2 -1
- package/build/components/conversation/reply_shadow_message.d.ts.map +1 -1
- package/build/components/conversation/reply_shadow_message.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +16 -6
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/contexts/conversation_context.d.ts +1 -8
- package/build/contexts/conversation_context.d.ts.map +1 -1
- package/build/contexts/conversation_context.js +3 -21
- package/build/contexts/conversation_context.js.map +1 -1
- package/build/hooks/use_attachment_uploader.d.ts.map +1 -1
- package/build/hooks/use_attachment_uploader.js +0 -9
- package/build/hooks/use_attachment_uploader.js.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts +6 -15
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +9 -62
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +4 -4
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/hooks/use_conversations_actions.d.ts +0 -5
- package/build/hooks/use_conversations_actions.d.ts.map +1 -1
- package/build/hooks/use_conversations_actions.js +0 -12
- package/build/hooks/use_conversations_actions.js.map +1 -1
- package/build/hooks/use_features.d.ts +0 -2
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +0 -2
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +1 -17
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_suspense_api.d.ts +0 -1
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +1 -1
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/hooks/use_upload_client.d.ts +0 -4
- package/build/hooks/use_upload_client.d.ts.map +1 -1
- package/build/hooks/use_upload_client.js +1 -13
- package/build/hooks/use_upload_client.js.map +1 -1
- package/build/jest.js +1 -1
- package/build/jest.js.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.js +1 -1
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/avatar_picker/emoji_tab.d.ts.map +1 -1
- package/build/screens/avatar_picker/emoji_tab.js +6 -2
- package/build/screens/avatar_picker/emoji_tab.js.map +1 -1
- package/build/screens/conversation_screen.d.ts +0 -1
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +48 -95
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/types/jolt_events/index.d.ts +1 -3
- package/build/types/jolt_events/index.d.ts.map +1 -1
- package/build/types/jolt_events/index.js.map +1 -1
- package/build/utils/cache/messages_cache.d.ts +0 -1
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +0 -4
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/group_messages.d.ts +2 -9
- package/build/utils/group_messages.d.ts.map +1 -1
- package/build/utils/group_messages.js +1 -20
- package/build/utils/group_messages.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/hooks/use_attachment_uploader.test.tsx +0 -36
- package/src/__tests__/jest.ts +1 -1
- package/src/components/conversation/jump_to_bottom_button.tsx +8 -57
- package/src/components/conversation/message_form.tsx +7 -21
- package/src/components/conversation/reply_shadow_message.tsx +1 -1
- package/src/components/conversations/conversations.tsx +16 -9
- package/src/contexts/conversation_context.tsx +2 -30
- package/src/hooks/use_attachment_uploader.ts +1 -14
- package/src/hooks/use_conversation_messages.ts +20 -120
- package/src/hooks/use_conversation_messages_jolt_events.ts +3 -4
- package/src/hooks/use_conversations_actions.ts +0 -15
- package/src/hooks/use_features.ts +0 -2
- package/src/hooks/use_mark_latest_message_read.ts +2 -16
- package/src/hooks/use_suspense_api.ts +1 -1
- package/src/hooks/use_upload_client.ts +1 -19
- package/src/jest.ts +1 -1
- package/src/screens/age_check/age_check_underage_screen.tsx +1 -1
- package/src/screens/avatar_picker/emoji_tab.tsx +6 -2
- package/src/screens/conversation_screen.tsx +76 -184
- package/src/types/jolt_events/index.ts +0 -3
- package/src/utils/__tests__/group_messages.test.ts +0 -71
- package/src/utils/cache/messages_cache.ts +0 -5
- package/src/utils/group_messages.ts +2 -42
- package/build/components/conversation/message_list.d.ts +0 -10
- package/build/components/conversation/message_list.d.ts.map +0 -1
- package/build/components/conversation/message_list.js +0 -13
- package/build/components/conversation/message_list.js.map +0 -1
- package/build/components/conversation/unread_divider.d.ts +0 -6
- package/build/components/conversation/unread_divider.d.ts.map +0 -1
- package/build/components/conversation/unread_divider.js +0 -59
- package/build/components/conversation/unread_divider.js.map +0 -1
- package/build/components/conversations/conversations_blank_state.d.ts +0 -8
- package/build/components/conversations/conversations_blank_state.d.ts.map +0 -1
- package/build/components/conversations/conversations_blank_state.js +0 -25
- package/build/components/conversations/conversations_blank_state.js.map +0 -1
- package/build/hooks/use_flat_list_viewability.d.ts +0 -20
- package/build/hooks/use_flat_list_viewability.d.ts.map +0 -1
- package/build/hooks/use_flat_list_viewability.js +0 -30
- package/build/hooks/use_flat_list_viewability.js.map +0 -1
- package/build/hooks/use_jump_to_bottom_action.d.ts +0 -9
- package/build/hooks/use_jump_to_bottom_action.d.ts.map +0 -1
- package/build/hooks/use_jump_to_bottom_action.js +0 -62
- package/build/hooks/use_jump_to_bottom_action.js.map +0 -1
- package/build/hooks/use_jump_to_unread_anchor.d.ts +0 -20
- package/build/hooks/use_jump_to_unread_anchor.d.ts.map +0 -1
- package/build/hooks/use_jump_to_unread_anchor.js +0 -53
- package/build/hooks/use_jump_to_unread_anchor.js.map +0 -1
- package/build/hooks/use_jump_to_unread_gates.d.ts +0 -5
- package/build/hooks/use_jump_to_unread_gates.d.ts.map +0 -1
- package/build/hooks/use_jump_to_unread_gates.js +0 -10
- package/build/hooks/use_jump_to_unread_gates.js.map +0 -1
- package/build/hooks/use_scroll_tracking.d.ts +0 -13
- package/build/hooks/use_scroll_tracking.d.ts.map +0 -1
- package/build/hooks/use_scroll_tracking.js +0 -45
- package/build/hooks/use_scroll_tracking.js.map +0 -1
- package/build/hooks/use_track_highest_seen_message.d.ts +0 -4
- package/build/hooks/use_track_highest_seen_message.d.ts.map +0 -1
- package/build/hooks/use_track_highest_seen_message.js +0 -35
- package/build/hooks/use_track_highest_seen_message.js.map +0 -1
- package/build/types/jolt_events/attachment_events.d.ts +0 -14
- package/build/types/jolt_events/attachment_events.d.ts.map +0 -1
- package/build/types/jolt_events/attachment_events.js +0 -2
- package/build/types/jolt_events/attachment_events.js.map +0 -1
- package/build/utils/conversation_messages.d.ts +0 -10
- package/build/utils/conversation_messages.d.ts.map +0 -1
- package/build/utils/conversation_messages.js +0 -22
- package/build/utils/conversation_messages.js.map +0 -1
- package/build/utils/highest_seen_tracker.d.ts +0 -12
- package/build/utils/highest_seen_tracker.d.ts.map +0 -1
- package/build/utils/highest_seen_tracker.js +0 -37
- package/build/utils/highest_seen_tracker.js.map +0 -1
- package/build/utils/message_viewability.d.ts +0 -24
- package/build/utils/message_viewability.d.ts.map +0 -1
- package/build/utils/message_viewability.js +0 -29
- package/build/utils/message_viewability.js.map +0 -1
- package/build/utils/unread_divider_helpers.d.ts +0 -18
- package/build/utils/unread_divider_helpers.d.ts.map +0 -1
- package/build/utils/unread_divider_helpers.js +0 -13
- package/build/utils/unread_divider_helpers.js.map +0 -1
- package/src/__tests__/hooks/use_conversation_messages.test.tsx +0 -109
- package/src/__tests__/hooks/use_mark_latest_message_read.test.tsx +0 -154
- package/src/__tests__/utils/cache/messages_cache.test.ts +0 -54
- package/src/components/conversation/__tests__/message_list.test.tsx +0 -14
- package/src/components/conversation/message_list.tsx +0 -42
- package/src/components/conversation/unread_divider.tsx +0 -90
- package/src/components/conversations/conversations_blank_state.tsx +0 -42
- package/src/hooks/use_flat_list_viewability.ts +0 -50
- package/src/hooks/use_jump_to_bottom_action.ts +0 -75
- package/src/hooks/use_jump_to_unread_anchor.ts +0 -68
- package/src/hooks/use_jump_to_unread_gates.ts +0 -10
- package/src/hooks/use_scroll_tracking.ts +0 -64
- package/src/hooks/use_track_highest_seen_message.ts +0 -43
- package/src/types/jolt_events/attachment_events.ts +0 -14
- package/src/utils/__tests__/conversation_messages.test.ts +0 -105
- package/src/utils/__tests__/highest_seen_tracker.test.ts +0 -82
- package/src/utils/__tests__/message_viewability.test.ts +0 -168
- package/src/utils/__tests__/unread_divider_helpers.test.ts +0 -85
- package/src/utils/conversation_messages.ts +0 -37
- package/src/utils/highest_seen_tracker.ts +0 -42
- package/src/utils/message_viewability.ts +0 -49
- package/src/utils/unread_divider_helpers.ts +0 -25
|
@@ -3,17 +3,14 @@ import React, { useMemo } from 'react';
|
|
|
3
3
|
import { FlatList, StyleSheet, View } from 'react-native';
|
|
4
4
|
import { useConversationsContext } from '../../contexts/conversations_context';
|
|
5
5
|
import { useTheme } from '../../hooks';
|
|
6
|
-
import { useCanCreateConversations } from '../../hooks/use_chat_permissions';
|
|
7
6
|
import { useConversationsJoltEvents } from '../../hooks/use_conversations_jolt_events';
|
|
8
7
|
import { throwResponseError } from '../../utils/response_error';
|
|
8
|
+
import BlankState from '../primitive/blank_state_primitive';
|
|
9
9
|
import { ConversationPreview, ConversationPreviewSkeleton } from './conversation_preview';
|
|
10
|
-
import { ConversationsBlankState } from './conversations_blank_state';
|
|
11
10
|
export const Conversations = ({ ListHeaderComponent }) => {
|
|
12
11
|
const styles = useStyles();
|
|
13
|
-
const { conversations, isLoading, fetchNextPage, refetch, isRefetching, isFetched, isError, error, args: { chat_group_graph_id
|
|
12
|
+
const { conversations, isLoading, fetchNextPage, refetch, isRefetching, isFetched, isError, error, args: { chat_group_graph_id }, } = useConversationsContext();
|
|
14
13
|
const navigation = useNavigation();
|
|
15
|
-
const canCreateConversations = useCanCreateConversations();
|
|
16
|
-
const isFilterApplied = !!chat_group_graph_id || !!group_source_app_name;
|
|
17
14
|
const showBadges = !chat_group_graph_id;
|
|
18
15
|
const data = useMemo(() => {
|
|
19
16
|
if (isLoading) {
|
|
@@ -30,7 +27,14 @@ export const Conversations = ({ ListHeaderComponent }) => {
|
|
|
30
27
|
}
|
|
31
28
|
useConversationsJoltEvents();
|
|
32
29
|
return (<View style={styles.container}>
|
|
33
|
-
<FlatList data={data} keyExtractor={item => item.id.toString()} contentContainerStyle={styles.contentContainer} onRefresh={refetch} refreshing={!isFetched && isRefetching} ListHeaderComponent={ListHeaderComponent} ListEmptyComponent={<
|
|
30
|
+
<FlatList data={data} keyExtractor={item => item.id.toString()} contentContainerStyle={styles.contentContainer} onRefresh={refetch} refreshing={!isFetched && isRefetching} ListHeaderComponent={ListHeaderComponent} ListEmptyComponent={<View style={styles.listEmpty}>
|
|
31
|
+
<BlankState.Root>
|
|
32
|
+
<BlankState.Imagery name="general.outlinedTextMessage"/>
|
|
33
|
+
<BlankState.Content>
|
|
34
|
+
<BlankState.Heading>No conversations</BlankState.Heading>
|
|
35
|
+
</BlankState.Content>
|
|
36
|
+
</BlankState.Root>
|
|
37
|
+
</View>} renderItem={({ item }) => {
|
|
34
38
|
if (item.type === 'loading') {
|
|
35
39
|
return <ConversationPreviewSkeleton />;
|
|
36
40
|
}
|
|
@@ -52,6 +56,12 @@ const useStyles = () => {
|
|
|
52
56
|
container: { flex: 1 },
|
|
53
57
|
contentContainer: { paddingVertical: 16 },
|
|
54
58
|
listItem: { color: colors.fillColorNeutral020 },
|
|
59
|
+
listEmpty: {
|
|
60
|
+
flex: 1,
|
|
61
|
+
justifyContent: 'center',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
paddingVertical: 32,
|
|
64
|
+
},
|
|
55
65
|
});
|
|
56
66
|
};
|
|
57
67
|
const loadingPlaceholder = Array.from({ length: 5 }, (_, i) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../../src/components/conversations/conversations.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAA;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../../src/components/conversations/conversations.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAA;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,UAAU,MAAM,oCAAoC,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAA2B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aAAa,EAAE,CAAC,EAExC;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE7B,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;QACtB,gBAAgB,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE;QACzC,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,mBAAmB,EAAE;QAC/C,SAAS,EAAE;YACT,IAAI,EAAE,CAAC;YACP,cAAc,EAAE,QAAQ;YACxB,UAAU,EAAE,QAAQ;YACpB,eAAe,EAAE,EAAE;SACpB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAaD,MAAM,kBAAkB,GAAmB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9E,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,UAAU,CAAC,EAAE;CAClB,CAAC,CAAC,CAAA","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport React, { useMemo } from 'react'\nimport { FlatList, StyleSheet, View } from 'react-native'\nimport { useConversationsContext } from '../../contexts/conversations_context'\nimport { useTheme } from '../../hooks'\nimport { useConversationsJoltEvents } from '../../hooks/use_conversations_jolt_events'\nimport { ConversationResource } from '../../types'\nimport { throwResponseError } from '../../utils/response_error'\nimport BlankState from '../primitive/blank_state_primitive'\nimport { ConversationPreview, ConversationPreviewSkeleton } from './conversation_preview'\n\ninterface ConversationsProps {\n ListHeaderComponent?:\n | React.ComponentType<any>\n | React.ReactElement<any, string | React.JSXElementConstructor<any>>\n | null\n | undefined\n}\n\nexport const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {\n const styles = useStyles()\n const {\n conversations,\n isLoading,\n fetchNextPage,\n refetch,\n isRefetching,\n isFetched,\n isError,\n error,\n args: { chat_group_graph_id },\n } = useConversationsContext()\n const navigation = useNavigation()\n\n const showBadges = !chat_group_graph_id\n\n const data: FlatListItem[] = useMemo(() => {\n if (isLoading) {\n return loadingPlaceholder\n }\n return conversations.map(conversation => ({\n type: 'conversation' as const,\n id: conversation.id,\n resource: conversation,\n }))\n }, [conversations, isLoading])\n\n if (isError) {\n throwResponseError(error)\n }\n\n useConversationsJoltEvents()\n\n return (\n <View style={styles.container}>\n <FlatList\n data={data}\n keyExtractor={item => item.id.toString()}\n contentContainerStyle={styles.contentContainer}\n onRefresh={refetch}\n refreshing={!isFetched && isRefetching}\n ListHeaderComponent={ListHeaderComponent}\n ListEmptyComponent={\n <View style={styles.listEmpty}>\n <BlankState.Root>\n <BlankState.Imagery name=\"general.outlinedTextMessage\" />\n <BlankState.Content>\n <BlankState.Heading>No conversations</BlankState.Heading>\n </BlankState.Content>\n </BlankState.Root>\n </View>\n }\n renderItem={({ item }) => {\n if (item.type === 'loading') {\n return <ConversationPreviewSkeleton />\n } else {\n return (\n <ConversationPreview\n conversation={item.resource}\n onPress={() =>\n navigation.navigate('Conversation', {\n conversation_id: item.resource.id,\n title: item.resource.title,\n badge: item.resource.badges?.[0],\n deleted: item.resource.deleted,\n muted: item.resource.muted,\n })\n }\n showBadges={showBadges}\n />\n )\n }\n }}\n onEndReached={() => fetchNextPage()}\n />\n </View>\n )\n}\n\nconst useStyles = () => {\n const { colors } = useTheme()\n\n return StyleSheet.create({\n container: { flex: 1 },\n contentContainer: { paddingVertical: 16 },\n listItem: { color: colors.fillColorNeutral020 },\n listEmpty: {\n flex: 1,\n justifyContent: 'center',\n alignItems: 'center',\n paddingVertical: 32,\n },\n })\n}\n\ninterface FlatListLoadingItem {\n type: 'loading'\n id: string\n}\ninterface FlatListConversationItem {\n type: 'conversation'\n resource: ConversationResource\n id: number\n}\ntype FlatListItem = FlatListLoadingItem | FlatListConversationItem\n\nconst loadingPlaceholder: FlatListItem[] = Array.from({ length: 5 }, (_, i) => ({\n type: 'loading',\n id: `loading${i}`,\n}))\n"]}
|
|
@@ -2,19 +2,12 @@ import React, { PropsWithChildren } from 'react';
|
|
|
2
2
|
interface ConversationContextValue {
|
|
3
3
|
conversationId: number;
|
|
4
4
|
currentPageReplyRootId: string | null;
|
|
5
|
-
initialMessageId: string | null;
|
|
6
|
-
setInitialMessageId: (id: string | null) => void;
|
|
7
|
-
initialMessageIdIsAnchor: boolean;
|
|
8
|
-
atEndOfMessageHistory: boolean;
|
|
9
|
-
setAtEndOfMessageHistory: (atEnd: boolean) => void;
|
|
10
5
|
}
|
|
11
6
|
interface ConversationContextProviderProps extends PropsWithChildren {
|
|
12
7
|
conversationId: number;
|
|
13
8
|
currentPageReplyRootId: string | null;
|
|
14
|
-
initialMessageId?: string | null;
|
|
15
|
-
initialMessageIdIsAnchor?: boolean;
|
|
16
9
|
}
|
|
17
|
-
export declare const ConversationContextProvider: ({ children, conversationId, currentPageReplyRootId,
|
|
10
|
+
export declare const ConversationContextProvider: ({ children, conversationId, currentPageReplyRootId, }: ConversationContextProviderProps) => React.JSX.Element;
|
|
18
11
|
export declare const useConversationContext: () => ConversationContextValue;
|
|
19
12
|
export {};
|
|
20
13
|
//# sourceMappingURL=conversation_context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation_context.d.ts","sourceRoot":"","sources":["../../src/contexts/conversation_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"conversation_context.d.ts","sourceRoot":"","sources":["../../src/contexts/conversation_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAuB,MAAM,OAAO,CAAA;AAEpF,UAAU,wBAAwB;IAChC,cAAc,EAAE,MAAM,CAAA;IACtB,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAA;CACtC;AAED,UAAU,gCAAiC,SAAQ,iBAAiB;IAClE,cAAc,EAAE,MAAM,CAAA;IACtB,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAA;CACtC;AAOD,eAAO,MAAM,2BAA2B,GAAI,uDAIzC,gCAAgC,sBAUlC,CAAA;AAED,eAAO,MAAM,sBAAsB,gCAAwC,CAAA"}
|
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
import React, { createContext, useContext, useMemo
|
|
1
|
+
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
2
|
const ConversationContext = createContext({
|
|
3
3
|
conversationId: 0,
|
|
4
4
|
currentPageReplyRootId: null,
|
|
5
|
-
initialMessageId: null,
|
|
6
|
-
setInitialMessageId: () => { },
|
|
7
|
-
initialMessageIdIsAnchor: false,
|
|
8
|
-
atEndOfMessageHistory: false,
|
|
9
|
-
setAtEndOfMessageHistory: () => { },
|
|
10
5
|
});
|
|
11
|
-
export const ConversationContextProvider = ({ children, conversationId, currentPageReplyRootId,
|
|
12
|
-
const [initialMessageId, setInitialMessageId] = useState(initialMessageIdProp);
|
|
13
|
-
const [atEndOfMessageHistory, setAtEndOfMessageHistory] = useState(false);
|
|
6
|
+
export const ConversationContextProvider = ({ children, conversationId, currentPageReplyRootId, }) => {
|
|
14
7
|
const value = useMemo(() => ({
|
|
15
8
|
conversationId,
|
|
16
9
|
currentPageReplyRootId,
|
|
17
|
-
|
|
18
|
-
setInitialMessageId,
|
|
19
|
-
initialMessageIdIsAnchor,
|
|
20
|
-
atEndOfMessageHistory,
|
|
21
|
-
setAtEndOfMessageHistory,
|
|
22
|
-
}), [
|
|
23
|
-
conversationId,
|
|
24
|
-
currentPageReplyRootId,
|
|
25
|
-
initialMessageId,
|
|
26
|
-
initialMessageIdIsAnchor,
|
|
27
|
-
atEndOfMessageHistory,
|
|
28
|
-
]);
|
|
10
|
+
}), [conversationId, currentPageReplyRootId]);
|
|
29
11
|
return <ConversationContext.Provider value={value}>{children}</ConversationContext.Provider>;
|
|
30
12
|
};
|
|
31
13
|
export const useConversationContext = () => useContext(ConversationContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation_context.js","sourceRoot":"","sources":["../../src/contexts/conversation_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"conversation_context.js","sourceRoot":"","sources":["../../src/contexts/conversation_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAYpF,MAAM,mBAAmB,GAAG,aAAa,CAA2B;IAClE,cAAc,EAAE,CAAC;IACjB,sBAAsB,EAAE,IAAI;CAC7B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,QAAQ,EACR,cAAc,EACd,sBAAsB,GACW,EAAE,EAAE;IACrC,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,cAAc;QACd,sBAAsB;KACvB,CAAC,EACF,CAAC,cAAc,EAAE,sBAAsB,CAAC,CACzC,CAAA;IAED,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAA;AAC9F,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAA","sourcesContent":["import React, { createContext, PropsWithChildren, useContext, useMemo } from 'react'\n\ninterface ConversationContextValue {\n conversationId: number\n currentPageReplyRootId: string | null\n}\n\ninterface ConversationContextProviderProps extends PropsWithChildren {\n conversationId: number\n currentPageReplyRootId: string | null\n}\n\nconst ConversationContext = createContext<ConversationContextValue>({\n conversationId: 0,\n currentPageReplyRootId: null,\n})\n\nexport const ConversationContextProvider = ({\n children,\n conversationId,\n currentPageReplyRootId,\n}: ConversationContextProviderProps) => {\n const value = useMemo(\n () => ({\n conversationId,\n currentPageReplyRootId,\n }),\n [conversationId, currentPageReplyRootId]\n )\n\n return <ConversationContext.Provider value={value}>{children}</ConversationContext.Provider>\n}\n\nexport const useConversationContext = () => useContext(ConversationContext)\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_attachment_uploader.d.ts","sourceRoot":"","sources":["../../src/hooks/use_attachment_uploader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use_attachment_uploader.d.ts","sourceRoot":"","sources":["../../src/hooks/use_attachment_uploader.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EAEd,oBAAoB,EACrB,MAAM,gEAAgE,CAAA;AAKvE,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,wBAAgB,qBAAqB,CAAC,EACpC,cAAc,EACd,gBAAgB,GACjB,EAAE;IACD,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,CAAC,EAAE,cAAc,EAAE,CAAA;CACpC;;;iCAaW,oBAAoB,EAAE;mCAkHkB,cAAc;;;;;;;EAmCjE"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { useApiGet } from './use_api';
|
|
3
2
|
import { useApiClient } from './use_api_client';
|
|
4
3
|
import { useChatConfiguration } from './use_chat_configuration';
|
|
5
|
-
import { currentPersonRequestArgs } from './use_current_person';
|
|
6
|
-
import { useJoltChannel, useJoltEvent } from './use_jolt';
|
|
7
4
|
import { useUploadClient } from './use_upload_client';
|
|
8
5
|
export function useAttachmentUploader({ conversationId, draftAttachments, }) {
|
|
9
6
|
const apiClient = useApiClient();
|
|
@@ -15,12 +12,6 @@ export function useAttachmentUploader({ conversationId, draftAttachments, }) {
|
|
|
15
12
|
const [lastUploadId, setLastUploadId] = useState();
|
|
16
13
|
const numberOfAttachments = attachments.length;
|
|
17
14
|
const [errorMessage, setErrorMessage] = useState(null);
|
|
18
|
-
const { data: currentPerson } = useApiGet(currentPersonRequestArgs);
|
|
19
|
-
const joltChannel = useJoltChannel(`chat.people.${currentPerson?.id}`, Boolean(currentPerson?.id));
|
|
20
|
-
useJoltEvent(joltChannel, 'attachment.flagged', (e) => {
|
|
21
|
-
const flaggedId = e.data.data.attachment_id;
|
|
22
|
-
setAttachments(prev => prev.map(a => (a.id === flaggedId ? { ...a, flagged: true, status: 'error' } : a)));
|
|
23
|
-
});
|
|
24
15
|
const handleFilesAttached = useCallback((files) => {
|
|
25
16
|
const fileErrors = {};
|
|
26
17
|
const validFiles = files.filter(file => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_attachment_uploader.js","sourceRoot":"","sources":["../../src/hooks/use_attachment_uploader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAQzE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAOrD,MAAM,UAAU,qBAAqB,CAAC,EACpC,cAAc,EACd,gBAAgB,GAIjB;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,SAAS,GAAG,eAAe,EAAE,CAAA;IACnC,MAAM,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAw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AAW;QACX,aAAa;QACb,mBAAmB;QACnB,gBAAgB;QAChB,wBAAwB;QACxB,KAAK;QACL,cAAc;QACd,YAAY;QACZ,sBAAsB;QACtB,mBAAmB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,wBAAwB,GAAG,mBAAmB,CAAC;KACjF,CAAA;AACH,CAAC;AAED,KAAK,UAAU,+BAA+B,CAAC,GAAY;IACzD,MAAM,QAAQ,GAAG,GAAsB,CAAA;IACvC,IAAI,CAAC,QAAQ,EAAE,KAAK;QAAE,OAAO,IAAI,CAAA;IACjC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAA;QAC1C,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,IAAI,EAAE,MAAM,CAAA;QACxD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { ApiResource, CurrentPersonResource } from '../types'\nimport { AttachmentFlaggedEvent } from '../types/jolt_events/attachment_events'\nimport {\n FileAttachment,\n FileUploadState,\n NativeAttachmentFile,\n} from '../types/resources/denormalized_attachment_resource_for_create'\nimport { useApiGet } from './use_api'\nimport { useApiClient } from './use_api_client'\nimport { useChatConfiguration } from './use_chat_configuration'\nimport { currentPersonRequestArgs } from './use_current_person'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\nimport { useUploadClient } from './use_upload_client'\n\nexport interface FileError {\n file_type?: string[]\n file_size?: boolean\n}\n\nexport function useAttachmentUploader({\n conversationId,\n draftAttachments,\n}: {\n conversationId: number\n draftAttachments?: FileAttachment[]\n}) {\n const apiClient = useApiClient()\n const uploadApi = useUploadClient()\n const { allowedFileExtensions, maxFileSizeInBytes, maxAttachmentsPerMessage } =\n useChatConfiguration()\n const maxFileSizeInMb = Number((maxFileSizeInBytes / (1024 * 1024)).toFixed(1))\n const [attachments, setAttachments] = useState<FileAttachment[]>(() => draftAttachments || [])\n const uploadState = useRef<FileUploadState>({})\n const [lastUploadId, setLastUploadId] = useState<string>()\n const numberOfAttachments = attachments.length\n const [errorMessage, setErrorMessage] = useState<string | null>(null)\n\n const { data: currentPerson } = useApiGet<CurrentPersonResource>(currentPersonRequestArgs)\n const joltChannel = useJoltChannel(`chat.people.${currentPerson?.id}`, Boolean(currentPerson?.id))\n useJoltEvent(joltChannel, 'attachment.flagged', (e: AttachmentFlaggedEvent) => {\n const flaggedId = e.data.data.attachment_id\n setAttachments(prev =>\n prev.map(a => (a.id === flaggedId ? { ...a, flagged: true, status: 'error' } : a))\n )\n })\n\n const handleFilesAttached = useCallback(\n (files: NativeAttachmentFile[]) => {\n const fileErrors = {} as FileError\n\n const validFiles = files.filter(file => {\n const extension = file.name.toLowerCase().split('.').pop() as string\n const isValidExtension = allowedFileExtensions.includes(`.${extension}`)\n const isValidFileSize = file.size <= maxFileSizeInBytes\n\n if (!isValidExtension) {\n fileErrors.file_type ||= []\n fileErrors.file_type.push(extension)\n }\n if (!isValidFileSize) {\n fileErrors.file_size = true\n }\n\n return isValidFileSize && isValidExtension\n })\n\n const errorMessages: string[] = []\n if (fileErrors.file_type) {\n errorMessages.push(\n `The following file types are not supported: ${fileErrors.file_type.join(', ')}`\n )\n }\n if (fileErrors.file_size) {\n errorMessages.push(`File size exceeds ${maxFileSizeInMb} MB`)\n }\n if (numberOfAttachments + validFiles.length > maxAttachmentsPerMessage) {\n errorMessages.push(`You can't attach more than ${maxAttachmentsPerMessage} files at once.`)\n }\n if (errorMessages.length > 0) {\n setErrorMessage(errorMessages.join('\\n'))\n return\n }\n\n const newAttachments: FileAttachment[] = validFiles.map(file => ({\n file,\n status: 'uploading',\n uploadedAt: Date.now(),\n }))\n\n if (newAttachments && newAttachments.length > 0) {\n setAttachments(prevAttachments => [...prevAttachments, ...newAttachments])\n\n newAttachments.forEach(attachment => {\n uploadApi\n .uploadFile(attachment.file)\n .then(({ id: uploadedFileId }) =>\n apiClient.chat.post<ApiResource<MessageAttachmentResource>>({\n url: `/me/conversations/${conversationId}/message_attachments`,\n data: {\n data: {\n type: 'MessageAttachment',\n attributes: { uploaded_file_id: uploadedFileId },\n },\n },\n })\n )\n .then(({ data: { id: messageAttachmentId } }) => {\n uploadState.current[attachment.file.name] = {\n status: 'success',\n id: messageAttachmentId,\n }\n setLastUploadId(messageAttachmentId)\n })\n .catch(async err => {\n const isFlagged = err?.code === 'image_flagged'\n uploadState.current[attachment.file.name] = {\n status: 'error',\n flagged: isFlagged,\n }\n if (!isFlagged) {\n // Dev builds surface the raw server detail to shorten the\n // feedback loop on backend errors (e.g. AWS SSO re-auth).\n // Production users always see the generic message.\n const serverDetail = __DEV__ ? await extractDevOnlyServerErrorDetail(err) : null\n setErrorMessage(serverDetail ?? 'This file could not be uploaded.')\n }\n setLastUploadId(attachment.file.name)\n })\n })\n }\n },\n [\n numberOfAttachments,\n uploadApi,\n apiClient.chat,\n conversationId,\n allowedFileExtensions,\n maxFileSizeInBytes,\n maxFileSizeInMb,\n maxAttachmentsPerMessage,\n ]\n )\n\n useEffect(() => {\n if (!lastUploadId) return\n\n setLastUploadId(undefined)\n setAttachments(\n attachments.map(attachment => {\n // Don't risk overwriting ids already set\n if (attachment.id) return attachment\n\n const state = uploadState.current[attachment.file.name]\n if (state) {\n return { ...attachment, id: state.id, status: state.status, flagged: state.flagged }\n }\n return attachment\n })\n )\n }, [attachments, lastUploadId])\n\n const removeAttachment = useCallback((attachment: FileAttachment) => {\n setAttachments(prevAttachments =>\n prevAttachments.filter(a => a.file.uri !== attachment.file.uri)\n )\n }, [])\n\n const removeFlaggedAttachments = useCallback(() => {\n setAttachments(prevAttachments => prevAttachments.filter(a => !a.flagged))\n }, [])\n\n const reset = useCallback(() => {\n setAttachments([])\n setErrorMessage(null)\n }, [])\n\n const pendingUploads = attachments.filter(a => a.status === 'uploading').length > 0\n const flaggedAttachmentCount = attachments.filter(a => a.flagged).length\n\n const attachmentIds = useMemo(\n () => attachments.filter(a => a.status === 'success' && a.id).map(a => a.id as string),\n [attachments]\n )\n\n return {\n attachments,\n attachmentIds,\n handleFilesAttached,\n removeAttachment,\n removeFlaggedAttachments,\n reset,\n pendingUploads,\n errorMessage,\n flaggedAttachmentCount,\n remainingAttachable: Math.max(0, maxAttachmentsPerMessage - numberOfAttachments),\n }\n}\n\nasync function extractDevOnlyServerErrorDetail(err: unknown): Promise<string | null> {\n const response = err as Response | null\n if (!response?.clone) return null\n try {\n const body = await response.clone().json()\n const detail = body?.errors?.[0]?.detail ?? body?.detail\n return typeof detail === 'string' ? detail : null\n } catch {\n return null\n }\n}\n\ninterface MessageAttachmentResource {\n type: 'MessageAttachment'\n id: string\n uploadedFileId: string\n filename: string\n messageSortKey: string\n metadata: Record<string, unknown>\n checksum: string\n contentType: string\n byteSize: number\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use_attachment_uploader.js","sourceRoot":"","sources":["../../src/hooks/use_attachment_uploader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAOzE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAOrD,MAAM,UAAU,qBAAqB,CAAC,EACpC,cAAc,EACd,gBAAgB,GAIjB;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,SAAS,GAAG,eAAe,EAAE,CAAA;IACnC,MAAM,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,G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AA;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { ApiResource } from '../types'\nimport {\n FileAttachment,\n FileUploadState,\n NativeAttachmentFile,\n} from '../types/resources/denormalized_attachment_resource_for_create'\nimport { useApiClient } from './use_api_client'\nimport { useChatConfiguration } from './use_chat_configuration'\nimport { useUploadClient } from './use_upload_client'\n\nexport interface FileError {\n file_type?: string[]\n file_size?: boolean\n}\n\nexport function useAttachmentUploader({\n conversationId,\n draftAttachments,\n}: {\n conversationId: number\n draftAttachments?: FileAttachment[]\n}) {\n const apiClient = useApiClient()\n const uploadApi = useUploadClient()\n const { allowedFileExtensions, maxFileSizeInBytes, maxAttachmentsPerMessage } =\n useChatConfiguration()\n const maxFileSizeInMb = Number((maxFileSizeInBytes / (1024 * 1024)).toFixed(1))\n const [attachments, setAttachments] = useState<FileAttachment[]>(() => draftAttachments || [])\n const uploadState = useRef<FileUploadState>({})\n const [lastUploadId, setLastUploadId] = useState<string>()\n const numberOfAttachments = attachments.length\n const [errorMessage, setErrorMessage] = useState<string | null>(null)\n\n const handleFilesAttached = useCallback(\n (files: NativeAttachmentFile[]) => {\n const fileErrors = {} as FileError\n\n const validFiles = files.filter(file => {\n const extension = file.name.toLowerCase().split('.').pop() as string\n const isValidExtension = allowedFileExtensions.includes(`.${extension}`)\n const isValidFileSize = file.size <= maxFileSizeInBytes\n\n if (!isValidExtension) {\n fileErrors.file_type ||= []\n fileErrors.file_type.push(extension)\n }\n if (!isValidFileSize) {\n fileErrors.file_size = true\n }\n\n return isValidFileSize && isValidExtension\n })\n\n const errorMessages: string[] = []\n if (fileErrors.file_type) {\n errorMessages.push(\n `The following file types are not supported: ${fileErrors.file_type.join(', ')}`\n )\n }\n if (fileErrors.file_size) {\n errorMessages.push(`File size exceeds ${maxFileSizeInMb} MB`)\n }\n if (numberOfAttachments + validFiles.length > maxAttachmentsPerMessage) {\n errorMessages.push(`You can't attach more than ${maxAttachmentsPerMessage} files at once.`)\n }\n if (errorMessages.length > 0) {\n setErrorMessage(errorMessages.join('\\n'))\n return\n }\n\n const newAttachments: FileAttachment[] = validFiles.map(file => ({\n file,\n status: 'uploading',\n uploadedAt: Date.now(),\n }))\n\n if (newAttachments && newAttachments.length > 0) {\n setAttachments(prevAttachments => [...prevAttachments, ...newAttachments])\n\n newAttachments.forEach(attachment => {\n uploadApi\n .uploadFile(attachment.file)\n .then(({ id: uploadedFileId }) =>\n apiClient.chat.post<ApiResource<MessageAttachmentResource>>({\n url: `/me/conversations/${conversationId}/message_attachments`,\n data: {\n data: {\n type: 'MessageAttachment',\n attributes: { uploaded_file_id: uploadedFileId },\n },\n },\n })\n )\n .then(({ data: { id: messageAttachmentId } }) => {\n uploadState.current[attachment.file.name] = {\n status: 'success',\n id: messageAttachmentId,\n }\n setLastUploadId(messageAttachmentId)\n })\n .catch(async err => {\n const isFlagged = err?.code === 'image_flagged'\n uploadState.current[attachment.file.name] = {\n status: 'error',\n flagged: isFlagged,\n }\n if (!isFlagged) {\n // Dev builds surface the raw server detail to shorten the\n // feedback loop on backend errors (e.g. AWS SSO re-auth).\n // Production users always see the generic message.\n const serverDetail = __DEV__ ? await extractDevOnlyServerErrorDetail(err) : null\n setErrorMessage(serverDetail ?? 'This file could not be uploaded.')\n }\n setLastUploadId(attachment.file.name)\n })\n })\n }\n },\n [\n numberOfAttachments,\n uploadApi,\n apiClient.chat,\n conversationId,\n allowedFileExtensions,\n maxFileSizeInBytes,\n maxFileSizeInMb,\n maxAttachmentsPerMessage,\n ]\n )\n\n useEffect(() => {\n if (!lastUploadId) return\n\n setLastUploadId(undefined)\n setAttachments(\n attachments.map(attachment => {\n // Don't risk overwriting ids already set\n if (attachment.id) return attachment\n\n const state = uploadState.current[attachment.file.name]\n if (state) {\n return { ...attachment, id: state.id, status: state.status, flagged: state.flagged }\n }\n return attachment\n })\n )\n }, [attachments, lastUploadId])\n\n const removeAttachment = useCallback((attachment: FileAttachment) => {\n setAttachments(prevAttachments =>\n prevAttachments.filter(a => a.file.uri !== attachment.file.uri)\n )\n }, [])\n\n const removeFlaggedAttachments = useCallback(() => {\n setAttachments(prevAttachments => prevAttachments.filter(a => !a.flagged))\n }, [])\n\n const reset = useCallback(() => {\n setAttachments([])\n setErrorMessage(null)\n }, [])\n\n const pendingUploads = attachments.filter(a => a.status === 'uploading').length > 0\n const flaggedAttachmentCount = attachments.filter(a => a.flagged).length\n\n const attachmentIds = useMemo(\n () => attachments.filter(a => a.status === 'success' && a.id).map(a => a.id as string),\n [attachments]\n )\n\n return {\n attachments,\n attachmentIds,\n handleFilesAttached,\n removeAttachment,\n removeFlaggedAttachments,\n reset,\n pendingUploads,\n errorMessage,\n flaggedAttachmentCount,\n remainingAttachable: Math.max(0, maxAttachmentsPerMessage - numberOfAttachments),\n }\n}\n\nasync function extractDevOnlyServerErrorDetail(err: unknown): Promise<string | null> {\n const response = err as Response | null\n if (!response?.clone) return null\n try {\n const body = await response.clone().json()\n const detail = body?.errors?.[0]?.detail ?? body?.detail\n return typeof detail === 'string' ? detail : null\n } catch {\n return null\n }\n}\n\ninterface MessageAttachmentResource {\n type: 'MessageAttachment'\n id: string\n uploadedFileId: string\n filename: string\n messageSortKey: string\n metadata: Record<string, unknown>\n checksum: string\n contentType: string\n byteSize: number\n}\n"]}
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type Args = {
|
|
1
|
+
import { MessageResource } from '../types';
|
|
2
|
+
import { SuspensePaginatorOptions } from './use_suspense_api';
|
|
3
|
+
export declare const useConversationMessages: ({ conversation_id, reply_root_id }: {
|
|
5
4
|
conversation_id: number;
|
|
6
5
|
reply_root_id?: string | null;
|
|
7
|
-
}
|
|
8
|
-
export type ConversationMessagesOptions = Omit<AnyUseSuspenseInfiniteQueryOptions, 'getNextPageParam' | 'getPreviousPageParam' | 'initialData' | 'initialPageParam' | 'queryFn' | 'queryKey'>;
|
|
9
|
-
export declare const useConversationMessages: ({ conversation_id, reply_root_id }: Args, opts?: ConversationMessagesOptions) => {
|
|
6
|
+
}, opts?: SuspensePaginatorOptions) => {
|
|
10
7
|
messages: MessageResource[];
|
|
11
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<InfiniteData<ApiCollection<MessageResource>,
|
|
8
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@tanstack/query-core").InfiniteData<import("..").ApiCollection<MessageResource>, unknown>, Response>>;
|
|
12
9
|
isRefetching: boolean;
|
|
13
|
-
|
|
14
|
-
hasMoreOlderMessages: boolean;
|
|
15
|
-
fetchNewerMessages: (options?: import("@tanstack/query-core").FetchPreviousPageOptions) => Promise<import("@tanstack/query-core").InfiniteQueryObserverResult<InfiniteData<ApiCollection<MessageResource>, MessagesPageParam>, Response>>;
|
|
16
|
-
hasMoreNewerMessages: boolean;
|
|
17
|
-
isFetchingNewerMessages: boolean;
|
|
18
|
-
cancelFetchNewerMessages: () => Promise<void>;
|
|
10
|
+
fetchNextPage: (options?: import("@tanstack/query-core").FetchNextPageOptions) => Promise<import("@tanstack/query-core").InfiniteQueryObserverResult<import("@tanstack/query-core").InfiniteData<import("..").ApiCollection<MessageResource>, unknown>, Response>>;
|
|
19
11
|
queryKey: import("./use_suspense_api").RequestQueryKey;
|
|
20
12
|
};
|
|
21
|
-
export {};
|
|
22
13
|
//# sourceMappingURL=use_conversation_messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,EAAE,wBAAwB,EAAwB,MAAM,oBAAoB,CAAA;AAEnF,eAAO,MAAM,uBAAuB,GAClC,oCAAoC;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC9F,OAAO,wBAAwB;;;;;;CAoBhC,CAAA"}
|
|
@@ -1,66 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import { useConversationContext } from '../contexts/conversation_context';
|
|
4
|
-
import { anchoredSeedPageParams, newerPageParam, olderPageParam, sortAndFilterMessages, } from '../utils/conversation_messages';
|
|
1
|
+
import { useMemo } from 'react';
|
|
5
2
|
import { getMessagesQueryKey, getMessagesRequestArgs } from '../utils/request/get_messages';
|
|
6
|
-
import {
|
|
7
|
-
import { throwResponseError } from './use_suspense_api';
|
|
3
|
+
import { useSuspensePaginator } from './use_suspense_api';
|
|
8
4
|
export const useConversationMessages = ({ conversation_id, reply_root_id }, opts) => {
|
|
9
|
-
const
|
|
10
|
-
const {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...requestArgs.data,
|
|
17
|
-
...(pageParam.where ? { where: pageParam.where } : {}),
|
|
18
|
-
...(pageParam.order ? { order: pageParam.order } : {}),
|
|
19
|
-
};
|
|
20
|
-
return apiClient.chat
|
|
21
|
-
.get({ url: requestArgs.url, data })
|
|
22
|
-
.catch(throwResponseError);
|
|
23
|
-
};
|
|
24
|
-
const seedPageParams = anchored ? anchoredSeedPageParams(initialMessageId) : [];
|
|
25
|
-
const seedQueries = useSuspenseQueries({
|
|
26
|
-
queries: seedPageParams.map((pageParam, index) => ({
|
|
27
|
-
queryKey: [...queryKey, 'seed', index],
|
|
28
|
-
queryFn: () => fetchPage(pageParam),
|
|
29
|
-
staleTime: Infinity,
|
|
30
|
-
gcTime: 0,
|
|
31
|
-
})),
|
|
32
|
-
});
|
|
33
|
-
const initialData = anchored
|
|
34
|
-
? {
|
|
35
|
-
pages: seedQueries.map(q => q.data),
|
|
36
|
-
pageParams: seedPageParams,
|
|
37
|
-
}
|
|
38
|
-
: undefined;
|
|
39
|
-
const initialPageParam = anchored ? seedPageParams[0] : {};
|
|
40
|
-
const { data, refetch, isRefetching, fetchNextPage, hasNextPage, fetchPreviousPage, hasPreviousPage, isFetchingPreviousPage, } = useSuspenseInfiniteQuery({
|
|
41
|
-
queryKey,
|
|
42
|
-
queryFn: ({ pageParam }) => fetchPage(pageParam),
|
|
43
|
-
initialPageParam,
|
|
44
|
-
initialData,
|
|
45
|
-
getNextPageParam: olderPageParam,
|
|
46
|
-
getPreviousPageParam: anchored ? newerPageParam : () => undefined,
|
|
47
|
-
...(opts || {}),
|
|
48
|
-
...(anchored ? { staleTime: Infinity, refetchOnMount: false } : {}),
|
|
49
|
-
});
|
|
50
|
-
const messages = useMemo(() => sortAndFilterMessages(data.pages), [data.pages]);
|
|
51
|
-
const queryClient = useQueryClient();
|
|
52
|
-
const cancelFetchNewerMessages = useCallback(() => queryClient.cancelQueries({ queryKey }), [queryClient, queryKey]);
|
|
53
|
-
return {
|
|
54
|
-
messages,
|
|
55
|
-
refetch,
|
|
56
|
-
isRefetching,
|
|
57
|
-
fetchOlderMessages: fetchNextPage,
|
|
58
|
-
hasMoreOlderMessages: hasNextPage,
|
|
59
|
-
fetchNewerMessages: fetchPreviousPage,
|
|
60
|
-
hasMoreNewerMessages: hasPreviousPage,
|
|
61
|
-
isFetchingNewerMessages: isFetchingPreviousPage,
|
|
62
|
-
cancelFetchNewerMessages,
|
|
63
|
-
queryKey,
|
|
64
|
-
};
|
|
5
|
+
const { data, refetch, isRefetching, fetchNextPage } = useSuspensePaginator(getMessagesRequestArgs({ conversation_id, reply_root_id }), opts);
|
|
6
|
+
const queryKey = getMessagesQueryKey({ conversation_id, reply_root_id });
|
|
7
|
+
const messages = useMemo(() => data
|
|
8
|
+
.filter(message => (!message.deletedAt || message.replyRootId) &&
|
|
9
|
+
(message.attachments?.length || message.text?.length))
|
|
10
|
+
.sort((a, b) => -a.id.localeCompare(b.id)), [data]);
|
|
11
|
+
return { messages, refetch, isRefetching, fetchNextPage, queryKey };
|
|
65
12
|
};
|
|
66
13
|
//# sourceMappingURL=use_conversation_messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAC3F,OAAO,EAA4B,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEnF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,EAAE,eAAe,EAAE,aAAa,EAA8D,EAC9F,IAA+B,EAC/B,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,oBAAoB,CACzE,sBAAsB,CAAC,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,EAC1D,IAAI,CACL,CAAA;IACD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAA;IACxE,MAAM,QAAQ,GAAG,OAAO,CACtB,GAAG,EAAE,CACH,IAAI;SACD,MAAM,CACL,OAAO,CAAC,EAAE,CACR,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC;QAC3C,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,IAAI,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CACxD;SACA,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAC9C,CAAC,IAAI,CAAC,CACP,CAAA;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAA;AACrE,CAAC,CAAA","sourcesContent":["import { useMemo } from 'react'\nimport { MessageResource } from '../types'\nimport { getMessagesQueryKey, getMessagesRequestArgs } from '../utils/request/get_messages'\nimport { SuspensePaginatorOptions, useSuspensePaginator } from './use_suspense_api'\n\nexport const useConversationMessages = (\n { conversation_id, reply_root_id }: { conversation_id: number; reply_root_id?: string | null },\n opts?: SuspensePaginatorOptions\n) => {\n const { data, refetch, isRefetching, fetchNextPage } = useSuspensePaginator<MessageResource>(\n getMessagesRequestArgs({ conversation_id, reply_root_id }),\n opts\n )\n const queryKey = getMessagesQueryKey({ conversation_id, reply_root_id })\n const messages = useMemo(\n () =>\n data\n .filter(\n message =>\n (!message.deletedAt || message.replyRootId) &&\n (message.attachments?.length || message.text?.length)\n )\n .sort((a, b) => -a.id.localeCompare(b.id)),\n [data]\n )\n\n return { messages, refetch, isRefetching, fetchNextPage, queryKey }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages_jolt_events.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use_conversation_messages_jolt_events.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"AAyBA,UAAU,KAAK;IACb,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,iCAAiC,CAAC,EAAE,cAAc,EAAE,EAAE,KAAK,QA+F1E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { deleteRecordInPagesData } from '../utils';
|
|
3
|
-
import { updateCacheWithMessage, updateCacheWithIndividualMessage, updateCacheWithReaction, getThreadedMessagesQueryKey,
|
|
3
|
+
import { updateCacheWithMessage, updateCacheWithIndividualMessage, updateCacheWithReaction, getThreadedMessagesQueryKey, } from '../utils/cache/messages_cache';
|
|
4
4
|
import { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource';
|
|
5
5
|
import { completeMessageCreationTracking } from '../utils/performance_tracking';
|
|
6
6
|
import { getMessageQueryKey } from '../utils/request/get_message';
|
|
@@ -30,9 +30,9 @@ export function useConversationMessagesJoltEvents({ conversationId }) {
|
|
|
30
30
|
completeMessageCreationTracking({ apiClient, idempotentKey: data.idempotent_key });
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Update the main conversation cache
|
|
34
|
+
updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event);
|
|
35
|
+
// If message has a reply_root_id, also update the threaded cache
|
|
36
36
|
if (data.reply_root_id) {
|
|
37
37
|
const threadedMessagesQueryKey = getThreadedMessagesQueryKey(conversationId, data.reply_root_id);
|
|
38
38
|
updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAQpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EACL,sBAAsB,EACtB,gCAAgC,EAChC,uBAAuB,EACvB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"use_conversation_messages_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,M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,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,uBAAuB,CAAC,CAAA;IAC3E,CAAC,CAAA;IAED,YAAY,CAAC,WAAW,EAAE,iBAAiB,EAAE,2BAA2B,CAAC,CAAA;IACzE,YAAY,CAAC,WAAW,EAAE,iBAAiB,EAAE,2BAA2B,CAAC,CAAA;IACzE,YAAY,CAAC,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,CAAC,CAAA;IACpE,YAAY,CAAC,WAAW,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAA;IAChE,YAAY,CAAC,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,CAAC,CAAA;AAClE,CAAC","sourcesContent":["import { InfiniteData, useQueryClient } from '@tanstack/react-query'\nimport { ApiCollection, MessageResource } from '../types'\nimport { JoltReactionEvent, JoltTypingEvent } from '../types/jolt_events'\nimport {\n MessageCreatedEvent,\n MessageUpdatedEvent,\n MessageDeletedEvent,\n} from '../types/jolt_events/message_events'\nimport { deleteRecordInPagesData } from '../utils'\nimport {\n updateCacheWithMessage,\n updateCacheWithIndividualMessage,\n updateCacheWithReaction,\n getThreadedMessagesQueryKey,\n} from '../utils/cache/messages_cache'\nimport { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'\nimport { completeMessageCreationTracking } from '../utils/performance_tracking'\nimport { getMessageQueryKey } from '../utils/request/get_message'\nimport { getMessagesRequestArgs } from '../utils/request/get_messages'\nimport { useApiClient } from './use_api_client'\nimport { useCurrentPerson } from './use_current_person'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\nimport { getRequestQueryKey } from './use_suspense_api'\nimport { TYPING_TIMEOUT_INTERVAL, useTypingStatusCache } from './use_typing_status_cache'\n\ninterface Props {\n conversationId: number\n}\n\nexport function useConversationMessagesJoltEvents({ conversationId }: Props) {\n const queryClient = useQueryClient()\n const currentPerson = useCurrentPerson()\n const joltChannel = useJoltChannel(`chat.conversations.${conversationId}`)\n const messagesRequestArgs = getMessagesRequestArgs({ conversation_id: conversationId })\n const messagesQueryKey = getRequestQueryKey(messagesRequestArgs)\n const apiClient = useApiClient()\n\n const { addTypingEvent, removeTypingEventById, removeAllTypingEventsByAuthorId } =\n useTypingStatusCache(conversationId)\n\n const handleMessageUpdateOrCreate = async (e: MessageCreatedEvent | MessageUpdatedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n if (e.event === 'message.created' && data.author_id) {\n removeAllTypingEventsByAuthorId(data.author_id)\n if (data.idempotent_key && data.author_id === currentPerson.id) {\n completeMessageCreationTracking({ apiClient, idempotentKey: data.idempotent_key })\n }\n }\n\n // Update the main conversation cache\n updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)\n\n // If message has a reply_root_id, also update the threaded cache\n if (data.reply_root_id) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(\n conversationId,\n data.reply_root_id\n )\n updateCacheWithMessage(queryClient, threadedMessagesQueryKey, message, e.event)\n }\n\n // Update individual message query cache so reply shadow messages update immediately\n if (e.event === 'message.updated') {\n const individualMessageQueryKey = getMessageQueryKey({\n conversation_id: conversationId,\n messageId: data.sort_key,\n })\n updateCacheWithIndividualMessage(queryClient, individualMessageQueryKey, message)\n }\n }\n\n const handleMessageDeleted = async (e: MessageDeletedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n // Update the main conversation cache\n queryClient.setQueryData<QueryData>(messagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n\n // If message has a reply_root_id, also update the threaded cache\n if (data.reply_root_id) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(\n conversationId,\n data.reply_root_id\n )\n queryClient.setQueryData<QueryData>(threadedMessagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n }\n }\n\n const handleReactionJoltEvent = async (e: JoltReactionEvent) => {\n // Update the main conversation cache and capture the reply_root_id if present\n updateCacheWithReaction(queryClient, messagesQueryKey, e, currentPerson.id)\n\n const replyRootId = e.data.data.reply_root_id\n\n // If the message has a reply_root_id, also update the threaded cache\n if (replyRootId) {\n const threadedMessagesQueryKey = getThreadedMessagesQueryKey(conversationId, replyRootId)\n updateCacheWithReaction(queryClient, threadedMessagesQueryKey, e, currentPerson.id)\n }\n }\n\n const handleTypingEvent = async (e: JoltTypingEvent) => {\n const { data } = e.data\n addTypingEvent(data)\n setTimeout(() => removeTypingEventById(data.id), TYPING_TIMEOUT_INTERVAL)\n }\n\n useJoltEvent(joltChannel, 'message.created', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.updated', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.destroyed', handleMessageDeleted)\n useJoltEvent(joltChannel, 'reaction.*', handleReactionJoltEvent)\n useJoltEvent(joltChannel, 'typing.broadcast', handleTypingEvent)\n}\n\ntype QueryData = InfiniteData<ApiCollection<MessageResource>>\n"]}
|
|
@@ -149,11 +149,6 @@ export declare const useConversationsMute: ({ conversation }: {
|
|
|
149
149
|
muted: boolean;
|
|
150
150
|
setMuted: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
151
151
|
};
|
|
152
|
-
export declare const useConversationsMarkReadUpTo: ({ conversationId }: {
|
|
153
|
-
conversationId: number;
|
|
154
|
-
}) => import("@tanstack/react-query").UseMutationResult<import("..").ApiCollection | ApiResource, Error, {
|
|
155
|
-
sortKey: string;
|
|
156
|
-
}, unknown>;
|
|
157
152
|
export declare const useMarkAllRead: () => {
|
|
158
153
|
data: undefined;
|
|
159
154
|
variables: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversations_actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversations_actions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAK5D,eAAO,MAAM,wBAAwB,GAAI,mBAEtC;IACD,YAAY,EAAE,oBAAoB,CAAA;CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CA,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,kBAAkB;IAAE,YAAY,EAAE,oBAAoB,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC5F,CAAA;AAED,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"use_conversations_actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversations_actions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAK5D,eAAO,MAAM,wBAAwB,GAAI,mBAEtC;IACD,YAAY,EAAE,oBAAoB,CAAA;CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CA,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,kBAAkB;IAAE,YAAY,EAAE,oBAAoB,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC5F,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsB1B,CAAA"}
|
|
@@ -83,18 +83,6 @@ export const useConversationsMute = ({ conversation }) => {
|
|
|
83
83
|
...mutation,
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
-
export const useConversationsMarkReadUpTo = ({ conversationId }) => {
|
|
87
|
-
const apiClient = useApiClient();
|
|
88
|
-
return useMutation({
|
|
89
|
-
mutationKey: ['markReadUpTo', conversationId],
|
|
90
|
-
mutationFn: async ({ sortKey }) => apiClient.chat.post({
|
|
91
|
-
url: `/me/conversations/${conversationId}/mark_read_up_to`,
|
|
92
|
-
data: {
|
|
93
|
-
data: { type: 'Conversation', attributes: { sort_key: sortKey } },
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
86
|
export const useMarkAllRead = () => {
|
|
99
87
|
const apiClient = useApiClient();
|
|
100
88
|
const { args } = useConversationsContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversations_actions.js","sourceRoot":"","sources":["../../src/hooks/use_conversations_actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,YAAY,GAGb,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,kBAAkB,GAAG,qBAAqB,EAAE,CAAA;IAClD,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;IAEvE,SAAS,uBAAuB,CAAC,IAAa;QAC5C,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE;YACrC,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAA;YACxC,MAAM,aAAa,GAAG,IAAI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Q,CAAC,IAAI,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,iEAAiE,CAAC,CAAA;YACtF,UAAU,EAAE,CAAA;QACd,CAAC;KACF,CAAC,CAAA;IAEF,OAAO;QACL,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,eAAe;QAC1C,QAAQ;QACR,GAAG,QAAQ;KACZ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;IAC7D,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,GAAG,WAAW,CAAC;QACpD,QAAQ,EAAE,GAAG,EAAE;YACb,SAAS,CAAC;gBACR,WAAW,EAAE,CAAC;aACf,CAAC,CAAA;QACJ,CAAC;QACD,WAAW,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC;QAClC,UAAU,EAAE,GAAG,EAAE,CACf,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;YAClB,GAAG,EAAE,mBAAmB;SACzB,CAAC;QACJ,SAAS,EAAE,UAAU;KACtB,CAAC,CAAA;IAEF,OAAO;QACL,WAAW;QACX,GAAG,KAAK;KACT,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { useMutation } from '@tanstack/react-query'\nimport { Alert } from 'react-native'\nimport { useConversationsContext } from '../contexts/conversations_context'\nimport { ApiResource, ConversationResource } from '../types'\nimport { useApiClient } from './use_api_client'\nimport { useConversationsCache } from './use_conversations_cache'\nimport { useCurrentPersonCache } from './use_current_person'\n\nexport const useConversationsMarkRead = ({\n conversation,\n}: {\n conversation: ConversationResource\n}) => {\n const apiClient = useApiClient()\n const { args } = useConversationsContext()\n const currentPersonCache = useCurrentPersonCache()\n const { update, invalidate, fetchUpdate } = useConversationsCache(args)\n\n function handlePersonUnreadCount(read: boolean) {\n currentPersonCache.update({}, person => {\n const currentUnread = person.unreadCount\n const updatedUnread = read ? Math.max(currentUnread - 1, 0) : currentUnread + 1\n return { ...person, unreadCount: updatedUnread, unreadReactionCount: 0 }\n })\n }\n\n const { mutate: handleMarkRead, ...mutation } = useMutation({\n onMutate: async (read: boolean) => {\n update({\n ...conversation,\n unreadCount: read ? 0 : 1,\n })\n handlePersonUnreadCount(read)\n },\n mutationKey: ['markRead', conversation.id],\n mutationFn: async (read: boolean) => {\n const action = read ? 'mark_read' : 'mark_unread'\n\n return apiClient.chat.post({\n url: `/me/conversations/${conversation.id}/${action}`,\n data: { data: { type: '', attributes: {} }, fields: { Conversation: 'unread_count,id' } },\n })\n },\n onSuccess: () => {\n fetchUpdate(conversation)\n },\n onError: () => {\n Alert.alert('Oops', 'Something went wrong updating this conversation, please try again')\n invalidate()\n },\n })\n\n return {\n read: conversation.unreadCount < 1, // prefer cache\n markRead: handleMarkRead,\n ...mutation,\n }\n}\n\nexport const useConversationsMute = ({ conversation }: { conversation: ConversationResource }) => {\n const apiClient = useApiClient()\n const { args } = useConversationsContext()\n const { update, invalidate } = useConversationsCache(args)\n\n const { mutate: setMuted, ...mutation } = useMutation({\n onMutate: async (muted: boolean) => {\n update({\n ...conversation,\n muted,\n conversationMembership: {\n ...conversation?.conversationMembership,\n muted,\n },\n })\n },\n mutationKey: ['muteConversation'],\n mutationFn: async (muted: boolean) => {\n const action = muted ? 'mute' : 'unmute'\n\n return apiClient.chat.post<ApiResource<ConversationResource>>({\n url: `/me/conversations/${conversation.id}/${action}`,\n data: { data: { type: '', attributes: {} }, fields: { Conversation: 'muted' } },\n })\n },\n onSuccess: (response: ApiResource<ConversationResource>) => {\n update(response.data)\n },\n onError: () => {\n Alert.alert('Oops', 'Something went wrong muting this conversation, please try again')\n invalidate()\n },\n })\n\n return {\n muted: conversation.muted, // prefer cache\n setMuted,\n ...mutation,\n }\n}\n\nexport const useMarkAllRead = () => {\n const apiClient = useApiClient()\n const { args } = useConversationsContext()\n const { invalidate, updateAll } = useConversationsCache(args)\n const { mutate: markAllRead, ...query } = useMutation({\n onMutate: () => {\n updateAll({\n unreadCount: 0,\n })\n },\n mutationKey: ['markAllRead', args],\n mutationFn: () =>\n apiClient.chat.post({\n url: '/me/mark_all_read',\n }),\n onSettled: invalidate,\n })\n\n return {\n markAllRead,\n ...query,\n }\n}\n"]}
|
|
@@ -9,9 +9,7 @@ export declare const availableFeatures: {
|
|
|
9
9
|
readonly message_reporting: "ROLLOUT_MOBILE_message_reporting";
|
|
10
10
|
readonly granular_notifications_ui: "ROLLOUT_granular_notification_preferences_ui";
|
|
11
11
|
readonly custom_conversation_avatars: "ROLLOUT_custom_conversation_avatars";
|
|
12
|
-
readonly jump_to_unread: "ROLLOUT_jump_to_unread";
|
|
13
12
|
readonly conversation_safety_lock: "ROLLOUT_conversation_safety_lock";
|
|
14
|
-
readonly video_moderation: "ROLLOUT_MOBILE_video_moderation";
|
|
15
13
|
};
|
|
16
14
|
export {};
|
|
17
15
|
//# sourceMappingURL=use_features.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_features.d.ts","sourceRoot":"","sources":["../../src/hooks/use_features.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAI1E,KAAK,WAAW,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAA;AAE7E,wBAAgB,WAAW;;kCAiBT,WAAW;EAS5B;AAED,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"use_features.d.ts","sourceRoot":"","sources":["../../src/hooks/use_features.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAI1E,KAAK,WAAW,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAA;AAE7E,wBAAgB,WAAW;;kCAiBT,WAAW;EAS5B;AAED,eAAO,MAAM,iBAAiB;;;;;;CAM0B,CAAA"}
|
|
@@ -26,9 +26,7 @@ export const availableFeatures = {
|
|
|
26
26
|
message_reporting: 'ROLLOUT_MOBILE_message_reporting',
|
|
27
27
|
granular_notifications_ui: 'ROLLOUT_granular_notification_preferences_ui',
|
|
28
28
|
custom_conversation_avatars: 'ROLLOUT_custom_conversation_avatars',
|
|
29
|
-
jump_to_unread: 'ROLLOUT_jump_to_unread',
|
|
30
29
|
conversation_safety_lock: 'ROLLOUT_conversation_safety_lock',
|
|
31
|
-
video_moderation: 'ROLLOUT_MOBILE_video_moderation',
|
|
32
30
|
};
|
|
33
31
|
const stableEmptyFeatures = {
|
|
34
32
|
data: [],
|