@planningcenter/chat-react-native 3.2.0-rc.24 → 3.2.0-rc.25

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.
@@ -1,5 +1,6 @@
1
1
  import { StaticScreenProps } from '@react-navigation/native';
2
2
  import React from 'react';
3
+ import { MessageResource } from '../types';
3
4
  type ConversationRouteProps = {
4
5
  conversation_id: number;
5
6
  chat_group_graph_id?: string;
@@ -7,5 +8,11 @@ type ConversationRouteProps = {
7
8
  };
8
9
  export type ConversationScreenProps = StaticScreenProps<ConversationRouteProps>;
9
10
  export declare function ConversationScreen({ route }: ConversationScreenProps): React.JSX.Element;
11
+ export type DateSeparator = {
12
+ type: 'DateSeparator';
13
+ id: string;
14
+ date: string;
15
+ };
16
+ export declare const groupMessages: (ms: MessageResource[]) => (MessageResource | DateSeparator)[];
10
17
  export {};
11
18
  //# sourceMappingURL=conversation_screen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"conversation_screen.d.ts","sourceRoot":"","sources":["../../src/screens/conversation_screen.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAIlB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAiC,MAAM,OAAO,CAAA;AAUrD,KAAK,sBAAsB,GAAG;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,CAAA;AAE/E,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,EAAE,uBAAuB,qBA0CpE"}
1
+ {"version":3,"file":"conversation_screen.d.ts","sourceRoot":"","sources":["../../src/screens/conversation_screen.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EAIlB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,KAAiC,MAAM,OAAO,CAAA;AAUrD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAG1C,KAAK,sBAAsB,GAAG;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,CAAA;AAE/E,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,EAAE,uBAAuB,qBAiDpE;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAwC/E,eAAO,MAAM,aAAa,OAAQ,eAAe,EAAE,wCAkClD,CAAA"}
@@ -1,14 +1,19 @@
1
+ // @ts-expect-error
2
+ import { date as formatDate } from '@planningcenter/datetime-fmt';
1
3
  import { HeaderTitle, PlatformPressable } from '@react-navigation/elements';
2
4
  import { useNavigation, useTheme as useNavigationTheme, useRoute, } from '@react-navigation/native';
5
+ import moment from 'moment';
3
6
  import React, { useCallback, useEffect } from 'react';
4
7
  import { FlatList, Platform, StyleSheet, View } from 'react-native';
5
8
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
6
- import { Badge, Icon } from '../components';
9
+ import { Badge, Icon, Text } from '../components';
7
10
  import { Message } from '../components/conversation/message';
8
11
  import { MessageForm } from '../components/conversation/message_form';
9
12
  import { KeyboardView } from '../components/display/keyboard_view';
13
+ import { useTheme } from '../hooks';
10
14
  import { useConversation } from '../hooks/use_conversation';
11
15
  import { useConversationMessages } from '../hooks/use_conversation_messages';
16
+ import { getRelativeDateStatus } from '../utils/date';
12
17
  export function ConversationScreen({ route }) {
13
18
  const styles = useStyles();
14
19
  const navigation = useNavigation();
@@ -17,6 +22,7 @@ export function ConversationScreen({ route }) {
17
22
  const { messages, refetch, isRefetching, fetchNextPage } = useConversationMessages({
18
23
  conversation_id,
19
24
  });
25
+ const messagesWithSeparators = groupMessages(messages);
20
26
  // Seems to be necessary to define this way so we get the route picked up
21
27
  const headerTitle = useCallback((props) => <PressableHeaderTitle {...props}/>, []);
22
28
  useEffect(() => {
@@ -24,7 +30,12 @@ export function ConversationScreen({ route }) {
24
30
  }, [conversation, conversation_id, navigation, headerTitle, conversation?.title]);
25
31
  return (<View style={styles.container}>
26
32
  <KeyboardView style={styles.keyboardView}>
27
- <FlatList inverted contentContainerStyle={styles.listContainer} refreshing={isRefetching} onRefresh={refetch} data={messages} keyExtractor={item => item.id} renderItem={({ item }) => <Message {...item} conversation_id={conversation_id}/>} onEndReached={() => fetchNextPage()}/>
33
+ <FlatList inverted contentContainerStyle={styles.listContainer} refreshing={isRefetching} onRefresh={refetch} data={messagesWithSeparators} keyExtractor={item => item.id} renderItem={({ item }) => {
34
+ if (item.type === 'DateSeparator') {
35
+ return <InlineDateSeparator {...item}/>;
36
+ }
37
+ return <Message {...item} conversation_id={conversation_id}/>;
38
+ }} onEndReached={() => fetchNextPage()}/>
28
39
  <MessageForm.Root conversation={conversation}>
29
40
  {/* <MessageForm.AttachmentPicker /> */}
30
41
  <MessageForm.Commands />
@@ -34,6 +45,69 @@ export function ConversationScreen({ route }) {
34
45
  </KeyboardView>
35
46
  </View>);
36
47
  }
48
+ function InlineDateSeparator({ date }) {
49
+ const styles = useDateSeparatorStyles();
50
+ const { isThisYear } = getRelativeDateStatus(date);
51
+ const showYear = !isThisYear;
52
+ const dateStamp = formatDate(date, { style: 'long', year: showYear });
53
+ return (<View style={styles.container}>
54
+ <View style={styles.separator}/>
55
+ <Text variant="footnote" style={styles.dateText}>
56
+ {dateStamp}
57
+ </Text>
58
+ <View style={styles.separator}/>
59
+ </View>);
60
+ }
61
+ const useDateSeparatorStyles = () => {
62
+ const theme = useTheme();
63
+ return StyleSheet.create({
64
+ container: {
65
+ alignItems: 'center',
66
+ flexDirection: 'row',
67
+ paddingHorizontal: 16,
68
+ paddingVertical: 16,
69
+ },
70
+ separator: {
71
+ flex: 1,
72
+ height: 1,
73
+ borderTopWidth: 1,
74
+ borderTopColor: theme.colors.borderColorDefaultBase,
75
+ },
76
+ dateText: {
77
+ paddingHorizontal: 8,
78
+ },
79
+ });
80
+ };
81
+ export const groupMessages = (ms) => {
82
+ let enrichedMessages = [];
83
+ let encounteredOneOfMyMessages = false;
84
+ ms.forEach((message, i) => {
85
+ const prevMessage = ms[i + 1];
86
+ const nextMessage = ms[i - 1];
87
+ const date = moment(message.createdAt).format('YYYY-MM-DD');
88
+ const prevMessageDifferentAuthor = message.author?.id !== prevMessage?.author?.id;
89
+ const nextMessageDifferentAuthor = message.author?.id !== nextMessage?.author?.id;
90
+ const prevMessageMoreThan5Minutes = prevMessage &&
91
+ new Date(message.createdAt).getTime() - new Date(prevMessage.createdAt).getTime() > 60000 * 5;
92
+ const nextMessageMoreThan5Minutes = nextMessage &&
93
+ new Date(nextMessage.createdAt).getTime() - new Date(message.createdAt).getTime() > 60000 * 5;
94
+ if (message.mine && !encounteredOneOfMyMessages) {
95
+ encounteredOneOfMyMessages = true;
96
+ message.myLatestInConversation = true;
97
+ }
98
+ else {
99
+ message.myLatestInConversation = false;
100
+ }
101
+ message.lastInGroup = !nextMessage || nextMessageDifferentAuthor || nextMessageMoreThan5Minutes;
102
+ message.renderAuthor =
103
+ !message.mine && (!prevMessage || prevMessageDifferentAuthor || prevMessageMoreThan5Minutes);
104
+ enrichedMessages.push(message);
105
+ if (!prevMessage || date !== moment(prevMessage.createdAt).format('YYYY-MM-DD')) {
106
+ enrichedMessages.push({ type: 'DateSeparator', id: `day-divider-${message.id}`, date });
107
+ }
108
+ });
109
+ return enrichedMessages;
110
+ };
37
111
  const PressableHeaderTitle = ({ style, children }) => {
38
112
  const styles = usePressableHeaderStyle();
39
113
  const navigation = useNavigation();
@@ -1 +1 @@
1
- {"version":3,"file":"conversation_screen.js","sourceRoot":"","sources":["../../src/screens/conversation_screen.tsx"],"names":[],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aticScreenProps,\n useNavigation,\n useTheme as useNavigationTheme,\n useRoute,\n} from '@react-navigation/native'\nimport React, { useCallback, useEffect } from 'react'\nimport { FlatList, Platform, StyleSheet, View } from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { Badge, Icon } from '../components'\nimport { Message } from '../components/conversation/message'\nimport { MessageForm } from '../components/conversation/message_form'\nimport { KeyboardView } from '../components/display/keyboard_view'\nimport { useConversation } from '../hooks/use_conversation'\nimport { useConversationMessages } from '../hooks/use_conversation_messages'\n\ntype ConversationRouteProps = {\n conversation_id: number\n chat_group_graph_id?: string\n clear_input?: boolean\n}\n\nexport type ConversationScreenProps = StaticScreenProps<ConversationRouteProps>\n\nexport function ConversationScreen({ route }: ConversationScreenProps) {\n const styles = useStyles()\n const navigation = useNavigation()\n\n const { conversation_id } = route.params\n const { data: conversation } = useConversation(route.params)\n const { messages, refetch, isRefetching, fetchNextPage } = useConversationMessages({\n conversation_id,\n })\n\n // Seems to be necessary to define this way so we get the route picked up\n const headerTitle = useCallback(\n (props: HeaderTitleProps) => <PressableHeaderTitle {...props} />,\n []\n )\n\n useEffect(() => {\n navigation.setOptions({ headerTitle, title: conversation?.title })\n }, [conversation, conversation_id, navigation, headerTitle, conversation?.title])\n\n return (\n <View style={styles.container}>\n <KeyboardView style={styles.keyboardView}>\n <FlatList\n inverted\n contentContainerStyle={styles.listContainer}\n refreshing={isRefetching}\n onRefresh={refetch}\n data={messages}\n keyExtractor={item => item.id}\n renderItem={({ item }) => <Message {...item} conversation_id={conversation_id} />}\n onEndReached={() => fetchNextPage()}\n />\n <MessageForm.Root conversation={conversation}>\n {/* <MessageForm.AttachmentPicker /> */}\n <MessageForm.Commands />\n <MessageForm.TextInput />\n <MessageForm.SubmitButton />\n </MessageForm.Root>\n </KeyboardView>\n </View>\n )\n}\n\nconst PressableHeaderTitle = ({ style, children }: HeaderTitleProps) => {\n const styles = usePressableHeaderStyle()\n const navigation = useNavigation()\n\n const route = useRoute() as ConversationScreenProps['route']\n\n const { data: conversation } = useConversation(route.params)\n const badge = conversation.badges?.[0]\n const resourceType = badge?.pcoResourceType || ''\n const productName = badge?.appName\n const name = badge?.text || undefined\n\n return (\n <PlatformPressable\n style={styles.container}\n onPress={() =>\n navigation.navigate('ConversationDetails', { conversation_id: conversation?.id })\n }\n >\n <View style={styles.titleWrapper}>\n <HeaderTitle style={[styles.title, style]}>{children}</HeaderTitle>\n <Icon name=\"general.downChevron\" size={12} />\n </View>\n <Badge\n variant=\"metaSubtle\"\n productLogoName={productName}\n label={resourceType}\n metaLabel={name}\n style={styles.badge}\n />\n </PlatformPressable>\n )\n}\n\nconst usePressableHeaderStyle = () => {\n return StyleSheet.create({\n container: {\n alignItems: Platform.select({ android: 'flex-start', default: 'center' }),\n },\n titleWrapper: {\n alignItems: 'center',\n columnGap: 4,\n flexDirection: 'row',\n },\n title: {\n padding: 0,\n margin: 0,\n },\n badge: {\n alignSelf: Platform.select({ android: 'flex-start', default: 'center' }),\n marginTop: 2,\n },\n })\n}\n\nconst useStyles = () => {\n const navigationTheme = useNavigationTheme()\n const { bottom } = useSafeAreaInsets()\n\n return StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: 'center',\n backgroundColor: navigationTheme.colors.card,\n paddingBottom: bottom,\n },\n keyboardView: {\n flex: 1,\n },\n listContainer: {\n gap: 12,\n paddingHorizontal: 16,\n paddingVertical: 12,\n },\n })\n}\n"]}
1
+ {"version":3,"file":"conversation_screen.js","sourceRoot":"","sources":["../../src/screens/conversation_screen.tsx"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,WAAW,EAAoB,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC7F,OAAO,EAEL,aAAa,EACb,QAAQ,IAAI,kBAAkB,EAC9B,QAAQ,GACT,MAAM,0BAA0B,CAAA;AACjC,OAAO,MAAM,MAAM,QAAQ,CAA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,EAAE;YACL,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;YACxE,SAAS,EAAE,CAAC;SACb;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAA;IAC5C,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAA;IAEtC,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE;YACT,IAAI,EAAE,CAAC;YACP,cAAc,EAAE,QAAQ;YACxB,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI;YAC5C,aAAa,EAAE,MAAM;SACtB;QACD,YAAY,EAAE;YACZ,IAAI,EAAE,CAAC;SACR;QACD,aAAa,EAAE;YACb,GAAG,EAAE,EAAE;YACP,iBAAiB,EAAE,EAAE;YACrB,eAAe,EAAE,EAAE;SACpB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["// @ts-expect-error\nimport { date as formatDate } from '@planningcenter/datetime-fmt'\nimport { HeaderTitle, HeaderTitleProps, PlatformPressable } from '@react-navigation/elements'\nimport {\n StaticScreenProps,\n useNavigation,\n useTheme as useNavigationTheme,\n useRoute,\n} from '@react-navigation/native'\nimport moment from 'moment'\nimport React, { useCallback, useEffect } from 'react'\nimport { FlatList, Platform, StyleSheet, View } from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { Badge, Icon, Text } from '../components'\nimport { Message } from '../components/conversation/message'\nimport { MessageForm } from '../components/conversation/message_form'\nimport { KeyboardView } from '../components/display/keyboard_view'\nimport { useTheme } from '../hooks'\nimport { useConversation } from '../hooks/use_conversation'\nimport { useConversationMessages } from '../hooks/use_conversation_messages'\nimport { MessageResource } from '../types'\nimport { getRelativeDateStatus } from '../utils/date'\n\ntype ConversationRouteProps = {\n conversation_id: number\n chat_group_graph_id?: string\n clear_input?: boolean\n}\n\nexport type ConversationScreenProps = StaticScreenProps<ConversationRouteProps>\n\nexport function ConversationScreen({ route }: ConversationScreenProps) {\n const styles = useStyles()\n const navigation = useNavigation()\n\n const { conversation_id } = route.params\n const { data: conversation } = useConversation(route.params)\n const { messages, refetch, isRefetching, fetchNextPage } = useConversationMessages({\n conversation_id,\n })\n const messagesWithSeparators = groupMessages(messages)\n\n // Seems to be necessary to define this way so we get the route picked up\n const headerTitle = useCallback(\n (props: HeaderTitleProps) => <PressableHeaderTitle {...props} />,\n []\n )\n\n useEffect(() => {\n navigation.setOptions({ headerTitle, title: conversation?.title })\n }, [conversation, conversation_id, navigation, headerTitle, conversation?.title])\n\n return (\n <View style={styles.container}>\n <KeyboardView style={styles.keyboardView}>\n <FlatList\n inverted\n contentContainerStyle={styles.listContainer}\n refreshing={isRefetching}\n onRefresh={refetch}\n data={messagesWithSeparators}\n keyExtractor={item => item.id}\n renderItem={({ item }) => {\n if (item.type === 'DateSeparator') {\n return <InlineDateSeparator {...item} />\n }\n\n return <Message {...item} conversation_id={conversation_id} />\n }}\n onEndReached={() => fetchNextPage()}\n />\n <MessageForm.Root conversation={conversation}>\n {/* <MessageForm.AttachmentPicker /> */}\n <MessageForm.Commands />\n <MessageForm.TextInput />\n <MessageForm.SubmitButton />\n </MessageForm.Root>\n </KeyboardView>\n </View>\n )\n}\n\nexport type DateSeparator = { type: 'DateSeparator'; id: string; date: string }\n\nfunction InlineDateSeparator({ date }: DateSeparator) {\n const styles = useDateSeparatorStyles()\n const { isThisYear } = getRelativeDateStatus(date)\n const showYear = !isThisYear\n const dateStamp = formatDate(date, { style: 'long', year: showYear })\n\n return (\n <View style={styles.container}>\n <View style={styles.separator} />\n <Text variant=\"footnote\" style={styles.dateText}>\n {dateStamp}\n </Text>\n <View style={styles.separator} />\n </View>\n )\n}\n\nconst useDateSeparatorStyles = () => {\n const theme = useTheme()\n return StyleSheet.create({\n container: {\n alignItems: 'center',\n flexDirection: 'row',\n paddingHorizontal: 16,\n paddingVertical: 16,\n },\n separator: {\n flex: 1,\n height: 1,\n borderTopWidth: 1,\n borderTopColor: theme.colors.borderColorDefaultBase,\n },\n dateText: {\n paddingHorizontal: 8,\n },\n })\n}\n\nexport const groupMessages = (ms: MessageResource[]) => {\n let enrichedMessages: (MessageResource | DateSeparator)[] = []\n let encounteredOneOfMyMessages = false\n\n ms.forEach((message, i) => {\n const prevMessage = ms[i + 1]\n const nextMessage = ms[i - 1]\n const date = moment(message.createdAt).format('YYYY-MM-DD')\n const prevMessageDifferentAuthor = message.author?.id !== prevMessage?.author?.id\n const nextMessageDifferentAuthor = message.author?.id !== nextMessage?.author?.id\n const prevMessageMoreThan5Minutes =\n prevMessage &&\n new Date(message.createdAt).getTime() - new Date(prevMessage.createdAt).getTime() > 60000 * 5\n const nextMessageMoreThan5Minutes =\n nextMessage &&\n new Date(nextMessage.createdAt).getTime() - new Date(message.createdAt).getTime() > 60000 * 5\n\n if (message.mine && !encounteredOneOfMyMessages) {\n encounteredOneOfMyMessages = true\n message.myLatestInConversation = true\n } else {\n message.myLatestInConversation = false\n }\n message.lastInGroup = !nextMessage || nextMessageDifferentAuthor || nextMessageMoreThan5Minutes\n message.renderAuthor =\n !message.mine && (!prevMessage || prevMessageDifferentAuthor || prevMessageMoreThan5Minutes)\n\n enrichedMessages.push(message)\n if (!prevMessage || date !== moment(prevMessage.createdAt).format('YYYY-MM-DD')) {\n enrichedMessages.push({ type: 'DateSeparator', id: `day-divider-${message.id}`, date })\n }\n })\n\n return enrichedMessages\n}\n\nconst PressableHeaderTitle = ({ style, children }: HeaderTitleProps) => {\n const styles = usePressableHeaderStyle()\n const navigation = useNavigation()\n\n const route = useRoute() as ConversationScreenProps['route']\n\n const { data: conversation } = useConversation(route.params)\n const badge = conversation.badges?.[0]\n const resourceType = badge?.pcoResourceType || ''\n const productName = badge?.appName\n const name = badge?.text || undefined\n\n return (\n <PlatformPressable\n style={styles.container}\n onPress={() =>\n navigation.navigate('ConversationDetails', { conversation_id: conversation?.id })\n }\n >\n <View style={styles.titleWrapper}>\n <HeaderTitle style={[styles.title, style]}>{children}</HeaderTitle>\n <Icon name=\"general.downChevron\" size={12} />\n </View>\n <Badge\n variant=\"metaSubtle\"\n productLogoName={productName}\n label={resourceType}\n metaLabel={name}\n style={styles.badge}\n />\n </PlatformPressable>\n )\n}\n\nconst usePressableHeaderStyle = () => {\n return StyleSheet.create({\n container: {\n alignItems: Platform.select({ android: 'flex-start', default: 'center' }),\n },\n titleWrapper: {\n alignItems: 'center',\n columnGap: 4,\n flexDirection: 'row',\n },\n title: {\n padding: 0,\n margin: 0,\n },\n badge: {\n alignSelf: Platform.select({ android: 'flex-start', default: 'center' }),\n marginTop: 2,\n },\n })\n}\n\nconst useStyles = () => {\n const navigationTheme = useNavigationTheme()\n const { bottom } = useSafeAreaInsets()\n\n return StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: 'center',\n backgroundColor: navigationTheme.colors.card,\n paddingBottom: bottom,\n },\n keyboardView: {\n flex: 1,\n },\n listContainer: {\n gap: 12,\n paddingHorizontal: 16,\n paddingVertical: 12,\n },\n })\n}\n"]}
@@ -15,5 +15,7 @@ export interface MessageResource {
15
15
  reactionCounts: ReactionCountResource[];
16
16
  renderAuthor?: boolean;
17
17
  renderTime?: boolean;
18
+ myLatestInConversation?: boolean;
19
+ lastInGroup?: boolean;
18
20
  }
19
21
  //# sourceMappingURL=message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/types/resources/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAA;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,8BAA8B,EAAE,CAAA;IAC7C,MAAM,EAAE,cAAc,CAAA;IACtB,cAAc,EAAE,qBAAqB,EAAE,CAAA;IAGvC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB"}
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/types/resources/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAA;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,8BAA8B,EAAE,CAAA;IAC7C,MAAM,EAAE,cAAc,CAAA;IACtB,cAAc,EAAE,qBAAqB,EAAE,CAAA;IAGvC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/types/resources/message.ts"],"names":[],"mappings":"","sourcesContent":["import { DenormalizedAttachmentResource } from './denormalized_attachment_resource'\nimport type { PersonResource } from './person'\nimport type { ReactionCountResource } from './reaction'\n\nexport interface MessageResource {\n type: 'Message'\n id: string\n text: string\n html: string\n createdAt: string\n deletedAt: string | null\n textEditedAt: string | null\n mine: boolean\n attachments: DenormalizedAttachmentResource[]\n author: PersonResource\n reactionCounts: ReactionCountResource[]\n\n // Custom Local Properties we set for rendering\n renderAuthor?: boolean\n renderTime?: boolean\n}\n"]}
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/types/resources/message.ts"],"names":[],"mappings":"","sourcesContent":["import { DenormalizedAttachmentResource } from './denormalized_attachment_resource'\nimport type { PersonResource } from './person'\nimport type { ReactionCountResource } from './reaction'\n\nexport interface MessageResource {\n type: 'Message'\n id: string\n text: string\n html: string\n createdAt: string\n deletedAt: string | null\n textEditedAt: string | null\n mine: boolean\n attachments: DenormalizedAttachmentResource[]\n author: PersonResource\n reactionCounts: ReactionCountResource[]\n\n // Custom Local Properties we set for rendering\n renderAuthor?: boolean\n renderTime?: boolean\n myLatestInConversation?: boolean\n lastInGroup?: boolean\n}\n"]}
@@ -1,4 +1,9 @@
1
1
  type DateProps = string | number | Date;
2
2
  export declare function formatDatePreview(date?: DateProps): any;
3
+ export declare function getRelativeDateStatus(date: DateProps): {
4
+ isToday: boolean;
5
+ isThisWeek: boolean;
6
+ isThisYear: boolean;
7
+ };
3
8
  export {};
4
9
  //# sourceMappingURL=date.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAIA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;AAEvC,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,SAAS,OAcjD"}
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAIA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;AAEvC,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,SAAS,OAcjD;AAOD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS;;;;EAQpD"}
@@ -1,4 +1,4 @@
1
- // @ts-ignore
1
+ // @ts-expect-error
2
2
  import { date as formatDate } from '@planningcenter/datetime-fmt';
3
3
  import moment from 'moment-timezone';
4
4
  export function formatDatePreview(date) {
@@ -21,4 +21,11 @@ const formatShorterDate = (date) => {
21
21
  // Drop the century from the year
22
22
  return formatDate(date, { style: 'short', year: true }).replace(/20(\d{2})/, '$1');
23
23
  };
24
+ export function getRelativeDateStatus(date) {
25
+ const now = moment();
26
+ const isToday = now.isSame(date, 'day');
27
+ const isThisWeek = now.isSame(date, 'week');
28
+ const isThisYear = now.isSame(date, 'year');
29
+ return { isToday, isThisWeek, isThisYear };
30
+ }
24
31
  //# sourceMappingURL=date.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,MAAM,MAAM,iBAAiB,CAAA;AAIpC,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAChD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IAEpB,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IACpB,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACvC,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC3C,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAE3C,IAAI,OAAO;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACjD,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAA;IACpE,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAA;IAEjE,wBAAwB;IACxB,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,IAAe,EAAE,EAAE;IAC5C,iCAAiC;IACjC,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;AACpF,CAAC,CAAA","sourcesContent":["// @ts-ignore\nimport { date as formatDate } from '@planningcenter/datetime-fmt'\nimport moment from 'moment-timezone'\n\ntype DateProps = string | number | Date\n\nexport function formatDatePreview(date?: DateProps) {\n if (!date) return ''\n\n const now = moment()\n const isToday = now.isSame(date, 'day')\n const isThisWeek = now.isSame(date, 'week')\n const isThisYear = now.isSame(date, 'year')\n\n if (isToday) return moment(date).format('h:mm a')\n if (isThisWeek) return formatDate(date, { style: 'relative-short' })\n if (isThisYear) return formatDate(date, { style: 'abbreviated' })\n\n // TODO: Org date format\n return formatShorterDate(date)\n}\n\nconst formatShorterDate = (date: DateProps) => {\n // Drop the century from the year\n return formatDate(date, { style: 'short', year: true }).replace(/20(\\d{2})/, '$1')\n}\n"]}
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,MAAM,MAAM,iBAAiB,CAAA;AAIpC,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IA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3C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA;AAC5C,CAAC","sourcesContent":["// @ts-expect-error\nimport { date as formatDate } from '@planningcenter/datetime-fmt'\nimport moment from 'moment-timezone'\n\ntype DateProps = string | number | Date\n\nexport function formatDatePreview(date?: DateProps) {\n if (!date) return ''\n\n const now = moment()\n const isToday = now.isSame(date, 'day')\n const isThisWeek = now.isSame(date, 'week')\n const isThisYear = now.isSame(date, 'year')\n\n if (isToday) return moment(date).format('h:mm a')\n if (isThisWeek) return formatDate(date, { style: 'relative-short' })\n if (isThisYear) return formatDate(date, { style: 'abbreviated' })\n\n // TODO: Org date format\n return formatShorterDate(date)\n}\n\nconst formatShorterDate = (date: DateProps) => {\n // Drop the century from the year\n return formatDate(date, { style: 'short', year: true }).replace(/20(\\d{2})/, '$1')\n}\n\nexport function getRelativeDateStatus(date: DateProps) {\n const now = moment()\n\n const isToday = now.isSame(date, 'day')\n const isThisWeek = now.isSame(date, 'week')\n const isThisYear = now.isSame(date, 'year')\n\n return { isToday, isThisWeek, isThisYear }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/chat-react-native",
3
- "version": "3.2.0-rc.24",
3
+ "version": "3.2.0-rc.25",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -55,5 +55,5 @@
55
55
  "prettier": "^3.4.2",
56
56
  "typescript": "<5.6.0"
57
57
  },
58
- "gitHead": "95297a29c653d2904fa975bc4f1e655d3ccc1366"
58
+ "gitHead": "5341fc7d2489707a08f20ce39b3fef50cbe9d5c5"
59
59
  }
@@ -1,3 +1,5 @@
1
+ // @ts-expect-error
2
+ import { date as formatDate } from '@planningcenter/datetime-fmt'
1
3
  import { HeaderTitle, HeaderTitleProps, PlatformPressable } from '@react-navigation/elements'
2
4
  import {
3
5
  StaticScreenProps,
@@ -5,15 +7,19 @@ import {
5
7
  useTheme as useNavigationTheme,
6
8
  useRoute,
7
9
  } from '@react-navigation/native'
10
+ import moment from 'moment'
8
11
  import React, { useCallback, useEffect } from 'react'
9
12
  import { FlatList, Platform, StyleSheet, View } from 'react-native'
10
13
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
11
- import { Badge, Icon } from '../components'
14
+ import { Badge, Icon, Text } from '../components'
12
15
  import { Message } from '../components/conversation/message'
13
16
  import { MessageForm } from '../components/conversation/message_form'
14
17
  import { KeyboardView } from '../components/display/keyboard_view'
18
+ import { useTheme } from '../hooks'
15
19
  import { useConversation } from '../hooks/use_conversation'
16
20
  import { useConversationMessages } from '../hooks/use_conversation_messages'
21
+ import { MessageResource } from '../types'
22
+ import { getRelativeDateStatus } from '../utils/date'
17
23
 
18
24
  type ConversationRouteProps = {
19
25
  conversation_id: number
@@ -32,6 +38,7 @@ export function ConversationScreen({ route }: ConversationScreenProps) {
32
38
  const { messages, refetch, isRefetching, fetchNextPage } = useConversationMessages({
33
39
  conversation_id,
34
40
  })
41
+ const messagesWithSeparators = groupMessages(messages)
35
42
 
36
43
  // Seems to be necessary to define this way so we get the route picked up
37
44
  const headerTitle = useCallback(
@@ -51,9 +58,15 @@ export function ConversationScreen({ route }: ConversationScreenProps) {
51
58
  contentContainerStyle={styles.listContainer}
52
59
  refreshing={isRefetching}
53
60
  onRefresh={refetch}
54
- data={messages}
61
+ data={messagesWithSeparators}
55
62
  keyExtractor={item => item.id}
56
- renderItem={({ item }) => <Message {...item} conversation_id={conversation_id} />}
63
+ renderItem={({ item }) => {
64
+ if (item.type === 'DateSeparator') {
65
+ return <InlineDateSeparator {...item} />
66
+ }
67
+
68
+ return <Message {...item} conversation_id={conversation_id} />
69
+ }}
57
70
  onEndReached={() => fetchNextPage()}
58
71
  />
59
72
  <MessageForm.Root conversation={conversation}>
@@ -67,6 +80,82 @@ export function ConversationScreen({ route }: ConversationScreenProps) {
67
80
  )
68
81
  }
69
82
 
83
+ export type DateSeparator = { type: 'DateSeparator'; id: string; date: string }
84
+
85
+ function InlineDateSeparator({ date }: DateSeparator) {
86
+ const styles = useDateSeparatorStyles()
87
+ const { isThisYear } = getRelativeDateStatus(date)
88
+ const showYear = !isThisYear
89
+ const dateStamp = formatDate(date, { style: 'long', year: showYear })
90
+
91
+ return (
92
+ <View style={styles.container}>
93
+ <View style={styles.separator} />
94
+ <Text variant="footnote" style={styles.dateText}>
95
+ {dateStamp}
96
+ </Text>
97
+ <View style={styles.separator} />
98
+ </View>
99
+ )
100
+ }
101
+
102
+ const useDateSeparatorStyles = () => {
103
+ const theme = useTheme()
104
+ return StyleSheet.create({
105
+ container: {
106
+ alignItems: 'center',
107
+ flexDirection: 'row',
108
+ paddingHorizontal: 16,
109
+ paddingVertical: 16,
110
+ },
111
+ separator: {
112
+ flex: 1,
113
+ height: 1,
114
+ borderTopWidth: 1,
115
+ borderTopColor: theme.colors.borderColorDefaultBase,
116
+ },
117
+ dateText: {
118
+ paddingHorizontal: 8,
119
+ },
120
+ })
121
+ }
122
+
123
+ export const groupMessages = (ms: MessageResource[]) => {
124
+ let enrichedMessages: (MessageResource | DateSeparator)[] = []
125
+ let encounteredOneOfMyMessages = false
126
+
127
+ ms.forEach((message, i) => {
128
+ const prevMessage = ms[i + 1]
129
+ const nextMessage = ms[i - 1]
130
+ const date = moment(message.createdAt).format('YYYY-MM-DD')
131
+ const prevMessageDifferentAuthor = message.author?.id !== prevMessage?.author?.id
132
+ const nextMessageDifferentAuthor = message.author?.id !== nextMessage?.author?.id
133
+ const prevMessageMoreThan5Minutes =
134
+ prevMessage &&
135
+ new Date(message.createdAt).getTime() - new Date(prevMessage.createdAt).getTime() > 60000 * 5
136
+ const nextMessageMoreThan5Minutes =
137
+ nextMessage &&
138
+ new Date(nextMessage.createdAt).getTime() - new Date(message.createdAt).getTime() > 60000 * 5
139
+
140
+ if (message.mine && !encounteredOneOfMyMessages) {
141
+ encounteredOneOfMyMessages = true
142
+ message.myLatestInConversation = true
143
+ } else {
144
+ message.myLatestInConversation = false
145
+ }
146
+ message.lastInGroup = !nextMessage || nextMessageDifferentAuthor || nextMessageMoreThan5Minutes
147
+ message.renderAuthor =
148
+ !message.mine && (!prevMessage || prevMessageDifferentAuthor || prevMessageMoreThan5Minutes)
149
+
150
+ enrichedMessages.push(message)
151
+ if (!prevMessage || date !== moment(prevMessage.createdAt).format('YYYY-MM-DD')) {
152
+ enrichedMessages.push({ type: 'DateSeparator', id: `day-divider-${message.id}`, date })
153
+ }
154
+ })
155
+
156
+ return enrichedMessages
157
+ }
158
+
70
159
  const PressableHeaderTitle = ({ style, children }: HeaderTitleProps) => {
71
160
  const styles = usePressableHeaderStyle()
72
161
  const navigation = useNavigation()
@@ -18,4 +18,6 @@ export interface MessageResource {
18
18
  // Custom Local Properties we set for rendering
19
19
  renderAuthor?: boolean
20
20
  renderTime?: boolean
21
+ myLatestInConversation?: boolean
22
+ lastInGroup?: boolean
21
23
  }
package/src/utils/date.ts CHANGED
@@ -1,4 +1,4 @@
1
- // @ts-ignore
1
+ // @ts-expect-error
2
2
  import { date as formatDate } from '@planningcenter/datetime-fmt'
3
3
  import moment from 'moment-timezone'
4
4
 
@@ -24,3 +24,13 @@ const formatShorterDate = (date: DateProps) => {
24
24
  // Drop the century from the year
25
25
  return formatDate(date, { style: 'short', year: true }).replace(/20(\d{2})/, '$1')
26
26
  }
27
+
28
+ export function getRelativeDateStatus(date: DateProps) {
29
+ const now = moment()
30
+
31
+ const isToday = now.isSame(date, 'day')
32
+ const isThisWeek = now.isSame(date, 'week')
33
+ const isThisYear = now.isSame(date, 'year')
34
+
35
+ return { isToday, isThisWeek, isThisYear }
36
+ }