@planningcenter/chat-react-native 3.1.0-rc.13 → 3.1.0-rc.15

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.
Files changed (252) hide show
  1. package/build/components/conversation/attachments/attachment_card.d.ts +9 -0
  2. package/build/components/conversation/attachments/attachment_card.d.ts.map +1 -0
  3. package/build/components/conversation/attachments/attachment_card.js +35 -0
  4. package/build/components/conversation/attachments/attachment_card.js.map +1 -0
  5. package/build/components/conversation/attachments/audio_attachment.d.ts +6 -0
  6. package/build/components/conversation/attachments/audio_attachment.d.ts.map +1 -0
  7. package/build/components/conversation/attachments/audio_attachment.js +84 -0
  8. package/build/components/conversation/attachments/audio_attachment.js.map +1 -0
  9. package/build/components/conversation/attachments/constants.d.ts +3 -0
  10. package/build/components/conversation/attachments/constants.d.ts.map +1 -0
  11. package/build/components/conversation/attachments/constants.js +4 -0
  12. package/build/components/conversation/attachments/constants.js.map +1 -0
  13. package/build/components/conversation/attachments/download_attachment_button.d.ts +9 -0
  14. package/build/components/conversation/attachments/download_attachment_button.d.ts.map +1 -0
  15. package/build/components/conversation/attachments/download_attachment_button.js +29 -0
  16. package/build/components/conversation/attachments/download_attachment_button.js.map +1 -0
  17. package/build/components/conversation/attachments/expanded_link.d.ts +5 -0
  18. package/build/components/conversation/attachments/expanded_link.d.ts.map +1 -0
  19. package/build/components/conversation/attachments/expanded_link.js +44 -0
  20. package/build/components/conversation/attachments/expanded_link.js.map +1 -0
  21. package/build/components/conversation/attachments/generic_file_attachment.d.ts +7 -0
  22. package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -0
  23. package/build/components/conversation/attachments/generic_file_attachment.js +63 -0
  24. package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -0
  25. package/build/components/conversation/attachments/giphy_attachment.d.ts +6 -0
  26. package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -0
  27. package/build/components/conversation/attachments/giphy_attachment.js +42 -0
  28. package/build/components/conversation/attachments/giphy_attachment.js.map +1 -0
  29. package/build/components/conversation/attachments/image_attachment.d.ts +5 -0
  30. package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -0
  31. package/build/components/conversation/attachments/image_attachment.js +24 -0
  32. package/build/components/conversation/attachments/image_attachment.js.map +1 -0
  33. package/build/components/conversation/attachments/video_attachment.d.ts +6 -0
  34. package/build/components/conversation/attachments/video_attachment.d.ts.map +1 -0
  35. package/build/components/conversation/attachments/video_attachment.js +64 -0
  36. package/build/components/conversation/attachments/video_attachment.js.map +1 -0
  37. package/build/components/conversation/message.d.ts +1 -1
  38. package/build/components/conversation/message.d.ts.map +1 -1
  39. package/build/components/conversation/message.js +13 -7
  40. package/build/components/conversation/message.js.map +1 -1
  41. package/build/components/conversation/message_attachments.d.ts +6 -0
  42. package/build/components/conversation/message_attachments.d.ts.map +1 -0
  43. package/build/components/conversation/message_attachments.js +52 -0
  44. package/build/components/conversation/message_attachments.js.map +1 -0
  45. package/build/components/conversation/message_markdown.d.ts +7 -0
  46. package/build/components/conversation/message_markdown.d.ts.map +1 -0
  47. package/build/components/conversation/message_markdown.js +38 -0
  48. package/build/components/conversation/message_markdown.js.map +1 -0
  49. package/build/components/conversations/conversation_preview.d.ts +9 -0
  50. package/build/components/conversations/conversation_preview.d.ts.map +1 -0
  51. package/build/components/conversations/conversation_preview.js +58 -0
  52. package/build/components/conversations/conversation_preview.js.map +1 -0
  53. package/build/components/conversations/conversations.d.ts +8 -0
  54. package/build/components/conversations/conversations.d.ts.map +1 -0
  55. package/build/components/conversations/conversations.js +40 -0
  56. package/build/components/conversations/conversations.js.map +1 -0
  57. package/build/components/conversations/unread_count_badge.d.ts +5 -0
  58. package/build/components/conversations/unread_count_badge.d.ts.map +1 -0
  59. package/build/components/conversations/unread_count_badge.js +33 -0
  60. package/build/components/conversations/unread_count_badge.js.map +1 -0
  61. package/build/components/display/badge.d.ts +9 -1
  62. package/build/components/display/badge.d.ts.map +1 -1
  63. package/build/components/display/badge.js +22 -10
  64. package/build/components/display/badge.js.map +1 -1
  65. package/build/components/display/button.d.ts +1 -1
  66. package/build/components/display/button.d.ts.map +1 -1
  67. package/build/components/display/button.js.map +1 -1
  68. package/build/components/display/child_notice.js +2 -2
  69. package/build/components/display/child_notice.js.map +1 -1
  70. package/build/components/display/icon.d.ts.map +1 -1
  71. package/build/components/display/icon.js +10 -8
  72. package/build/components/display/icon.js.map +1 -1
  73. package/build/components/display/text.js +2 -8
  74. package/build/components/display/text.js.map +1 -1
  75. package/build/components/index.d.ts +1 -1
  76. package/build/components/index.d.ts.map +1 -1
  77. package/build/components/index.js +1 -1
  78. package/build/components/index.js.map +1 -1
  79. package/build/components/page/error_boundary.d.ts +1 -1
  80. package/build/hooks/use_api.d.ts +6 -4
  81. package/build/hooks/use_api.d.ts.map +1 -1
  82. package/build/hooks/use_api.js +5 -2
  83. package/build/hooks/use_api.js.map +1 -1
  84. package/build/hooks/use_api_client.d.ts +1 -2
  85. package/build/hooks/use_api_client.d.ts.map +1 -1
  86. package/build/hooks/use_api_client.js.map +1 -1
  87. package/build/hooks/use_conversation.js +1 -1
  88. package/build/hooks/use_conversation.js.map +1 -1
  89. package/build/hooks/use_conversation_jolt_events.js +1 -1
  90. package/build/hooks/use_conversation_jolt_events.js.map +1 -1
  91. package/build/hooks/use_conversation_messages_jolt_events.js +1 -1
  92. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
  93. package/build/hooks/use_conversations.d.ts +2 -3
  94. package/build/hooks/use_conversations.d.ts.map +1 -1
  95. package/build/hooks/use_conversations.js +3 -29
  96. package/build/hooks/use_conversations.js.map +1 -1
  97. package/build/hooks/use_groups.d.ts +214 -0
  98. package/build/hooks/use_groups.d.ts.map +1 -0
  99. package/build/hooks/use_groups.js +22 -0
  100. package/build/hooks/use_groups.js.map +1 -0
  101. package/build/hooks/use_groups_groups.d.ts +208 -0
  102. package/build/hooks/use_groups_groups.d.ts.map +1 -0
  103. package/build/hooks/use_groups_groups.js +18 -0
  104. package/build/hooks/use_groups_groups.js.map +1 -0
  105. package/build/hooks/use_services_team.d.ts +4 -0
  106. package/build/hooks/use_services_team.d.ts.map +1 -0
  107. package/build/hooks/use_services_team.js +22 -0
  108. package/build/hooks/use_services_team.js.map +1 -0
  109. package/build/hooks/use_suspense_api.d.ts +2 -1
  110. package/build/hooks/use_suspense_api.d.ts.map +1 -1
  111. package/build/hooks/use_suspense_api.js +2 -1
  112. package/build/hooks/use_suspense_api.js.map +1 -1
  113. package/build/hooks/use_teams.d.ts +208 -0
  114. package/build/hooks/use_teams.d.ts.map +1 -0
  115. package/build/hooks/use_teams.js +22 -0
  116. package/build/hooks/use_teams.js.map +1 -0
  117. package/build/navigation/index.d.ts +11 -0
  118. package/build/navigation/index.d.ts.map +1 -1
  119. package/build/navigation/index.js +5 -0
  120. package/build/navigation/index.js.map +1 -1
  121. package/build/screens/conversation_details_screen.d.ts.map +1 -1
  122. package/build/screens/conversation_details_screen.js +86 -62
  123. package/build/screens/conversation_details_screen.js.map +1 -1
  124. package/build/screens/conversation_filters_screen.d.ts +13 -0
  125. package/build/screens/conversation_filters_screen.d.ts.map +1 -0
  126. package/build/screens/conversation_filters_screen.js +346 -0
  127. package/build/screens/conversation_filters_screen.js.map +1 -0
  128. package/build/screens/conversation_screen.js +2 -1
  129. package/build/screens/conversation_screen.js.map +1 -1
  130. package/build/screens/conversations_screen.d.ts +4 -2
  131. package/build/screens/conversations_screen.d.ts.map +1 -1
  132. package/build/screens/conversations_screen.js +139 -11
  133. package/build/screens/conversations_screen.js.map +1 -1
  134. package/build/screens/create/conversation_select_recipients_screen.d.ts.map +1 -1
  135. package/build/screens/create/conversation_select_recipients_screen.js +3 -11
  136. package/build/screens/create/conversation_select_recipients_screen.js.map +1 -1
  137. package/build/types/resources/group_resource.d.ts +4 -2
  138. package/build/types/resources/group_resource.d.ts.map +1 -1
  139. package/build/types/resources/group_resource.js.map +1 -1
  140. package/build/types/resources/index.d.ts +1 -0
  141. package/build/types/resources/index.d.ts.map +1 -1
  142. package/build/types/resources/index.js +1 -0
  143. package/build/types/resources/index.js.map +1 -1
  144. package/build/types/resources/services/index.d.ts +2 -0
  145. package/build/types/resources/services/index.d.ts.map +1 -0
  146. package/build/types/resources/services/index.js +2 -0
  147. package/build/types/resources/services/index.js.map +1 -0
  148. package/build/types/resources/services/team_resource.d.ts +48 -0
  149. package/build/types/resources/services/team_resource.d.ts.map +1 -0
  150. package/build/types/resources/services/team_resource.js +7 -0
  151. package/build/types/resources/services/team_resource.js.map +1 -0
  152. package/build/utils/index.d.ts +1 -0
  153. package/build/utils/index.d.ts.map +1 -1
  154. package/build/utils/index.js +1 -0
  155. package/build/utils/index.js.map +1 -1
  156. package/build/utils/native_adapters/audio.d.ts +13 -0
  157. package/build/utils/native_adapters/audio.d.ts.map +1 -0
  158. package/build/utils/native_adapters/audio.js +7 -0
  159. package/build/utils/native_adapters/audio.js.map +1 -0
  160. package/build/utils/native_adapters/configuration.d.ts +7 -1
  161. package/build/utils/native_adapters/configuration.d.ts.map +1 -1
  162. package/build/utils/native_adapters/configuration.js +17 -1
  163. package/build/utils/native_adapters/configuration.js.map +1 -1
  164. package/build/utils/native_adapters/index.d.ts +2 -0
  165. package/build/utils/native_adapters/index.d.ts.map +1 -1
  166. package/build/utils/native_adapters/index.js +2 -0
  167. package/build/utils/native_adapters/index.js.map +1 -1
  168. package/build/utils/native_adapters/video.d.ts +25 -0
  169. package/build/utils/native_adapters/video.d.ts.map +1 -0
  170. package/build/utils/native_adapters/video.js +7 -0
  171. package/build/utils/native_adapters/video.js.map +1 -0
  172. package/build/utils/parse_simple_markdown.d.ts +7 -0
  173. package/build/utils/parse_simple_markdown.d.ts.map +1 -0
  174. package/build/utils/parse_simple_markdown.js +32 -0
  175. package/build/utils/parse_simple_markdown.js.map +1 -0
  176. package/build/utils/pluralize.d.ts +2 -0
  177. package/build/utils/pluralize.d.ts.map +1 -0
  178. package/build/utils/pluralize.js +10 -0
  179. package/build/utils/pluralize.js.map +1 -0
  180. package/build/utils/request/conversation.d.ts +10 -0
  181. package/build/utils/request/conversation.d.ts.map +1 -0
  182. package/build/utils/request/conversation.js +32 -0
  183. package/build/utils/request/conversation.js.map +1 -0
  184. package/build/utils/request/messages.d.ts +15 -0
  185. package/build/utils/request/messages.d.ts.map +1 -0
  186. package/build/utils/request/messages.js +22 -0
  187. package/build/utils/request/messages.js.map +1 -0
  188. package/build/utils/theme.d.ts +1 -1
  189. package/build/utils/theme.d.ts.map +1 -1
  190. package/build/utils/theme.js +1 -1
  191. package/build/utils/theme.js.map +1 -1
  192. package/package.json +2 -2
  193. package/src/__tests__/utils/parse_simple_markdown.ts +93 -0
  194. package/src/__tests__/utils/pluralize.tsx +17 -0
  195. package/src/components/conversation/attachments/attachment_card.tsx +46 -0
  196. package/src/components/conversation/attachments/audio_attachment.tsx +102 -0
  197. package/src/components/conversation/attachments/constants.ts +5 -0
  198. package/src/components/conversation/attachments/download_attachment_button.tsx +46 -0
  199. package/src/components/conversation/attachments/expanded_link.tsx +54 -0
  200. package/src/components/conversation/attachments/generic_file_attachment.tsx +75 -0
  201. package/src/components/conversation/attachments/giphy_attachment.tsx +56 -0
  202. package/src/components/conversation/attachments/image_attachment.tsx +31 -0
  203. package/src/components/conversation/attachments/video_attachment.tsx +92 -0
  204. package/src/components/conversation/message.tsx +15 -6
  205. package/src/components/conversation/message_attachments.tsx +61 -0
  206. package/src/components/conversation/message_markdown.tsx +52 -0
  207. package/src/components/conversations/conversation_preview.tsx +84 -0
  208. package/src/components/conversations/conversations.tsx +79 -0
  209. package/src/components/conversations/unread_count_badge.tsx +38 -0
  210. package/src/components/display/badge.tsx +41 -10
  211. package/src/components/display/button.tsx +1 -1
  212. package/src/components/display/child_notice.tsx +2 -2
  213. package/src/components/display/icon.tsx +10 -8
  214. package/src/components/display/text.tsx +1 -7
  215. package/src/components/index.tsx +1 -1
  216. package/src/hooks/use_api.ts +11 -10
  217. package/src/hooks/use_api_client.ts +1 -1
  218. package/src/hooks/use_conversation.ts +1 -1
  219. package/src/hooks/use_conversation_jolt_events.ts +1 -1
  220. package/src/hooks/use_conversation_messages_jolt_events.ts +1 -1
  221. package/src/hooks/use_conversations.ts +3 -31
  222. package/src/hooks/use_groups.ts +31 -0
  223. package/src/hooks/use_groups_groups.ts +20 -0
  224. package/src/hooks/use_services_team.ts +30 -0
  225. package/src/hooks/use_suspense_api.ts +4 -4
  226. package/src/hooks/use_teams.ts +25 -0
  227. package/src/navigation/index.tsx +8 -0
  228. package/src/screens/conversation_details_screen.tsx +149 -117
  229. package/src/screens/conversation_filters_screen.tsx +488 -0
  230. package/src/screens/conversation_screen.tsx +8 -1
  231. package/src/screens/conversations_screen.tsx +210 -13
  232. package/src/screens/create/conversation_select_recipients_screen.tsx +3 -11
  233. package/src/types/resources/group_resource.ts +5 -2
  234. package/src/types/resources/index.ts +1 -0
  235. package/src/types/resources/services/index.ts +1 -0
  236. package/src/types/resources/services/team_resource.ts +60 -0
  237. package/src/utils/client/types.d.ts +2 -1
  238. package/src/utils/index.ts +1 -0
  239. package/src/utils/native_adapters/audio.ts +15 -0
  240. package/src/utils/native_adapters/configuration.ts +24 -1
  241. package/src/utils/native_adapters/index.ts +2 -0
  242. package/src/utils/native_adapters/video.ts +30 -0
  243. package/src/utils/parse_simple_markdown.ts +40 -0
  244. package/src/utils/pluralize.ts +11 -0
  245. package/src/utils/request/conversation.ts +46 -0
  246. package/src/utils/request/messages.ts +21 -0
  247. package/src/utils/theme.ts +2 -2
  248. package/build/components/conversations.d.ts +0 -3
  249. package/build/components/conversations.d.ts.map +0 -1
  250. package/build/components/conversations.js +0 -100
  251. package/build/components/conversations.js.map +0 -1
  252. package/src/components/conversations.tsx +0 -144
