@planningcenter/chat-react-native 3.0.0 → 3.1.0-rc.1

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 (82) hide show
  1. package/build/components/display/badge.js +3 -0
  2. package/build/components/display/badge.js.map +1 -1
  3. package/build/components/display/index.d.ts +5 -4
  4. package/build/components/display/index.d.ts.map +1 -1
  5. package/build/components/display/index.js +5 -4
  6. package/build/components/display/index.js.map +1 -1
  7. package/build/components/display/person.d.ts +10 -0
  8. package/build/components/display/person.d.ts.map +1 -0
  9. package/build/components/display/person.js +67 -0
  10. package/build/components/display/person.js.map +1 -0
  11. package/build/hooks/use_conversation_messages.d.ts.map +1 -1
  12. package/build/hooks/use_conversation_messages.js +5 -0
  13. package/build/hooks/use_conversation_messages.js.map +1 -1
  14. package/build/hooks/use_conversation_messages_jolt_events.d.ts +7 -0
  15. package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -0
  16. package/build/hooks/use_conversation_messages_jolt_events.js +36 -0
  17. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -0
  18. package/build/hooks/use_current_person.d.ts +2 -2
  19. package/build/hooks/use_current_person.d.ts.map +1 -1
  20. package/build/hooks/use_current_person.js.map +1 -1
  21. package/build/screens/conversation_details_screen.js +2 -16
  22. package/build/screens/conversation_details_screen.js.map +1 -1
  23. package/build/screens/design_system_screen.d.ts.map +1 -1
  24. package/build/screens/design_system_screen.js +29 -2
  25. package/build/screens/design_system_screen.js.map +1 -1
  26. package/build/types/jolt_events/conversation_events.d.ts +38 -0
  27. package/build/types/jolt_events/conversation_events.d.ts.map +1 -0
  28. package/build/types/jolt_events/conversation_events.js +2 -0
  29. package/build/types/jolt_events/conversation_events.js.map +1 -0
  30. package/build/types/jolt_events/index.d.ts +10 -0
  31. package/build/types/jolt_events/index.d.ts.map +1 -0
  32. package/build/types/jolt_events/index.js +2 -0
  33. package/build/types/jolt_events/index.js.map +1 -0
  34. package/build/types/jolt_events/message_events.d.ts +32 -0
  35. package/build/types/jolt_events/message_events.d.ts.map +1 -0
  36. package/build/types/jolt_events/message_events.js +2 -0
  37. package/build/types/jolt_events/message_events.js.map +1 -0
  38. package/build/types/jolt_events/reaction_events.d.ts +25 -0
  39. package/build/types/jolt_events/reaction_events.d.ts.map +1 -0
  40. package/build/types/jolt_events/reaction_events.js +2 -0
  41. package/build/types/jolt_events/reaction_events.js.map +1 -0
  42. package/build/types/jolt_events/typing_events.d.ts +15 -0
  43. package/build/types/jolt_events/typing_events.d.ts.map +1 -0
  44. package/build/types/jolt_events/typing_events.js +2 -0
  45. package/build/types/jolt_events/typing_events.js.map +1 -0
  46. package/build/types/resources/denormalized_attachment_resource.d.ts +88 -0
  47. package/build/types/resources/denormalized_attachment_resource.d.ts.map +1 -0
  48. package/build/types/resources/denormalized_attachment_resource.js +6 -0
  49. package/build/types/resources/denormalized_attachment_resource.js.map +1 -0
  50. package/build/types/resources/message.d.ts +4 -1
  51. package/build/types/resources/message.d.ts.map +1 -1
  52. package/build/types/resources/message.js.map +1 -1
  53. package/build/types/resources/person.d.ts +2 -0
  54. package/build/types/resources/person.d.ts.map +1 -1
  55. package/build/types/resources/person.js.map +1 -1
  56. package/build/utils/deepCamelCaseKeys.d.ts +4 -0
  57. package/build/utils/deepCamelCaseKeys.d.ts.map +1 -0
  58. package/build/utils/deepCamelCaseKeys.js +11 -0
  59. package/build/utils/deepCamelCaseKeys.js.map +1 -0
  60. package/build/utils/jolt/transform_message_event_data_to_message_resource.d.ts +7 -0
  61. package/build/utils/jolt/transform_message_event_data_to_message_resource.d.ts.map +1 -0
  62. package/build/utils/jolt/transform_message_event_data_to_message_resource.js +22 -0
  63. package/build/utils/jolt/transform_message_event_data_to_message_resource.js.map +1 -0
  64. package/package.json +2 -2
  65. package/src/components/display/badge.tsx +3 -0
  66. package/src/components/display/index.ts +5 -4
  67. package/src/components/display/person.tsx +90 -0
  68. package/src/hooks/use_conversation_messages.ts +6 -0
  69. package/src/hooks/use_conversation_messages_jolt_events.ts +51 -0
  70. package/src/hooks/use_current_person.ts +2 -2
  71. package/src/screens/conversation_details_screen.tsx +3 -30
  72. package/src/screens/design_system_screen.tsx +37 -1
  73. package/src/types/jolt_events/conversation_events.ts +41 -0
  74. package/src/types/jolt_events/index.ts +28 -0
  75. package/src/types/jolt_events/message_events.ts +34 -0
  76. package/src/types/jolt_events/reaction_events.ts +26 -0
  77. package/src/types/jolt_events/typing_events.ts +16 -0
  78. package/src/types/resources/denormalized_attachment_resource.ts +101 -0
  79. package/src/types/resources/message.ts +4 -1
  80. package/src/types/resources/person.ts +3 -0
  81. package/src/utils/deepCamelCaseKeys.ts +15 -0
  82. package/src/utils/jolt/transform_message_event_data_to_message_resource.ts +31 -0
