@planningcenter/chat-react-native 4.6.4-qa-staging.4 → 4.6.4-rc.0

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 (92) hide show
  1. package/build/components/conversation/message_list.d.ts.map +1 -1
  2. package/build/components/conversation/message_list.js +0 -7
  3. package/build/components/conversation/message_list.js.map +1 -1
  4. package/build/contexts/api_provider.d.ts +0 -1
  5. package/build/contexts/api_provider.d.ts.map +1 -1
  6. package/build/contexts/api_provider.js +38 -50
  7. package/build/contexts/api_provider.js.map +1 -1
  8. package/build/contexts/chat_context.d.ts +0 -1
  9. package/build/contexts/chat_context.d.ts.map +1 -1
  10. package/build/contexts/chat_context.js +25 -28
  11. package/build/contexts/chat_context.js.map +1 -1
  12. package/build/contexts/session_context.d.ts +1 -2
  13. package/build/contexts/session_context.d.ts.map +1 -1
  14. package/build/contexts/session_context.js +6 -10
  15. package/build/contexts/session_context.js.map +1 -1
  16. package/build/hooks/index.d.ts +0 -1
  17. package/build/hooks/index.d.ts.map +1 -1
  18. package/build/hooks/index.js +0 -1
  19. package/build/hooks/index.js.map +1 -1
  20. package/build/screens/system_message_people_screen.d.ts.map +1 -1
  21. package/build/screens/system_message_people_screen.js +96 -33
  22. package/build/screens/system_message_people_screen.js.map +1 -1
  23. package/build/types/jolt_events/message_events.d.ts +0 -3
  24. package/build/types/jolt_events/message_events.d.ts.map +1 -1
  25. package/build/types/jolt_events/message_events.js.map +1 -1
  26. package/build/types/resources/message.d.ts +0 -3
  27. package/build/types/resources/message.d.ts.map +1 -1
  28. package/build/types/resources/message.js.map +1 -1
  29. package/build/utils/jolt/transform_message_event_data_to_message_resource.d.ts.map +1 -1
  30. package/build/utils/jolt/transform_message_event_data_to_message_resource.js +0 -2
  31. package/build/utils/jolt/transform_message_event_data_to_message_resource.js.map +1 -1
  32. package/build/utils/request/messages_data_options.d.ts.map +1 -1
  33. package/build/utils/request/messages_data_options.js +1 -1
  34. package/build/utils/request/messages_data_options.js.map +1 -1
  35. package/build/utils/session.d.ts +1 -3
  36. package/build/utils/session.d.ts.map +1 -1
  37. package/build/utils/session.js +0 -3
  38. package/build/utils/session.js.map +1 -1
  39. package/build/utils/session_manager.d.ts +1 -1
  40. package/build/utils/session_manager.d.ts.map +1 -1
  41. package/build/utils/session_manager.js +1 -2
  42. package/build/utils/session_manager.js.map +1 -1
  43. package/build/utils/upload_uri.d.ts.map +1 -1
  44. package/build/utils/upload_uri.js +0 -3
  45. package/build/utils/upload_uri.js.map +1 -1
  46. package/build/utils/uri.d.ts.map +1 -1
  47. package/build/utils/uri.js +0 -4
  48. package/build/utils/uri.js.map +1 -1
  49. package/package.json +3 -3
  50. package/src/components/conversation/__tests__/message_list.test.tsx +1 -1
  51. package/src/components/conversation/message_list.tsx +0 -6
  52. package/src/contexts/__tests__/api_provider.test.tsx +4 -17
  53. package/src/contexts/api_provider.tsx +11 -25
  54. package/src/contexts/chat_context.tsx +2 -4
  55. package/src/contexts/session_context.tsx +10 -18
  56. package/src/hooks/index.ts +0 -1
  57. package/src/screens/system_message_people_screen.tsx +20 -6
  58. package/src/types/jolt_events/message_events.ts +0 -3
  59. package/src/types/resources/message.ts +0 -5
  60. package/src/utils/__tests__/session_manager.test.ts +0 -12
  61. package/src/utils/jolt/__tests__/transform_message_event_data_to_message_resource.test.ts +0 -10
  62. package/src/utils/jolt/transform_message_event_data_to_message_resource.ts +0 -2
  63. package/src/utils/request/messages_data_options.ts +0 -1
  64. package/src/utils/session.ts +3 -11
  65. package/src/utils/session_manager.ts +1 -2
  66. package/src/utils/upload_uri.ts +0 -4
  67. package/src/utils/uri.ts +0 -5
  68. package/build/components/conversation/unsupported_message.d.ts +0 -15
  69. package/build/components/conversation/unsupported_message.d.ts.map +0 -1
  70. package/build/components/conversation/unsupported_message.js +0 -415
  71. package/build/components/conversation/unsupported_message.js.map +0 -1
  72. package/build/hooks/use_system_message_people.d.ts +0 -14
  73. package/build/hooks/use_system_message_people.d.ts.map +0 -1
  74. package/build/hooks/use_system_message_people.js +0 -101
  75. package/build/hooks/use_system_message_people.js.map +0 -1
  76. package/build/types/resources/fallback_content.d.ts +0 -20
  77. package/build/types/resources/fallback_content.d.ts.map +0 -1
  78. package/build/types/resources/fallback_content.js +0 -2
  79. package/build/types/resources/fallback_content.js.map +0 -1
  80. package/build/utils/message_types.d.ts +0 -5
  81. package/build/utils/message_types.d.ts.map +0 -1
  82. package/build/utils/message_types.js +0 -10
  83. package/build/utils/message_types.js.map +0 -1
  84. package/src/components/conversation/__tests__/unsupported_message.test.tsx +0 -109
  85. package/src/components/conversation/unsupported_message.tsx +0 -202
  86. package/src/contexts/__tests__/configured_retry.test.ts +0 -39
  87. package/src/hooks/__tests__/use_system_message_people.test.tsx +0 -79
  88. package/src/hooks/use_system_message_people.ts +0 -55
  89. package/src/types/resources/fallback_content.ts +0 -20
  90. package/src/utils/__tests__/message_types.test.ts +0 -22
  91. package/src/utils/__tests__/uri.test.ts +0 -26
  92. package/src/utils/message_types.ts +0 -22
