@planningcenter/chat-react-native 3.35.0-rc.3 → 3.35.0-rc.5
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/README.md +1 -1
- package/build/components/conversation/jump_to_bottom_button.d.ts +2 -1
- package/build/components/conversation/jump_to_bottom_button.d.ts.map +1 -1
- package/build/components/conversation/jump_to_bottom_button.js +39 -7
- package/build/components/conversation/jump_to_bottom_button.js.map +1 -1
- package/build/components/conversation/reply_shadow_message.d.ts +1 -2
- 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/conversation/unread_divider.d.ts +6 -0
- package/build/components/conversation/unread_divider.d.ts.map +1 -0
- package/build/components/conversation/unread_divider.js +59 -0
- package/build/components/conversation/unread_divider.js.map +1 -0
- package/build/contexts/conversation_context.d.ts +2 -0
- package/build/contexts/conversation_context.d.ts.map +1 -1
- package/build/contexts/conversation_context.js +13 -5
- package/build/contexts/conversation_context.js.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts +2 -0
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +9 -5
- 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 +5 -0
- package/build/hooks/use_conversations_actions.d.ts.map +1 -1
- package/build/hooks/use_conversations_actions.js +12 -0
- package/build/hooks/use_conversations_actions.js.map +1 -1
- package/build/hooks/use_flat_list_viewability.d.ts +20 -0
- package/build/hooks/use_flat_list_viewability.d.ts.map +1 -0
- package/build/hooks/use_flat_list_viewability.js +30 -0
- package/build/hooks/use_flat_list_viewability.js.map +1 -0
- package/build/hooks/use_jump_to_bottom_action.d.ts +9 -0
- package/build/hooks/use_jump_to_bottom_action.d.ts.map +1 -0
- package/build/hooks/use_jump_to_bottom_action.js +62 -0
- package/build/hooks/use_jump_to_bottom_action.js.map +1 -0
- package/build/hooks/use_jump_to_unread_anchor.d.ts +20 -0
- package/build/hooks/use_jump_to_unread_anchor.d.ts.map +1 -0
- package/build/hooks/use_jump_to_unread_anchor.js +53 -0
- package/build/hooks/use_jump_to_unread_anchor.js.map +1 -0
- package/build/hooks/use_jump_to_unread_gates.d.ts +5 -0
- package/build/hooks/use_jump_to_unread_gates.d.ts.map +1 -0
- package/build/hooks/use_jump_to_unread_gates.js +10 -0
- package/build/hooks/use_jump_to_unread_gates.js.map +1 -0
- 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 +17 -1
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_scroll_tracking.d.ts +13 -0
- package/build/hooks/use_scroll_tracking.d.ts.map +1 -0
- package/build/hooks/use_scroll_tracking.js +45 -0
- package/build/hooks/use_scroll_tracking.js.map +1 -0
- package/build/hooks/use_track_highest_seen_message.d.ts +4 -0
- package/build/hooks/use_track_highest_seen_message.d.ts.map +1 -0
- package/build/hooks/use_track_highest_seen_message.js +35 -0
- package/build/hooks/use_track_highest_seen_message.js.map +1 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +87 -44
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/group_notification_settings_screen.d.ts.map +1 -1
- package/build/screens/group_notification_settings_screen.js +6 -3
- package/build/screens/group_notification_settings_screen.js.map +1 -1
- package/build/screens/notification_settings_screen.js +2 -2
- package/build/screens/notification_settings_screen.js.map +1 -1
- package/build/screens/preferred_app_selection_screen.js +3 -3
- package/build/screens/preferred_app_selection_screen.js.map +1 -1
- package/build/utils/cache/messages_cache.d.ts +1 -0
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +4 -0
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/group_messages.d.ts +9 -2
- package/build/utils/group_messages.d.ts.map +1 -1
- package/build/utils/group_messages.js +20 -1
- package/build/utils/group_messages.js.map +1 -1
- package/build/utils/highest_seen_tracker.d.ts +12 -0
- package/build/utils/highest_seen_tracker.d.ts.map +1 -0
- package/build/utils/highest_seen_tracker.js +37 -0
- package/build/utils/highest_seen_tracker.js.map +1 -0
- package/build/utils/message_viewability.d.ts +24 -0
- package/build/utils/message_viewability.d.ts.map +1 -0
- package/build/utils/message_viewability.js +29 -0
- package/build/utils/message_viewability.js.map +1 -0
- package/build/utils/unread_divider_helpers.d.ts +18 -0
- package/build/utils/unread_divider_helpers.d.ts.map +1 -0
- package/build/utils/unread_divider_helpers.js +13 -0
- package/build/utils/unread_divider_helpers.js.map +1 -0
- package/package.json +10 -4
- package/src/__tests__/contexts/session_context.tsx +1 -1
- package/src/__tests__/hooks/use_async_storage.test.tsx +1 -1
- package/src/__tests__/hooks/use_attachment_uploader.test.tsx +1 -1
- package/src/__tests__/hooks/use_chat_configuration.test.tsx +1 -1
- package/src/__tests__/hooks/use_conversation_messages.test.tsx +1 -1
- package/src/__tests__/hooks/use_mark_latest_message_read.test.tsx +154 -0
- package/src/__tests__/utils/cache/messages_cache.test.ts +54 -0
- package/src/components/conversation/jump_to_bottom_button.tsx +57 -8
- package/src/components/conversation/reply_shadow_message.tsx +4 -2
- package/src/components/conversation/unread_divider.tsx +90 -0
- package/src/contexts/conversation_context.tsx +15 -13
- package/src/hooks/use_conversation_messages.ts +19 -3
- package/src/hooks/use_conversation_messages_jolt_events.ts +4 -3
- package/src/hooks/use_conversations_actions.ts +15 -0
- package/src/hooks/use_flat_list_viewability.ts +50 -0
- package/src/hooks/use_jump_to_bottom_action.ts +75 -0
- package/src/hooks/use_jump_to_unread_anchor.ts +68 -0
- package/src/hooks/use_jump_to_unread_gates.ts +10 -0
- package/src/hooks/use_mark_latest_message_read.ts +16 -2
- package/src/hooks/use_scroll_tracking.ts +64 -0
- package/src/hooks/use_track_highest_seen_message.ts +43 -0
- package/src/screens/conversation_screen.tsx +173 -70
- package/src/screens/group_notification_settings_screen.tsx +6 -3
- package/src/screens/notification_settings_screen.tsx +2 -2
- package/src/screens/preferred_app_selection_screen.tsx +3 -3
- package/src/utils/__tests__/group_messages.test.ts +71 -0
- package/src/utils/__tests__/highest_seen_tracker.test.ts +82 -0
- package/src/utils/__tests__/message_viewability.test.ts +168 -0
- package/src/utils/__tests__/unread_divider_helpers.test.ts +85 -0
- package/src/utils/cache/messages_cache.ts +5 -0
- package/src/utils/group_messages.ts +42 -2
- package/src/utils/highest_seen_tracker.ts +42 -0
- package/src/utils/message_viewability.ts +49 -0
- package/src/utils/unread_divider_helpers.ts +25 -0
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
interface JumpToBottomButtonProps {
|
|
2
2
|
onPress: () => void;
|
|
3
3
|
visible: boolean;
|
|
4
|
+
loading?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare const JumpToBottomButton: ({ onPress, visible }: JumpToBottomButtonProps) => import("react").JSX.Element;
|
|
6
|
+
export declare const JumpToBottomButton: ({ onPress, visible, loading, }: JumpToBottomButtonProps) => import("react").JSX.Element;
|
|
6
7
|
export {};
|
|
7
8
|
//# sourceMappingURL=jump_to_bottom_button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jump_to_bottom_button.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/jump_to_bottom_button.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jump_to_bottom_button.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/jump_to_bottom_button.tsx"],"names":[],"mappings":"AAeA,UAAU,uBAAuB;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,kBAAkB,GAAI,gCAIhC,uBAAuB,gCAqEzB,CAAA"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import Animated, {
|
|
2
|
+
import { ActivityIndicator, Pressable, StyleSheet, View } from 'react-native';
|
|
3
|
+
import Animated, { Extrapolation, interpolate, ReduceMotion, useAnimatedStyle, useSharedValue, withSpring, withTiming, } from 'react-native-reanimated';
|
|
4
4
|
import { useTheme } from '../../hooks';
|
|
5
5
|
import { platformFontWeightMedium } from '../../utils';
|
|
6
6
|
import { Icon, Text } from '../display';
|
|
7
|
-
export const JumpToBottomButton = ({ onPress, visible }) => {
|
|
7
|
+
export const JumpToBottomButton = ({ onPress, visible, loading = false, }) => {
|
|
8
8
|
const styles = useStyles();
|
|
9
9
|
const progress = useSharedValue(0);
|
|
10
|
+
const loadingProgress = useSharedValue(0);
|
|
10
11
|
useEffect(() => {
|
|
11
12
|
progress.value = withSpring(visible ? 1 : 0, {
|
|
12
13
|
mass: 1,
|
|
@@ -16,6 +17,12 @@ export const JumpToBottomButton = ({ onPress, visible }) => {
|
|
|
16
17
|
reduceMotion: ReduceMotion.System,
|
|
17
18
|
});
|
|
18
19
|
}, [visible, progress]);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
loadingProgress.value = withTiming(loading ? 1 : 0, {
|
|
22
|
+
duration: 750,
|
|
23
|
+
reduceMotion: ReduceMotion.System,
|
|
24
|
+
});
|
|
25
|
+
}, [loading, loadingProgress]);
|
|
19
26
|
const animatedStyle = useAnimatedStyle(() => {
|
|
20
27
|
return {
|
|
21
28
|
opacity: progress.value,
|
|
@@ -29,17 +36,27 @@ export const JumpToBottomButton = ({ onPress, visible }) => {
|
|
|
29
36
|
],
|
|
30
37
|
};
|
|
31
38
|
});
|
|
39
|
+
const iconStyle = useAnimatedStyle(() => ({ opacity: 1 - loadingProgress.value }));
|
|
40
|
+
const spinnerStyle = useAnimatedStyle(() => ({ opacity: loadingProgress.value }));
|
|
32
41
|
return (<View>
|
|
33
|
-
<Animated.View style={[styles.container, animatedStyle]}>
|
|
34
|
-
<Pressable onPress={onPress} style={({ pressed }) => [styles.button, pressed && styles.pressed]}>
|
|
35
|
-
<
|
|
42
|
+
<Animated.View style={[styles.container, animatedStyle]} pointerEvents={visible ? 'auto' : 'none'}>
|
|
43
|
+
<Pressable onPress={onPress} disabled={loading} accessibilityRole="button" accessibilityLabel="Jump to most recent message" accessibilityState={{ busy: loading }} hitSlop={hitSlop} style={({ pressed }) => [styles.button, pressed && styles.pressed]}>
|
|
44
|
+
<View style={styles.glyph}>
|
|
45
|
+
<Animated.View style={[styles.glyphLayer, iconStyle]}>
|
|
46
|
+
<Icon name="general.downArrow" style={styles.icon}/>
|
|
47
|
+
</Animated.View>
|
|
48
|
+
<Animated.View style={[styles.glyphLayer, spinnerStyle]}>
|
|
49
|
+
<ActivityIndicator size="small" color={styles.icon.color} style={styles.spinner}/>
|
|
50
|
+
</Animated.View>
|
|
51
|
+
</View>
|
|
36
52
|
<Text variant="tertiary" style={styles.text}>
|
|
37
|
-
Jump to bottom
|
|
53
|
+
{loading ? 'Jumping to latest…' : 'Jump to bottom'}
|
|
38
54
|
</Text>
|
|
39
55
|
</Pressable>
|
|
40
56
|
</Animated.View>
|
|
41
57
|
</View>);
|
|
42
58
|
};
|
|
59
|
+
const hitSlop = { top: 12, bottom: 12, left: 12, right: 12 };
|
|
43
60
|
const useStyles = () => {
|
|
44
61
|
const { colors } = useTheme();
|
|
45
62
|
return StyleSheet.create({
|
|
@@ -70,10 +87,25 @@ const useStyles = () => {
|
|
|
70
87
|
color: colors.fillColorNeutral100Inverted,
|
|
71
88
|
fontWeight: platformFontWeightMedium,
|
|
72
89
|
},
|
|
90
|
+
glyph: {
|
|
91
|
+
width: 14,
|
|
92
|
+
height: 14,
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
justifyContent: 'center',
|
|
95
|
+
},
|
|
96
|
+
glyphLayer: {
|
|
97
|
+
position: 'absolute',
|
|
98
|
+
alignItems: 'center',
|
|
99
|
+
justifyContent: 'center',
|
|
100
|
+
},
|
|
73
101
|
icon: {
|
|
74
102
|
color: colors.fillColorNeutral100Inverted,
|
|
75
103
|
fontSize: 14,
|
|
76
104
|
},
|
|
105
|
+
spinner: {
|
|
106
|
+
width: 14,
|
|
107
|
+
height: 14,
|
|
108
|
+
},
|
|
77
109
|
pressed: {
|
|
78
110
|
transform: [{ scale: 0.95 }],
|
|
79
111
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jump_to_bottom_button.js","sourceRoot":"","sources":["../../../src/components/conversation/jump_to_bottom_button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"jump_to_bottom_button.js","sourceRoot":"","sources":["../../../src/components/conversation/jump_to_bottom_button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC7E,OAAO,QAAQ,EAAE,EACf,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,UAAU,GACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAQvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,OAAO,EACP,OAAO,EACP,OAAO,GAAG,KAAK,GACS,EAAE,EAAE;IAC5B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,QAAQ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gBACR,MAAM,EAAE,CAAC;aACV;YACD,aAAa,EAAE,IAAI;YACnB,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,CAAC;SACb;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,MAAM,CAAC,2BAA2B;YACzC,UAAU,EAAE,wBAAwB;SACrC;QACD,KAAK,EAAE;YACL,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;SACzB;QACD,UAAU,EAAE;YACV,QAAQ,EAAE,UAAU;YACpB,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;SACzB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,MAAM,CAAC,2BAA2B;YACzC,QAAQ,EAAE,EAAE;SACb;QACD,OAAO,EAAE;YACP,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;SACX;QACD,OAAO,EAAE;YACP,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAC7B;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { useEffect } from 'react'\nimport { ActivityIndicator, Pressable, StyleSheet, View } from 'react-native'\nimport Animated, {\n Extrapolation,\n interpolate,\n ReduceMotion,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n withTiming,\n} from 'react-native-reanimated'\nimport { useTheme } from '../../hooks'\nimport { platformFontWeightMedium } from '../../utils'\nimport { Icon, Text } from '../display'\n\ninterface JumpToBottomButtonProps {\n onPress: () => void\n visible: boolean\n loading?: boolean\n}\n\nexport const JumpToBottomButton = ({\n onPress,\n visible,\n loading = false,\n}: JumpToBottomButtonProps) => {\n const styles = useStyles()\n const progress = useSharedValue(0)\n const loadingProgress = useSharedValue(0)\n\n useEffect(() => {\n progress.value = withSpring(visible ? 1 : 0, {\n mass: 1,\n damping: 16,\n stiffness: 170,\n overshootClamping: false,\n reduceMotion: ReduceMotion.System,\n })\n }, [visible, progress])\n\n useEffect(() => {\n loadingProgress.value = withTiming(loading ? 1 : 0, {\n duration: 750,\n reduceMotion: ReduceMotion.System,\n })\n }, [loading, loadingProgress])\n\n const animatedStyle = useAnimatedStyle(() => {\n return {\n opacity: progress.value,\n transform: [\n {\n translateY: interpolate(progress.value, [0, 1], [12, 0], Extrapolation.CLAMP),\n },\n {\n scale: interpolate(progress.value, [0, 1], [0.9, 1], Extrapolation.CLAMP),\n },\n ],\n }\n })\n\n const iconStyle = useAnimatedStyle(() => ({ opacity: 1 - loadingProgress.value }))\n const spinnerStyle = useAnimatedStyle(() => ({ opacity: loadingProgress.value }))\n\n return (\n <View>\n <Animated.View\n style={[styles.container, animatedStyle]}\n pointerEvents={visible ? 'auto' : 'none'}\n >\n <Pressable\n onPress={onPress}\n disabled={loading}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Jump to most recent message\"\n accessibilityState={{ busy: loading }}\n hitSlop={hitSlop}\n style={({ pressed }) => [styles.button, pressed && styles.pressed]}\n >\n <View style={styles.glyph}>\n <Animated.View style={[styles.glyphLayer, iconStyle]}>\n <Icon name=\"general.downArrow\" style={styles.icon} />\n </Animated.View>\n <Animated.View style={[styles.glyphLayer, spinnerStyle]}>\n <ActivityIndicator size=\"small\" color={styles.icon.color} style={styles.spinner} />\n </Animated.View>\n </View>\n <Text variant=\"tertiary\" style={styles.text}>\n {loading ? 'Jumping to latest…' : 'Jump to bottom'}\n </Text>\n </Pressable>\n </Animated.View>\n </View>\n )\n}\n\nconst hitSlop = { top: 12, bottom: 12, left: 12, right: 12 }\n\nconst useStyles = () => {\n const { colors } = useTheme()\n\n return StyleSheet.create({\n container: {\n alignSelf: 'center',\n position: 'absolute',\n bottom: 16,\n zIndex: 2,\n },\n button: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: 6,\n paddingHorizontal: 12,\n paddingVertical: 6,\n borderRadius: 20,\n backgroundColor: colors.fillColorNeutral020,\n shadowColor: colors.fillColorNeutral000,\n shadowOffset: {\n width: 0,\n height: 1,\n },\n shadowOpacity: 0.25,\n shadowRadius: 2.84,\n elevation: 5,\n },\n text: {\n color: colors.fillColorNeutral100Inverted,\n fontWeight: platformFontWeightMedium,\n },\n glyph: {\n width: 14,\n height: 14,\n alignItems: 'center',\n justifyContent: 'center',\n },\n glyphLayer: {\n position: 'absolute',\n alignItems: 'center',\n justifyContent: 'center',\n },\n icon: {\n color: colors.fillColorNeutral100Inverted,\n fontSize: 14,\n },\n spinner: {\n width: 14,\n height: 14,\n },\n pressed: {\n transform: [{ scale: 0.95 }],\n },\n })\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reply_shadow_message.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/reply_shadow_message.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"reply_shadow_message.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/reply_shadow_message.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AA4BzB,UAAU,uBAAuB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,OAAO,CAAA;IAC7B,iBAAiB,EAAE,OAAO,CAAA;CAC3B;AAED,wBAAgB,kBAAkB,CAAC,EACjC,eAAe,EACf,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,iBAAiB,GAClB,EAAE,uBAAuB,4BAczB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reply_shadow_message.js","sourceRoot":"","sources":["../../../src/components/conversation/reply_shadow_message.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS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AAC,CAAC,YAAY;SACjD;QACD,cAAc,EAAE;YACd,KAAK,EAAE,MAAM,CAAC,WAAW;YACzB,UAAU,EAAE,wBAAwB;SACrC;QACD,YAAY,EAAE;YACZ,KAAK,EAAE,EAAE,GAAG,SAAS;YACrB,WAAW,EAAE,UAAU,GAAG,WAAW;YACrC,OAAO,EAAE,GAAG;SACb;QACD,KAAK,EAAE;YACL,YAAY,EAAE,CAAC;SAChB;QACD,cAAc,EAAE;YACd,KAAK,EAAE,MAAM,CAAC,mBAAmB;YACjC,QAAQ,EAAE,EAAE;SACb;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport { some } from 'lodash'\nimport React from 'react'\nimport { Pressable, StyleSheet, useWindowDimensions, View } from 'react-native'\nimport Animated from 'react-native-reanimated'\nimport {\n useAnimatedMessageBackgroundColor,\n useFontScale,\n useScalableNumberOfLines,\n useTheme,\n} from '../../hooks'\nimport { useConversationMessage } from '../../hooks/use_conversation_message'\nimport { useLiveRelativeTime } from '../../hooks/use_live_relative_time'\nimport { MessageResource } from '../../types'\nimport {\n DenormalizedAttachmentResource,\n DenormalizedGiphyAttachmentResource,\n DenormalizedExpandedLinkAttachmentResource,\n DenormalizedMessageAttachmentResource,\n} from '../../types/resources/denormalized_attachment_resource'\nimport { assertKeysAreNumbers, pluralize } from '../../utils'\nimport {\n CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,\n MAX_FONT_SIZE_MULTIPLIER,\n MESSAGE_AUTHOR_AVATAR_COLUMN_WIDTH,\n platformFontWeightMedium,\n} from '../../utils/styles'\nimport { Avatar, Icon, IconProps, Image, Text } from '../display'\nimport { TheirReplyConnector, MyReplyConnector } from './reply_connectors'\n\ninterface ReplyShadowMessageProps extends MessageResource {\n messageId: string\n conversation_id: number\n inReplyScreen?: boolean\n isReplyShadowMessage: boolean\n nextRendersAuthor: boolean\n}\n\nexport function ReplyShadowMessage({\n conversation_id,\n inReplyScreen,\n messageId,\n isReplyShadowMessage,\n nextRendersAuthor,\n}: ReplyShadowMessageProps) {\n const { message, isError, isLoading } = useConversationMessage({ conversation_id, messageId })\n\n if (inReplyScreen) return null\n if (isLoading) return <ShadowMessageFallback text=\"Loading...\" />\n if (isError || !message) return <ShadowMessageFallback text=\"Message deleted\" />\n\n const enrichedMessage = {\n ...message,\n isReplyShadowMessage,\n nextRendersAuthor,\n }\n\n return <ShadowMessageContent conversation_id={conversation_id} {...enrichedMessage} />\n}\n\ninterface ShadowMessageContentProps extends MessageResource {\n conversation_id: number\n}\n\nfunction ShadowMessageContent({ conversation_id, ...message }: ShadowMessageContentProps) {\n const { text, deletedAt, author, attachments } = message\n const styles = useStyles(message)\n const { colors } = useTheme()\n const navigation = useNavigation()\n const timestamp = useLiveRelativeTime(message.createdAt)\n\n const [messageBubbleHeight, setMessageBubbleHeight] = React.useState(0)\n const { animatedBackgroundColor, handleMessagePressIn, handleMessagePressOut } =\n useAnimatedMessageBackgroundColor()\n const scalableNumberOfLines = useScalableNumberOfLines(2)\n const replyCountText = pluralize(message.replyCount, 'reply')\n const isDeleted = !!deletedAt\n const messageText = isDeleted ? 'Message deleted' : text\n\n const handleNavigateToReplies = () => {\n navigation.navigate('ConversationReply', {\n conversation_id,\n reply_root_id: message.replyRootId,\n reply_root_author_name: message.author.name,\n })\n }\n\n const attachmentLabel = some(attachments) ? pluralize(attachments.length, 'attachment') : ''\n const accessibilityLabel = `${author?.name || ''} Reply Preview ${attachmentLabel} ${messageText || ''} ${timestamp} ${replyCountText}`\n\n return (\n <Pressable\n android_ripple={{ color: colors.androidRippleNeutral }}\n onPress={handleNavigateToReplies}\n onPressIn={handleMessagePressIn}\n onPressOut={handleMessagePressOut}\n accessibilityLabel={accessibilityLabel}\n accessibilityHint=\"Navigate to reply screen for this message\"\n accessibilityRole=\"link\"\n >\n <Animated.View style={[styles.message, animatedBackgroundColor]}>\n {!message.mine && (\n <View>\n <View style={[styles.avatarWrapper, !isDeleted && styles.avatarOpacity]}>\n <Avatar\n size=\"xs\"\n sourceUri={message.author.avatar}\n style={styles.avatar}\n maxFontSizeMultiplier={1}\n fallbackIconName={isDeleted ? 'publishing.trash' : 'general.person'}\n showFallback={isDeleted}\n />\n </View>\n <TheirReplyConnector message={message} messageBubbleHeight={messageBubbleHeight} />\n </View>\n )}\n <View style={styles.messageContent}>\n <View\n style={styles.messageBubble}\n onLayout={e => setMessageBubbleHeight(e.nativeEvent.layout.height)}\n >\n <MessageAttachmentImagery attachments={attachments} />\n {text && (\n <Text\n variant=\"footnote\"\n style={styles.messageText}\n numberOfLines={scalableNumberOfLines}\n >\n {messageText}\n </Text>\n )}\n </View>\n <View style={styles.messageMeta}>\n <Text variant=\"footnote\" style={styles.replyCountText}>\n {replyCountText}\n </Text>\n </View>\n </View>\n {message.mine && (\n <MyReplyConnector message={message} messageBubbleHeight={messageBubbleHeight} />\n )}\n </Animated.View>\n </Pressable>\n )\n}\n\nfunction MessageAttachmentImagery({\n attachments,\n}: {\n attachments: DenormalizedAttachmentResource[]\n}) {\n if (!attachments || attachments.length === 0) return null\n\n const attachment = attachments[0]\n\n if (attachment.type === 'giphy') {\n return <GiphyImage attachment={attachment} />\n }\n if (attachment.type === 'ExpandedLink') {\n return <ExpandedLinkImage attachment={attachment} />\n }\n if (attachment.type === 'MessageAttachment') {\n const contentType = attachment.attributes?.contentType\n const basicType = contentType?.split('/')[0]\n\n switch (basicType) {\n case 'image':\n return <MessageAttachmentImage attachment={attachment} />\n case 'video':\n return <MessageAttachmentIcon iconName=\"general.outlinedVideoFile\" />\n case 'audio':\n return <MessageAttachmentIcon iconName=\"general.outlinedMusicFile\" />\n case 'application':\n return <MessageAttachmentIcon iconName=\"general.outlinedGenericFile\" />\n default:\n return null\n }\n }\n\n return null\n}\n\nfunction GiphyImage({ attachment }: { attachment: DenormalizedGiphyAttachmentResource }) {\n const { title, giphy } = attachment\n const { url } = giphy.fixedWidth\n const { width, height } = assertKeysAreNumbers(giphy.fixedWidth)\n const styles = useStyles({ imageWidth: width, imageHeight: height })\n\n return (\n <Image\n source={{ uri: url }}\n wrapperStyle={styles.imageWrapper}\n style={styles.image}\n alt={title}\n loaderSize={16}\n />\n )\n}\n\nfunction ExpandedLinkImage({\n attachment,\n}: {\n attachment: DenormalizedExpandedLinkAttachmentResource\n}) {\n const { title = '', imageUrl, imageHeight, imageWidth } = attachment.attributes\n const styles = useStyles({ imageWidth, imageHeight })\n\n return (\n <Image\n source={{ uri: imageUrl }}\n wrapperStyle={styles.imageWrapper}\n style={styles.image}\n alt={title}\n loaderSize={16}\n />\n )\n}\n\nfunction MessageAttachmentImage({\n attachment,\n}: {\n attachment: DenormalizedMessageAttachmentResource\n}) {\n const { url, urlMedium, filename, metadata = {} } = attachment.attributes\n const styles = useStyles({ imageWidth: metadata.width, imageHeight: metadata.height })\n\n return (\n <Image\n source={{ uri: urlMedium || url }}\n style={styles.image}\n wrapperStyle={styles.imageWrapper}\n alt={filename}\n loaderSize={16}\n />\n )\n}\n\nfunction MessageAttachmentIcon({ iconName }: { iconName: IconProps['name'] }) {\n const styles = useStyles()\n return (\n <Icon\n name={iconName}\n style={styles.attachmentIcon}\n maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}\n />\n )\n}\n\n// TODO: The mine prop is not used yet, but in the future we will be adding a way to find the `mine` value for this fallback.\nfunction ShadowMessageFallback({ text, mine }: { text: string; mine?: boolean }) {\n const styles = useStyles({ mine })\n\n return (\n <View style={styles.message}>\n <View style={styles.messageContent}>\n <View style={styles.messageBubble}>\n <Text variant=\"footnote\" style={styles.messageText}>\n {text}\n </Text>\n </View>\n </View>\n </View>\n )\n}\n\ninterface StylesProps {\n imageWidth?: number\n imageHeight?: number\n mine?: boolean\n}\n\nconst useStyles = ({ mine, imageWidth = 32, imageHeight = 32 }: StylesProps = {}) => {\n const { colors } = useTheme()\n const fontScale = useFontScale({ maxFontSizeMultiplier: MAX_FONT_SIZE_MULTIPLIER })\n const { width } = useWindowDimensions()\n const tabletWidth = width >= 744 // Smallest iPad Mini's width\n\n return StyleSheet.create({\n message: {\n gap: 8,\n flexDirection: mine ? 'row-reverse' : 'row',\n paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,\n },\n messageContent: {\n flex: 1,\n gap: 4,\n marginBottom: 12,\n },\n avatarWrapper: {\n width: MESSAGE_AUTHOR_AVATAR_COLUMN_WIDTH,\n alignItems: 'center',\n },\n avatar: {\n marginBottom: 8,\n },\n avatarOpacity: {\n opacity: 0.5,\n },\n messageBubble: {\n flexDirection: 'row',\n alignSelf: mine ? 'flex-end' : 'flex-start',\n alignItems: 'center',\n gap: 8,\n borderColor: colors.borderColorDefaultBase,\n borderWidth: 1,\n borderRadius: 8,\n maxWidth: tabletWidth ? 360 : '80%',\n paddingVertical: 6,\n paddingHorizontal: 8,\n },\n messageText: {\n color: colors.textColorDefaultPlaceholder,\n flexShrink: 1,\n },\n messageMeta: {\n flexDirection: 'row',\n justifyContent: mine ? 'flex-end' : 'flex-start',\n },\n replyCountText: {\n color: colors.interaction,\n fontWeight: platformFontWeightMedium,\n },\n imageWrapper: {\n width: 32 * fontScale,\n aspectRatio: imageWidth / imageHeight,\n opacity: 0.5,\n },\n image: {\n borderRadius: 4,\n },\n attachmentIcon: {\n color: colors.iconColorDefaultDim,\n fontSize: 16,\n },\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"reply_shadow_message.js","sourceRoot":"","sources":["../../../src/components/conversation/reply_shadow_message.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,QAAQ,MAAM,yBAAyB,CAAA;AAC9C,OAAO,EACL,iCAAiC,EACjC,YAAY,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EAAE,GAAG,SAAS;YACrB,WAAW,EAAE,UAAU,GAAG,WAAW;YACrC,OAAO,EAAE,GAAG;SACb;QACD,KAAK,EAAE;YACL,YAAY,EAAE,CAAC;SAChB;QACD,cAAc,EAAE;YACd,KAAK,EAAE,MAAM,CAAC,mBAAmB;YACjC,QAAQ,EAAE,EAAE;SACb;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport { some } from 'lodash'\nimport React from 'react'\nimport { Pressable, StyleSheet, useWindowDimensions, View } from 'react-native'\nimport Animated from 'react-native-reanimated'\nimport {\n useAnimatedMessageBackgroundColor,\n useFontScale,\n useScalableNumberOfLines,\n useTheme,\n} from '../../hooks'\nimport { useConversationMessage } from '../../hooks/use_conversation_message'\nimport { useLiveRelativeTime } from '../../hooks/use_live_relative_time'\nimport { MessageResource } from '../../types'\nimport {\n DenormalizedAttachmentResource,\n DenormalizedGiphyAttachmentResource,\n DenormalizedExpandedLinkAttachmentResource,\n DenormalizedMessageAttachmentResource,\n} from '../../types/resources/denormalized_attachment_resource'\nimport { assertKeysAreNumbers, pluralize } from '../../utils'\nimport {\n CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,\n MAX_FONT_SIZE_MULTIPLIER,\n MESSAGE_AUTHOR_AVATAR_COLUMN_WIDTH,\n platformFontWeightMedium,\n} from '../../utils/styles'\nimport { Avatar, Icon, IconProps, Image, Text } from '../display'\nimport { TheirReplyConnector, MyReplyConnector } from './reply_connectors'\n\ninterface ReplyShadowMessageProps {\n messageId: string\n conversation_id: number\n inReplyScreen?: boolean\n isReplyShadowMessage: boolean\n nextRendersAuthor: boolean\n}\n\nexport function ReplyShadowMessage({\n conversation_id,\n inReplyScreen,\n messageId,\n isReplyShadowMessage,\n nextRendersAuthor,\n}: ReplyShadowMessageProps) {\n const { message, isError, isLoading } = useConversationMessage({ conversation_id, messageId })\n\n if (inReplyScreen) return null\n if (isLoading) return <ShadowMessageFallback text=\"Loading...\" />\n if (isError || !message) return <ShadowMessageFallback text=\"Message deleted\" />\n\n const enrichedMessage = {\n ...message,\n isReplyShadowMessage,\n nextRendersAuthor,\n }\n\n return <ShadowMessageContent conversation_id={conversation_id} {...enrichedMessage} />\n}\n\ninterface ShadowMessageContentProps extends MessageResource {\n conversation_id: number\n}\n\nfunction ShadowMessageContent({ conversation_id, ...message }: ShadowMessageContentProps) {\n const { text, deletedAt, author, attachments } = message\n const styles = useStyles(message)\n const { colors } = useTheme()\n const navigation = useNavigation()\n const timestamp = useLiveRelativeTime(message.createdAt)\n\n const [messageBubbleHeight, setMessageBubbleHeight] = React.useState(0)\n const { animatedBackgroundColor, handleMessagePressIn, handleMessagePressOut } =\n useAnimatedMessageBackgroundColor()\n const scalableNumberOfLines = useScalableNumberOfLines(2)\n const replyCountText = pluralize(message.replyCount, 'reply')\n const isDeleted = !!deletedAt\n const messageText = isDeleted ? 'Message deleted' : text\n\n const handleNavigateToReplies = () => {\n navigation.navigate('ConversationReply', {\n conversation_id,\n reply_root_id: message.replyRootId,\n reply_root_author_name: message.author.name,\n })\n }\n\n const attachmentLabel = some(attachments) ? pluralize(attachments.length, 'attachment') : ''\n const accessibilityLabel = `${author?.name || ''} Reply Preview ${attachmentLabel} ${\n messageText || ''\n } ${timestamp} ${replyCountText}`\n\n return (\n <Pressable\n android_ripple={{ color: colors.androidRippleNeutral }}\n onPress={handleNavigateToReplies}\n onPressIn={handleMessagePressIn}\n onPressOut={handleMessagePressOut}\n accessibilityLabel={accessibilityLabel}\n accessibilityHint=\"Navigate to reply screen for this message\"\n accessibilityRole=\"link\"\n >\n <Animated.View style={[styles.message, animatedBackgroundColor]}>\n {!message.mine && (\n <View>\n <View style={[styles.avatarWrapper, !isDeleted && styles.avatarOpacity]}>\n <Avatar\n size=\"xs\"\n sourceUri={message.author.avatar}\n style={styles.avatar}\n maxFontSizeMultiplier={1}\n fallbackIconName={isDeleted ? 'publishing.trash' : 'general.person'}\n showFallback={isDeleted}\n />\n </View>\n <TheirReplyConnector message={message} messageBubbleHeight={messageBubbleHeight} />\n </View>\n )}\n <View style={styles.messageContent}>\n <View\n style={styles.messageBubble}\n onLayout={e => setMessageBubbleHeight(e.nativeEvent.layout.height)}\n >\n <MessageAttachmentImagery attachments={attachments} />\n {text && (\n <Text\n variant=\"footnote\"\n style={styles.messageText}\n numberOfLines={scalableNumberOfLines}\n >\n {messageText}\n </Text>\n )}\n </View>\n <View style={styles.messageMeta}>\n <Text variant=\"footnote\" style={styles.replyCountText}>\n {replyCountText}\n </Text>\n </View>\n </View>\n {message.mine && (\n <MyReplyConnector message={message} messageBubbleHeight={messageBubbleHeight} />\n )}\n </Animated.View>\n </Pressable>\n )\n}\n\nfunction MessageAttachmentImagery({\n attachments,\n}: {\n attachments: DenormalizedAttachmentResource[]\n}) {\n if (!attachments || attachments.length === 0) return null\n\n const attachment = attachments[0]\n\n if (attachment.type === 'giphy') {\n return <GiphyImage attachment={attachment} />\n }\n if (attachment.type === 'ExpandedLink') {\n return <ExpandedLinkImage attachment={attachment} />\n }\n if (attachment.type === 'MessageAttachment') {\n const contentType = attachment.attributes?.contentType\n const basicType = contentType?.split('/')[0]\n\n switch (basicType) {\n case 'image':\n return <MessageAttachmentImage attachment={attachment} />\n case 'video':\n return <MessageAttachmentIcon iconName=\"general.outlinedVideoFile\" />\n case 'audio':\n return <MessageAttachmentIcon iconName=\"general.outlinedMusicFile\" />\n case 'application':\n return <MessageAttachmentIcon iconName=\"general.outlinedGenericFile\" />\n default:\n return null\n }\n }\n\n return null\n}\n\nfunction GiphyImage({ attachment }: { attachment: DenormalizedGiphyAttachmentResource }) {\n const { title, giphy } = attachment\n const { url } = giphy.fixedWidth\n const { width, height } = assertKeysAreNumbers(giphy.fixedWidth)\n const styles = useStyles({ imageWidth: width, imageHeight: height })\n\n return (\n <Image\n source={{ uri: url }}\n wrapperStyle={styles.imageWrapper}\n style={styles.image}\n alt={title}\n loaderSize={16}\n />\n )\n}\n\nfunction ExpandedLinkImage({\n attachment,\n}: {\n attachment: DenormalizedExpandedLinkAttachmentResource\n}) {\n const { title = '', imageUrl, imageHeight, imageWidth } = attachment.attributes\n const styles = useStyles({ imageWidth, imageHeight })\n\n return (\n <Image\n source={{ uri: imageUrl }}\n wrapperStyle={styles.imageWrapper}\n style={styles.image}\n alt={title}\n loaderSize={16}\n />\n )\n}\n\nfunction MessageAttachmentImage({\n attachment,\n}: {\n attachment: DenormalizedMessageAttachmentResource\n}) {\n const { url, urlMedium, filename, metadata = {} } = attachment.attributes\n const styles = useStyles({ imageWidth: metadata.width, imageHeight: metadata.height })\n\n return (\n <Image\n source={{ uri: urlMedium || url }}\n style={styles.image}\n wrapperStyle={styles.imageWrapper}\n alt={filename}\n loaderSize={16}\n />\n )\n}\n\nfunction MessageAttachmentIcon({ iconName }: { iconName: IconProps['name'] }) {\n const styles = useStyles()\n return (\n <Icon\n name={iconName}\n style={styles.attachmentIcon}\n maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}\n />\n )\n}\n\n// TODO: The mine prop is not used yet, but in the future we will be adding a way to find the `mine` value for this fallback.\nfunction ShadowMessageFallback({ text, mine }: { text: string; mine?: boolean }) {\n const styles = useStyles({ mine })\n\n return (\n <View style={styles.message}>\n <View style={styles.messageContent}>\n <View style={styles.messageBubble}>\n <Text variant=\"footnote\" style={styles.messageText}>\n {text}\n </Text>\n </View>\n </View>\n </View>\n )\n}\n\ninterface StylesProps {\n imageWidth?: number\n imageHeight?: number\n mine?: boolean\n}\n\nconst useStyles = ({ mine, imageWidth = 32, imageHeight = 32 }: StylesProps = {}) => {\n const { colors } = useTheme()\n const fontScale = useFontScale({ maxFontSizeMultiplier: MAX_FONT_SIZE_MULTIPLIER })\n const { width } = useWindowDimensions()\n const tabletWidth = width >= 744 // Smallest iPad Mini's width\n\n return StyleSheet.create({\n message: {\n gap: 8,\n flexDirection: mine ? 'row-reverse' : 'row',\n paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,\n },\n messageContent: {\n flex: 1,\n gap: 4,\n marginBottom: 12,\n },\n avatarWrapper: {\n width: MESSAGE_AUTHOR_AVATAR_COLUMN_WIDTH,\n alignItems: 'center',\n },\n avatar: {\n marginBottom: 8,\n },\n avatarOpacity: {\n opacity: 0.5,\n },\n messageBubble: {\n flexDirection: 'row',\n alignSelf: mine ? 'flex-end' : 'flex-start',\n alignItems: 'center',\n gap: 8,\n borderColor: colors.borderColorDefaultBase,\n borderWidth: 1,\n borderRadius: 8,\n maxWidth: tabletWidth ? 360 : '80%',\n paddingVertical: 6,\n paddingHorizontal: 8,\n },\n messageText: {\n color: colors.textColorDefaultPlaceholder,\n flexShrink: 1,\n },\n messageMeta: {\n flexDirection: 'row',\n justifyContent: mine ? 'flex-end' : 'flex-start',\n },\n replyCountText: {\n color: colors.interaction,\n fontWeight: platformFontWeightMedium,\n },\n imageWrapper: {\n width: 32 * fontScale,\n aspectRatio: imageWidth / imageHeight,\n opacity: 0.5,\n },\n image: {\n borderRadius: 4,\n },\n attachmentIcon: {\n color: colors.iconColorDefaultDim,\n fontSize: 16,\n },\n })\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unread_divider.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/unread_divider.tsx"],"names":[],"mappings":"AAQA,UAAU,kBAAkB;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAMD,wBAAgB,aAAa,CAAC,EAAE,YAAoB,EAAE,EAAE,kBAAkB,sCAqBzE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { StyleSheet, View } from 'react-native';
|
|
2
|
+
import Animated, { FadeIn, FadeOut } from 'react-native-reanimated';
|
|
3
|
+
import Svg, { Defs, Path, Pattern, Rect } from 'react-native-svg';
|
|
4
|
+
import { useConversationContext } from '../../contexts/conversation_context';
|
|
5
|
+
import { useTheme } from '../../hooks';
|
|
6
|
+
import { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles';
|
|
7
|
+
import { Text } from '../display';
|
|
8
|
+
const WAVE_WIDTH = 16;
|
|
9
|
+
const WAVE_HEIGHT = 8;
|
|
10
|
+
const FADE_DURATION = 750;
|
|
11
|
+
export function UnreadDivider({ scrolledPast = false }) {
|
|
12
|
+
const styles = useStyles();
|
|
13
|
+
const { atEndOfMessageHistory } = useConversationContext();
|
|
14
|
+
if (scrolledPast || atEndOfMessageHistory)
|
|
15
|
+
return null;
|
|
16
|
+
return (<Animated.View entering={FadeIn.duration(FADE_DURATION)} exiting={FadeOut.duration(FADE_DURATION)} style={styles.container} accessibilityRole="header" accessibilityLabel="Unread messages start here">
|
|
17
|
+
<SquigglyLine />
|
|
18
|
+
<Text variant="footnote" style={styles.label}>
|
|
19
|
+
New
|
|
20
|
+
</Text>
|
|
21
|
+
<SquigglyLine />
|
|
22
|
+
</Animated.View>);
|
|
23
|
+
}
|
|
24
|
+
function SquigglyLine() {
|
|
25
|
+
const { colors } = useTheme();
|
|
26
|
+
return (<View style={squigglyStyle.container}>
|
|
27
|
+
<Svg width="100%" height={WAVE_HEIGHT}>
|
|
28
|
+
<Defs>
|
|
29
|
+
<Pattern id="wave" x="0" y="0" width={WAVE_WIDTH} height={WAVE_HEIGHT} patternUnits="userSpaceOnUse">
|
|
30
|
+
<Path d="M 0 4 Q 4 0 8 4 T 16 4" stroke={colors.interaction} strokeWidth={1.5} fill="none"/>
|
|
31
|
+
</Pattern>
|
|
32
|
+
</Defs>
|
|
33
|
+
<Rect x="0" y="0" width="100%" height={WAVE_HEIGHT} fill="url(#wave)"/>
|
|
34
|
+
</Svg>
|
|
35
|
+
</View>);
|
|
36
|
+
}
|
|
37
|
+
const squigglyStyle = StyleSheet.create({
|
|
38
|
+
container: {
|
|
39
|
+
flex: 1,
|
|
40
|
+
height: WAVE_HEIGHT,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const useStyles = () => {
|
|
44
|
+
const { colors } = useTheme();
|
|
45
|
+
return StyleSheet.create({
|
|
46
|
+
container: {
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
flexDirection: 'row',
|
|
49
|
+
paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,
|
|
50
|
+
paddingVertical: 8,
|
|
51
|
+
gap: 8,
|
|
52
|
+
},
|
|
53
|
+
label: {
|
|
54
|
+
color: colors.interaction,
|
|
55
|
+
fontWeight: '600',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=unread_divider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unread_divider.js","sourceRoot":"","sources":["../../../src/components/conversation/unread_divider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,4CAA4C,EAAE,MAAM,oBAAoB,CAAA;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAMjC,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,WAAW,GAAG,CAAC,CAAA;AACrB,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,MAAM,UAAU,aAAa,CAAC,EAAE,YAAY,GAAG,KAAK,EAAsB;IACxE,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,EAAE,qBAAqB,EAAE,GAAG,sBAAsB,EAAE,CAAA;IAE1D,IAAI,YAAY,IAAI,qBAAqB;QAAE,OAAO,IAAI,CAAA;IAEtD,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GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,YAAY,EACvE;MAAA,EAAE,GAAG,CACP;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC;AAED,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC;IACtC,SAAS,EAAE;QACT,IAAI,EAAE,CAAC;QACP,MAAM,EAAE,WAAW;KACpB;CACF,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAA;IAC7B,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE;YACT,UAAU,EAAE,QAAQ;YACpB,aAAa,EAAE,KAAK;YACpB,iBAAiB,EAAE,4CAA4C;YAC/D,eAAe,EAAE,CAAC;YAClB,GAAG,EAAE,CAAC;SACP;QACD,KAAK,EAAE;YACL,KAAK,EAAE,MAAM,CAAC,WAAW;YACzB,UAAU,EAAE,KAAK;SAClB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { StyleSheet, View } from 'react-native'\nimport Animated, { FadeIn, FadeOut } from 'react-native-reanimated'\nimport Svg, { Defs, Path, Pattern, Rect } from 'react-native-svg'\nimport { useConversationContext } from '../../contexts/conversation_context'\nimport { useTheme } from '../../hooks'\nimport { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles'\nimport { Text } from '../display'\n\ninterface UnreadDividerProps {\n scrolledPast?: boolean\n}\n\nconst WAVE_WIDTH = 16\nconst WAVE_HEIGHT = 8\nconst FADE_DURATION = 750\n\nexport function UnreadDivider({ scrolledPast = false }: UnreadDividerProps) {\n const styles = useStyles()\n const { atEndOfMessageHistory } = useConversationContext()\n\n if (scrolledPast || atEndOfMessageHistory) return null\n\n return (\n <Animated.View\n entering={FadeIn.duration(FADE_DURATION)}\n exiting={FadeOut.duration(FADE_DURATION)}\n style={styles.container}\n accessibilityRole=\"header\"\n accessibilityLabel=\"Unread messages start here\"\n >\n <SquigglyLine />\n <Text variant=\"footnote\" style={styles.label}>\n New\n </Text>\n <SquigglyLine />\n </Animated.View>\n )\n}\n\nfunction SquigglyLine() {\n const { colors } = useTheme()\n return (\n <View style={squigglyStyle.container}>\n <Svg width=\"100%\" height={WAVE_HEIGHT}>\n <Defs>\n <Pattern\n id=\"wave\"\n x=\"0\"\n y=\"0\"\n width={WAVE_WIDTH}\n height={WAVE_HEIGHT}\n patternUnits=\"userSpaceOnUse\"\n >\n <Path\n d=\"M 0 4 Q 4 0 8 4 T 16 4\"\n stroke={colors.interaction}\n strokeWidth={1.5}\n fill=\"none\"\n />\n </Pattern>\n </Defs>\n <Rect x=\"0\" y=\"0\" width=\"100%\" height={WAVE_HEIGHT} fill=\"url(#wave)\" />\n </Svg>\n </View>\n )\n}\n\nconst squigglyStyle = StyleSheet.create({\n container: {\n flex: 1,\n height: WAVE_HEIGHT,\n },\n})\n\nconst useStyles = () => {\n const { colors } = useTheme()\n return StyleSheet.create({\n container: {\n alignItems: 'center',\n flexDirection: 'row',\n paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,\n paddingVertical: 8,\n gap: 8,\n },\n label: {\n color: colors.interaction,\n fontWeight: '600',\n },\n })\n}\n"]}
|
|
@@ -5,6 +5,8 @@ interface ConversationContextValue {
|
|
|
5
5
|
initialMessageId: string | null;
|
|
6
6
|
setInitialMessageId: (id: string | null) => void;
|
|
7
7
|
initialMessageIdIsAnchor: boolean;
|
|
8
|
+
atEndOfMessageHistory: boolean;
|
|
9
|
+
setAtEndOfMessageHistory: (atEnd: boolean) => void;
|
|
8
10
|
}
|
|
9
11
|
interface ConversationContextProviderProps extends PropsWithChildren {
|
|
10
12
|
conversationId: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation_context.d.ts","sourceRoot":"","sources":["../../src/contexts/conversation_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"conversation_context.d.ts","sourceRoot":"","sources":["../../src/contexts/conversation_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAiC,MAAM,OAAO,CAAA;AAE9F,UAAU,wBAAwB;IAChC,cAAc,EAAE,MAAM,CAAA;IACtB,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IAChD,wBAAwB,EAAE,OAAO,CAAA;IACjC,qBAAqB,EAAE,OAAO,CAAA;IAC9B,wBAAwB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnD;AAED,UAAU,gCAAiC,SAAQ,iBAAiB;IAClE,cAAc,EAAE,MAAM,CAAA;IACtB,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAYD,eAAO,MAAM,2BAA2B,GAAI,yHAMzC,gCAAgC,sBAwBlC,CAAA;AAED,eAAO,MAAM,sBAAsB,gCAAwC,CAAA"}
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import React, { createContext, useContext,
|
|
1
|
+
import React, { createContext, useContext, useMemo, useState } from 'react';
|
|
2
2
|
const ConversationContext = createContext({
|
|
3
3
|
conversationId: 0,
|
|
4
4
|
currentPageReplyRootId: null,
|
|
5
5
|
initialMessageId: null,
|
|
6
6
|
setInitialMessageId: () => { },
|
|
7
7
|
initialMessageIdIsAnchor: false,
|
|
8
|
+
atEndOfMessageHistory: false,
|
|
9
|
+
setAtEndOfMessageHistory: () => { },
|
|
8
10
|
});
|
|
9
11
|
export const ConversationContextProvider = ({ children, conversationId, currentPageReplyRootId, initialMessageId: initialMessageIdProp = null, initialMessageIdIsAnchor = false, }) => {
|
|
10
12
|
const [initialMessageId, setInitialMessageId] = useState(initialMessageIdProp);
|
|
11
|
-
|
|
12
|
-
setInitialMessageId(initialMessageIdProp);
|
|
13
|
-
}, [initialMessageIdProp]);
|
|
13
|
+
const [atEndOfMessageHistory, setAtEndOfMessageHistory] = useState(false);
|
|
14
14
|
const value = useMemo(() => ({
|
|
15
15
|
conversationId,
|
|
16
16
|
currentPageReplyRootId,
|
|
17
17
|
initialMessageId,
|
|
18
18
|
setInitialMessageId,
|
|
19
19
|
initialMessageIdIsAnchor,
|
|
20
|
-
|
|
20
|
+
atEndOfMessageHistory,
|
|
21
|
+
setAtEndOfMessageHistory,
|
|
22
|
+
}), [
|
|
23
|
+
conversationId,
|
|
24
|
+
currentPageReplyRootId,
|
|
25
|
+
initialMessageId,
|
|
26
|
+
initialMessageIdIsAnchor,
|
|
27
|
+
atEndOfMessageHistory,
|
|
28
|
+
]);
|
|
21
29
|
return <ConversationContext.Provider value={value}>{children}</ConversationContext.Provider>;
|
|
22
30
|
};
|
|
23
31
|
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,
|
|
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,QAAQ,EAAE,MAAM,OAAO,CAAA;AAmB9F,MAAM,mBAAmB,GAAG,aAAa,CAA2B;IAClE,cAAc,EAAE,CAAC;IACjB,sBAAsB,EAAE,IAAI;IAC5B,gBAAgB,EAAE,IAAI;IACtB,mBAAmB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC7B,wBAAwB,EAAE,KAAK;IAC/B,qBAAqB,EAAE,KAAK;IAC5B,wBAAwB,EAAE,GAAG,EAAE,GAAE,CAAC;CACnC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAAE,oBAAoB,GAAG,IAAI,EAC7C,wBAAwB,GAAG,KAAK,GACC,EAAE,EAAE;IACrC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAAA;IAC9E,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEzE,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,cAAc;QACd,sBAAsB;QACtB,gBAAgB;QAChB,mBAAmB;QACnB,wBAAwB;QACxB,qBAAqB;QACrB,wBAAwB;KACzB,CAAC,EACF;QACE,cAAc;QACd,sBAAsB;QACtB,gBAAgB;QAChB,wBAAwB;QACxB,qBAAqB;KACtB,CACF,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, useState } from 'react'\n\ninterface ConversationContextValue {\n conversationId: number\n currentPageReplyRootId: string | null\n initialMessageId: string | null\n setInitialMessageId: (id: string | null) => void\n initialMessageIdIsAnchor: boolean\n atEndOfMessageHistory: boolean\n setAtEndOfMessageHistory: (atEnd: boolean) => void\n}\n\ninterface ConversationContextProviderProps extends PropsWithChildren {\n conversationId: number\n currentPageReplyRootId: string | null\n initialMessageId?: string | null\n initialMessageIdIsAnchor?: boolean\n}\n\nconst ConversationContext = createContext<ConversationContextValue>({\n conversationId: 0,\n currentPageReplyRootId: null,\n initialMessageId: null,\n setInitialMessageId: () => {},\n initialMessageIdIsAnchor: false,\n atEndOfMessageHistory: false,\n setAtEndOfMessageHistory: () => {},\n})\n\nexport const ConversationContextProvider = ({\n children,\n conversationId,\n currentPageReplyRootId,\n initialMessageId: initialMessageIdProp = null,\n initialMessageIdIsAnchor = false,\n}: ConversationContextProviderProps) => {\n const [initialMessageId, setInitialMessageId] = useState(initialMessageIdProp)\n const [atEndOfMessageHistory, setAtEndOfMessageHistory] = useState(false)\n\n const value = useMemo(\n () => ({\n conversationId,\n currentPageReplyRootId,\n initialMessageId,\n setInitialMessageId,\n initialMessageIdIsAnchor,\n atEndOfMessageHistory,\n setAtEndOfMessageHistory,\n }),\n [\n conversationId,\n currentPageReplyRootId,\n initialMessageId,\n initialMessageIdIsAnchor,\n atEndOfMessageHistory,\n ]\n )\n\n return <ConversationContext.Provider value={value}>{children}</ConversationContext.Provider>\n}\n\nexport const useConversationContext = () => useContext(ConversationContext)\n"]}
|
|
@@ -14,6 +14,8 @@ export declare const useConversationMessages: ({ conversation_id, reply_root_id
|
|
|
14
14
|
hasMoreOlderMessages: boolean;
|
|
15
15
|
fetchNewerMessages: (options?: import("@tanstack/query-core").FetchPreviousPageOptions) => Promise<import("@tanstack/query-core").InfiniteQueryObserverResult<InfiniteData<ApiCollection<MessageResource>, MessagesPageParam>, Response>>;
|
|
16
16
|
hasMoreNewerMessages: boolean;
|
|
17
|
+
isFetchingNewerMessages: boolean;
|
|
18
|
+
cancelFetchNewerMessages: () => Promise<void>;
|
|
17
19
|
queryKey: import("./use_suspense_api").RequestQueryKey;
|
|
18
20
|
};
|
|
19
21
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,YAAY,
|
|
1
|
+
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,YAAY,EAIb,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EAEL,iBAAiB,EAIlB,MAAM,gCAAgC,CAAA;AAKvC,KAAK,IAAI,GAAG;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAEtE,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,kCAAkC,EAChC,kBAAkB,GAClB,sBAAsB,GACtB,aAAa,GACb,kBAAkB,GAClB,SAAS,GACT,UAAU,CACb,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,oCAAoC,IAAI,EACxC,OAAO,2BAA2B;;;;;;;;;;;CA4FnC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useSuspenseInfiniteQuery, useSuspenseQueries, } from '@tanstack/react-query';
|
|
2
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { useQueryClient, useSuspenseInfiniteQuery, useSuspenseQueries, } from '@tanstack/react-query';
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
3
|
import { useConversationContext } from '../contexts/conversation_context';
|
|
4
4
|
import { anchoredSeedPageParams, newerPageParam, olderPageParam, sortAndFilterMessages, } from '../utils/conversation_messages';
|
|
5
5
|
import { getMessagesQueryKey, getMessagesRequestArgs } from '../utils/request/get_messages';
|
|
@@ -9,8 +9,8 @@ export const useConversationMessages = ({ conversation_id, reply_root_id }, opts
|
|
|
9
9
|
const apiClient = useApiClient();
|
|
10
10
|
const { initialMessageId } = useConversationContext();
|
|
11
11
|
const anchored = !reply_root_id && !!initialMessageId;
|
|
12
|
-
const requestArgs = getMessagesRequestArgs({ conversation_id, reply_root_id });
|
|
13
|
-
const queryKey = getMessagesQueryKey({ conversation_id, reply_root_id });
|
|
12
|
+
const requestArgs = useMemo(() => getMessagesRequestArgs({ conversation_id, reply_root_id }), [conversation_id, reply_root_id]);
|
|
13
|
+
const queryKey = useMemo(() => getMessagesQueryKey({ conversation_id, reply_root_id }), [conversation_id, reply_root_id]);
|
|
14
14
|
const fetchPage = (pageParam) => {
|
|
15
15
|
const data = {
|
|
16
16
|
...requestArgs.data,
|
|
@@ -37,7 +37,7 @@ export const useConversationMessages = ({ conversation_id, reply_root_id }, opts
|
|
|
37
37
|
}
|
|
38
38
|
: undefined;
|
|
39
39
|
const initialPageParam = anchored ? seedPageParams[0] : {};
|
|
40
|
-
const { data, refetch, isRefetching, fetchNextPage, hasNextPage, fetchPreviousPage, hasPreviousPage, } = useSuspenseInfiniteQuery({
|
|
40
|
+
const { data, refetch, isRefetching, fetchNextPage, hasNextPage, fetchPreviousPage, hasPreviousPage, isFetchingPreviousPage, } = useSuspenseInfiniteQuery({
|
|
41
41
|
queryKey,
|
|
42
42
|
queryFn: ({ pageParam }) => fetchPage(pageParam),
|
|
43
43
|
initialPageParam,
|
|
@@ -48,6 +48,8 @@ export const useConversationMessages = ({ conversation_id, reply_root_id }, opts
|
|
|
48
48
|
...(anchored ? { staleTime: Infinity, refetchOnMount: false } : {}),
|
|
49
49
|
});
|
|
50
50
|
const messages = useMemo(() => sortAndFilterMessages(data.pages), [data.pages]);
|
|
51
|
+
const queryClient = useQueryClient();
|
|
52
|
+
const cancelFetchNewerMessages = useCallback(() => queryClient.cancelQueries({ queryKey }), [queryClient, queryKey]);
|
|
51
53
|
return {
|
|
52
54
|
messages,
|
|
53
55
|
refetch,
|
|
@@ -56,6 +58,8 @@ export const useConversationMessages = ({ conversation_id, reply_root_id }, opts
|
|
|
56
58
|
hasMoreOlderMessages: hasNextPage,
|
|
57
59
|
fetchNewerMessages: fetchPreviousPage,
|
|
58
60
|
hasMoreNewerMessages: hasPreviousPage,
|
|
61
|
+
isFetchingNewerMessages: isFetchingPreviousPage,
|
|
62
|
+
cancelFetchNewerMessages,
|
|
59
63
|
queryKey,
|
|
60
64
|
};
|
|
61
65
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EACd,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAA;AAEzE,OAAO,EACL,sBAAsB,EAEtB,cAAc,EACd,cAAc,EACd,qBAAqB,GACtB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAcvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,EAAE,eAAe,EAAE,aAAa,EAAQ,EACxC,IAAkC,EAClC,EAAE;IACF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAA;IACrD,MAAM,QAAQ,GAAG,CAAC,aAAa,IAAI,CAAC,CAAC,gBAAgB,CAAA;IAErD,MAAM,W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AQ,CAAC,CACxB,CAAA;IAED,OAAO;QACL,QAAQ;QACR,OAAO;QACP,YAAY;QACZ,kBAAkB,EAAE,aAAa;QACjC,oBAAoB,EAAE,WAAW;QACjC,kBAAkB,EAAE,iBAAiB;QACrC,oBAAoB,EAAE,eAAe;QACrC,uBAAuB,EAAE,sBAAsB;QAC/C,wBAAwB;QACxB,QAAQ;KACT,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {\n AnyUseSuspenseInfiniteQueryOptions,\n InfiniteData,\n useQueryClient,\n useSuspenseInfiniteQuery,\n useSuspenseQueries,\n} from '@tanstack/react-query'\nimport { useCallback, useMemo } from 'react'\nimport { useConversationContext } from '../contexts/conversation_context'\nimport { ApiCollection, MessageResource } from '../types'\nimport {\n anchoredSeedPageParams,\n MessagesPageParam,\n newerPageParam,\n olderPageParam,\n sortAndFilterMessages,\n} from '../utils/conversation_messages'\nimport { getMessagesQueryKey, getMessagesRequestArgs } from '../utils/request/get_messages'\nimport { useApiClient } from './use_api_client'\nimport { throwResponseError } from './use_suspense_api'\n\ntype Args = { conversation_id: number; reply_root_id?: string | null }\n\nexport type ConversationMessagesOptions = Omit<\n AnyUseSuspenseInfiniteQueryOptions,\n | 'getNextPageParam'\n | 'getPreviousPageParam'\n | 'initialData'\n | 'initialPageParam'\n | 'queryFn'\n | 'queryKey'\n>\n\nexport const useConversationMessages = (\n { conversation_id, reply_root_id }: Args,\n opts?: ConversationMessagesOptions\n) => {\n const apiClient = useApiClient()\n const { initialMessageId } = useConversationContext()\n const anchored = !reply_root_id && !!initialMessageId\n\n const requestArgs = useMemo(\n () => getMessagesRequestArgs({ conversation_id, reply_root_id }),\n [conversation_id, reply_root_id]\n )\n const queryKey = useMemo(\n () => getMessagesQueryKey({ conversation_id, reply_root_id }),\n [conversation_id, reply_root_id]\n )\n\n const fetchPage = (pageParam: MessagesPageParam) => {\n const data = {\n ...requestArgs.data,\n ...(pageParam.where ? { where: pageParam.where } : {}),\n ...(pageParam.order ? { order: pageParam.order } : {}),\n }\n return apiClient.chat\n .get<ApiCollection<MessageResource>>({ url: requestArgs.url, data })\n .catch(throwResponseError)\n }\n\n const seedPageParams = anchored ? anchoredSeedPageParams(initialMessageId) : []\n const seedQueries = useSuspenseQueries({\n queries: seedPageParams.map((pageParam, index) => ({\n queryKey: [...queryKey, 'seed', index],\n queryFn: () => fetchPage(pageParam),\n staleTime: Infinity,\n gcTime: 0,\n })),\n })\n\n const initialData: InfiniteData<ApiCollection<MessageResource>, MessagesPageParam> | undefined =\n anchored\n ? {\n pages: seedQueries.map(q => q.data),\n pageParams: seedPageParams,\n }\n : undefined\n\n const initialPageParam: MessagesPageParam = anchored ? seedPageParams[0] : {}\n\n const {\n data,\n refetch,\n isRefetching,\n fetchNextPage,\n hasNextPage,\n fetchPreviousPage,\n hasPreviousPage,\n isFetchingPreviousPage,\n } = useSuspenseInfiniteQuery<\n ApiCollection<MessageResource>,\n Response,\n InfiniteData<ApiCollection<MessageResource>, MessagesPageParam>,\n typeof queryKey,\n MessagesPageParam\n >({\n queryKey,\n queryFn: ({ pageParam }) => fetchPage(pageParam),\n initialPageParam,\n initialData,\n getNextPageParam: olderPageParam,\n getPreviousPageParam: anchored ? newerPageParam : () => undefined,\n ...(opts || {}),\n ...(anchored ? { staleTime: Infinity, refetchOnMount: false } : {}),\n })\n\n const messages = useMemo(() => sortAndFilterMessages(data.pages), [data.pages])\n\n const queryClient = useQueryClient()\n const cancelFetchNewerMessages = useCallback(\n () => queryClient.cancelQueries({ queryKey }),\n [queryClient, queryKey]\n )\n\n return {\n messages,\n refetch,\n isRefetching,\n fetchOlderMessages: fetchNextPage,\n hasMoreOlderMessages: hasNextPage,\n fetchNewerMessages: fetchPreviousPage,\n hasMoreNewerMessages: hasPreviousPage,\n isFetchingNewerMessages: isFetchingPreviousPage,\n cancelFetchNewerMessages,\n queryKey,\n }\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":"AA0BA,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, } from '../utils/cache/messages_cache';
|
|
3
|
+
import { updateCacheWithMessage, updateCacheWithIndividualMessage, updateCacheWithReaction, getThreadedMessagesQueryKey, hasUnloadedNewerPages, } 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
|
+
if (e.event === 'message.updated' || !hasUnloadedNewerPages(queryClient, messagesQueryKey)) {
|
|
34
|
+
updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event);
|
|
35
|
+
}
|
|
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,MAAM,uBAAuB,CAAA;AAQpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EACL,sBAAsB,EACtB,gCAAgC,EAChC,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAA;AAC3H,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAMzF,MAAM,UAAU,iCAAiC,CAAC,EAAE,cAAc,EAAS;IACzE,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE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AAgB,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAA;QAE3E,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAA;QAE7C,qEAAqE;QACrE,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,wBAAwB,GAAG,2BAA2B,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;YACzF,uBAAuB,CAAC,WAAW,EAAE,wBAAwB,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAA;QACrF,CAAC;IACH,CAAC,CAAA;IAED,MAAM,iBAAiB,GAAG,KAAK,EAAE,CAAkB,EAAE,EAAE;QACrD,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAA;QACvB,cAAc,CAAC,IAAI,CAAC,CAAA;QACpB,UAAU,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 hasUnloadedNewerPages,\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 if (e.event === 'message.updated' || !hasUnloadedNewerPages(queryClient, messagesQueryKey)) {\n updateCacheWithMessage(queryClient, messagesQueryKey, message, e.event)\n }\n\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"]}
|