@linktr.ee/messaging-react 1.24.1 → 1.24.2-rc-1773232561
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.js +183 -177
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ChannelList/index.tsx +1 -0
- package/src/components/MessagingShell/channelFilters.test.ts +41 -0
- package/src/components/MessagingShell/channelFilters.ts +21 -0
- package/src/components/MessagingShell/index.tsx +5 -21
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ChannelFilters } from 'stream-chat'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { buildChannelFilters } from './channelFilters'
|
|
5
|
+
|
|
6
|
+
describe('buildChannelFilters', () => {
|
|
7
|
+
it('includes base filters and has_visitor_message when userId is present', () => {
|
|
8
|
+
const result = buildChannelFilters('user-123')
|
|
9
|
+
|
|
10
|
+
expect(result).toEqual({
|
|
11
|
+
type: 'messaging',
|
|
12
|
+
last_message_at: { $exists: true },
|
|
13
|
+
members: { $in: ['user-123'] },
|
|
14
|
+
hidden: false,
|
|
15
|
+
has_visitor_message: true,
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('omits members and hidden when userId is undefined', () => {
|
|
20
|
+
const result = buildChannelFilters(undefined)
|
|
21
|
+
|
|
22
|
+
expect(result).toEqual({
|
|
23
|
+
type: 'messaging',
|
|
24
|
+
last_message_at: { $exists: true },
|
|
25
|
+
has_visitor_message: true,
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('merges consumer filters and allows overrides', () => {
|
|
30
|
+
const consumerFilters = {
|
|
31
|
+
type: 'custom-type',
|
|
32
|
+
custom_field: 'value',
|
|
33
|
+
} as ChannelFilters
|
|
34
|
+
|
|
35
|
+
const result = buildChannelFilters('user-123', consumerFilters)
|
|
36
|
+
|
|
37
|
+
expect(result).toHaveProperty('type', 'custom-type')
|
|
38
|
+
expect(result).toHaveProperty('custom_field', 'value')
|
|
39
|
+
expect(result).toHaveProperty('has_visitor_message', true)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChannelFilters } from 'stream-chat'
|
|
2
|
+
|
|
3
|
+
export function buildChannelFilters(
|
|
4
|
+
userId: string | undefined,
|
|
5
|
+
consumerFilters?: ChannelFilters
|
|
6
|
+
): ChannelFilters {
|
|
7
|
+
const baseFilters = {
|
|
8
|
+
type: 'messaging',
|
|
9
|
+
last_message_at: { $exists: true },
|
|
10
|
+
...(userId && {
|
|
11
|
+
members: { $in: [userId] },
|
|
12
|
+
hidden: false,
|
|
13
|
+
}),
|
|
14
|
+
has_visitor_message: true,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
...baseFilters,
|
|
19
|
+
...consumerFilters,
|
|
20
|
+
} as ChannelFilters
|
|
21
|
+
}
|
|
@@ -8,6 +8,7 @@ import { ChannelList } from '../ChannelList'
|
|
|
8
8
|
import { ChannelView } from '../ChannelView'
|
|
9
9
|
import { ParticipantPicker } from '../ParticipantPicker'
|
|
10
10
|
|
|
11
|
+
import { buildChannelFilters } from './channelFilters'
|
|
11
12
|
import { EmptyState } from './EmptyState'
|
|
12
13
|
import { ErrorState } from './ErrorState'
|
|
13
14
|
import { LoadingState } from './LoadingState'
|
|
@@ -71,27 +72,10 @@ export const MessagingShell: React.FC<MessagingShellProps> = ({
|
|
|
71
72
|
showDeleteConversation = true,
|
|
72
73
|
} = capabilities
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Base filters that should always be present
|
|
79
|
-
const baseFilters = {
|
|
80
|
-
type: 'messaging',
|
|
81
|
-
last_message_at: { $exists: true },
|
|
82
|
-
...(userId && {
|
|
83
|
-
members: { $in: [userId] },
|
|
84
|
-
hidden: false,
|
|
85
|
-
}),
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Merge provided filters with base filters
|
|
89
|
-
// Provided filters can override base filters if needed
|
|
90
|
-
return {
|
|
91
|
-
...baseFilters,
|
|
92
|
-
...filters,
|
|
93
|
-
}
|
|
94
|
-
}, [filters, client?.userID])
|
|
75
|
+
const channelFilters = React.useMemo(
|
|
76
|
+
() => buildChannelFilters(client?.userID, filters),
|
|
77
|
+
[filters, client?.userID]
|
|
78
|
+
)
|
|
95
79
|
|
|
96
80
|
// Track if we've already synced channels to prevent repeated API calls
|
|
97
81
|
const syncedRef = useRef<string | null>(null)
|