@@ -1 +0,0 @@
1
- {"version":3,"file":"use_system_message_people.js","names":["useSuspenseQueries","chunk","sortBy","throwResponseError","useApiClient","getRequestQueryKey","MEMBERS_PER_REQUEST","systemMessagePeopleRequest","conversationId","personIds","url","data","fields","Member","where","id","perPage","useSystemMessagePeople","t0","$","_c","apiClient","t1","t2","t3","ids","requests","map","t4","request","queryKey","queryFn","chat","get","catch","queries","orderById","Object","fromEntries","_temp","flatMap","_temp2","person","length","people","t5","index","query"],"sources":["../../src/hooks/use_system_message_people.ts"],"sourcesContent":["import { useSuspenseQueries } from '@tanstack/react-query'\nimport { chunk, sortBy } from 'lodash'\nimport { ApiCollection, MemberResource } from '../types'\nimport { GetRequest } from '../utils/client'\nimport { throwResponseError } from '../utils/response_error'\nimport { useApiClient } from './use_api_client'\nimport { getRequestQueryKey } from './use_suspense_api'\n\nexport const MEMBERS_PER_REQUEST = 100\n\ntype SystemMessagePeopleArgs = {\n conversationId: number\n personIds: number[]\n}\n\nexport type SystemMessagePerson = Pick<MemberResource, 'type' | 'id' | 'name' | 'avatar'>\n\nexport const systemMessagePeopleRequest = (\n conversationId: number,\n personIds: number[]\n): GetRequest => ({\n url: `/me/conversations/${conversationId}/members`,\n data: {\n fields: {\n Member: ['id', 'name', 'avatar'],\n },\n where: {\n id: personIds,\n },\n perPage: MEMBERS_PER_REQUEST,\n },\n})\n\nexport const useSystemMessagePeople = ({ conversationId, personIds }: SystemMessagePeopleArgs) => {\n const apiClient = useApiClient()\n const requests = chunk(personIds, MEMBERS_PER_REQUEST).map(ids =>\n systemMessagePeopleRequest(conversationId, ids)\n )\n\n const queries = useSuspenseQueries({\n queries: requests.map(request => ({\n queryKey: getRequestQueryKey(request),\n queryFn: (): Promise<ApiCollection<SystemMessagePerson>> =>\n apiClient.chat.get<ApiCollection<SystemMessagePerson>>(request).catch(throwResponseError),\n })),\n })\n\n const orderById = Object.fromEntries(personIds.map((id, index) => [id, index]))\n const people = sortBy(\n queries.flatMap(query => query.data.data),\n person => orderById[person.id] ?? personIds.length\n )\n\n return { data: people }\n}\n"],"mappings":";AAAA,SAASA,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,KAAK,EAAEC,MAAM,QAAQ,QAAQ;AAGtC,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB;AAEvD,OAAO,MAAMC,mBAAmB,GAAG,GAAG;AAStC,OAAO,MAAMC,0BAA0B,GAAGA,CACxCC,cAAsB,EACtBC,SAAmB,MACH;EAChBC,GAAG,EAAE,qBAAqBF,cAAc,UAAU;EAClDG,IAAI,EAAE;IACJC,MAAM,EAAE;MACNC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ;IACjC,CAAC;IACDC,KAAK,EAAE;MACLC,EAAE,EAAEN;IACN,CAAC;IACDO,OAAO,EAAEV;EACX;AACF,CAAC,CAAC;AAEF,OAAO,MAA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 @@
1
- /** FallbackContent
2
- * The read-only shape the server sends for a message type this build can't render: text and
3
- * numbers only, nothing actionable, and only `title` is guaranteed. It is a contract with
4
- * shipped builds, so it only ever gains optional fields.
5
- */
6
- export interface FallbackContentItem {
7
- label: string;
8
- detail?: string | null;
9
- fraction?: number | null;
10
- selected?: boolean | null;
11
- }
12
- export interface FallbackContent {
13
- kind: string;
14
- title: string;
15
- subtitle?: string | null;
16
- items?: FallbackContentItem[] | null;
17
- footer?: string | null;
18
- hint?: string | null;
19
- }
20
- //# sourceMappingURL=fallback_content.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fallback_content.d.ts","sourceRoot":"","sources":["../../../src/types/resources/fallback_content.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,KAAK,CAAC,EAAE,mBAAmB,EAAE,GAAG,IAAI,CAAA;IACpC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=fallback_content.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fallback_content.js","names":[],"sources":["../../../src/types/resources/fallback_content.ts"],"sourcesContent":["/** FallbackContent\n * The read-only shape the server sends for a message type this build can't render: text and\n * numbers only, nothing actionable, and only `title` is guaranteed. It is a contract with\n * shipped builds, so it only ever gains optional fields.\n */\nexport interface FallbackContentItem {\n label: string\n detail?: string | null\n fraction?: number | null\n selected?: boolean | null\n}\n\nexport interface FallbackContent {\n kind: string\n title: string\n subtitle?: string | null\n items?: FallbackContentItem[] | null\n footer?: string | null\n hint?: string | null\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,5 +0,0 @@
1
- import type { MessageResource } from '../types/resources/message';
2
- export declare const UNSUPPORTED_MESSAGE_TYPE = "unsupported";
3
- export declare const SUPPORTED_MESSAGE_TYPES: readonly ["user", "user_joined", "conversation_archived", "conversation_unarchived"];
4
- export declare function isUnsupportedMessage(message: Pick<MessageResource, 'messageType'>): boolean;
5
- //# sourceMappingURL=message_types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message_types.d.ts","sourceRoot":"","sources":["../../src/utils/message_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAKjE,eAAO,MAAM,wBAAwB,gBAAgB,CAAA;AAErD,eAAO,MAAM,uBAAuB,sFAK1B,CAAA;AAEV,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,GAAG,OAAO,CAO3F"}
@@ -1,10 +0,0 @@
1
- // The server reports a type newer than this build's API version as 'unsupported'. Jolt payloads
2
- // are not versioned, so a type this build has no code for can still arrive under its real name
3
- // and gets the same treatment.
4
- export const UNSUPPORTED_MESSAGE_TYPE = 'unsupported';
5
- export const SUPPORTED_MESSAGE_TYPES = ['user', 'user_joined', 'conversation_archived', 'conversation_unarchived'];
6
- export function isUnsupportedMessage(message) {
7
- if (!message.messageType) return false;
8
- return message.messageType === UNSUPPORTED_MESSAGE_TYPE || !SUPPORTED_MESSAGE_TYPES.includes(message.messageType);
9
- }
10
- //# sourceMappingURL=message_types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message_types.js","names":["UNSUPPORTED_MESSAGE_TYPE","SUPPORTED_MESSAGE_TYPES","isUnsupportedMessage","message","messageType","includes"],"sources":["../../src/utils/message_types.ts"],"sourcesContent":["import type { MessageResource } from '../types/resources/message'\n\n// The server reports a type newer than this build's API version as 'unsupported'. Jolt payloads\n// are not versioned, so a type this build has no code for can still arrive under its real name\n// and gets the same treatment.\nexport const UNSUPPORTED_MESSAGE_TYPE = 'unsupported'\n\nexport const SUPPORTED_MESSAGE_TYPES = [\n 'user',\n 'user_joined',\n 'conversation_archived',\n 'conversation_unarchived',\n] as const\n\nexport function isUnsupportedMessage(message: Pick<MessageResource, 'messageType'>): boolean {\n if (!message.messageType) return false\n\n return (\n message.messageType === UNSUPPORTED_MESSAGE_TYPE ||\n !(SUPPORTED_MESSAGE_TYPES as readonly string[]).includes(message.messageType)\n )\n}\n"],"mappings":"AAEA;AACA;AACA;AACA,OAAO,MAAMA,wBAAwB,GAAG,aAAa;AAErD,OAAO,MAAMC,uBAAuB,GAAG,CACrC,MAAM,EACN,aAAa,EACb,uBAAuB,EACvB,yBAAyB,CACjB;AAEV,OAAO,SAASC,oBAAoBA,CAACC,OAA6C,EAAW;EAC3F,IAAI,CAACA,OAAO,CAACC,WAAW,EAAE,OAAO,KAAK;EAEtC,OACED,OAAO,CAACC,WAAW,KAAKJ,wBAAwB,IAChD,CAAEC,uBAAuB,CAAuBI,QAAQ,CAACF,OAAO,CAACC,WAAW,CAAC;AAEjF","ignoreList":[]}
@@ -1,109 +0,0 @@
1
- import { render, screen } from '@testing-library/react-native'
2
- import React from 'react'
3
- import type { MessageResource } from '../../../types/resources/message'
4
- import type { PersonResource } from '../../../types/resources/person'
5
- import {
6
- UNSUPPORTED_MESSAGE_FALLBACK,
7
- UNSUPPORTED_MESSAGE_HINT,
8
- UnsupportedMessage,
9
- } from '../unsupported_message'
10
-
11
- const author = { id: 1, type: 'Person', name: 'Wes', avatar: null } as unknown as PersonResource
12
-
13
- const message = (overrides: Partial<MessageResource>): MessageResource => ({
14
- type: 'Message',
15
- id: '01',
16
- text: null,
17
- html: '',
18
- createdAt: '2026-02-03T14:18:00',
19
- deletedAt: null,
20
- textEditedAt: null,
21
- mine: false,
22
- attachments: [],
23
- author,
24
- reactionCounts: [],
25
- replyCount: 0,
26
- replyRootId: null,
27
- messageType: 'unsupported',
28
- ...overrides,
29
- })
30
-
31
- describe('UnsupportedMessage', () => {
32
- it("shows the server's fallback text and the update hint", () => {
33
- render(
34
- <UnsupportedMessage
35
- message={message({ text: '📊 Poll: Lunch? — Update Church Center to vote' })}
36
- />
37
- )
38
-
39
- expect(screen.getByText('📊 Poll: Lunch? — Update Church Center to vote')).toBeTruthy()
40
- expect(screen.getByText(UNSUPPORTED_MESSAGE_HINT)).toBeTruthy()
41
- })
42
-
43
- it('falls back to a generic line when the server sent no text', () => {
44
- render(<UnsupportedMessage message={message({ text: ' ' })} />)
45
-
46
- expect(screen.getByText(UNSUPPORTED_MESSAGE_FALLBACK)).toBeTruthy()
47
- })
48
-
49
- it('names the author when grouping asks for it, so follow-ups stay attributed', () => {
50
- render(<UnsupportedMessage message={message({ text: 'Poll', renderAuthor: true })} />)
51
-
52
- expect(screen.getByText('Wes')).toBeTruthy()
53
- })
54
-
55
- it('omits the author inside a group and on my own messages', () => {
56
- const { rerender } = render(
57
- <UnsupportedMessage message={message({ text: 'Poll', renderAuthor: false })} />
58
- )
59
- expect(screen.queryByText('Wes')).toBeNull()
60
-
61
- rerender(
62
- <UnsupportedMessage message={message({ text: 'Poll', mine: true, renderAuthor: true })} />
63
- )
64
- expect(screen.queryByText('Wes')).toBeNull()
65
- })
66
-
67
- it('renders the fallback content read-only: title, items with totals, footer and hint', () => {
68
- render(
69
- <UnsupportedMessage
70
- message={message({
71
- text: '📊 Poll: Lunch? — Update Church Center to vote',
72
- fallbackContent: {
73
- kind: 'poll',
74
- title: 'Lunch?',
75
- subtitle: 'Select one · 3 votes',
76
- items: [
77
- { label: 'Tacos', detail: '2', fraction: 0.67, selected: true },
78
- { label: 'Pizza', detail: '1', fraction: 0.33 },
79
- ],
80
- footer: 'Ends Friday',
81
- hint: 'Update Church Center to vote',
82
- },
83
- })}
84
- />
85
- )
86
-
87
- expect(screen.getByText('Lunch?')).toBeTruthy()
88
- expect(screen.getByText('Select one · 3 votes')).toBeTruthy()
89
- expect(screen.getByText('● Tacos')).toBeTruthy()
90
- expect(screen.getByText('2')).toBeTruthy()
91
- expect(screen.getByText('Pizza')).toBeTruthy()
92
- expect(screen.getByText('Ends Friday')).toBeTruthy()
93
- expect(screen.getByText('Update Church Center to vote')).toBeTruthy()
94
- expect(screen.queryByText(/📊 Poll/)).toBeNull()
95
- expect(screen.queryByRole('button')).toBeNull()
96
- })
97
-
98
- it('does not repeat the update hint when the server text already carries it', () => {
99
- render(
100
- <UnsupportedMessage
101
- message={message({
102
- text: "This message can't be shown here. Update Church Center to see it.",
103
- })}
104
- />
105
- )
106
-
107
- expect(screen.getAllByText(/Update Church Center/)).toHaveLength(1)
108
- })
109
- })
@@ -1,202 +0,0 @@
1
- import React from 'react'
2
- import { StyleSheet, View } from 'react-native'
3
- import { useTheme } from '../../hooks'
4
- import type { FallbackContent, FallbackContentItem } from '../../types/resources/fallback_content'
5
- import type { MessageResource } from '../../types/resources/message'
6
- import {
7
- CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,
8
- MESSAGE_AUTHOR_AVATAR_COLUMN_WIDTH,
9
- platformFontWeightMedium,
10
- } from '../../utils/styles'
11
- import { Avatar, Text } from '../display'
12
-
13
- export const UNSUPPORTED_MESSAGE_FALLBACK = "This message can't be shown here."
14
- export const UNSUPPORTED_MESSAGE_HINT = 'Update Church Center to see it.'
15
-
16
- interface UnsupportedMessageProps {
17
- message: MessageResource
18
- }
19
-
20
- /** UnsupportedMessage
21
- * Read-only bubble for a message type this build can't render. With `fallbackContent` it shows
22
- * the type's title, subtitle, items (label, detail, share) and footer; without it, the server's
23
- * fallback text or a generic line. Always ends with a hint to update. No actions, no reactions.
24
- * It keeps the regular message's author column so grouping stays attributed around it.
25
- */
26
- export function UnsupportedMessage({ message }: UnsupportedMessageProps) {
27
- const styles = useStyles(message.mine)
28
- const content = message.fallbackContent ?? null
29
- const text = message.text?.trim() || UNSUPPORTED_MESSAGE_FALLBACK
30
- const hint =
31
- content?.hint || (text.includes(UNSUPPORTED_MESSAGE_HINT) ? null : UNSUPPORTED_MESSAGE_HINT)
32
- const renderAuthor = !message.mine && !!message.renderAuthor
33
- const summary = content ? contentSummary(content) : text
34
-
35
- return (
36
- <View
37
- style={styles.container}
38
- accessibilityRole="text"
39
- accessibilityLabel={`${message.author?.name || ''} ${summary} ${hint ?? ''}`}
40
- testID={`unsupported-message-${message.id}`}
41
- >
42
- {!message.mine &&
43
- (renderAuthor ? (
44
- <Avatar
45
- size="md"
46
- sourceUri={message.author?.avatar}
47
- maxFontSizeMultiplier={1}
48
- minFontSizeMultiplier={1}
49
- />
50
- ) : (
51
- <View style={styles.avatarPlaceholder} />
52
- ))}
53
- <View style={styles.content}>
54
- {renderAuthor && (
55
- <Text variant="footnote" style={styles.authorName}>
56
- {message.author?.name}
57
- </Text>
58
- )}
59
- <View style={styles.bubble}>
60
- {content ? (
61
- <FallbackContentBody content={content} styles={styles} />
62
- ) : (
63
- <Text style={styles.text}>{text}</Text>
64
- )}
65
- {!!hint && (
66
- <Text variant="tertiary" style={styles.hint}>
67
- {hint}
68
- </Text>
69
- )}
70
- </View>
71
- </View>
72
- </View>
73
- )
74
- }
75
-
76
- function FallbackContentBody({
77
- content,
78
- styles,
79
- }: {
80
- content: FallbackContent
81
- styles: ReturnType<typeof useStyles>
82
- }) {
83
- return (
84
- <>
85
- <Text style={styles.title}>{content.title}</Text>
86
- {!!content.subtitle && <Text variant="tertiary">{content.subtitle}</Text>}
87
- {(content.items ?? []).map((item, index) => (
88
- <FallbackItem key={`${index}-${item.label}`} item={item} styles={styles} />
89
- ))}
90
- {!!content.footer && (
91
- <Text variant="tertiary" style={styles.footer}>
92
- {content.footer}
93
- </Text>
94
- )}
95
- </>
96
- )
97
- }
98
-
99
- function FallbackItem({
100
- item,
101
- styles,
102
- }: {
103
- item: FallbackContentItem
104
- styles: ReturnType<typeof useStyles>
105
- }) {
106
- const fraction =
107
- typeof item.fraction === 'number' ? Math.min(Math.max(item.fraction, 0), 1) : null
108
-
109
- return (
110
- <View style={styles.item}>
111
- <View style={styles.itemRow}>
112
- <Text style={[styles.itemLabel, item.selected ? styles.itemSelected : null]}>
113
- {(item.selected ? '● ' : '') + item.label}
114
- </Text>
115
- {!!item.detail && <Text variant="tertiary">{item.detail}</Text>}
116
- </View>
117
- {fraction !== null && (
118
- <View style={styles.track}>
119
- <View style={[styles.fill, { width: `${Math.round(fraction * 100)}%` }]} />
120
- </View>
121
- )}
122
- </View>
123
- )
124
- }
125
-
126
- function contentSummary(content: FallbackContent): string {
127
- const items = (content.items ?? [])
128
- .map(item => (item.detail ? `${item.label} ${item.detail}` : item.label))
129
- .join(', ')
130
- return [content.title, content.subtitle, items, content.footer].filter(Boolean).join('. ')
131
- }
132
-
133
- const useStyles = (mine: boolean) => {
134
- const { colors } = useTheme()
135
- return StyleSheet.create({
136
- container: {
137
- gap: 8,
138
- flexDirection: mine ? 'row-reverse' : 'row',
139
- paddingHorizontal: CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL,
140
- paddingVertical: 4,
141
- },
142
- avatarPlaceholder: {
143
- width: MESSAGE_AUTHOR_AVATAR_COLUMN_WIDTH,
144
- },
145
- content: {
146
- flex: 1,
147
- gap: 4,
148
- },
149
- authorName: {
150
- fontWeight: platformFontWeightMedium,
151
- },
152
- bubble: {
153
- maxWidth: '80%',
154
- minWidth: '60%',
155
- alignSelf: mine ? 'flex-end' : 'flex-start',
156
- borderRadius: 8,
157
- paddingVertical: 6,
158
- paddingHorizontal: 8,
159
- gap: 4,
160
- borderWidth: StyleSheet.hairlineWidth,
161
- borderColor: colors.textColorDefaultSecondary,
162
- },
163
- text: {
164
- color: colors.textColorDefaultSecondary,
165
- },
166
- title: {
167
- fontWeight: platformFontWeightMedium,
168
- },
169
- item: {
170
- gap: 2,
171
- marginTop: 2,
172
- },
173
- itemRow: {
174
- flexDirection: 'row',
175
- justifyContent: 'space-between',
176
- alignItems: 'center',
177
- gap: 8,
178
- },
179
- itemLabel: {
180
- flexShrink: 1,
181
- },
182
- itemSelected: {
183
- fontWeight: platformFontWeightMedium,
184
- },
185
- track: {
186
- height: 4,
187
- borderRadius: 2,
188
- backgroundColor: colors.fillColorNeutral070,
189
- overflow: 'hidden',
190
- },
191
- fill: {
192
- height: 4,
193
- backgroundColor: colors.textColorDefaultSecondary,
194
- },
195
- footer: {
196
- marginTop: 2,
197
- },
198
- hint: {
199
- marginTop: 2,
200
- },
201
- })
202
- }
@@ -1,39 +0,0 @@
1
- import { ResponseError } from '../../utils/response_error'
2
- import { configuredRetry } from '../api_provider'
3
-
4
- jest.mock('../../hooks/use_api_client')
5
-
6
- const responseWithStatus = (status: number) =>
7
- ({
8
- status,
9
- statusText: 'Error',
10
- ok: false,
11
- url: 'https://api.pco.test/chat/v2/me',
12
- headers: {},
13
- clone: () => ({}),
14
- json: () => Promise.resolve({}),
15
- text: () => Promise.resolve(''),
16
- arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
17
- errors: [],
18
- }) as unknown as Response
19
-
20
- describe('configuredRetry', () => {
21
- it('does not retry client errors', () => {
22
- ;[400, 404, 414, 422, 429].forEach(status => {
23
- expect(configuredRetry(0, new ResponseError(responseWithStatus(status) as any))).toBe(false)
24
- expect(configuredRetry(0, responseWithStatus(status))).toBe(false)
25
- })
26
- })
27
-
28
- it('retries server errors up to three times', () => {
29
- const error = new ResponseError(responseWithStatus(503) as any)
30
-
31
- expect(configuredRetry(0, error)).toBe(true)
32
- expect(configuredRetry(2, error)).toBe(true)
33
- expect(configuredRetry(3, error)).toBe(false)
34
- })
35
-
36
- it('retries network failures', () => {
37
- expect(configuredRetry(0, new TypeError('Network request failed'))).toBe(true)
38
- })
39
- })
@@ -1,79 +0,0 @@
1
- import { notifyManager, QueryClient, QueryClientProvider } from '@tanstack/react-query'
2
- import { act, renderHook, waitFor } from '@testing-library/react-native'
3
- import React, { Suspense } from 'react'
4
- import { MEMBERS_PER_REQUEST, useSystemMessagePeople } from '../use_system_message_people'
5
-
6
- const mockGet = jest.fn()
7
- jest.mock('../use_api_client', () => ({
8
- useApiClient: () => ({ chat: { get: mockGet } }),
9
- }))
10
-
11
- notifyManager.setNotifyFunction(fn => act(fn))
12
-
13
- const conversationId = 7
14
-
15
- const member = (id: number) => ({ type: 'Member', id, name: `Person ${id}`, avatar: '' })
16
-
17
- const membersPage = (ids: number[]) => ({
18
- data: ids.map(member),
19
- links: {},
20
- meta: { count: ids.length, totalCount: ids.length },
21
- })
22
-
23
- const requestedIds = () => mockGet.mock.calls.map(([request]) => request.data.where.id as number[])
24
-
25
- const render = (personIds: number[]) => {
26
- const queryClient = new QueryClient({
27
- defaultOptions: { queries: { retry: false, gcTime: 0 } },
28
- })
29
- const wrapper = ({ children }: { children: React.ReactNode }) => (
30
- <QueryClientProvider client={queryClient}>
31
- <Suspense fallback={null}>{children}</Suspense>
32
- </QueryClientProvider>
33
- )
34
-
35
- return renderHook(() => useSystemMessagePeople({ conversationId, personIds }), { wrapper })
36
- }
37
-
38
- beforeEach(() => {
39
- mockGet.mockReset()
40
- mockGet.mockImplementation(({ data }) =>
41
- Promise.resolve(membersPage([...(data.where.id as number[])].reverse()))
42
- )
43
- })
44
-
45
- describe('useSystemMessagePeople', () => {
46
- it('requests members in batches no larger than a page', async () => {
47
- const personIds = Array.from({ length: 250 }, (_, i) => i + 1)
48
-
49
- render(personIds)
50
-
51
- await waitFor(() => expect(mockGet).toHaveBeenCalledTimes(3))
52
-
53
- expect(requestedIds().map(ids => ids.length)).toEqual([100, 100, 50])
54
- expect(requestedIds().flat()).toEqual(personIds)
55
- mockGet.mock.calls.forEach(([request]) => {
56
- expect(request.url).toEqual(`/me/conversations/${conversationId}/members`)
57
- expect(request.data.perPage).toEqual(MEMBERS_PER_REQUEST)
58
- })
59
- })
60
-
61
- it('returns everyone in the order of the system message', async () => {
62
- const personIds = Array.from({ length: 150 }, (_, i) => 1000 - i)
63
-
64
- const { result } = render(personIds)
65
-
66
- await waitFor(() => expect(result.current?.data).toHaveLength(150))
67
-
68
- expect(result.current.data.map(({ id }) => id)).toEqual(personIds)
69
- })
70
-
71
- it('makes a single request for a small list', async () => {
72
- const { result } = render([3, 1, 2])
73
-
74
- await waitFor(() => expect(result.current?.data).toHaveLength(3))
75
-
76
- expect(mockGet).toHaveBeenCalledTimes(1)
77
- expect(result.current.data.map(({ id }) => id)).toEqual([3, 1, 2])
78
- })
79
- })
@@ -1,55 +0,0 @@
1
- import { useSuspenseQueries } from '@tanstack/react-query'
2
- import { chunk, sortBy } from 'lodash'
3
- import { ApiCollection, MemberResource } from '../types'
4
- import { GetRequest } from '../utils/client'
5
- import { throwResponseError } from '../utils/response_error'
6
- import { useApiClient } from './use_api_client'
7
- import { getRequestQueryKey } from './use_suspense_api'
8
-
9
- export const MEMBERS_PER_REQUEST = 100
10
-
11
- type SystemMessagePeopleArgs = {
12
- conversationId: number
13
- personIds: number[]
14
- }
15
-
16
- export type SystemMessagePerson = Pick<MemberResource, 'type' | 'id' | 'name' | 'avatar'>
17
-
18
- export const systemMessagePeopleRequest = (
19
- conversationId: number,
20
- personIds: number[]
21
- ): GetRequest => ({
22
- url: `/me/conversations/${conversationId}/members`,
23
- data: {
24
- fields: {
25
- Member: ['id', 'name', 'avatar'],
26
- },
27
- where: {
28
- id: personIds,
29
- },
30
- perPage: MEMBERS_PER_REQUEST,
31
- },
32
- })
33
-
34
- export const useSystemMessagePeople = ({ conversationId, personIds }: SystemMessagePeopleArgs) => {
35
- const apiClient = useApiClient()
36
- const requests = chunk(personIds, MEMBERS_PER_REQUEST).map(ids =>
37
- systemMessagePeopleRequest(conversationId, ids)
38
- )
39
-
40
- const queries = useSuspenseQueries({
41
- queries: requests.map(request => ({
42
- queryKey: getRequestQueryKey(request),
43
- queryFn: (): Promise<ApiCollection<SystemMessagePerson>> =>
44
- apiClient.chat.get<ApiCollection<SystemMessagePerson>>(request).catch(throwResponseError),
45
- })),
46
- })
47
-
48
- const orderById = Object.fromEntries(personIds.map((id, index) => [id, index]))
49
- const people = sortBy(
50
- queries.flatMap(query => query.data.data),
51
- person => orderById[person.id] ?? personIds.length
52
- )
53
-
54
- return { data: people }
55
- }
@@ -1,20 +0,0 @@
1
- /** FallbackContent
2
- * The read-only shape the server sends for a message type this build can't render: text and
3
- * numbers only, nothing actionable, and only `title` is guaranteed. It is a contract with
4
- * shipped builds, so it only ever gains optional fields.
5
- */
6
- export interface FallbackContentItem {
7
- label: string
8
- detail?: string | null
9
- fraction?: number | null
10
- selected?: boolean | null
11
- }
12
-
13
- export interface FallbackContent {
14
- kind: string
15
- title: string
16
- subtitle?: string | null
17
- items?: FallbackContentItem[] | null
18
- footer?: string | null
19
- hint?: string | null
20
- }
@@ -1,22 +0,0 @@
1
- import { isUnsupportedMessage } from '../message_types'
2
-
3
- describe('isUnsupportedMessage', () => {
4
- it('is false for every type this build renders', () => {
5
- for (const messageType of [
6
- 'user',
7
- 'user_joined',
8
- 'conversation_archived',
9
- 'conversation_unarchived',
10
- ]) {
11
- expect(isUnsupportedMessage({ messageType })).toBe(false)
12
- }
13
- })
14
-
15
- it("is true for the server's unsupported placeholder", () => {
16
- expect(isUnsupportedMessage({ messageType: 'unsupported' })).toBe(true)
17
- })
18
-
19
- it('is true for a type this build has no code for, as Jolt can deliver one', () => {
20
- expect(isUnsupportedMessage({ messageType: 'poll' })).toBe(true)
21
- })
22
- })
@@ -1,26 +0,0 @@
1
- import { Session } from '../session'
2
- import { UploadUri } from '../upload_uri'
3
- import { Uri } from '../uri'
4
-
5
- const prototypeSession = (type?: 'OAuth' | 'ChurchCenterOauth') =>
6
- new Session({ env: 'prototype', prototypeName: 'chat-812', type })
7
-
8
- describe('on a Protonova environment', () => {
9
- it('sends Planning Center requests to the environment', () => {
10
- const uri = new Uri({ session: prototypeSession('OAuth'), app: 'chat' })
11
-
12
- expect(uri.appUrl('/me')).toBe('https://chat-812.api.planningcenter.ninja/chat/v2/me')
13
- })
14
-
15
- it('sends Church Center requests to the environment', () => {
16
- const uri = new Uri({ session: prototypeSession('ChurchCenterOauth'), app: 'chat' })
17
-
18
- expect(uri.appUrl('/me')).toBe('https://chat-812.api.churchcenter.ninja/chat/v2/me')
19
- })
20
-
21
- it('uploads to the environment', () => {
22
- expect(new UploadUri({ session: prototypeSession() }).baseUrl).toBe(
23
- 'https://chat-812.upload.planningcenter.ninja'
24
- )
25
- })
26
- })
@@ -1,22 +0,0 @@
1
- import type { MessageResource } from '../types/resources/message'
2
-
3
- // The server reports a type newer than this build's API version as 'unsupported'. Jolt payloads
4
- // are not versioned, so a type this build has no code for can still arrive under its real name
5
- // and gets the same treatment.
6
- export const UNSUPPORTED_MESSAGE_TYPE = 'unsupported'
7
-
8
- export const SUPPORTED_MESSAGE_TYPES = [
9
- 'user',
10
- 'user_joined',
11
- 'conversation_archived',
12
- 'conversation_unarchived',
13
- ] as const
14
-
15
- export function isUnsupportedMessage(message: Pick<MessageResource, 'messageType'>): boolean {
16
- if (!message.messageType) return false
17
-
18
- return (
19
- message.messageType === UNSUPPORTED_MESSAGE_TYPE ||
20
- !(SUPPORTED_MESSAGE_TYPES as readonly string[]).includes(message.messageType)
21
- )
22
- }