@@ -0,0 +1,54 @@
1
+ import React from 'react'
2
+ import { Image, Linking, Pressable, StyleSheet, Text, View } from 'react-native'
3
+ import { useTheme } from '../../../hooks'
4
+ import { tokens } from '../../../vendor/tapestry/tokens'
5
+
6
+ export function ExpandedLink({ attachment }: { attachment: any }) {
7
+ const styles = useStyles()
8
+ const { attributes } = attachment
9
+ const { url, title, description, imageUrl, imageHeight, imageWidth } = attributes
10
+
11
+ const aspectRatio = imageWidth && imageHeight ? imageWidth / imageHeight : 1
12
+
13
+ async function openUrl() {
14
+ if (url) Linking.openURL(url)
15
+ }
16
+
17
+ return (
18
+ <Pressable style={styles.container} onPress={openUrl}>
19
+ {imageUrl && (
20
+ <Image source={{ uri: imageUrl }} style={[styles.image, { aspectRatio }]} alt={title} />
21
+ )}
22
+ {(title || description) && (
23
+ <View style={styles.textWrapper}>
24
+ {title && <Text style={styles.title}>{title}</Text>}
25
+ {description && <Text style={styles.description}>{description}</Text>}
26
+ </View>
27
+ )}
28
+ </Pressable>
29
+ )
30
+ }
31
+
32
+ const useStyles = () => {
33
+ const { colors } = useTheme()
34
+
35
+ return StyleSheet.create({
36
+ container: {},
37
+ image: {
38
+ borderRadius: 8,
39
+ },
40
+ textWrapper: {
41
+ gap: 4,
42
+ padding: 8,
43
+ },
44
+ title: {
45
+ fontSize: tokens.fontSizeSm,
46
+ fontWeight: tokens.fontWeightMedium,
47
+ color: colors.textColorDefaultPrimary,
48
+ },
49
+ description: {
50
+ fontSize: tokens.fontSizeXs,
51
+ color: colors.textColorDefaultPrimary,
52
+ },
53
+ })
54
+ }
@@ -0,0 +1,75 @@
1
+ import React from 'react'
2
+ import { Pressable, StyleSheet, View } from 'react-native'
3
+ import { DenormalizedMessageAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
4
+ import { AttachmentCard, AttachmentCardTitle } from './attachment_card'
5
+ import { Icon } from '../../display'
6
+ import { DownloadAttachmentButton } from './download_attachment_button'
7
+ import { useTheme } from '../../../hooks'
8
+
9
+ export function GenericFileAttachment({
10
+ attachment,
11
+ }: {
12
+ attachment: DenormalizedMessageAttachmentResource
13
+ }) {
14
+ const styles = useStyles()
15
+ const { url, filename, contentType } = attachment.attributes
16
+ const iconName = getAttachmentIconName(contentType)
17
+ const fileTypeLabel = contentType === 'application/pdf' ? 'PDF' : 'file'
18
+
19
+ return (
20
+ <Pressable>
21
+ <AttachmentCard>
22
+ <View style={styles.container}>
23
+ <View style={styles.stack}>
24
+ <Icon name={iconName} />
25
+ <AttachmentCardTitle>{filename}</AttachmentCardTitle>
26
+ </View>
27
+ <DownloadAttachmentButton
28
+ to={url}
29
+ filename={filename}
30
+ title={`Download ${fileTypeLabel}`}
31
+ />
32
+ </View>
33
+ </AttachmentCard>
34
+ </Pressable>
35
+ )
36
+ }
37
+
38
+ const useStyles = () => {
39
+ const { colors } = useTheme()
40
+
41
+ return StyleSheet.create({
42
+ container: {
43
+ padding: 8,
44
+ gap: 4,
45
+ flexDirection: 'row',
46
+ alignItems: 'center',
47
+ justifyContent: 'space-between',
48
+ minHeight: 48,
49
+ },
50
+ stack: {
51
+ gap: 4,
52
+ flexDirection: 'row',
53
+ alignItems: 'center',
54
+ maxWidth: '70%',
55
+ },
56
+ icon: {
57
+ color: colors.textColorDefaultPrimary,
58
+ width: 24,
59
+ height: 24,
60
+ },
61
+ })
62
+ }
63
+
64
+ export function getAttachmentIconName(type: string) {
65
+ const isImage = type.startsWith('image/')
66
+ const isVideo = type.startsWith('video/')
67
+ const isAudio = type.startsWith('audio/')
68
+ const isPdf = type === 'application/pdf'
69
+
70
+ if (isImage) return 'general.outlinedImageFile'
71
+ if (isVideo) return 'general.outlinedVideoFile'
72
+ if (isAudio) return 'general.outlinedMusicFile'
73
+ if (isPdf) return 'general.outlinedPdfFile'
74
+ return 'general.outlinedGenericFile'
75
+ }
@@ -0,0 +1,56 @@
1
+ import React from 'react'
2
+ import { Text, Image, StyleSheet, Linking, Pressable } from 'react-native'
3
+ import { tokens } from '../../../vendor/tapestry/tokens'
4
+ import { useTheme } from '../../../hooks'
5
+ import { DenormalizedGiphyAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
6
+
7
+ export function GiphyAttachment({
8
+ attachment,
9
+ }: {
10
+ attachment: DenormalizedGiphyAttachmentResource
11
+ }) {
12
+ const styles = useStyles()
13
+ const { title, titleLink, giphy } = attachment
14
+ const { url, width, height } = giphy.fixedWidth
15
+
16
+ function handlePress() {
17
+ if (titleLink) {
18
+ // Open Giphy link in the default web browser
19
+ Linking.openURL(titleLink)
20
+ }
21
+ }
22
+
23
+ return (
24
+ <Pressable onPress={handlePress} style={styles.container}>
25
+ <Image
26
+ source={{ uri: url }}
27
+ style={[styles.image, { width, height }]}
28
+ accessibilityLabel={title}
29
+ />
30
+ <Text style={styles.link}>
31
+ <Text style={styles.tag}>/giphy</Text> {title}
32
+ </Text>
33
+ </Pressable>
34
+ )
35
+ }
36
+
37
+ const useStyles = () => {
38
+ const { colors } = useTheme()
39
+ return StyleSheet.create({
40
+ container: {
41
+ gap: 4,
42
+ },
43
+ image: {
44
+ borderRadius: 8,
45
+ },
46
+ link: {
47
+ fontSize: tokens.fontSizeSm,
48
+ color: colors.fillColorInteractionDefault,
49
+ paddingHorizontal: 8,
50
+ paddingVertical: 6,
51
+ },
52
+ tag: {
53
+ fontWeight: 'bold',
54
+ },
55
+ })
56
+ }
@@ -0,0 +1,31 @@
1
+ import React from 'react'
2
+ import { View, Image, StyleSheet } from 'react-native'
3
+
4
+ export function ImageAttachment({ attachment }: { attachment: any }) {
5
+ const styles = useStyles()
6
+ const { attributes } = attachment
7
+ const { url, urlMedium, filename, metadata = {} } = attributes
8
+ const width = metadata.width || 100
9
+ const height = metadata.height || 100
10
+ return (
11
+ <View style={styles.container}>
12
+ <Image
13
+ source={{ uri: urlMedium || url }}
14
+ style={[styles.image, { aspectRatio: width / height }]}
15
+ accessibilityLabel={filename}
16
+ />
17
+ </View>
18
+ )
19
+ }
20
+
21
+ const useStyles = () => {
22
+ return StyleSheet.create({
23
+ container: {
24
+ maxWidth: '100%',
25
+ },
26
+ image: {
27
+ borderRadius: 8,
28
+ minWidth: 200,
29
+ },
30
+ })
31
+ }
@@ -0,0 +1,92 @@
1
+ import React, { useRef, useState } from 'react'
2
+ import { View, StyleSheet, Pressable } from 'react-native'
3
+ import { DenormalizedMessageAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
4
+ import { MESSAGE_ATTACHMENT_WIDTH_SINGLE } from './constants'
5
+ import { IconButton } from '../../display'
6
+ import { Video, VideoPlayerHandle } from '../../../utils/native_adapters'
7
+
8
+ export function VideoAttachment({
9
+ attachment,
10
+ }: {
11
+ attachment: DenormalizedMessageAttachmentResource
12
+ }) {
13
+ const { attributes } = attachment
14
+ const { width = MESSAGE_ATTACHMENT_WIDTH_SINGLE, height = MESSAGE_ATTACHMENT_WIDTH_SINGLE } =
15
+ attributes.metadata || {}
16
+ const { url } = attributes
17
+
18
+ const videoRef = useRef<VideoPlayerHandle>(null)
19
+ const [isOpen, setIsOpen] = useState(false)
20
+
21
+ function openVideo() {
22
+ if (!isOpen && videoRef.current) {
23
+ videoRef.current.presentFullscreenPlayer()
24
+ videoRef.current.play()
25
+ setIsOpen(true)
26
+ }
27
+ }
28
+
29
+ function onFullscreenPlayerWillDismiss() {
30
+ videoRef.current?.pause()
31
+ setIsOpen(false)
32
+ }
33
+
34
+ const viewRef = useRef<View>(null)
35
+
36
+ return (
37
+ <View style={styles.container} ref={viewRef}>
38
+ <Pressable onPress={openVideo}>
39
+ <Video.Player
40
+ ref={videoRef}
41
+ source={{ uri: url }}
42
+ aspectRatio={width / height}
43
+ style={styles.video}
44
+ onFullscreenPlayerWillDismiss={onFullscreenPlayerWillDismiss}
45
+ />
46
+ {!isOpen && (
47
+ <View style={styles.playButtonWrapper}>
48
+ <IconButton
49
+ name="services.play"
50
+ size="md"
51
+ accessibilityLabel="Play Video"
52
+ onPress={openVideo}
53
+ style={styles.button}
54
+ />
55
+ </View>
56
+ )}
57
+ </Pressable>
58
+ </View>
59
+ )
60
+ }
61
+
62
+ const styles = StyleSheet.create({
63
+ container: {
64
+ maxWidth: 320,
65
+ maxHeight: 320,
66
+ },
67
+ video: {
68
+ width: '100%',
69
+ height: 'auto',
70
+ backgroundColor: 'black',
71
+ borderRadius: 8,
72
+ },
73
+ playButtonWrapper: {
74
+ position: 'absolute',
75
+ top: 0,
76
+ left: 0,
77
+ right: 0,
78
+ bottom: 0,
79
+ justifyContent: 'center',
80
+ alignItems: 'center',
81
+ },
82
+ button: {
83
+ width: 42,
84
+ height: 42,
85
+ justifyContent: 'center',
86
+ alignItems: 'center',
87
+ borderRadius: 25,
88
+ backgroundColor: '#eee',
89
+ borderColor: '#aaa',
90
+ borderWidth: 1,
91
+ },
92
+ })
@@ -8,6 +8,9 @@ import { Avatar, Text } from '../../components/display'
8
8
  import { useTheme } from '../../hooks'
9
9
  import { MessageResource } from '../../types'
10
10
  import { ReactionCountResource } from '../../types/resources/reaction'
11
+ import { MessageAttachments } from './message_attachments'
12
+ import ErrorBoundary from '../page/error_boundary'
13
+ import { MessageMarkdown } from './message_markdown'
11
14
 
12
15
  /** Message
13
16
  * Component for display of a message within a conversation list
@@ -29,7 +32,6 @@ export function Message(props: MessageResource & { conversation_id: number }) {
29
32
  reaction_value: reaction.value,
30
33
  })
31
34
  }
32
- if (!text) return null
33
35
 
34
36
  return (
35
37
  <View style={styles.message}>
@@ -41,7 +43,14 @@ export function Message(props: MessageResource & { conversation_id: number }) {
41
43
  <View style={styles.messageContent}>
42
44
  {!props.mine && <Text variant="tertiary">{props.author.name}</Text>}
43
45
  <PlatformPressable style={styles.messageBubble} onLongPress={handleMessagePress}>
44
- <Text style={styles.messageText}>{text}</Text>
46
+ <ErrorBoundary>
47
+ <MessageAttachments attachments={props.attachments} />
48
+ </ErrorBoundary>
49
+ {text && (
50
+ <View style={styles.messageText}>
51
+ <MessageMarkdown text={text} />
52
+ </View>
53
+ )}
45
54
  </PlatformPressable>
46
55
  <View style={styles.messageReactions}>
47
56
  {reactionCounts.map(reaction => (
@@ -76,12 +85,12 @@ const useMessageStyles = ({ mine }: MessageResource) => {
76
85
  },
77
86
  messageBubble: {
78
87
  backgroundColor: mine ? activeColor : colors.fillColorNeutral070,
79
- borderRadius: 12,
80
- paddingVertical: 6,
81
- paddingHorizontal: 8,
88
+ borderRadius: 8,
89
+ maxWidth: 232,
82
90
  },
83
91
  messageText: {
84
- color: colors.textColorDefaultPrimary,
92
+ paddingVertical: 6,
93
+ paddingHorizontal: 8,
85
94
  },
86
95
  messageReactions: {
87
96
  flexDirection: 'row',
@@ -0,0 +1,61 @@
1
+ import React from 'react'
2
+ import { View, StyleSheet } from 'react-native'
3
+ import { DenormalizedAttachmentResource } from '../../types/resources/denormalized_attachment_resource'
4
+ import { AudioAttachment } from './attachments/audio_attachment'
5
+ import { VideoAttachment } from './attachments/video_attachment'
6
+ import { GiphyAttachment } from './attachments/giphy_attachment'
7
+ import { GenericFileAttachment } from './attachments/generic_file_attachment'
8
+ import { ExpandedLink } from './attachments/expanded_link'
9
+ import { ImageAttachment } from './attachments/image_attachment'
10
+
11
+ export function MessageAttachments(props: { attachments: DenormalizedAttachmentResource[] }) {
12
+ const styles = useStyles()
13
+ const { attachments } = props
14
+ if (!attachments || attachments.length === 0) return null
15
+ return (
16
+ <View style={styles.attachmentsContainer}>
17
+ {attachments.map(attachment => {
18
+ switch (attachment.type) {
19
+ case 'MessageAttachment':
20
+ return <MessageAttachment key={attachment.id} attachment={attachment} />
21
+ case 'giphy':
22
+ return (
23
+ <GiphyAttachment
24
+ key={attachment.id || attachment.titleLink}
25
+ attachment={attachment}
26
+ />
27
+ )
28
+ case 'ExpandedLink':
29
+ return <ExpandedLink key={attachment.id} attachment={attachment} />
30
+ default:
31
+ return null
32
+ }
33
+ })}
34
+ </View>
35
+ )
36
+ }
37
+
38
+ function MessageAttachment({ attachment }: { attachment: any }) {
39
+ const { attributes } = attachment
40
+ const contentType = attributes?.contentType
41
+ const basicType = contentType ? contentType.split('/')[0] : ''
42
+ switch (basicType) {
43
+ case 'image':
44
+ return <ImageAttachment attachment={attachment} />
45
+ case 'video':
46
+ return <VideoAttachment attachment={attachment} />
47
+ case 'audio':
48
+ return <AudioAttachment attachment={attachment} />
49
+ default:
50
+ return <GenericFileAttachment attachment={attachment} />
51
+ }
52
+ }
53
+
54
+ const useStyles = () => {
55
+ return StyleSheet.create({
56
+ attachmentsContainer: {
57
+ gap: 4,
58
+ padding: 2,
59
+ },
60
+ })
61
+ }
@@ -0,0 +1,52 @@
1
+ import React from 'react'
2
+ import { Linking, StyleSheet } from 'react-native'
3
+ import { Text } from '../display'
4
+ import { parseSimpleMarkdown } from '../../utils/parse_simple_markdown'
5
+
6
+ interface Props {
7
+ text: string
8
+ }
9
+
10
+ export function MessageMarkdown({ text }: Props) {
11
+ if (!text) return null
12
+
13
+ // Skip markdown for excessively long messages for performance reasons
14
+ if (text.length > 5000) return <Text>{text}</Text>
15
+
16
+ const parsed = parseSimpleMarkdown(text)
17
+
18
+ return (
19
+ <Text>
20
+ {parsed.map((part, i) => {
21
+ switch (part.type) {
22
+ case 'bold':
23
+ return (
24
+ <Text key={i} style={styles.bold}>
25
+ {part.content}
26
+ </Text>
27
+ )
28
+ case 'italic':
29
+ return (
30
+ <Text key={i} style={styles.italic}>
31
+ {part.content}
32
+ </Text>
33
+ )
34
+ case 'link':
35
+ return (
36
+ <Text key={i} style={styles.link} onPress={() => Linking.openURL(part.content)}>
37
+ {part.content}
38
+ </Text>
39
+ )
40
+ default:
41
+ return <Text key={i}>{part.content}</Text>
42
+ }
43
+ })}
44
+ </Text>
45
+ )
46
+ }
47
+
48
+ const styles = StyleSheet.create({
49
+ bold: { fontWeight: 'bold' },
50
+ italic: { fontStyle: 'italic' },
51
+ link: { color: 'blue', textDecorationLine: 'underline' },
52
+ })
@@ -0,0 +1,84 @@
1
+ import React from 'react'
2
+ import { Pressable, StyleSheet, View } from 'react-native'
3
+ import { ConversationResource } from '../../types'
4
+ import { AvatarGroup, Heading, Text, Badge } from '../display'
5
+ import { formatDatePreview } from '../../utils/date'
6
+ import { useTheme } from '../../hooks'
7
+ import { UnreadCountBadge } from './unread_count_badge'
8
+
9
+ interface ConversationPreviewProps {
10
+ conversation: ConversationResource
11
+ onPress: () => void
12
+ }
13
+
14
+ export const ConversationPreview = ({ conversation, onPress }: ConversationPreviewProps) => {
15
+ const styles = useStyles()
16
+ const {
17
+ lastMessageAuthorName,
18
+ lastMessageCreatedAt,
19
+ lastMessageTextPreview,
20
+ previewAvatarUrls,
21
+ title,
22
+ unreadCount,
23
+ badges,
24
+ } = conversation
25
+ return (
26
+ <Pressable style={styles.previewRow} onPress={onPress}>
27
+ <AvatarGroup size="lg" sourceUris={previewAvatarUrls || []} />
28
+ <View style={styles.conversationBody}>
29
+ <Heading numberOfLines={1} variant="h3" style={styles.title}>
30
+ {title}
31
+ </Heading>
32
+ <Text variant="tertiary" numberOfLines={2}>
33
+ {lastMessageAuthorName}: {lastMessageTextPreview}
34
+ </Text>
35
+ <View style={styles.badges}>
36
+ {badges?.map(badge => (
37
+ <Badge
38
+ key={badge.text}
39
+ variant="meta"
40
+ productLogoName={badge.appName}
41
+ label={badge.pcoResourceType}
42
+ metaLabel={badge.text || ''}
43
+ />
44
+ ))}
45
+ </View>
46
+ </View>
47
+ <View style={styles.metaContainer}>
48
+ <Text variant="tertiary">{formatDatePreview(lastMessageCreatedAt)}</Text>
49
+ <UnreadCountBadge count={unreadCount} />
50
+ </View>
51
+ </Pressable>
52
+ )
53
+ }
54
+
55
+ const useStyles = () => {
56
+ const { colors } = useTheme()
57
+
58
+ return StyleSheet.create({
59
+ previewRow: {
60
+ flexDirection: 'row',
61
+ gap: 8,
62
+ borderBottomWidth: 1,
63
+ borderBottomColor: colors.borderColorDefaultDim,
64
+ paddingTop: 12,
65
+ paddingBottom: 12,
66
+ paddingHorizontal: 16,
67
+ },
68
+ title: {
69
+ fontSize: 16,
70
+ color: colors.textColorDefaultPrimary,
71
+ },
72
+ conversationBody: {
73
+ flex: 1,
74
+ rowGap: 2,
75
+ },
76
+ metaContainer: {
77
+ rowGap: 4,
78
+ },
79
+ badges: {
80
+ marginTop: 4,
81
+ alignItems: 'flex-start',
82
+ },
83
+ })
84
+ }
@@ -0,0 +1,79 @@
1
+ import { useNavigation } from '@react-navigation/native'
2
+ import { FlashList } from '@shopify/flash-list'
3
+ import React from 'react'
4
+ import { StyleSheet, View } from 'react-native'
5
+ import { useTheme } from '../../hooks'
6
+ import { useConversationsJoltEvents } from '../../hooks/use_conversation_jolt_events'
7
+ import { useConversations } from '../../hooks/use_conversations'
8
+ import { Text } from '../display'
9
+ import { ConversationRequestArgs } from '../../utils/request/conversation'
10
+ import { ConversationPreview } from './conversation_preview'
11
+
12
+ interface ConversationsProps extends Partial<ConversationRequestArgs> {
13
+ ListHeaderComponent?:
14
+ | React.ComponentType<any>
15
+ | React.ReactElement<any, string | React.JSXElementConstructor<any>>
16
+ | null
17
+ | undefined
18
+ }
19
+
20
+ export const Conversations = ({
21
+ ListHeaderComponent,
22
+ filter,
23
+ group,
24
+ gids,
25
+ group_source_app_name,
26
+ }: ConversationsProps) => {
27
+ const styles = useStyles()
28
+
29
+ const { conversations, fetchNextPage, refetch, isRefetching, isFetched } = useConversations({
30
+ filter,
31
+ group,
32
+ gids,
33
+ group_source_app_name,
34
+ })
35
+ const navigation = useNavigation()
36
+
37
+ useConversationsJoltEvents()
38
+
39
+ return (
40
+ <View style={styles.container}>
41
+ <FlashList
42
+ data={conversations}
43
+ estimatedItemSize={97}
44
+ contentContainerStyle={styles.contentContainer}
45
+ onRefresh={refetch}
46
+ refreshing={!isFetched && isRefetching}
47
+ ListHeaderComponent={ListHeaderComponent}
48
+ ListEmptyComponent={
49
+ <View style={styles.listEmpty}>
50
+ <Text variant="secondary">No conversations found</Text>
51
+ </View>
52
+ }
53
+ renderItem={({ item }) => (
54
+ <ConversationPreview
55
+ conversation={item}
56
+ onPress={() => navigation.navigate('Conversation', { conversation_id: item.id })}
57
+ />
58
+ )}
59
+ onEndReached={() => fetchNextPage()}
60
+ />
61
+ </View>
62
+ )
63
+ }
64
+
65
+ const useStyles = () => {
66
+ const { colors } = useTheme()
67
+
68
+ return StyleSheet.create({
69
+ container: { flex: 1 },
70
+ contentContainer: { paddingVertical: 16 },
71
+ listItem: { color: colors.fillColorNeutral020 },
72
+ listEmpty: {
73
+ flex: 1,
74
+ justifyContent: 'center',
75
+ alignItems: 'center',
76
+ paddingVertical: 16,
77
+ },
78
+ })
79
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react'
2
+ import { StyleSheet, View } from 'react-native'
3
+ import { Text } from '../display'
4
+ import { useTheme } from '../../hooks'
5
+ import { platformFontWeightBold } from '../../utils'
6
+
7
+ export const UnreadCountBadge = ({ count }: { count: number }) => {
8
+ const styles = useStyles()
9
+ const displayCount = count > 99 ? '99+' : count
10
+
11
+ if (count === 0) return null
12
+
13
+ return (
14
+ <View style={styles.badge}>
15
+ <Text variant="footnote" style={styles.count}>
16
+ {displayCount}
17
+ </Text>
18
+ </View>
19
+ )
20
+ }
21
+
22
+ const useStyles = () => {
23
+ const { colors } = useTheme()
24
+
25
+ return StyleSheet.create({
26
+ badge: {
27
+ alignSelf: 'flex-end',
28
+ backgroundColor: colors.fillColorInteractionDefault,
29
+ paddingVertical: 2,
30
+ paddingHorizontal: 8,
31
+ borderRadius: 24,
32
+ },
33
+ count: {
34
+ fontWeight: platformFontWeightBold,
35
+ color: 'white',
36
+ },
37
+ })
38
+ }