@planningcenter/chat-react-native 4.6.4-rc.0 → 4.7.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.
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +7 -0
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/unsupported_message.d.ts +15 -0
- package/build/components/conversation/unsupported_message.d.ts.map +1 -0
- package/build/components/conversation/unsupported_message.js +415 -0
- package/build/components/conversation/unsupported_message.js.map +1 -0
- package/build/contexts/api_provider.js +39 -33
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/chat_context.d.ts +1 -0
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +28 -25
- package/build/contexts/chat_context.js.map +1 -1
- package/build/contexts/session_context.d.ts +2 -1
- package/build/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js +10 -6
- package/build/contexts/session_context.js.map +1 -1
- package/build/types/jolt_events/message_events.d.ts +3 -0
- package/build/types/jolt_events/message_events.d.ts.map +1 -1
- package/build/types/jolt_events/message_events.js.map +1 -1
- package/build/types/resources/fallback_content.d.ts +20 -0
- package/build/types/resources/fallback_content.d.ts.map +1 -0
- package/build/types/resources/fallback_content.js +2 -0
- package/build/types/resources/fallback_content.js.map +1 -0
- package/build/types/resources/message.d.ts +3 -0
- package/build/types/resources/message.d.ts.map +1 -1
- package/build/types/resources/message.js.map +1 -1
- package/build/utils/jolt/transform_message_event_data_to_message_resource.d.ts.map +1 -1
- package/build/utils/jolt/transform_message_event_data_to_message_resource.js +2 -0
- package/build/utils/jolt/transform_message_event_data_to_message_resource.js.map +1 -1
- package/build/utils/message_types.d.ts +5 -0
- package/build/utils/message_types.d.ts.map +1 -0
- package/build/utils/message_types.js +10 -0
- package/build/utils/message_types.js.map +1 -0
- package/build/utils/request/messages_data_options.d.ts.map +1 -1
- package/build/utils/request/messages_data_options.js +1 -1
- package/build/utils/request/messages_data_options.js.map +1 -1
- package/build/utils/session.d.ts +3 -1
- package/build/utils/session.d.ts.map +1 -1
- package/build/utils/session.js +3 -0
- package/build/utils/session.js.map +1 -1
- package/build/utils/session_manager.d.ts +1 -1
- package/build/utils/session_manager.d.ts.map +1 -1
- package/build/utils/session_manager.js +2 -1
- package/build/utils/session_manager.js.map +1 -1
- package/build/utils/upload_uri.d.ts.map +1 -1
- package/build/utils/upload_uri.js +3 -0
- package/build/utils/upload_uri.js.map +1 -1
- package/build/utils/uri.d.ts.map +1 -1
- package/build/utils/uri.js +4 -0
- package/build/utils/uri.js.map +1 -1
- package/package.json +2 -2
- package/src/components/conversation/__tests__/message_list.test.tsx +1 -1
- package/src/components/conversation/__tests__/unsupported_message.test.tsx +109 -0
- package/src/components/conversation/message_list.tsx +6 -0
- package/src/components/conversation/unsupported_message.tsx +202 -0
- package/src/contexts/__tests__/api_provider.test.tsx +17 -4
- package/src/contexts/api_provider.tsx +13 -6
- package/src/contexts/chat_context.tsx +4 -2
- package/src/contexts/session_context.tsx +18 -10
- package/src/types/jolt_events/message_events.ts +3 -0
- package/src/types/resources/fallback_content.ts +20 -0
- package/src/types/resources/message.ts +5 -0
- package/src/utils/__tests__/message_types.test.ts +22 -0
- package/src/utils/__tests__/session_manager.test.ts +12 -0
- package/src/utils/__tests__/uri.test.ts +26 -0
- package/src/utils/jolt/__tests__/transform_message_event_data_to_message_resource.test.ts +10 -0
- package/src/utils/jolt/transform_message_event_data_to_message_resource.ts +2 -0
- package/src/utils/message_types.ts +22 -0
- package/src/utils/request/messages_data_options.ts +1 -0
- package/src/utils/session.ts +11 -3
- package/src/utils/session_manager.ts +2 -1
- package/src/utils/upload_uri.ts +4 -0
- package/src/utils/uri.ts +5 -0
|
@@ -0,0 +1,202 @@
|
|
|
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 your app 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
|
+
}
|
|
@@ -37,16 +37,18 @@ const Probe = () => {
|
|
|
37
37
|
return <Text>{`${status}:${fetchStatus}:${data?.id ?? ''}`}</Text>
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const Tree = ({ accessToken }: { accessToken: string }) => {
|
|
40
|
+
const Tree = ({ accessToken, prototypeName }: { accessToken: string; prototypeName?: string }) => {
|
|
41
41
|
const value = useMemo(() => {
|
|
42
|
-
const
|
|
42
|
+
const env = prototypeName ? 'prototype' : 'production'
|
|
43
|
+
const session = new Session({ token: { access_token: accessToken }, env, prototypeName })
|
|
43
44
|
return {
|
|
44
45
|
session,
|
|
45
46
|
token: session.token,
|
|
46
|
-
env
|
|
47
|
+
env,
|
|
48
|
+
prototypeName,
|
|
47
49
|
onUnauthorizedResponse: () => {},
|
|
48
50
|
} as unknown as ChatContextValue
|
|
49
|
-
}, [accessToken])
|
|
51
|
+
}, [accessToken, prototypeName])
|
|
50
52
|
|
|
51
53
|
return (
|
|
52
54
|
<ChatContext.Provider value={value}>
|
|
@@ -104,3 +106,14 @@ describe('ApiProvider on access token change', () => {
|
|
|
104
106
|
expect(await screen.findByText('success:idle:42')).toBeTruthy()
|
|
105
107
|
})
|
|
106
108
|
})
|
|
109
|
+
|
|
110
|
+
describe('ApiProvider on Protonova environment change', () => {
|
|
111
|
+
it("drops the old environment's data and refetches", async () => {
|
|
112
|
+
const { rerender } = render(<Tree accessToken="fresh" prototypeName="chat-1" />)
|
|
113
|
+
expect(await screen.findByText('success:idle:42')).toBeTruthy()
|
|
114
|
+
|
|
115
|
+
rerender(<Tree accessToken="fresh" prototypeName="chat-2" />)
|
|
116
|
+
|
|
117
|
+
await waitFor(() => expect(meRequests()).toEqual(['fresh', 'fresh']))
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -49,8 +49,8 @@ export const chatQueryClient = new QueryClient({
|
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
export function ApiProvider({ children }: ViewProps) {
|
|
52
|
-
const { token, env, session } = useContext(ChatContext)
|
|
53
|
-
const sessionChanged = useSessionChanged({ token, env })
|
|
52
|
+
const { token, env, prototypeName, session } = useContext(ChatContext)
|
|
53
|
+
const sessionChanged = useSessionChanged({ token, env, prototypeName })
|
|
54
54
|
|
|
55
55
|
const client = useApiClient()
|
|
56
56
|
|
|
@@ -108,9 +108,15 @@ export function useFocusManager() {
|
|
|
108
108
|
return appState
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
function useSessionChanged(
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
function useSessionChanged(
|
|
112
|
+
value: Pick<ChatContextValue, 'token' | 'env' | 'prototypeName'>
|
|
113
|
+
): boolean {
|
|
114
|
+
const { token: newToken, env: newEnv, prototypeName: newPrototypeName } = value
|
|
115
|
+
const {
|
|
116
|
+
token: prevToken,
|
|
117
|
+
env: prevEnv,
|
|
118
|
+
prototypeName: prevPrototypeName,
|
|
119
|
+
} = usePrevious<typeof value>(value)
|
|
114
120
|
|
|
115
121
|
const isInitialLogin = !prevToken && !!newToken
|
|
116
122
|
if (isInitialLogin) return false
|
|
@@ -120,8 +126,9 @@ function useSessionChanged(value: Pick<ChatContextValue, 'token' | 'env'>): bool
|
|
|
120
126
|
)
|
|
121
127
|
|
|
122
128
|
const envChanged = Boolean(prevEnv && newEnv !== prevEnv)
|
|
129
|
+
const prototypeChanged = Boolean(prevEnv && newPrototypeName !== prevPrototypeName)
|
|
123
130
|
|
|
124
|
-
return tokenChanged || envChanged
|
|
131
|
+
return tokenChanged || envChanged || prototypeChanged
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
function usePrevious<T>(value: T): T {
|
|
@@ -12,6 +12,7 @@ import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
|
|
|
12
12
|
|
|
13
13
|
export interface ChatProviderProps {
|
|
14
14
|
env?: ENV
|
|
15
|
+
prototypeName?: string
|
|
15
16
|
giphyApiKey?: string
|
|
16
17
|
onAgeDisqualification?: (params: AgeCheckContactInfo) => void
|
|
17
18
|
onUnauthorizedResponse: (_response: FailedResponse) => void
|
|
@@ -45,6 +46,7 @@ export const ChatContext = createContext<ChatContextValue>({
|
|
|
45
46
|
export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
|
|
46
47
|
const {
|
|
47
48
|
env,
|
|
49
|
+
prototypeName,
|
|
48
50
|
token,
|
|
49
51
|
onAgeDisqualification = (_params: AgeCheckContactInfo) => {},
|
|
50
52
|
onUnauthorizedResponse,
|
|
@@ -58,8 +60,8 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
|
|
|
58
60
|
setLiquidGlassCapability(liquidGlassEnabled)
|
|
59
61
|
const theme = useCreateChatTheme(value.theme || {})
|
|
60
62
|
const session = useMemo(
|
|
61
|
-
() => new Session({ token, env, type: tokenType }),
|
|
62
|
-
[env, token, tokenType]
|
|
63
|
+
() => new Session({ token, env, prototypeName, type: tokenType }),
|
|
64
|
+
[env, prototypeName, token, tokenType]
|
|
63
65
|
)
|
|
64
66
|
|
|
65
67
|
const productAnalyticsConfig = useProductAnalyticsConfig(session)
|
|
@@ -23,7 +23,7 @@ type Sessions = Record<string, string> // Key is session ID
|
|
|
23
23
|
|
|
24
24
|
export type SessionContextValue = {
|
|
25
25
|
env: ENV
|
|
26
|
-
setEnv: (_env: ENV) => void
|
|
26
|
+
setEnv: (_env: ENV, _prototypeName?: string) => void
|
|
27
27
|
session: Session
|
|
28
28
|
sessions: Sessions
|
|
29
29
|
token: OAuthToken | undefined
|
|
@@ -52,7 +52,11 @@ export type SessionContextConfig = {
|
|
|
52
52
|
secureStorage: StorageAdapter // For sensitive data (tokens/sessions)
|
|
53
53
|
|
|
54
54
|
// Functional callbacks
|
|
55
|
-
refreshTokenFn: (params: {
|
|
55
|
+
refreshTokenFn: (params: {
|
|
56
|
+
refresh_token: string
|
|
57
|
+
env: ENV
|
|
58
|
+
prototypeName?: string
|
|
59
|
+
}) => Promise<OAuthToken>
|
|
56
60
|
onLogout: () => void | Promise<void>
|
|
57
61
|
|
|
58
62
|
// Optional configuration
|
|
@@ -127,9 +131,11 @@ export function SessionContextProvider({
|
|
|
127
131
|
if (!token?.refresh_token) {
|
|
128
132
|
return Promise.reject(new Error('Refresh token is required'))
|
|
129
133
|
}
|
|
130
|
-
return refreshTokenFn({
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
return refreshTokenFn({
|
|
135
|
+
refresh_token: token.refresh_token,
|
|
136
|
+
env: currentSession.env,
|
|
137
|
+
prototypeName: currentSession.prototypeName,
|
|
138
|
+
}).then(handleTokenUpdate)
|
|
133
139
|
},
|
|
134
140
|
onError: (t: Partial<FailedResponse>) => {
|
|
135
141
|
handleRefreshFailed(t)
|
|
@@ -142,22 +148,24 @@ export function SessionContextProvider({
|
|
|
142
148
|
}, [queryClient])
|
|
143
149
|
|
|
144
150
|
const handleSetEnv = useCallback(
|
|
145
|
-
async (_env: ENV) => {
|
|
151
|
+
async (_env: ENV, _prototypeName?: string) => {
|
|
146
152
|
const updatedManager = SessionManager.hydrate(managerString)
|
|
147
153
|
const session = updatedManager.currentSession
|
|
148
|
-
|
|
154
|
+
const sameEnvironment = _env === session.env && _prototypeName === session.prototypeName
|
|
155
|
+
if (sameEnvironment) return
|
|
149
156
|
|
|
150
157
|
const productionEnvironments = ['production', 'staging']
|
|
151
158
|
const switchingToDevelopment =
|
|
152
159
|
_env === 'development' && productionEnvironments.includes(session.env)
|
|
153
160
|
const switchingToProduction = _env === 'production' && session.env === 'development'
|
|
161
|
+
const switchingPrototype = _env === 'prototype' || session.env === 'prototype'
|
|
154
162
|
|
|
155
|
-
if (switchingToDevelopment || switchingToProduction) {
|
|
156
|
-
const newSession = new Session({ env: _env })
|
|
163
|
+
if (switchingToDevelopment || switchingToProduction || switchingPrototype) {
|
|
164
|
+
const newSession = new Session({ env: _env, prototypeName: _prototypeName })
|
|
157
165
|
updatedManager.upsertSession(newSession)
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
updatedManager.setEnv(_env)
|
|
168
|
+
updatedManager.setEnv(_env, _prototypeName)
|
|
161
169
|
await setManagerString(updatedManager.toString())
|
|
162
170
|
},
|
|
163
171
|
[managerString, setManagerString]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
|
|
2
2
|
import { DenormalizedAttachmentResource } from '../resources/denormalized_attachment_resource'
|
|
3
|
+
import type { FallbackContent } from '../resources/fallback_content'
|
|
3
4
|
import type { SystemTextFormat } from '../resources/message'
|
|
4
5
|
|
|
5
6
|
interface BaseMessageEventData extends Record<string, unknown> {
|
|
@@ -20,6 +21,8 @@ interface BaseMessageEventData extends Record<string, unknown> {
|
|
|
20
21
|
reply_count: number
|
|
21
22
|
reply_root_id: string | null
|
|
22
23
|
message_type: string
|
|
24
|
+
unsupported_message_type?: string | null
|
|
25
|
+
fallback_content?: FallbackContent | null
|
|
23
26
|
system_event_person_ids: number[] | null
|
|
24
27
|
system_text_parts: { names: string[]; overflow_count: number; action: string } | null
|
|
25
28
|
system_text_format: SystemTextFormat | null
|
|
@@ -0,0 +1,20 @@
|
|
|
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,5 +1,6 @@
|
|
|
1
1
|
import { DenormalizedAttachmentResource } from './denormalized_attachment_resource'
|
|
2
2
|
import { DenormalizedAttachmentResourceForCreate } from './denormalized_attachment_resource_for_create'
|
|
3
|
+
import type { FallbackContent } from './fallback_content'
|
|
3
4
|
import type { PersonResource } from './person'
|
|
4
5
|
import type { ReactionCountResource } from './reaction'
|
|
5
6
|
|
|
@@ -22,6 +23,10 @@ export interface MessageResource {
|
|
|
22
23
|
replyRoot?: MessageResource | null
|
|
23
24
|
idempotentKey?: string | null
|
|
24
25
|
messageType: string
|
|
26
|
+
// Set when messageType is 'unsupported': the type the server would have sent a newer client.
|
|
27
|
+
unsupportedMessageType?: string | null
|
|
28
|
+
// Set when messageType is 'unsupported': what to show read-only in place of the type.
|
|
29
|
+
fallbackContent?: FallbackContent | null
|
|
25
30
|
personIdsForSystemEvent?: number[] | null
|
|
26
31
|
systemTextParts?: { names: string[]; overflowCount: number; action: string } | null
|
|
27
32
|
systemTextFormat?: SystemTextFormat | null
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
})
|
|
@@ -110,6 +110,18 @@ describe('SessionManager', () => {
|
|
|
110
110
|
expect(manager.currentSession.id).toBe(UNAUTHENTICATED_SESSION_ID)
|
|
111
111
|
expect(manager.sessions).toHaveProperty(UNAUTHENTICATED_SESSION_ID)
|
|
112
112
|
})
|
|
113
|
+
|
|
114
|
+
it('keeps the Protonova environment name only while on Protonova', () => {
|
|
115
|
+
const manager = new SessionManager()
|
|
116
|
+
|
|
117
|
+
manager.setEnv('prototype', 'chat-812')
|
|
118
|
+
expect(SessionManager.hydrate(manager.toString()).currentSession.prototypeName).toBe(
|
|
119
|
+
'chat-812'
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
manager.setEnv('production', 'chat-812')
|
|
123
|
+
expect(manager.currentSession.prototypeName).toBeUndefined()
|
|
124
|
+
})
|
|
113
125
|
})
|
|
114
126
|
|
|
115
127
|
describe('upsertSession', () => {
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
})
|
|
@@ -32,4 +32,14 @@ describe('transformMessageEventDataToMessageResource', () => {
|
|
|
32
32
|
|
|
33
33
|
expect(isSystemMessage(message)).toBe(true)
|
|
34
34
|
})
|
|
35
|
+
|
|
36
|
+
it('carries the fallback content through so unsupported types render read-only in realtime', () => {
|
|
37
|
+
const fallback = { kind: 'poll', title: 'Lunch?', items: [{ label: 'Tacos', detail: '2' }] }
|
|
38
|
+
const message = transformMessageEventDataToMessageResource({
|
|
39
|
+
data: { ...archivedEventData, message_type: 'poll', fallback_content: fallback },
|
|
40
|
+
currentPersonId: 2,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
expect(message.fallbackContent).toEqual(fallback)
|
|
44
|
+
})
|
|
35
45
|
})
|
|
@@ -31,6 +31,8 @@ export function transformMessageEventDataToMessageResource({
|
|
|
31
31
|
replyRootId: data.reply_root_id || null,
|
|
32
32
|
idempotentKey: data.idempotent_key ?? null,
|
|
33
33
|
messageType: data.message_type,
|
|
34
|
+
unsupportedMessageType: data.unsupported_message_type ?? null,
|
|
35
|
+
fallbackContent: data.fallback_content ?? null,
|
|
34
36
|
personIdsForSystemEvent: data.system_event_person_ids,
|
|
35
37
|
systemTextParts: data.system_text_parts
|
|
36
38
|
? {
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
package/src/utils/session.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OAuthToken, OrganizationResource, PersonResource } from '../types'
|
|
2
2
|
|
|
3
|
-
export type ENV = 'production' | 'staging' | 'development'
|
|
3
|
+
export type ENV = 'production' | 'staging' | 'development' | 'prototype'
|
|
4
4
|
export type OauthType = 'OAuth' | 'ChurchCenterOauth'
|
|
5
5
|
export type PartialToken = Pick<OAuthToken, 'access_token'> & Partial<OAuthToken>
|
|
6
6
|
export type SessionMeta = {
|
|
@@ -11,6 +11,7 @@ export type SessionMeta = {
|
|
|
11
11
|
}
|
|
12
12
|
export type SessionProps<T extends PartialToken> = {
|
|
13
13
|
env?: ENV
|
|
14
|
+
prototypeName?: string
|
|
14
15
|
token?: T
|
|
15
16
|
type?: OauthType
|
|
16
17
|
meta?: SessionMeta
|
|
@@ -25,13 +26,15 @@ type SessionId = string | typeof UNAUTHENTICATED_SESSION_ID
|
|
|
25
26
|
*/
|
|
26
27
|
export class Session<T extends PartialToken = PartialToken> {
|
|
27
28
|
env: ENV
|
|
29
|
+
prototypeName: string | undefined
|
|
28
30
|
token: T | undefined
|
|
29
31
|
type: OauthType
|
|
30
32
|
meta: Record<string, any>
|
|
31
33
|
|
|
32
34
|
constructor(props?: SessionProps<T>) {
|
|
33
|
-
const { env = 'production', token, type, meta } = props || {}
|
|
35
|
+
const { env = 'production', prototypeName, token, type, meta } = props || {}
|
|
34
36
|
this.env = env
|
|
37
|
+
this.prototypeName = env === 'prototype' ? prototypeName : undefined
|
|
35
38
|
this.token = token
|
|
36
39
|
this.type = type || 'OAuth'
|
|
37
40
|
this.meta = meta || {}
|
|
@@ -54,7 +57,12 @@ export class Session<T extends PartialToken = PartialToken> {
|
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
toString() {
|
|
57
|
-
return JSON.stringify({
|
|
60
|
+
return JSON.stringify({
|
|
61
|
+
env: this.env,
|
|
62
|
+
prototypeName: this.prototypeName,
|
|
63
|
+
token: this.token,
|
|
64
|
+
meta: this.meta,
|
|
65
|
+
})
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
// Convenience methods to set the person and organization
|
|
@@ -32,10 +32,11 @@ export class SessionManager {
|
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
setEnv(env: ENV) {
|
|
35
|
+
setEnv(env: ENV, prototypeName?: string) {
|
|
36
36
|
// Get the current session (handles case where it doesn't exist)
|
|
37
37
|
const session = this.currentSession
|
|
38
38
|
session.env = env
|
|
39
|
+
session.prototypeName = prototypeName
|
|
39
40
|
// Store the session with its ID
|
|
40
41
|
this.upsertSession(session)
|
|
41
42
|
}
|
package/src/utils/upload_uri.ts
CHANGED
package/src/utils/uri.ts
CHANGED
|
@@ -24,6 +24,11 @@ export class Uri {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
get host() {
|
|
27
|
+
if (this.env === 'prototype') {
|
|
28
|
+
const graphDomain = this.isChurchCenter ? 'churchcenter' : 'planningcenter'
|
|
29
|
+
return `${this.session.prototypeName}.api.${graphDomain}.ninja`
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
return `${this.subdomain}.${this.domain}.${this.tld}`
|
|
28
33
|
}
|
|
29
34
|
|