@planningcenter/chat-react-native 4.5.1-qa-staging.13 → 4.5.1-qa-staging.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.
- package/build/components/conversation/message.d.ts.map +1 -1
- package/build/components/conversation/message.js +73 -64
- package/build/components/conversation/message.js.map +1 -1
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +106 -89
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/pinned_messages_bar.d.ts +4 -0
- package/build/components/conversation/pinned_messages_bar.d.ts.map +1 -0
- package/build/components/conversation/pinned_messages_bar.js +188 -0
- package/build/components/conversation/pinned_messages_bar.js.map +1 -0
- package/build/components/conversation/pinned_tag.d.ts +5 -0
- package/build/components/conversation/pinned_tag.d.ts.map +1 -0
- package/build/components/conversation/pinned_tag.js +89 -0
- package/build/components/conversation/pinned_tag.js.map +1 -0
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +1 -1
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +89 -52
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/hooks/use_features.d.ts +1 -0
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -0
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_message_pin.d.ts +11 -0
- package/build/hooks/use_message_pin.d.ts.map +1 -0
- package/build/hooks/use_message_pin.js +189 -0
- package/build/hooks/use_message_pin.js.map +1 -0
- package/build/hooks/use_pinned_messages.d.ts +8 -0
- package/build/hooks/use_pinned_messages.d.ts.map +1 -0
- package/build/hooks/use_pinned_messages.js +70 -0
- package/build/hooks/use_pinned_messages.js.map +1 -0
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation/pinned_messages_screen.d.ts +7 -0
- package/build/screens/conversation/pinned_messages_screen.d.ts.map +1 -0
- package/build/screens/conversation/pinned_messages_screen.js +372 -0
- package/build/screens/conversation/pinned_messages_screen.js.map +1 -0
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +2 -1
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +102 -88
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +135 -57
- package/build/screens/message_actions_screen.js.map +1 -1
- package/build/types/jolt_events/index.d.ts +4 -2
- package/build/types/jolt_events/index.d.ts.map +1 -1
- package/build/types/jolt_events/index.js.map +1 -1
- package/build/types/jolt_events/pin_events.d.ts +19 -0
- package/build/types/jolt_events/pin_events.d.ts.map +1 -0
- package/build/types/jolt_events/pin_events.js +2 -0
- package/build/types/jolt_events/pin_events.js.map +1 -0
- package/build/types/resources/member_ability.d.ts +1 -0
- package/build/types/resources/member_ability.d.ts.map +1 -1
- package/build/types/resources/member_ability.js.map +1 -1
- package/build/types/resources/message.d.ts +2 -0
- package/build/types/resources/message.d.ts.map +1 -1
- package/build/types/resources/message.js.map +1 -1
- package/build/utils/cache/messages_cache.d.ts +1 -0
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +19 -0
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/pinned_message_preview.d.ts +3 -0
- package/build/utils/pinned_message_preview.d.ts.map +1 -0
- package/build/utils/pinned_message_preview.js +7 -0
- package/build/utils/pinned_message_preview.js.map +1 -0
- package/build/utils/request/get_pinned_messages.d.ts +18 -0
- package/build/utils/request/get_pinned_messages.d.ts.map +1 -0
- package/build/utils/request/get_pinned_messages.js +18 -0
- package/build/utils/request/get_pinned_messages.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/package.json +3 -3
- package/src/__tests__/hooks/use_message_pin.test.tsx +107 -0
- package/src/__tests__/hooks/use_pinned_messages.test.tsx +46 -0
- package/src/__tests__/utils/update_cache_with_pin.test.ts +54 -0
- package/src/components/conversation/__tests__/pinned_messages_bar.test.tsx +62 -0
- package/src/components/conversation/message.tsx +9 -1
- package/src/components/conversation/message_list.tsx +17 -4
- package/src/components/conversation/pinned_messages_bar.tsx +64 -0
- package/src/components/conversation/pinned_tag.tsx +32 -0
- package/src/hooks/use_conversation.ts +1 -0
- package/src/hooks/use_conversation_messages_jolt_events.ts +19 -1
- package/src/hooks/use_features.ts +1 -0
- package/src/hooks/use_message_pin.ts +86 -0
- package/src/hooks/use_pinned_messages.ts +16 -0
- package/src/navigation/index.tsx +8 -0
- package/src/screens/conversation/pinned_messages_screen.tsx +155 -0
- package/src/screens/conversation_details_screen.tsx +1 -0
- package/src/screens/conversation_screen.tsx +3 -0
- package/src/screens/message_actions_screen.tsx +38 -0
- package/src/types/jolt_events/index.ts +4 -1
- package/src/types/jolt_events/pin_events.ts +20 -0
- package/src/types/resources/member_ability.ts +1 -0
- package/src/types/resources/message.ts +2 -0
- package/src/utils/cache/messages_cache.ts +22 -0
- package/src/utils/pinned_message_preview.ts +9 -0
- package/src/utils/request/get_pinned_messages.ts +19 -0
- package/src/utils/request/messages_data_options.ts +2 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
|
+
import { StackActions, StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
3
|
+
import { isNil, omitBy } from 'lodash'
|
|
4
|
+
import React, { useCallback, useMemo, useState } from 'react'
|
|
5
|
+
import { LayoutChangeEvent, Platform, StyleSheet, View } from 'react-native'
|
|
6
|
+
import { FlatList } from 'react-native-gesture-handler'
|
|
7
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
8
|
+
import { Icon, Text } from '../../components'
|
|
9
|
+
import FormSheet, { getFormSheetScreenOptions } from '../../components/primitive/form_sheet'
|
|
10
|
+
import { useTheme } from '../../hooks'
|
|
11
|
+
import { usePinnedMessages } from '../../hooks/use_pinned_messages'
|
|
12
|
+
import { MessageResource } from '../../types'
|
|
13
|
+
import { pinnedMessagePreview } from '../../utils/pinned_message_preview'
|
|
14
|
+
import { pluralize } from '../../utils/pluralize'
|
|
15
|
+
|
|
16
|
+
const LIST_BOTTOM_PADDING = 24
|
|
17
|
+
|
|
18
|
+
export const PinnedMessagesScreenOptions = getFormSheetScreenOptions({
|
|
19
|
+
sheetAllowedDetents: Platform.select({
|
|
20
|
+
android: [0.5, 0.94],
|
|
21
|
+
default: [0.5, 1],
|
|
22
|
+
}),
|
|
23
|
+
headerTitle: 'Pinned',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export type PinnedMessagesScreenProps = StaticScreenProps<{
|
|
27
|
+
conversation_id: number
|
|
28
|
+
}>
|
|
29
|
+
|
|
30
|
+
export function PinnedMessagesScreen({ route }: PinnedMessagesScreenProps) {
|
|
31
|
+
const styles = useStyles()
|
|
32
|
+
const navigation = useNavigation()
|
|
33
|
+
const [formSheetHeaderHeight, setFormSheetHeaderHeight] = useState(0)
|
|
34
|
+
const { bottom } = useSafeAreaInsets()
|
|
35
|
+
const { conversation_id } = route.params
|
|
36
|
+
const { pinnedMessages } = usePinnedMessages({ conversation_id })
|
|
37
|
+
|
|
38
|
+
const contentContainerPaddingBottomStyles = useMemo(() => {
|
|
39
|
+
return Platform.select({
|
|
40
|
+
android: { paddingBottom: bottom + LIST_BOTTOM_PADDING },
|
|
41
|
+
default: { paddingBottom: bottom + formSheetHeaderHeight + LIST_BOTTOM_PADDING },
|
|
42
|
+
})
|
|
43
|
+
}, [bottom, formSheetHeaderHeight])
|
|
44
|
+
|
|
45
|
+
const handleFormSheetHeaderLayout = useCallback((event: LayoutChangeEvent) => {
|
|
46
|
+
setFormSheetHeaderHeight(event.nativeEvent.layout.height)
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
const jumpToMessage = useCallback(
|
|
50
|
+
(message: MessageResource) => {
|
|
51
|
+
const conversationRoute = navigation
|
|
52
|
+
.getState?.()
|
|
53
|
+
?.routes?.find(r => r.name === 'Conversation')
|
|
54
|
+
const params = omitBy(
|
|
55
|
+
{
|
|
56
|
+
...(conversationRoute?.params || {}),
|
|
57
|
+
conversation_id,
|
|
58
|
+
initial_message_id: message.id,
|
|
59
|
+
},
|
|
60
|
+
isNil
|
|
61
|
+
)
|
|
62
|
+
navigation.dispatch(StackActions.popTo('Conversation', params))
|
|
63
|
+
},
|
|
64
|
+
[navigation, conversation_id]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<FormSheet.Root>
|
|
69
|
+
<View onLayout={handleFormSheetHeaderLayout}>
|
|
70
|
+
<FormSheet.Header>
|
|
71
|
+
<FormSheet.HeaderTitle>
|
|
72
|
+
Pinned ({pluralize(pinnedMessages.length, 'item')})
|
|
73
|
+
</FormSheet.HeaderTitle>
|
|
74
|
+
<FormSheet.HeaderActions>
|
|
75
|
+
<FormSheet.HeaderTextButton onPress={() => navigation.goBack()}>
|
|
76
|
+
Close
|
|
77
|
+
</FormSheet.HeaderTextButton>
|
|
78
|
+
</FormSheet.HeaderActions>
|
|
79
|
+
</FormSheet.Header>
|
|
80
|
+
</View>
|
|
81
|
+
<FlatList
|
|
82
|
+
data={pinnedMessages}
|
|
83
|
+
contentContainerStyle={[styles.contentContainer, contentContainerPaddingBottomStyles]}
|
|
84
|
+
keyExtractor={item => item.id}
|
|
85
|
+
renderItem={({ item }) => <PinnedMessageRow message={item} onPress={jumpToMessage} />}
|
|
86
|
+
nestedScrollEnabled
|
|
87
|
+
ListEmptyComponent={<Text style={styles.emptyText}>Nothing is pinned yet.</Text>}
|
|
88
|
+
/>
|
|
89
|
+
</FormSheet.Root>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const PinnedMessageRow = ({
|
|
94
|
+
message,
|
|
95
|
+
onPress,
|
|
96
|
+
}: {
|
|
97
|
+
message: MessageResource
|
|
98
|
+
onPress: (message: MessageResource) => void
|
|
99
|
+
}) => {
|
|
100
|
+
const styles = useStyles()
|
|
101
|
+
const { colors } = useTheme()
|
|
102
|
+
const from = message.mine ? 'you' : message.author?.name || 'a deleted user'
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<PlatformPressable
|
|
106
|
+
testID={`pinned-message-${message.id}`}
|
|
107
|
+
style={styles.row}
|
|
108
|
+
accessibilityRole="button"
|
|
109
|
+
accessibilityHint="Jumps to this message in the conversation"
|
|
110
|
+
onPress={() => onPress(message)}
|
|
111
|
+
>
|
|
112
|
+
<Icon name="services.pin" size={18} color={colors.iconColorDefaultSecondary} />
|
|
113
|
+
<View style={styles.rowText}>
|
|
114
|
+
<Text numberOfLines={2} style={styles.preview}>
|
|
115
|
+
{pinnedMessagePreview(message)}
|
|
116
|
+
</Text>
|
|
117
|
+
<Text variant="footnote">Message from {from}</Text>
|
|
118
|
+
</View>
|
|
119
|
+
<Icon name="general.rightChevron" size={14} color={colors.iconColorDefaultSecondary} />
|
|
120
|
+
</PlatformPressable>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const useStyles = () => {
|
|
125
|
+
const { colors } = useTheme()
|
|
126
|
+
|
|
127
|
+
return StyleSheet.create({
|
|
128
|
+
contentContainer: {
|
|
129
|
+
paddingTop: 8,
|
|
130
|
+
},
|
|
131
|
+
row: {
|
|
132
|
+
flexDirection: 'row',
|
|
133
|
+
alignItems: 'center',
|
|
134
|
+
gap: 12,
|
|
135
|
+
paddingHorizontal: 16,
|
|
136
|
+
paddingVertical: 12,
|
|
137
|
+
borderBottomWidth: 1,
|
|
138
|
+
borderBottomColor: colors.borderColorDefaultBase,
|
|
139
|
+
},
|
|
140
|
+
rowText: {
|
|
141
|
+
flex: 1,
|
|
142
|
+
minWidth: 0,
|
|
143
|
+
gap: 2,
|
|
144
|
+
},
|
|
145
|
+
preview: {
|
|
146
|
+
fontWeight: '500',
|
|
147
|
+
},
|
|
148
|
+
emptyText: {
|
|
149
|
+
textAlign: 'center',
|
|
150
|
+
color: colors.textColorDefaultSecondary,
|
|
151
|
+
marginTop: 32,
|
|
152
|
+
fontSize: 16,
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
LeaderMessagesDisabledBanner,
|
|
21
21
|
MemberMessagesDisabledBanner,
|
|
22
22
|
} from '../components/conversation/messages_disabled_banners'
|
|
23
|
+
import { PinnedMessagesBar } from '../components/conversation/pinned_messages_bar'
|
|
23
24
|
import { TypingIndicator } from '../components/conversation/typing_indicator'
|
|
24
25
|
import { KeyboardView } from '../components/display/keyboard_view'
|
|
25
26
|
import { useHeaderSlotReserve } from '../components/display/platform_modal_header_buttons'
|
|
@@ -170,6 +171,7 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
170
171
|
useEffect(() => {
|
|
171
172
|
if (!initial_message_id) return
|
|
172
173
|
|
|
174
|
+
setAnchorMessageId(initial_message_id)
|
|
173
175
|
navigation.setParams({ initial_message_id: null })
|
|
174
176
|
}, [initial_message_id, navigation])
|
|
175
177
|
|
|
@@ -201,6 +203,7 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
201
203
|
return (
|
|
202
204
|
<View style={styles.container}>
|
|
203
205
|
<KeyboardView>
|
|
206
|
+
{!reply_root_id && <PinnedMessagesBar conversationId={conversation_id} />}
|
|
204
207
|
{noMessages ? (
|
|
205
208
|
<View style={styles.emptyState}>
|
|
206
209
|
<ConversationStartBanner conversation={conversation} hasMessages={false} />
|
|
@@ -12,6 +12,7 @@ import { useApiClient } from '../hooks/use_api_client'
|
|
|
12
12
|
import { useConversation } from '../hooks/use_conversation'
|
|
13
13
|
import { useConversationMessages } from '../hooks/use_conversation_messages'
|
|
14
14
|
import { availableFeatures, useFeatures } from '../hooks/use_features'
|
|
15
|
+
import { useMessagePin } from '../hooks/use_message_pin'
|
|
15
16
|
import { useMessageReactionToggle } from '../hooks/use_message_reaction_toggle'
|
|
16
17
|
import { MessageResource } from '../types'
|
|
17
18
|
import { ReactionCountResource } from '../types/resources/reaction'
|
|
@@ -61,6 +62,7 @@ export function MessageActionsScreen({ route }: MessageActionsScreenProps) {
|
|
|
61
62
|
conversation_id={conversation_id}
|
|
62
63
|
conversationDisabled={!!conversation.disabled}
|
|
63
64
|
canDeleteNonAuthoredMessages={canDeleteNonAuthoredMessages || false}
|
|
65
|
+
canPinNonAuthoredMessages={!!conversation.memberAbility?.canPin}
|
|
64
66
|
refetchMessages={refetch}
|
|
65
67
|
inReplyScreen={inReplyScreen}
|
|
66
68
|
replyRootAuthorName={reply_root_author_name}
|
|
@@ -74,6 +76,7 @@ function MessageActionsScreenContent({
|
|
|
74
76
|
conversation_id,
|
|
75
77
|
conversationDisabled,
|
|
76
78
|
canDeleteNonAuthoredMessages,
|
|
79
|
+
canPinNonAuthoredMessages,
|
|
77
80
|
refetchMessages,
|
|
78
81
|
inReplyScreen,
|
|
79
82
|
replyRootAuthorName,
|
|
@@ -83,6 +86,7 @@ function MessageActionsScreenContent({
|
|
|
83
86
|
conversation_id: number
|
|
84
87
|
conversationDisabled: boolean
|
|
85
88
|
canDeleteNonAuthoredMessages: boolean
|
|
89
|
+
canPinNonAuthoredMessages: boolean
|
|
86
90
|
refetchMessages: () => void
|
|
87
91
|
inReplyScreen?: boolean
|
|
88
92
|
replyRootAuthorName?: string
|
|
@@ -244,8 +248,28 @@ function MessageActionsScreenContent({
|
|
|
244
248
|
])
|
|
245
249
|
}, [handleRemoveLinkPreview])
|
|
246
250
|
|
|
251
|
+
const { pin, unpin, isPinning, isUnpinning } = useMessagePin({ conversation_id, message })
|
|
252
|
+
const isPinned = !!message.pinnedAt
|
|
253
|
+
|
|
254
|
+
const handlePinPress = useCallback(() => {
|
|
255
|
+
pin()
|
|
256
|
+
navigation.goBack()
|
|
257
|
+
}, [pin, navigation])
|
|
258
|
+
|
|
259
|
+
const handleUnpinPress = useCallback(() => {
|
|
260
|
+
unpin()
|
|
261
|
+
navigation.goBack()
|
|
262
|
+
}, [unpin, navigation])
|
|
263
|
+
|
|
247
264
|
const showReportMessageAction =
|
|
248
265
|
!message?.mine && featureEnabled(availableFeatures.message_reporting)
|
|
266
|
+
const isThreadReply = !!message.replyRootId && message.replyRootId !== message.id
|
|
267
|
+
const showPinMessageAction =
|
|
268
|
+
!inReplyScreen &&
|
|
269
|
+
!isThreadReply &&
|
|
270
|
+
!conversationDisabled &&
|
|
271
|
+
featureEnabled(availableFeatures.pinned_messages) &&
|
|
272
|
+
(message?.mine || canPinNonAuthoredMessages)
|
|
249
273
|
const showDeleteMessageAction =
|
|
250
274
|
!conversationDisabled && (message?.mine || canDeleteNonAuthoredMessages)
|
|
251
275
|
|
|
@@ -310,6 +334,20 @@ function MessageActionsScreenContent({
|
|
|
310
334
|
accessibilityHint="Opens a modal with a list of people who read your message."
|
|
311
335
|
/>
|
|
312
336
|
)}
|
|
337
|
+
{showPinMessageAction && (
|
|
338
|
+
<FormSheet.Action
|
|
339
|
+
onPress={isPinned ? handleUnpinPress : handlePinPress}
|
|
340
|
+
title={isPinned ? 'Unpin message' : 'Pin message'}
|
|
341
|
+
iconName="services.pin"
|
|
342
|
+
disabled={isPinning || isUnpinning}
|
|
343
|
+
accessibilityHint={
|
|
344
|
+
isPinned
|
|
345
|
+
? 'Removes this message from the top of the chat.'
|
|
346
|
+
: 'Shows this message at the top of the chat for everyone.'
|
|
347
|
+
}
|
|
348
|
+
testID="pin-message-action"
|
|
349
|
+
/>
|
|
350
|
+
)}
|
|
313
351
|
{message?.mine && hasExpandedLink && !conversationDisabled && (
|
|
314
352
|
<FormSheet.Action
|
|
315
353
|
onPress={() => handleRemoveLinkPreviewConfirm()}
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
MessageDeletedEvent,
|
|
11
11
|
MessageUpdatedEvent,
|
|
12
12
|
} from './message_events'
|
|
13
|
+
import type { PinCreatedEvent, PinDestroyedEvent } from './pin_events'
|
|
13
14
|
import type { ReactionCreatedEvent, ReactionDeletedEvent } from './reaction_events'
|
|
14
15
|
import type { TypingBroadcastEvent } from './typing_events'
|
|
15
16
|
|
|
@@ -21,6 +22,7 @@ export type JoltConversationEvent =
|
|
|
21
22
|
export type JoltMessageEvent = MessageCreatedEvent | MessageUpdatedEvent | MessageDeletedEvent
|
|
22
23
|
export type JoltReactionEvent = ReactionCreatedEvent | ReactionDeletedEvent
|
|
23
24
|
export type JoltTypingEvent = TypingBroadcastEvent
|
|
25
|
+
export type JoltPinEvent = PinCreatedEvent | PinDestroyedEvent
|
|
24
26
|
export type JoltAttachmentEvent = AttachmentFlaggedEvent
|
|
25
27
|
|
|
26
28
|
export type CustomJoltEvent =
|
|
@@ -29,6 +31,7 @@ export type CustomJoltEvent =
|
|
|
29
31
|
| JoltReactionEvent
|
|
30
32
|
| JoltTypingEvent
|
|
31
33
|
| JoltAttachmentEvent
|
|
34
|
+
| JoltPinEvent
|
|
32
35
|
|
|
33
36
|
export type JoltEventName = CustomJoltEvent['event'] | 'STREAM_USER_UPDATED'
|
|
34
|
-
export type JoltSubscriptionPattern = JoltEventName | 'reaction.*'
|
|
37
|
+
export type JoltSubscriptionPattern = JoltEventName | 'reaction.*' | 'pin.*'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
|
|
2
|
+
|
|
3
|
+
interface PinEventData extends Record<string, unknown> {
|
|
4
|
+
data: {
|
|
5
|
+
conversation_id: number
|
|
6
|
+
message_sort_key: string
|
|
7
|
+
reply_root_id: string | null
|
|
8
|
+
pinned_at: string
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface PinCreatedEvent extends CustomMessage {
|
|
13
|
+
event: 'pin.created'
|
|
14
|
+
data: PinEventData
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PinDestroyedEvent extends CustomMessage {
|
|
18
|
+
event: 'pin.destroyed'
|
|
19
|
+
data: PinEventData
|
|
20
|
+
}
|
|
@@ -25,6 +25,8 @@ export interface MessageResource {
|
|
|
25
25
|
personIdsForSystemEvent?: number[] | null
|
|
26
26
|
systemTextParts?: { names: string[]; overflowCount: number; action: string } | null
|
|
27
27
|
systemTextFormat?: SystemTextFormat | null
|
|
28
|
+
pinnedAt?: string | null
|
|
29
|
+
pinnedById?: number | null
|
|
28
30
|
|
|
29
31
|
// Custom Local Properties we set for rendering
|
|
30
32
|
renderAuthor?: boolean
|
|
@@ -191,6 +191,28 @@ export function applyMessageDeletionToCaches(
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
export function updateCacheWithPin(
|
|
195
|
+
queryClient: QueryClient,
|
|
196
|
+
conversationId: number,
|
|
197
|
+
messageSortKey: string,
|
|
198
|
+
pinnedAt: string | null,
|
|
199
|
+
replyRootId?: string | null
|
|
200
|
+
) {
|
|
201
|
+
const queryKeys = [getMessagesQueryKey({ conversation_id: conversationId })]
|
|
202
|
+
if (replyRootId) queryKeys.push(getThreadedMessagesQueryKey(conversationId, replyRootId))
|
|
203
|
+
|
|
204
|
+
const record = { id: messageSortKey } as MessageResource
|
|
205
|
+
queryKeys.forEach(queryKey => {
|
|
206
|
+
queryClient.setQueryData<MessagesQueryData>(queryKey, prev =>
|
|
207
|
+
updateRecordInPagesData({
|
|
208
|
+
data: prev,
|
|
209
|
+
record,
|
|
210
|
+
processRecord: (_record, current) => ({ ...current, pinnedAt }),
|
|
211
|
+
})
|
|
212
|
+
)
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
194
216
|
export function mergeMessageUpdate(
|
|
195
217
|
record: MessageResource,
|
|
196
218
|
current?: MessageResource
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MessageResource } from '../types'
|
|
2
|
+
import { pluralize } from './pluralize'
|
|
3
|
+
|
|
4
|
+
export function pinnedMessagePreview(message: MessageResource) {
|
|
5
|
+
if (message.text) return message.text
|
|
6
|
+
|
|
7
|
+
const attachmentCount = message.attachments?.length ?? 0
|
|
8
|
+
return attachmentCount > 0 ? pluralize(attachmentCount, 'attachment') : ''
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getRequestQueryKey } from '../../hooks/use_suspense_api'
|
|
2
|
+
import { getMessageFields } from './messages_data_options'
|
|
3
|
+
|
|
4
|
+
export const PINNED_MESSAGES_PER_PAGE = 50
|
|
5
|
+
|
|
6
|
+
export const getPinnedMessagesRequestArgs = ({ conversation_id }: { conversation_id: number }) => ({
|
|
7
|
+
url: `/me/conversations/${conversation_id}/pinned_messages`,
|
|
8
|
+
data: {
|
|
9
|
+
per_page: PINNED_MESSAGES_PER_PAGE,
|
|
10
|
+
fields: {
|
|
11
|
+
Message: getMessageFields.Message.filter(field => field !== 'reaction_counts'),
|
|
12
|
+
Person: getMessageFields.Person,
|
|
13
|
+
},
|
|
14
|
+
include: ['author'],
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const getPinnedMessagesQueryKey = (args: { conversation_id: number }) =>
|
|
19
|
+
getRequestQueryKey(getPinnedMessagesRequestArgs(args))
|