@@ -0,0 +1,28 @@
1
+ import type {
2
+ ConversationCreatedEvent,
3
+ ConversationDeletedEvent,
4
+ ConversationUpdatedEvent,
5
+ ConversationReadEvent,
6
+ } from './conversation_events'
7
+ import type {
8
+ MessageCreatedEvent,
9
+ MessageDeletedEvent,
10
+ MessageUpdatedEvent,
11
+ } from './message_events'
12
+ import type { ReactionCreatedEvent, ReactionDeletedEvent } from './reaction_events'
13
+ import type { TypingBroadcastEvent } from './typing_events'
14
+
15
+ export type JoltConversationEvent =
16
+ | ConversationCreatedEvent
17
+ | ConversationUpdatedEvent
18
+ | ConversationDeletedEvent
19
+ | ConversationReadEvent
20
+ export type JoltMessageEvent = MessageCreatedEvent | MessageUpdatedEvent | MessageDeletedEvent
21
+ export type JoltReactionEvent = ReactionCreatedEvent | ReactionDeletedEvent
22
+ export type JoltTypingEvent = TypingBroadcastEvent
23
+
24
+ export type CustomJoltEvent =
25
+ | JoltConversationEvent
26
+ | JoltMessageEvent
27
+ | JoltReactionEvent
28
+ | JoltTypingEvent
@@ -0,0 +1,34 @@
1
+ import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
2
+ import { DenormalizedAttachmentResource } from '../resources/denormalized_attachment_resource'
3
+
4
+ interface BaseMessageEventData extends Record<string, unknown> {
5
+ data: {
6
+ author_avatar: string
7
+ author_id: number
8
+ author_name: string
9
+ conversation_id: number
10
+ created_at: string
11
+ deleted_at: string | null
12
+ organization_id: number | null
13
+ sort_key: string
14
+ text: string
15
+ text_edited_at: string | null
16
+ html: string
17
+ attachments: DenormalizedAttachmentResource[]
18
+ }
19
+ }
20
+
21
+ export interface MessageCreatedEvent extends CustomMessage {
22
+ event: 'message.created'
23
+ data: BaseMessageEventData
24
+ }
25
+
26
+ export interface MessageUpdatedEvent extends CustomMessage {
27
+ event: 'message.updated'
28
+ data: BaseMessageEventData
29
+ }
30
+
31
+ export interface MessageDeletedEvent extends CustomMessage {
32
+ event: 'message.destroyed'
33
+ data: BaseMessageEventData
34
+ }
@@ -0,0 +1,26 @@
1
+ import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
2
+ import { ReactionCountResource } from '../resources/reaction'
3
+
4
+ interface BaseReactionEventData extends Record<string, unknown> {
5
+ data: {
6
+ author_id: number
7
+ conversation_id: number
8
+ message_sort_key: string
9
+ created_at: string
10
+ organization_id: number
11
+ value: ReactionCountResource['value']
12
+ author_name?: string
13
+ author_avatar?: string
14
+ count: number
15
+ }
16
+ }
17
+
18
+ export interface ReactionCreatedEvent extends CustomMessage {
19
+ event: 'reaction.created'
20
+ data: BaseReactionEventData
21
+ }
22
+
23
+ export interface ReactionDeletedEvent extends CustomMessage {
24
+ event: 'reaction.destroyed'
25
+ data: BaseReactionEventData
26
+ }
@@ -0,0 +1,16 @@
1
+ import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
2
+
3
+ interface TypingBroadcastData extends Record<string, unknown> {
4
+ data: TypingBroadcastDataAttributes
5
+ }
6
+
7
+ export interface TypingBroadcastEvent extends CustomMessage {
8
+ event: 'typing.broadcast'
9
+ data: TypingBroadcastData
10
+ }
11
+
12
+ export interface TypingBroadcastDataAttributes {
13
+ author_id: number
14
+ author_name: string
15
+ id: string
16
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * This is the type of message attachment that is denormalized onto the message resource.
3
+ * It is what we receive from `MessageVertex#attachments`.
4
+ */
5
+
6
+ export type DenormalizedAttachmentResource =
7
+ | DenormalizedMessageAttachmentResource
8
+ | DenormalizedGiphyAttachmentResource
9
+ | DenormalizedExpandedLinkAttachmentResource
10
+
11
+ export type DenormalizedAttachmentResourceForCreate =
12
+ | DenormalizedMessageAttachmentResourceForCreate
13
+ | DenormalizedGiphyAttachmentResourceForCreate
14
+ | DenormalizedExpandedLinkAttachmentResource
15
+
16
+ interface GenericAttachmentResource {
17
+ type: string
18
+ id?: string
19
+ [key: string]: unknown
20
+ }
21
+
22
+ export interface DenormalizedMessageAttachmentResource extends GenericAttachmentResource {
23
+ type: 'MessageAttachment'
24
+ id: string
25
+ attributes: {
26
+ filename: string
27
+ key: string
28
+ contentType: string
29
+ byteSize: number
30
+ checksum: string
31
+ metadata?: {
32
+ width?: number
33
+ height?: number
34
+ analyzed?: boolean
35
+ identified?: boolean
36
+ }
37
+ url: string
38
+ urlMedium?: string
39
+ }
40
+ }
41
+
42
+ export interface DenormalizedMessageAttachmentResourceForCreate extends GenericAttachmentResource {
43
+ type: 'MessageAttachment'
44
+ id: string
45
+ }
46
+
47
+ export interface DenormalizedGiphyAttachmentResource extends GenericAttachmentResource {
48
+ type: 'giphy'
49
+ id: string
50
+ title: string
51
+ originalGiphyTitle?: string
52
+ titleLink: string
53
+ thumbUrl: string
54
+ giphy: {
55
+ original: GiphyVariant
56
+ fixedHeight: GiphyVariant
57
+ fixedHeightStill: GiphyVariant
58
+ fixedHeightDownsampled: GiphyVariant
59
+ fixedWidth: GiphyVariant
60
+ fixedWidthStill: GiphyVariant
61
+ fixedWidthDownsampled: GiphyVariant
62
+ }
63
+ }
64
+
65
+ export interface DenormalizedGiphyAttachmentResourceForCreate extends GenericAttachmentResource {
66
+ type: 'giphy'
67
+ id: string
68
+ title: string
69
+ original_giphy_title: string
70
+ title_link: string
71
+ thumb_url: string
72
+ giphy: {
73
+ original: GiphyVariant
74
+ fixed_height: GiphyVariant
75
+ fixed_height_still: GiphyVariant
76
+ fixed_height_downsampled: GiphyVariant
77
+ fixed_width: GiphyVariant
78
+ fixed_width_still: GiphyVariant
79
+ fixed_width_downsampled: GiphyVariant
80
+ }
81
+ }
82
+
83
+ interface GiphyVariant {
84
+ url: string
85
+ width: number
86
+ height: number
87
+ size: string
88
+ frames: string
89
+ }
90
+
91
+ export interface DenormalizedExpandedLinkAttachmentResource extends GenericAttachmentResource {
92
+ type: 'ExpandedLink'
93
+ attributes: {
94
+ url: string
95
+ title?: string
96
+ description?: string
97
+ imageUrl?: string
98
+ imageHeight?: number
99
+ imageWidth?: number
100
+ }
101
+ }
@@ -1,3 +1,4 @@
1
+ import { DenormalizedAttachmentResource } from './denormalized_attachment_resource'
1
2
  import type { PersonResource } from './person'
2
3
  import type { ReactionCountResource } from './reaction'
3
4
 
@@ -5,10 +6,12 @@ export interface MessageResource {
5
6
  type: 'Message'
6
7
  id: string
7
8
  text: string
9
+ html: string
8
10
  createdAt: string
11
+ deletedAt: string | null
9
12
  textEditedAt: string | null
10
13
  mine: boolean
11
- attachments: unknown[]
14
+ attachments: DenormalizedAttachmentResource[]
12
15
  author: PersonResource
13
16
  reactionCounts: ReactionCountResource[]
14
17
 
@@ -3,6 +3,9 @@ import { ResourceObject } from '../api_primitives'
3
3
  export interface PersonResource extends ResourceObject {
4
4
  name: string
5
5
  avatar: string
6
+ }
7
+
8
+ export interface CurrentPersonResource extends PersonResource {
6
9
  canChat: boolean
7
10
  unreadCount: number
8
11
  pcoChatEnabled: boolean
@@ -0,0 +1,15 @@
1
+ import { camelCase, isArray, isObject, mapKeys, mapValues } from 'lodash'
2
+
3
+ type ObjType = Record<string, unknown> | unknown[] | unknown
4
+
5
+ export function deepCamelCaseKeys<T extends ObjType>(obj: T): T {
6
+ if (isArray(obj)) {
7
+ return (obj as T & any[]).map(deepCamelCaseKeys) as T
8
+ } else if (isObject(obj)) {
9
+ return mapValues(
10
+ mapKeys(obj, (_value, key) => camelCase(key)),
11
+ deepCamelCaseKeys
12
+ ) as T
13
+ }
14
+ return obj
15
+ }
@@ -0,0 +1,31 @@
1
+ import { MessageResource } from '../../types'
2
+ import { MessageCreatedEvent } from '../../types/jolt_events/message_events'
3
+ import { DenormalizedAttachmentResource } from '../../types/resources/denormalized_attachment_resource'
4
+ import { deepCamelCaseKeys } from '../deepCamelCaseKeys'
5
+
6
+ export function transformMessageEventDataToMessageResource({
7
+ data,
8
+ currentPersonId,
9
+ }: {
10
+ data: MessageCreatedEvent['data']['data']
11
+ currentPersonId: string
12
+ }): MessageResource {
13
+ return {
14
+ type: 'Message',
15
+ id: data.sort_key,
16
+ text: data.text,
17
+ html: data.html,
18
+ createdAt: data.created_at,
19
+ deletedAt: data.deleted_at,
20
+ textEditedAt: data.text_edited_at,
21
+ mine: data.author_id.toString() === currentPersonId.toString(),
22
+ attachments: deepCamelCaseKeys<DenormalizedAttachmentResource[]>(data.attachments) || [],
23
+ author: {
24
+ type: 'Person',
25
+ id: data.author_id.toString(),
26
+ name: data.author_name,
27
+ avatar: data.author_avatar,
28
+ },
29
+ reactionCounts: [],
30
+ }
31
+ }