@linktr.ee/messaging-react 1.24.3 → 1.24.4
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/dist/index.d.ts +21 -0
- package/dist/index.js +327 -322
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ChannelList/index.test.tsx +79 -0
- package/src/components/ChannelList/index.tsx +8 -1
- package/src/types.ts +24 -1
package/package.json
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { renderWithProviders } from '../../test/utils'
|
|
5
|
+
|
|
6
|
+
import { ChannelList } from '.'
|
|
7
|
+
|
|
8
|
+
const streamChannelListMock = vi.fn()
|
|
9
|
+
|
|
10
|
+
vi.mock('stream-chat-react', () => ({
|
|
11
|
+
ChannelList: (props: unknown) => {
|
|
12
|
+
streamChannelListMock(props)
|
|
13
|
+
return <div data-testid="stream-channel-list" />
|
|
14
|
+
},
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
vi.mock('../../providers/MessagingProvider', () => ({
|
|
18
|
+
useMessagingContext: () => ({ debug: false }),
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
vi.mock('./CustomChannelPreview', () => ({
|
|
22
|
+
default: () => null,
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
describe('ChannelList', () => {
|
|
26
|
+
const defaultProps = {
|
|
27
|
+
filters: { type: 'messaging' },
|
|
28
|
+
onChannelSelect: vi.fn(),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
streamChannelListMock.mockClear()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('defaults unseen-channel promotion to false', () => {
|
|
36
|
+
renderWithProviders(<ChannelList {...defaultProps} />)
|
|
37
|
+
|
|
38
|
+
expect(streamChannelListMock).toHaveBeenCalledOnce()
|
|
39
|
+
expect(streamChannelListMock.mock.calls[0][0]).toMatchObject({
|
|
40
|
+
allowNewMessagesFromUnfilteredChannels: false,
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('passes allowNewMessagesFromUnfilteredChannels through to Stream ChannelList', () => {
|
|
45
|
+
const props: React.ComponentProps<typeof ChannelList> = {
|
|
46
|
+
...defaultProps,
|
|
47
|
+
allowNewMessagesFromUnfilteredChannels: true,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
renderWithProviders(React.createElement(ChannelList, props))
|
|
51
|
+
|
|
52
|
+
expect(streamChannelListMock).toHaveBeenCalledOnce()
|
|
53
|
+
expect(streamChannelListMock.mock.calls[0][0]).toMatchObject({
|
|
54
|
+
allowNewMessagesFromUnfilteredChannels: true,
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('passes new-channel event handlers through to Stream ChannelList', () => {
|
|
59
|
+
const onMessageNew = vi.fn()
|
|
60
|
+
const onAddedToChannel = vi.fn()
|
|
61
|
+
|
|
62
|
+
renderWithProviders(
|
|
63
|
+
React.createElement(ChannelList, {
|
|
64
|
+
...defaultProps,
|
|
65
|
+
onMessageNew,
|
|
66
|
+
onAddedToChannel,
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expect(streamChannelListMock).toHaveBeenCalledOnce()
|
|
71
|
+
const streamProps = streamChannelListMock.mock.calls[0][0] as {
|
|
72
|
+
onMessageNew?: unknown
|
|
73
|
+
onAddedToChannel?: unknown
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
expect(streamProps.onMessageNew).toBe(onMessageNew)
|
|
77
|
+
expect(streamProps.onAddedToChannel).toBe(onAddedToChannel)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -18,6 +18,9 @@ export const ChannelList = React.memo<ChannelListProps>(
|
|
|
18
18
|
onChannelSelect,
|
|
19
19
|
selectedChannel,
|
|
20
20
|
filters,
|
|
21
|
+
allowNewMessagesFromUnfilteredChannels = false,
|
|
22
|
+
onMessageNew,
|
|
23
|
+
onAddedToChannel,
|
|
21
24
|
sort = DEFAULT_SORT,
|
|
22
25
|
className,
|
|
23
26
|
customEmptyStateIndicator,
|
|
@@ -63,7 +66,11 @@ export const ChannelList = React.memo<ChannelListProps>(
|
|
|
63
66
|
filters={filters}
|
|
64
67
|
sort={sort}
|
|
65
68
|
options={{ limit: 30 }}
|
|
66
|
-
allowNewMessagesFromUnfilteredChannels={
|
|
69
|
+
allowNewMessagesFromUnfilteredChannels={
|
|
70
|
+
allowNewMessagesFromUnfilteredChannels
|
|
71
|
+
}
|
|
72
|
+
onMessageNew={onMessageNew}
|
|
73
|
+
onAddedToChannel={onAddedToChannel}
|
|
67
74
|
Preview={CustomChannelPreview}
|
|
68
75
|
EmptyStateIndicator={customEmptyStateIndicator}
|
|
69
76
|
/>
|
package/src/types.ts
CHANGED
|
@@ -9,7 +9,10 @@ import type {
|
|
|
9
9
|
LocalMessage,
|
|
10
10
|
SendMessageAPIResponse,
|
|
11
11
|
} from 'stream-chat'
|
|
12
|
-
import {
|
|
12
|
+
import type {
|
|
13
|
+
ChannelListProps as StreamChannelListProps,
|
|
14
|
+
EmptyStateIndicatorProps,
|
|
15
|
+
} from 'stream-chat-react'
|
|
13
16
|
|
|
14
17
|
import type { MessageMetadata } from './stream-custom-data'
|
|
15
18
|
|
|
@@ -68,6 +71,26 @@ export interface ChannelListProps {
|
|
|
68
71
|
participantLabel?: string
|
|
69
72
|
className?: string
|
|
70
73
|
filters: ChannelFilters
|
|
74
|
+
/**
|
|
75
|
+
* Controls whether new-message events can promote channels that are not
|
|
76
|
+
* already present in the current list.
|
|
77
|
+
*
|
|
78
|
+
* Defaults to `false` for backward compatibility with existing filtered
|
|
79
|
+
* ChannelList consumers.
|
|
80
|
+
*/
|
|
81
|
+
allowNewMessagesFromUnfilteredChannels?: boolean
|
|
82
|
+
/**
|
|
83
|
+
* Advanced override for handling `notification.message_new` events.
|
|
84
|
+
* Use for filtered/product-defined views that need to verify whether a
|
|
85
|
+
* channel belongs in the current list before inserting it.
|
|
86
|
+
*/
|
|
87
|
+
onMessageNew?: StreamChannelListProps['onMessageNew']
|
|
88
|
+
/**
|
|
89
|
+
* Advanced override for handling `notification.added_to_channel` events.
|
|
90
|
+
* Use for filtered/product-defined views that need to verify whether a
|
|
91
|
+
* channel belongs in the current list before inserting it.
|
|
92
|
+
*/
|
|
93
|
+
onAddedToChannel?: StreamChannelListProps['onAddedToChannel']
|
|
71
94
|
/**
|
|
72
95
|
* Sort order for the channel list query.
|
|
73
96
|
* Defaults to `{ last_message_at: -1 }` (most recent first).
|