@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "1.24.1",
3
+ "version": "1.24.2-rc-1773232561",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -63,6 +63,7 @@ export const ChannelList = React.memo<ChannelListProps>(
63
63
  filters={filters}
64
64
  sort={sort}
65
65
  options={{ limit: 30 }}
66
+ allowNewMessagesFromUnfilteredChannels={false}
66
67
  Preview={CustomChannelPreview}
67
68
  EmptyStateIndicator={customEmptyStateIndicator}
68
69
  />
@@ -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
- // Create default filters and merge with provided filters
75
- const channelFilters = React.useMemo(() => {
76
- const userId = client?.userID
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)