@cometchat/chat-uikit-react-native 5.2.3 → 5.2.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.
Files changed (75) hide show
  1. package/package.json +1 -1
  2. package/src/CometChatConversations/CometChatConversations.tsx +167 -86
  3. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +312 -116
  4. package/src/CometChatMessageComposer/styles.tsx +2 -1
  5. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +83 -17
  6. package/src/CometChatMessageList/CometChatMessageList.tsx +549 -70
  7. package/src/CometChatMessageList/style.ts +4 -2
  8. package/src/CometChatSearch/CometChatSearch.tsx +1718 -0
  9. package/src/CometChatSearch/SearchConstants.ts +46 -0
  10. package/src/CometChatSearch/Skeleton.tsx +192 -0
  11. package/src/CometChatSearch/index.ts +1 -0
  12. package/src/CometChatSearch/style.ts +414 -0
  13. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +43 -7
  14. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +45 -7
  15. package/src/extensions/Polls/Polls.tsx +36 -2
  16. package/src/extensions/Polls/PollsBubble.tsx +13 -9
  17. package/src/extensions/Polls/PollsDecorator.tsx +13 -1
  18. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +50 -11
  19. package/src/extensions/Stickers/style.ts +0 -1
  20. package/src/index.ts +5 -0
  21. package/src/shared/base/Types.ts +8 -0
  22. package/src/shared/constants/UIKitConstants.ts +2 -0
  23. package/src/shared/events/CometChatMessageEvents/index.ts +8 -7
  24. package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -0
  25. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +158 -27
  26. package/src/shared/framework/DataSource.ts +7 -0
  27. package/src/shared/framework/DataSourceDecorator.tsx +12 -0
  28. package/src/shared/framework/MessageDataSource.tsx +182 -1
  29. package/src/shared/helper/functions.js +0 -67
  30. package/src/shared/helper/helperFunctions.ts +73 -0
  31. package/src/shared/icons/components/documents.tsx +23 -0
  32. package/src/shared/icons/components/empty-search.tsx +52 -0
  33. package/src/shared/icons/components/message-blocked.tsx +1 -1
  34. package/src/shared/icons/components/unread.tsx +29 -0
  35. package/src/shared/icons/icon-mapping.tsx +7 -0
  36. package/src/shared/index.ts +2 -1
  37. package/src/shared/modals/CometChatMessageTemplate.ts +23 -0
  38. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +4 -4
  39. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +17 -1
  40. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +70 -34
  41. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +60 -24
  42. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +37 -1
  43. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +60 -24
  44. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +37 -1
  45. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +37 -1
  46. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +37 -1
  47. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +37 -1
  48. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +40 -4
  49. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +37 -1
  50. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +37 -1
  51. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +37 -1
  52. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +37 -1
  53. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +38 -2
  54. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +37 -1
  55. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +37 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +40 -4
  57. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +274 -23
  58. package/src/shared/utils/MessageUtils.tsx +0 -1
  59. package/src/shared/views/CometChatAudioBubble/style.ts +0 -2
  60. package/src/shared/views/CometChatFileBubble/style.ts +0 -4
  61. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +1 -0
  62. package/src/shared/views/CometChatList/CometChatList.tsx +12 -0
  63. package/src/shared/views/CometChatList/Header.tsx +79 -49
  64. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
  65. package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +390 -0
  66. package/src/shared/views/CometChatReportDialog/index.ts +3 -0
  67. package/src/shared/views/CometChatReportDialog/style.ts +164 -0
  68. package/src/shared/views/CometChatStatusIndicator/private.png +0 -0
  69. package/src/shared/views/CometChatStatusIndicator/protected.png +0 -0
  70. package/src/shared/views/CometChatStatusIndicator/styles.ts +2 -2
  71. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +18 -2
  72. package/src/shared/views/index.ts +6 -0
  73. package/src/theme/default/default.ts +3 -0
  74. package/src/theme/provider.tsx +7 -5
  75. package/src/theme/type.ts +2 -0
@@ -0,0 +1,1718 @@
1
+ import React, { useCallback, useEffect, useReducer, useRef, useState, useMemo } from 'react';
2
+ import { View, TextInput, TouchableOpacity, Text, ScrollView, Image } from 'react-native';
3
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
4
+ import {
5
+ CometChatAvatar,
6
+ CometChatStatusIndicator,
7
+ CometChatBadge,
8
+ CometChatDate,
9
+ useTheme
10
+ } from '@cometchat/chat-uikit-react-native';
11
+ import { Icon } from '../shared/icons/Icon';
12
+ import { GroupTypeConstants, ReceiverTypeConstants, MessageCategoryConstants, MessageTypeConstants } from '@cometchat/chat-uikit-react-native/src/shared/constants/UIKitConstants';
13
+ import { CometChatSearchScope, CometChatSearchFilter, States } from './SearchConstants';
14
+ import { Skeleton } from './Skeleton';
15
+ import { SearchStyle, getSearchStyleLight, getSearchStyleDark } from './style';
16
+ import { deepMerge } from '../shared/helper/helperFunctions';
17
+ import { DeepPartial } from '../shared/helper/types';
18
+ import Video from 'react-native-video';
19
+ import { getCometChatTranslation } from '../shared/resources/CometChatLocalizeNew/LocalizationManager';
20
+
21
+
22
+ // ERROR HANDLER
23
+ function useCometChatErrorHandler(onError?: (error: CometChat.CometChatException) => void) {
24
+ return useCallback(
25
+ (error: any, source?: string) => {
26
+ console.error(`CometChat Error${source ? ` in ${source}` : ''}:`, error);
27
+
28
+ if (onError && error instanceof CometChat.CometChatException) {
29
+ onError(error);
30
+ }
31
+ },
32
+ [onError]
33
+ );
34
+ }
35
+
36
+ // SEARCH UTILITIES
37
+ function hasValidConversationSearchCriteria(searchKeyword: string, filters: CometChatSearchFilter[]): boolean {
38
+ if (searchKeyword && searchKeyword.trim() !== "") {
39
+ return true;
40
+ }
41
+
42
+ const validFilters = [
43
+ CometChatSearchFilter.Unread,
44
+ CometChatSearchFilter.Groups,
45
+ CometChatSearchFilter.Conversations
46
+ ];
47
+
48
+ if (filters.length === 0) {
49
+ return false;
50
+ }
51
+
52
+ return filters.every(filter => validFilters.includes(filter));
53
+ }
54
+
55
+ function hasValidMessageSearchCriteria(searchKeyword: string, filters: CometChatSearchFilter[]): boolean {
56
+ if (searchKeyword && searchKeyword.trim() !== "") {
57
+ return true;
58
+ }
59
+
60
+ const validMessageFilters = [
61
+ CometChatSearchFilter.Photos,
62
+ CometChatSearchFilter.Videos,
63
+ CometChatSearchFilter.Documents,
64
+ CometChatSearchFilter.Audio,
65
+ CometChatSearchFilter.Links
66
+ ];
67
+
68
+ if (filters.length === 0) {
69
+ return false;
70
+ }
71
+
72
+ return filters.some(filter => validMessageFilters.includes(filter));
73
+ }
74
+
75
+ interface SearchState {
76
+ searchText: string;
77
+ conversations: CometChat.Conversation[];
78
+ messages: CometChat.BaseMessage[];
79
+ fetchState: States;
80
+ activeFilters: CometChatSearchFilter[];
81
+ }
82
+
83
+ type SearchAction =
84
+ | { type: "setSearchText"; searchText: string }
85
+ | { type: "setResults"; conversations?: CometChat.Conversation[]; messages?: CometChat.BaseMessage[] }
86
+ | { type: "clearResults" }
87
+ | { type: "setFetchState"; fetchState: States }
88
+ | { type: "setActiveFilter"; filterId: CometChatSearchFilter }
89
+ | { type: "resetActiveFilters" };
90
+
91
+ const initialState: SearchState = {
92
+ searchText: "",
93
+ conversations: [],
94
+ messages: [],
95
+ fetchState: States.loaded,
96
+ activeFilters: [],
97
+ };
98
+
99
+ function searchStateReducer(state: SearchState, action: SearchAction): SearchState {
100
+ switch (action.type) {
101
+ case "setSearchText":
102
+ return { ...state, searchText: action.searchText };
103
+
104
+ case "setResults":
105
+ return {
106
+ ...state,
107
+ conversations: action.conversations ?? state.conversations,
108
+ messages: action.messages ?? state.messages,
109
+ fetchState: States.loaded,
110
+ };
111
+
112
+ case "clearResults":
113
+ return { ...state, conversations: [], messages: [] };
114
+
115
+ case "setFetchState":
116
+ return { ...state, fetchState: action.fetchState };
117
+
118
+ case "setActiveFilter": {
119
+ const newActiveFilters = [...state.activeFilters];
120
+ const filterIndex = newActiveFilters.findIndex(f => f === action.filterId);
121
+
122
+ // Define filter pairs
123
+ const filterPairs = {
124
+ conversationPair: [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups],
125
+ photosVideosPair: [CometChatSearchFilter.Photos, CometChatSearchFilter.Videos],
126
+ audioDocumentsPair: [CometChatSearchFilter.Audio, CometChatSearchFilter.Documents],
127
+ linkStandalone: [CometChatSearchFilter.Links]
128
+ };
129
+
130
+ if (filterIndex >= 0) {
131
+ // If filter is already active, remove it
132
+ newActiveFilters.splice(filterIndex, 1);
133
+ } else {
134
+ // Clear incompatible filters before adding new one
135
+
136
+ // If selecting Links (standalone), clear all other filters
137
+ if (action.filterId === CometChatSearchFilter.Links) {
138
+ newActiveFilters.length = 0; // Clear all filters
139
+ }
140
+ // If selecting conversation pair filter, clear other pairs
141
+ else if (filterPairs.conversationPair.includes(action.filterId)) {
142
+ // Remove all non-conversation filters
143
+ const filtersToRemove = [
144
+ ...filterPairs.photosVideosPair,
145
+ ...filterPairs.audioDocumentsPair,
146
+ ...filterPairs.linkStandalone
147
+ ];
148
+ filtersToRemove.forEach(filter => {
149
+ const idx = newActiveFilters.findIndex(f => f === filter);
150
+ if (idx >= 0) newActiveFilters.splice(idx, 1);
151
+ });
152
+ }
153
+ // If selecting photos/videos pair filter, clear other pairs
154
+ else if (filterPairs.photosVideosPair.includes(action.filterId)) {
155
+ const filtersToRemove = [
156
+ ...filterPairs.conversationPair,
157
+ ...filterPairs.audioDocumentsPair,
158
+ ...filterPairs.linkStandalone
159
+ ];
160
+ filtersToRemove.forEach(filter => {
161
+ const idx = newActiveFilters.findIndex(f => f === filter);
162
+ if (idx >= 0) newActiveFilters.splice(idx, 1);
163
+ });
164
+ }
165
+ // If selecting audio/documents pair filter, clear other pairs
166
+ else if (filterPairs.audioDocumentsPair.includes(action.filterId)) {
167
+ const filtersToRemove = [
168
+ ...filterPairs.conversationPair,
169
+ ...filterPairs.photosVideosPair,
170
+ ...filterPairs.linkStandalone
171
+ ];
172
+ filtersToRemove.forEach(filter => {
173
+ const idx = newActiveFilters.findIndex(f => f === filter);
174
+ if (idx >= 0) newActiveFilters.splice(idx, 1);
175
+ });
176
+ }
177
+
178
+ newActiveFilters.push(action.filterId);
179
+ }
180
+
181
+ return { ...state, activeFilters: newActiveFilters };
182
+ }
183
+
184
+ case "resetActiveFilters":
185
+ return { ...state, activeFilters: [] };
186
+
187
+ default:
188
+ return state;
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Props for the CometChatSearch component
194
+ */
195
+ interface CometChatSearchProps {
196
+ /**
197
+ * Callback triggered when the back button is clicked
198
+ * Use this to handle navigation when user clicks the back button
199
+ */
200
+ onBack?: () => void;
201
+
202
+ /**
203
+ * Whether to hide the back button
204
+ */
205
+ hideBackButton?: boolean;
206
+
207
+ /**
208
+ * Callback triggered when a conversation is clicked in search results
209
+ * @param conversation - The conversation that was clicked
210
+ * @param searchKeyword - The keyword that was used in the search
211
+ */
212
+ onConversationClicked?: (conversation: CometChat.Conversation, searchKeyword?: string) => void;
213
+
214
+ /**
215
+ * Callback triggered when a message is clicked in search results
216
+ * @param message - The message that was clicked
217
+ * @param searchKeyword - The keyword that was used in the search
218
+ */
219
+ onMessageClicked?: (message: CometChat.BaseMessage, searchKeyword?: string) => void;
220
+
221
+ /**
222
+ * Array of search filters to display in the filter bar
223
+ */
224
+ searchFilters?: Array<CometChatSearchFilter>;
225
+
226
+ /**
227
+ * Filter that should be active by default when the component loads
228
+ */
229
+ initialSearchFilter?: CometChatSearchFilter;
230
+
231
+ /**
232
+ * Scopes to search in (Conversations, Messages, or both)
233
+ */
234
+ searchIn?: Array<CometChatSearchScope>;
235
+
236
+ /**
237
+ * Request builder for conversations search
238
+ */
239
+ conversationsRequestBuilder?: CometChat.ConversationsRequestBuilder;
240
+
241
+ /**
242
+ * Request builder for messages search
243
+ */
244
+ messagesRequestBuilder?: CometChat.MessagesRequestBuilder;
245
+
246
+ /**
247
+ * Custom error handler for search operations
248
+ */
249
+ onError?: (error: CometChat.CometChatException) => void;
250
+
251
+ /**
252
+ * User ID to search within specific user's messages
253
+ */
254
+ uid?: string;
255
+
256
+ /**
257
+ * Group ID to search within specific group's messages
258
+ */
259
+ guid?: string;
260
+
261
+ /**
262
+ * Search placeholder text
263
+ */
264
+ searchPlaceholder?: string;
265
+
266
+ /**
267
+ * Custom styles for the component
268
+ */
269
+ style?: DeepPartial<SearchStyle>;
270
+
271
+ /**
272
+ * Custom loading view component that will be shown during search operations
273
+ */
274
+ loadingView?: () => React.ReactElement;
275
+
276
+ /**
277
+ * Custom empty state view component that will be shown when no results are found
278
+ */
279
+ emptyView?: () => React.ReactElement;
280
+
281
+ /**
282
+ * Custom error state view component that will be shown when search fails
283
+ */
284
+ errorView?: () => React.ReactElement;
285
+
286
+ /**
287
+ * Custom view component for conversation items (both unread and group conversations)
288
+ * @param conversation - The conversation object to render
289
+ * @param searchKeyword - The search keyword used
290
+ */
291
+ conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
292
+
293
+ /**
294
+ * Custom view component for text message items
295
+ * @param message - The text message object to render
296
+ * @param searchKeyword - The search keyword used
297
+ */
298
+ textMessageItemView?: (message: CometChat.BaseMessage, searchKeyword?: string) => React.ReactElement;
299
+
300
+ /**
301
+ * Custom view component for image message items
302
+ * @param message - The image message object to render
303
+ * @param searchKeyword - The search keyword used
304
+ */
305
+ imageMessageItemView?: (message: CometChat.BaseMessage, searchKeyword?: string) => React.ReactElement;
306
+
307
+ /**
308
+ * Custom view component for audio message items
309
+ * @param message - The audio message object to render
310
+ * @param searchKeyword - The search keyword used
311
+ */
312
+ audioMessageItemView?: (message: CometChat.BaseMessage, searchKeyword?: string) => React.ReactElement;
313
+
314
+ /**
315
+ * Custom view component for video message items
316
+ * @param message - The video message object to render
317
+ * @param searchKeyword - The search keyword used
318
+ */
319
+ videoMessageItemView?: (message: CometChat.BaseMessage, searchKeyword?: string) => React.ReactElement;
320
+
321
+ /**
322
+ * Custom view component for document/file message items
323
+ * @param message - The document message object to render
324
+ * @param searchKeyword - The search keyword used
325
+ */
326
+ documentMessageItemView?: (message: CometChat.BaseMessage, searchKeyword?: string) => React.ReactElement;
327
+
328
+ /**
329
+ * Custom view component for link message items (text messages with link previews)
330
+ * @param message - The link message object to render
331
+ * @param searchKeyword - The search keyword used
332
+ */
333
+ linkMessageItemView?: (message: CometChat.BaseMessage, searchKeyword?: string) => React.ReactElement;
334
+ }
335
+ const t = getCometChatTranslation();
336
+
337
+ interface LinkPreviewImageProps {
338
+ uri: string;
339
+ mergedStyles: any;
340
+ theme: any;
341
+ }
342
+
343
+ const LinkPreviewImage: React.FC<LinkPreviewImageProps> = ({ uri, mergedStyles, theme }) => {
344
+ const [imageError, setImageError] = useState(false);
345
+
346
+ if (imageError) {
347
+ return (
348
+ <View style={mergedStyles.messageItemStyle?.iconContainerStyle}>
349
+ <Icon
350
+ name='link-fill'
351
+ size={48}
352
+ height={48}
353
+ width={48}
354
+ color={theme.color.iconSecondary}
355
+ />
356
+ </View>
357
+ );
358
+ }
359
+
360
+ return (
361
+ <View style={mergedStyles.messageItemStyle?.iconContainerStyle}>
362
+ <Image
363
+ source={{ uri }}
364
+ style={mergedStyles.messageItemStyle?.linkPreviewImageStyle}
365
+ resizeMode="cover"
366
+ onError={() => setImageError(true)}
367
+ />
368
+ </View>
369
+ );
370
+ };
371
+
372
+ /**
373
+ * CometChatSearch component for searching conversations and messages in CometChat
374
+ */
375
+ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
376
+ onBack = () => { },
377
+ hideBackButton = false,
378
+ onConversationClicked,
379
+ onMessageClicked,
380
+ searchFilters = [
381
+ CometChatSearchFilter.Unread,
382
+ CometChatSearchFilter.Groups,
383
+ CometChatSearchFilter.Photos,
384
+ CometChatSearchFilter.Videos,
385
+ CometChatSearchFilter.Links,
386
+ CometChatSearchFilter.Documents,
387
+ CometChatSearchFilter.Audio
388
+ ],
389
+ initialSearchFilter,
390
+ searchIn = [],
391
+ conversationsRequestBuilder,
392
+ messagesRequestBuilder,
393
+ onError,
394
+ uid,
395
+ guid,
396
+ searchPlaceholder = t("SEARCH_PLACEHOLDER") || "Search...",
397
+ style,
398
+ loadingView,
399
+ emptyView,
400
+ errorView,
401
+ conversationItemView,
402
+ textMessageItemView,
403
+ imageMessageItemView,
404
+ audioMessageItemView,
405
+ videoMessageItemView,
406
+ documentMessageItemView,
407
+ linkMessageItemView
408
+ }) => {
409
+ const [searchState, dispatch] = useReducer(searchStateReducer, initialState);
410
+ const [searchValue, setSearchValue] = useState("");
411
+ const [loggedInUser, setLoggedInUser] = useState<CometChat.User | null>(null);
412
+
413
+ const theme = useTheme();
414
+ const errorHandler = useCometChatErrorHandler(onError);
415
+ const timeoutIdRef = useRef<any | null>(null);
416
+ const searchInputRef = useRef<TextInput>(null);
417
+
418
+ // Merge theme styles with provided style overrides
419
+ const mergedStyles = useMemo(() => {
420
+ const baseStyles = getSearchStyleLight(theme.color, theme.spacing, theme.typography);
421
+ return deepMerge(baseStyles, style ?? {});
422
+ }, [theme, style]);
423
+
424
+ // Initialize active filters with initial filter if provided
425
+ useEffect(() => {
426
+ if (searchState.activeFilters.length === 0 && initialSearchFilter) {
427
+ dispatch({ type: "setActiveFilter", filterId: initialSearchFilter });
428
+ }
429
+ }, [initialSearchFilter, searchState.activeFilters.length]);
430
+
431
+ // Get logged in user
432
+ useEffect(() => {
433
+ const getLoggedInUser = async () => {
434
+ try {
435
+ const user = await CometChat.getLoggedinUser();
436
+ setLoggedInUser(user);
437
+ } catch (error) {
438
+ errorHandler(error as CometChat.CometChatException, "getLoggedInUser");
439
+ }
440
+ };
441
+
442
+ getLoggedInUser();
443
+ }, [errorHandler]);
444
+
445
+ // Handle search input changes with debouncing
446
+ const handleSearch = useCallback((text: string) => {
447
+ setSearchValue(text);
448
+ const newSearchText = text.trim();
449
+
450
+ if (timeoutIdRef.current) {
451
+ clearTimeout(timeoutIdRef.current);
452
+ }
453
+
454
+ timeoutIdRef.current = setTimeout(() => {
455
+ dispatch({ type: "setSearchText", searchText: newSearchText });
456
+ timeoutIdRef.current = null;
457
+ }, 500);
458
+ }, []);
459
+
460
+ // Clear search
461
+ const handleClearSearch = useCallback(() => {
462
+ setSearchValue("");
463
+ dispatch({ type: "setSearchText", searchText: "" });
464
+ dispatch({ type: "resetActiveFilters" });
465
+ dispatch({ type: "clearResults" });
466
+ }, []);
467
+
468
+ // Toggle filter
469
+ const toggleFilter = useCallback((filterId: CometChatSearchFilter) => {
470
+ dispatch({ type: "setActiveFilter", filterId });
471
+ }, []);
472
+
473
+ // Auto-focus the search input when component mounts
474
+ useEffect(() => {
475
+ const timer = setTimeout(() => {
476
+ if (searchInputRef.current) {
477
+ searchInputRef.current.focus();
478
+ }
479
+ }, 100);
480
+ return () => clearTimeout(timer);
481
+ }, []);
482
+
483
+ // Cleanup timeout on unmount
484
+ useEffect(() => {
485
+ return () => {
486
+ if (timeoutIdRef.current) {
487
+ clearTimeout(timeoutIdRef.current);
488
+ }
489
+ };
490
+ }, []);
491
+
492
+ const renderHeader = () => (
493
+ <View style={[mergedStyles.headerStyle]}>
494
+ {!hideBackButton && (
495
+ <TouchableOpacity
496
+ style={[mergedStyles.backButtonStyle]}
497
+ onPress={onBack}
498
+ >
499
+ <Icon
500
+ name='arrow-back'
501
+ imageStyle={mergedStyles.backButtonIconStyle}
502
+ color={mergedStyles?.backButtonIconStyle?.tintColor}
503
+ />
504
+ </TouchableOpacity>
505
+ )}
506
+ <View style={[mergedStyles.searchContainerStyle]}>
507
+ <View style={[mergedStyles.searchInputContainerStyle]}>
508
+ <TextInput
509
+ ref={searchInputRef}
510
+ style={[mergedStyles.searchInputStyle]}
511
+ value={searchValue}
512
+ onChangeText={handleSearch}
513
+ placeholder={searchPlaceholder}
514
+ placeholderTextColor={theme.color.textTertiary}
515
+ />
516
+
517
+ <TouchableOpacity
518
+ style={[mergedStyles.clearButtonStyle]}
519
+ onPress={handleClearSearch}
520
+ accessibilityLabel="Clear search"
521
+ >
522
+ <Icon
523
+ name='close'
524
+ imageStyle={mergedStyles.clearButtonIconStyle}
525
+ />
526
+ </TouchableOpacity>
527
+ </View>
528
+ </View>
529
+ </View>
530
+ );
531
+
532
+ const getVisibleFilters = useCallback(() => {
533
+ const conversationFilters = [
534
+ CometChatSearchFilter.Conversations,
535
+ CometChatSearchFilter.Unread,
536
+ CometChatSearchFilter.Groups
537
+ ];
538
+
539
+ const messageFilters = [
540
+ CometChatSearchFilter.Messages,
541
+ CometChatSearchFilter.Photos,
542
+ CometChatSearchFilter.Videos,
543
+ CometChatSearchFilter.Documents,
544
+ CometChatSearchFilter.Audio,
545
+ CometChatSearchFilter.Links
546
+ ];
547
+
548
+ // Define filter pairs
549
+ const filterPairs = {
550
+ conversationPair: [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups],
551
+ photosVideosPair: [CometChatSearchFilter.Photos, CometChatSearchFilter.Videos],
552
+ audioDocumentsPair: [CometChatSearchFilter.Audio, CometChatSearchFilter.Documents],
553
+ linkStandalone: [CometChatSearchFilter.Links]
554
+ };
555
+
556
+ // If searchIn is empty, search in both conversations and messages
557
+ const effectiveSearchIn = searchIn.length === 0
558
+ ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
559
+ : searchIn;
560
+
561
+ let availableFilters: CometChatSearchFilter[] = [];
562
+
563
+ // Add filters based on searchIn scope
564
+ if (effectiveSearchIn.includes(CometChatSearchScope.Conversations)) {
565
+ availableFilters.push(...conversationFilters);
566
+ }
567
+ if (effectiveSearchIn.includes(CometChatSearchScope.Messages)) {
568
+ availableFilters.push(...messageFilters);
569
+ }
570
+
571
+ // Filter the searchFilters prop to only include available filters
572
+ let filteredAvailableFilters = searchFilters.filter(filter => availableFilters.includes(filter));
573
+
574
+ // Filter out conversation filters if uid or guid is present
575
+ if (uid || guid) {
576
+ filteredAvailableFilters = filteredAvailableFilters.filter(filter => !conversationFilters.includes(filter));
577
+ }
578
+
579
+ // If no filters are selected, return filtered available filters
580
+ if (searchState.activeFilters.length === 0) {
581
+ return filteredAvailableFilters;
582
+ }
583
+
584
+ // Handle pairing logic
585
+ const activeFilters = searchState.activeFilters;
586
+
587
+ // Check which pair is active
588
+ const hasConversationPair = activeFilters.some(filter => filterPairs.conversationPair.includes(filter));
589
+ const hasPhotosVideosPair = activeFilters.some(filter => filterPairs.photosVideosPair.includes(filter));
590
+ const hasAudioDocumentsPair = activeFilters.some(filter => filterPairs.audioDocumentsPair.includes(filter));
591
+ const hasLinkStandalone = activeFilters.includes(CometChatSearchFilter.Links);
592
+
593
+ // If conversation pair is active, show only conversation filters
594
+ if (hasConversationPair && effectiveSearchIn.includes(CometChatSearchScope.Conversations) && !uid && !guid) {
595
+ return filterPairs.conversationPair.filter(filter => filteredAvailableFilters.includes(filter));
596
+ }
597
+
598
+ // If photos/videos pair is active, show only photos and videos
599
+ if (hasPhotosVideosPair) {
600
+ return filterPairs.photosVideosPair.filter(filter => filteredAvailableFilters.includes(filter));
601
+ }
602
+
603
+ // If audio/documents pair is active, show only audio and documents
604
+ if (hasAudioDocumentsPair) {
605
+ return filterPairs.audioDocumentsPair.filter(filter => filteredAvailableFilters.includes(filter));
606
+ }
607
+
608
+ // If links is active (standalone), show only links
609
+ if (hasLinkStandalone) {
610
+ return filterPairs.linkStandalone.filter(filter => filteredAvailableFilters.includes(filter));
611
+ }
612
+
613
+ // Fallback: return filtered available filters
614
+ return filteredAvailableFilters;
615
+ }, [searchState.activeFilters, searchFilters, searchIn, uid, guid]);
616
+
617
+ const getFilterText = (filterId: CometChatSearchFilter): string => {
618
+ const filterTextMap = {
619
+ [CometChatSearchFilter.Audio]: t("SEARCH_FILTER_AUDIO") || "Audio",
620
+ [CometChatSearchFilter.Conversations]: t("SEARCH_FILTER_CONVERSATIONS") || "Conversations",
621
+ [CometChatSearchFilter.Documents]: t("SEARCH_FILTER_DOCUMENTS") || "Documents",
622
+ [CometChatSearchFilter.Groups]: t("SEARCH_FILTER_GROUPS") || "Groups",
623
+ [CometChatSearchFilter.Links]: t("SEARCH_FILTER_LINKS") || "Links",
624
+ [CometChatSearchFilter.Messages]: t("SEARCH_FILTER_MESSAGES") || "Messages",
625
+ [CometChatSearchFilter.Photos]: t("SEARCH_FILTER_PHOTOS") || "Photos",
626
+ [CometChatSearchFilter.Unread]: t("SEARCH_FILTER_UNREAD") || "Unread",
627
+ [CometChatSearchFilter.Videos]: t("SEARCH_FILTER_VIDEOS") || "Videos",
628
+ };
629
+ return filterTextMap[filterId] || "";
630
+ };
631
+
632
+ const getFilterIcon = (filterId: CometChatSearchFilter) => {
633
+ const filterIconMap = {
634
+ [CometChatSearchFilter.Audio]: "mic-fill" as const,
635
+ [CometChatSearchFilter.Documents]: "documents" as const,
636
+ [CometChatSearchFilter.Groups]: "group" as const,
637
+ [CometChatSearchFilter.Links]: "link" as const,
638
+ [CometChatSearchFilter.Messages]: "chat" as const,
639
+ [CometChatSearchFilter.Photos]: "photo" as const,
640
+ [CometChatSearchFilter.Unread]: "unread" as const,
641
+ [CometChatSearchFilter.Videos]: "videocam" as const,
642
+ [CometChatSearchFilter.Conversations]: "chat" as const,
643
+ };
644
+ return filterIconMap[filterId];
645
+ };
646
+
647
+ const renderFilters = () => {
648
+ const visibleFilters = getVisibleFilters();
649
+
650
+ if (visibleFilters.length === 0) {
651
+ return null;
652
+ }
653
+
654
+ return (
655
+ <View style={[mergedStyles.filtersContainerStyle]}>
656
+ <View style={mergedStyles.filtersContentStyle}>
657
+ {visibleFilters.map((filterId) => {
658
+ const isActive = searchState.activeFilters.includes(filterId);
659
+ const iconName = getFilterIcon(filterId);
660
+ return (
661
+ <TouchableOpacity
662
+ key={filterId}
663
+ style={[
664
+ mergedStyles.filterButtonStyle,
665
+ isActive && mergedStyles.filterButtonActiveStyle
666
+ ]}
667
+ onPress={() => toggleFilter(filterId)}
668
+ >
669
+ <View style={mergedStyles.filterButtonContentStyle}>
670
+ {iconName && (
671
+ <Icon
672
+ name={iconName}
673
+ imageStyle={[
674
+ mergedStyles.filterButtonIconStyle,
675
+ isActive && mergedStyles.filterButtonIconActiveStyle
676
+ ]}
677
+ width={16}
678
+ height={16}
679
+ />
680
+ )}
681
+ <Text style={[
682
+ mergedStyles.filterButtonTextStyle,
683
+ isActive && mergedStyles.filterButtonTextActiveStyle
684
+ ]}>
685
+ {getFilterText(filterId)}
686
+ </Text>
687
+ </View>
688
+ </TouchableOpacity>
689
+ );
690
+ })}
691
+ </View>
692
+ </View>
693
+ );
694
+ };
695
+
696
+ // ============================================================================
697
+ // CONVERSATIONS SEARCH LOGIC (moved from useCometChatSearchConversationsList.ts)
698
+ // ============================================================================
699
+ const [conversationState, setConversationState] = useState({
700
+ conversationList: [] as CometChat.Conversation[],
701
+ fetchState: States.loaded,
702
+ hasMoreResults: false,
703
+ });
704
+
705
+ const conversationRequestRef = useRef<CometChat.ConversationsRequest | null>(null);
706
+ const lastConversationSearchKeyword = useRef<string>(searchState.searchText);
707
+ const lastConversationActiveFilters = useRef<CometChatSearchFilter[]>(searchState.activeFilters);
708
+ const isConversationMoreResultsLoading = useRef<boolean>(false);
709
+
710
+ // ============================================================================
711
+ // MESSAGES SEARCH LOGIC (moved from useCometChatSearchMessagesList.ts)
712
+ // ============================================================================
713
+ const [messageState, setMessageState] = useState({
714
+ messageList: [] as CometChat.BaseMessage[],
715
+ fetchState: States.loaded,
716
+ hasMoreResults: false,
717
+ });
718
+
719
+ const messageRequestRef = useRef<CometChat.MessagesRequest | null>(null);
720
+ const lastMessageSearchKeyword = useRef<string>(searchState.searchText);
721
+ const lastMessageActiveFilters = useRef<CometChatSearchFilter[]>(searchState.activeFilters);
722
+ const isMessageMoreResultsLoading = useRef<boolean>(false);
723
+
724
+ // ============================================================================
725
+ // CONVERSATION SEARCH FUNCTIONS
726
+ // ============================================================================
727
+ const buildConversationsRequest = useCallback(() => {
728
+ let builder = conversationsRequestBuilder
729
+ ? Object.assign(Object.create(Object.getPrototypeOf(conversationsRequestBuilder)), conversationsRequestBuilder)
730
+ : new CometChat.ConversationsRequestBuilder();
731
+
732
+ if (searchState.searchText && searchState.searchText.trim() !== "") {
733
+ builder = builder.setSearchKeyword(searchState.searchText);
734
+ }
735
+
736
+ const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
737
+ builder = builder.setLimit(limit);
738
+
739
+ // Apply filters - both can be active simultaneously for unread group conversations
740
+ if (searchState.activeFilters.includes(CometChatSearchFilter.Unread)) {
741
+ builder = builder.setUnread(true);
742
+ }
743
+
744
+ if (searchState.activeFilters.includes(CometChatSearchFilter.Groups)) {
745
+ builder = builder.setConversationType(ReceiverTypeConstants.group);
746
+ }
747
+
748
+ return builder.build();
749
+ }, [conversationsRequestBuilder, searchState.searchText, searchState.activeFilters, guid, uid]);
750
+
751
+ const loadMoreConversations = useCallback(async () => {
752
+ if (isConversationMoreResultsLoading.current || !conversationRequestRef.current || !conversationState.hasMoreResults) {
753
+ return;
754
+ }
755
+
756
+ try {
757
+ isConversationMoreResultsLoading.current = true;
758
+ const moreConversations = await conversationRequestRef.current.fetchNext();
759
+
760
+ if (moreConversations.length > 0) {
761
+ setConversationState(prev => ({
762
+ ...prev,
763
+ conversationList: [...prev.conversationList, ...moreConversations],
764
+ hasMoreResults: moreConversations.length === 3 || moreConversations.length === 30 // Check if more results might be available
765
+ }));
766
+ } else {
767
+ setConversationState(prev => ({
768
+ ...prev,
769
+ hasMoreResults: false
770
+ }));
771
+ }
772
+ } catch (error) {
773
+ errorHandler(error, "loadMoreConversations");
774
+ } finally {
775
+ isConversationMoreResultsLoading.current = false;
776
+ }
777
+ }, [errorHandler, conversationState.hasMoreResults]);
778
+
779
+ const searchConversations = useCallback(async () => {
780
+ try {
781
+ setConversationState(prev => ({ ...prev, fetchState: States.loading }));
782
+
783
+ if (!hasValidConversationSearchCriteria(searchState.searchText, searchState.activeFilters)) {
784
+ setConversationState(prev => ({
785
+ ...prev,
786
+ conversationList: [],
787
+ fetchState: States.loaded,
788
+ hasMoreResults: false
789
+ }));
790
+ return;
791
+ }
792
+
793
+ conversationRequestRef.current = buildConversationsRequest();
794
+ const conversations = await conversationRequestRef.current!.fetchNext();
795
+
796
+ if (conversations.length > 0) {
797
+ const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
798
+ setConversationState({
799
+ conversationList: conversations,
800
+ fetchState: States.loaded,
801
+ hasMoreResults: conversations.length >= limit,
802
+ });
803
+ } else {
804
+ setConversationState({
805
+ conversationList: [],
806
+ fetchState: States.loaded,
807
+ hasMoreResults: false,
808
+ });
809
+ }
810
+ } catch (error) {
811
+ errorHandler(error, "searchConversations");
812
+ setConversationState(prev => ({ ...prev, fetchState: States.error }));
813
+ }
814
+ }, [searchState.searchText, searchState.activeFilters, buildConversationsRequest, guid, uid, errorHandler]);
815
+
816
+ // ============================================================================
817
+ // MESSAGE SEARCH FUNCTIONS
818
+ // ============================================================================
819
+ const buildMessagesRequest = useCallback(() => {
820
+ let builder = messagesRequestBuilder
821
+ ? Object.assign(Object.create(Object.getPrototypeOf(messagesRequestBuilder)), messagesRequestBuilder)
822
+ : new CometChat.MessagesRequestBuilder();
823
+
824
+ builder = builder.hideDeletedMessages(true);
825
+ const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
826
+
827
+ if (!messagesRequestBuilder) {
828
+ builder = builder
829
+ .setCategories([MessageCategoryConstants.message, MessageCategoryConstants.custom])
830
+ .setTypes([MessageTypeConstants.text, MessageTypeConstants.image, MessageTypeConstants.video, MessageTypeConstants.audio, MessageTypeConstants.file])
831
+ .setLimit(limit);
832
+ }
833
+
834
+ if (searchState.searchText && searchState.searchText.trim() !== "") {
835
+ builder = builder.setSearchKeyword(searchState.searchText);
836
+ }
837
+
838
+ if (uid) {
839
+ builder = builder.setUID(uid);
840
+ } else if (guid) {
841
+ builder = builder.setGUID(guid);
842
+ }
843
+
844
+ if (searchState.activeFilters && searchState.activeFilters.length > 0) {
845
+ if (searchState.activeFilters.includes(CometChatSearchFilter.Links)) {
846
+ builder = builder.hasLinks(true);
847
+ }
848
+
849
+ const attachmentTypeMap = {
850
+ [CometChatSearchFilter.Photos]: CometChat.AttachmentType.IMAGE,
851
+ [CometChatSearchFilter.Videos]: CometChat.AttachmentType.VIDEO,
852
+ [CometChatSearchFilter.Documents]: CometChat.AttachmentType.FILE,
853
+ [CometChatSearchFilter.Audio]: CometChat.AttachmentType.AUDIO,
854
+ };
855
+
856
+ // Collect all attachment types for active filters
857
+ const activeAttachmentTypes: CometChat.AttachmentType[] = [];
858
+ for (const [filter, attachmentType] of Object.entries(attachmentTypeMap)) {
859
+ if (searchState.activeFilters.includes(filter as CometChatSearchFilter)) {
860
+ activeAttachmentTypes.push(attachmentType);
861
+ }
862
+ }
863
+
864
+ // Set all active attachment types (supports multiple types for paired filters)
865
+ if (activeAttachmentTypes.length > 0) {
866
+ builder = builder.setAttachmentTypes(activeAttachmentTypes);
867
+ }
868
+ }
869
+
870
+ return builder.build();
871
+ }, [messagesRequestBuilder, searchState.activeFilters, searchState.searchText, uid, guid]);
872
+
873
+ const loadMoreMessages = useCallback(async () => {
874
+ if (isMessageMoreResultsLoading.current || !messageRequestRef.current || !messageState.hasMoreResults) {
875
+ return;
876
+ }
877
+
878
+ try {
879
+ isMessageMoreResultsLoading.current = true;
880
+ const moreMessages = await messageRequestRef.current.fetchPrevious();
881
+
882
+ if (moreMessages.length > 0) {
883
+
884
+ const filteredMoreMessages = moreMessages.filter(msg => {
885
+ const isDeleted = (msg as any).getDeletedAt && (msg as any).getDeletedAt() > 0;
886
+ const isActionMessage = msg.getCategory() === MessageCategoryConstants.action;
887
+ return !isDeleted && !isActionMessage;
888
+ });
889
+
890
+ setMessageState(prev => ({
891
+ ...prev,
892
+ messageList: [...prev.messageList, ...filteredMoreMessages],
893
+ hasMoreResults: moreMessages.length === 3 || moreMessages.length === 30 // Check if more results might be available
894
+ }));
895
+ } else {
896
+ setMessageState(prev => ({
897
+ ...prev,
898
+ hasMoreResults: false
899
+ }));
900
+ }
901
+ } catch (error) {
902
+ errorHandler(error, "loadMoreMessages");
903
+ } finally {
904
+ isMessageMoreResultsLoading.current = false;
905
+ }
906
+ }, [errorHandler, messageState.hasMoreResults]);
907
+
908
+ const searchMessages = useCallback(async () => {
909
+ try {
910
+ setMessageState(prev => ({ ...prev, fetchState: States.loading }));
911
+
912
+ if (!hasValidMessageSearchCriteria(searchState.searchText, searchState.activeFilters)) {
913
+ setMessageState(prev => ({
914
+ ...prev,
915
+ messageList: [],
916
+ fetchState: States.loaded,
917
+ hasMoreResults: false
918
+ }));
919
+ return;
920
+ }
921
+
922
+ messageRequestRef.current = buildMessagesRequest();
923
+ const messages = await messageRequestRef.current!.fetchPrevious();
924
+
925
+ if (messages.length > 0) {
926
+ const reversedList = messages.reverse();
927
+
928
+ const filteredMessages = reversedList.filter(msg => {
929
+ const isDeleted = (msg as any).getDeletedAt && (msg as any).getDeletedAt() > 0;
930
+ const isActionMessage = msg.getCategory() === MessageCategoryConstants.action;
931
+ return !isDeleted && !isActionMessage;
932
+ });
933
+
934
+ const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
935
+ setMessageState({
936
+ messageList: filteredMessages,
937
+ fetchState: States.loaded,
938
+ hasMoreResults: messages.length >= limit,
939
+ });
940
+ } else {
941
+ setMessageState({
942
+ messageList: [],
943
+ fetchState: States.loaded,
944
+ hasMoreResults: false,
945
+ });
946
+ }
947
+ } catch (error) {
948
+ errorHandler(error, "searchMessages");
949
+ setMessageState(prev => ({ ...prev, fetchState: States.error }));
950
+ }
951
+ }, [searchState.searchText, searchState.activeFilters, buildMessagesRequest, guid, uid, errorHandler]);
952
+
953
+ // ============================================================================
954
+ // SEARCH EFFECTS - Trigger searches when search text or filters change
955
+ // ============================================================================
956
+ useEffect(() => {
957
+ const hasKeywordChanged = searchState.searchText !== lastConversationSearchKeyword.current;
958
+ const haveFiltersChanged = JSON.stringify(searchState.activeFilters) !== JSON.stringify(lastConversationActiveFilters.current);
959
+
960
+ if (hasKeywordChanged || haveFiltersChanged) {
961
+ lastConversationSearchKeyword.current = searchState.searchText;
962
+ lastConversationActiveFilters.current = [...searchState.activeFilters];
963
+ searchConversations();
964
+ }
965
+ }, [searchState.searchText, searchState.activeFilters, searchConversations]);
966
+
967
+ useEffect(() => {
968
+ const hasKeywordChanged = searchState.searchText !== lastMessageSearchKeyword.current;
969
+ const haveFiltersChanged = JSON.stringify(searchState.activeFilters) !== JSON.stringify(lastMessageActiveFilters.current);
970
+
971
+ if (hasKeywordChanged || haveFiltersChanged) {
972
+ lastMessageSearchKeyword.current = searchState.searchText;
973
+ lastMessageActiveFilters.current = [...searchState.activeFilters];
974
+ searchMessages();
975
+ }
976
+ }, [searchState.searchText, searchState.activeFilters, searchMessages]);
977
+
978
+ const shouldRenderConversations = useCallback(() => {
979
+ // If searchIn is empty, search in both conversations and messages
980
+ const effectiveSearchIn = searchIn.length === 0
981
+ ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
982
+ : searchIn;
983
+
984
+ // Don't render conversations if searchIn doesn't include conversations scope
985
+ if (!effectiveSearchIn.includes(CometChatSearchScope.Conversations)) {
986
+ return false;
987
+ }
988
+
989
+ // Don't render conversations if uid or guid is present (searching within specific user/group)
990
+ if (uid || guid) {
991
+ return false;
992
+ }
993
+
994
+ // Define conversation filters
995
+ const conversationFilters = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
996
+
997
+ if (searchState.searchText && searchState.searchText.trim() !== "" && searchState.activeFilters.length === 0) {
998
+ return true;
999
+ }
1000
+
1001
+ if (searchState.activeFilters.length > 0) {
1002
+ return searchState.activeFilters.some(filter => conversationFilters.includes(filter));
1003
+ }
1004
+
1005
+ return false;
1006
+ }, [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]);
1007
+
1008
+ const shouldRenderMessages = useCallback(() => {
1009
+ // If searchIn is empty, search in both conversations and messages
1010
+ const effectiveSearchIn = searchIn.length === 0
1011
+ ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
1012
+ : searchIn;
1013
+
1014
+ // Don't render messages if searchIn doesn't include messages scope
1015
+ if (!effectiveSearchIn.includes(CometChatSearchScope.Messages)) {
1016
+ return false;
1017
+ }
1018
+
1019
+ // Always render messages if uid or guid is present (searching within specific user/group)
1020
+ if (uid || guid) {
1021
+ return true;
1022
+ }
1023
+
1024
+ // Define message filters
1025
+ const messageFilters = [
1026
+ CometChatSearchFilter.Photos,
1027
+ CometChatSearchFilter.Videos,
1028
+ CometChatSearchFilter.Documents,
1029
+ CometChatSearchFilter.Audio,
1030
+ CometChatSearchFilter.Links
1031
+ ];
1032
+
1033
+ // Define conversation filters
1034
+ const conversationFilters = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
1035
+
1036
+ if (searchState.searchText && searchState.searchText.trim() !== "" && searchState.activeFilters.length === 0) {
1037
+ return true;
1038
+ }
1039
+
1040
+ if (searchState.activeFilters.length > 0) {
1041
+ // Show messages if any message filter is selected and no conversation filter is selected
1042
+ return searchState.activeFilters.some(filter => messageFilters.includes(filter)) &&
1043
+ !searchState.activeFilters.some(filter => conversationFilters.includes(filter));
1044
+ }
1045
+
1046
+ return false;
1047
+ }, [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]);
1048
+
1049
+ // Handle scroll-based fetching for messages
1050
+ const handleScrollEnd = useCallback((event: any) => {
1051
+ if (!shouldRenderMessages() || !messageState.hasMoreResults) return;
1052
+
1053
+ const contentOffsetY = event.nativeEvent.contentOffset.y;
1054
+ const contentHeight = event.nativeEvent.contentSize.height;
1055
+ const layoutHeight = event.nativeEvent.layoutMeasurement.height;
1056
+
1057
+ if (contentOffsetY + layoutHeight >= contentHeight - 10) {
1058
+ loadMoreMessages();
1059
+ }
1060
+ }, [shouldRenderMessages, messageState.hasMoreResults, loadMoreMessages]);
1061
+
1062
+ // Get status indicator for conversation
1063
+ const getStatusIndicator = (conv: CometChat.Conversation) => {
1064
+ const withObj = conv.getConversationWith();
1065
+
1066
+ if (withObj instanceof CometChat.Group) {
1067
+ if (withObj.getType() === GroupTypeConstants.password) return "password";
1068
+ if (withObj.getType() === GroupTypeConstants.private) return "private";
1069
+ } else if (withObj instanceof CometChat.User) {
1070
+ if (withObj.getStatus() === 'online' && !withObj.getHasBlockedMe() && !withObj.getBlockedByMe()) {
1071
+ return "online";
1072
+ }
1073
+ return "offline";
1074
+ }
1075
+ return undefined;
1076
+ };
1077
+
1078
+ // Render conversation avatar
1079
+ const renderConversationLeadingView = (conversation: CometChat.Conversation) => {
1080
+ const withObj = conversation.getConversationWith();
1081
+ const avatarURL = withObj instanceof CometChat.User ? withObj.getAvatar() : withObj.getIcon();
1082
+ const name = withObj.getName();
1083
+
1084
+ return (
1085
+ <View style={{ position: 'relative' }}>
1086
+ <View style={{ height: 48, width: 48 }}>
1087
+ <CometChatAvatar
1088
+ image={{ uri: avatarURL }}
1089
+ name={name}
1090
+ />
1091
+ <View style={{
1092
+ position: 'absolute',
1093
+ bottom: 0,
1094
+ right: 0,
1095
+ }}>
1096
+ <CometChatStatusIndicator
1097
+ type={getStatusIndicator(conversation)}
1098
+ />
1099
+ </View>
1100
+ </View>
1101
+ </View>
1102
+ );
1103
+ };
1104
+
1105
+ // Render conversation trailing view (date and badge)
1106
+ const renderConversationTrailingView = (conversation: CometChat.Conversation) => {
1107
+ const timestamp = conversation.getLastMessage()?.getSentAt();
1108
+ if (!timestamp) return null;
1109
+
1110
+ return (
1111
+ <View style={mergedStyles.conversationItemStyle?.trailingContainerStyle}>
1112
+ <CometChatDate
1113
+ timeStamp={timestamp * 1000}
1114
+ pattern={"conversationDate"}
1115
+ />
1116
+ <CometChatBadge
1117
+ count={conversation.getUnreadMessageCount()}
1118
+ />
1119
+ </View>
1120
+ );
1121
+ };
1122
+
1123
+ // Get file type icon based on file extension
1124
+ const getFileTypeIcon = (fileName: string): 'audio-file-type' | 'image-file-type' | 'video-file-type' | 'pdf-file-type' | 'presentation-file-type' | 'spreadsheet-file-type' | 'text-file-type' | 'zip-file-type' | 'document-file-type' | 'unknown-file-type' => {
1125
+ if (!fileName) return 'unknown-file-type';
1126
+
1127
+ const extension = fileName.toLowerCase().split('.').pop() || '';
1128
+
1129
+ // Audio files
1130
+ if (['mp3', 'wav', 'ogg', 'aac', 'm4a', 'flac'].includes(extension)) {
1131
+ return 'audio-file-type';
1132
+ }
1133
+
1134
+ // Image files
1135
+ if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'].includes(extension)) {
1136
+ return 'image-file-type';
1137
+ }
1138
+
1139
+ // Video files
1140
+ if (['mp4', 'avi', 'mov', 'wmv', 'flv', 'webm', 'mkv'].includes(extension)) {
1141
+ return 'video-file-type';
1142
+ }
1143
+
1144
+ // PDF files
1145
+ if (extension === 'pdf') {
1146
+ return 'pdf-file-type';
1147
+ }
1148
+
1149
+ // Presentation files
1150
+ if (['ppt', 'pptx', 'key'].includes(extension)) {
1151
+ return 'presentation-file-type';
1152
+ }
1153
+
1154
+ // Spreadsheet files
1155
+ if (['xls', 'xlsx', 'csv', 'numbers'].includes(extension)) {
1156
+ return 'spreadsheet-file-type';
1157
+ }
1158
+
1159
+ // Text/Document files
1160
+ if (['txt', 'rtf', 'doc', 'docx', 'pages'].includes(extension)) {
1161
+ return 'text-file-type';
1162
+ }
1163
+
1164
+ // ZIP/Archive files
1165
+ if (['zip', 'rar', '7z', 'tar', 'gz'].includes(extension)) {
1166
+ return 'zip-file-type';
1167
+ }
1168
+
1169
+ // Default document type for other files
1170
+ return 'document-file-type';
1171
+ };
1172
+
1173
+ // Format mentions in raw message text: convert <@all:alias> to @alias
1174
+ // and <@uid:UID> to @Name when message provides mentioned users
1175
+ const formatMentionsInText = (rawText: any, message?: CometChat.BaseMessage) => {
1176
+ if (typeof rawText !== 'string') return rawText;
1177
+
1178
+ let text = rawText.replace(/<@all:(.*?)>/g, '@$1');
1179
+
1180
+ try {
1181
+ const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
1182
+ if (mentionedUsers && mentionedUsers.length > 0) {
1183
+ mentionedUsers.forEach((u: CometChat.User) => {
1184
+ const uid = u.getUid();
1185
+ const name = u.getName();
1186
+ if (uid && name) {
1187
+ const uidRegex = new RegExp(`<@uid:${uid}>`, 'g');
1188
+ text = text.replace(uidRegex, `@${name}`);
1189
+ }
1190
+ });
1191
+ }
1192
+ } catch (e) {
1193
+ console.log(e)
1194
+ }
1195
+
1196
+ return text;
1197
+ };
1198
+
1199
+ // Render message leading view (for audio/file icons)
1200
+ const renderMessageLeadingView = (message: CometChat.BaseMessage) => {
1201
+ const messageType = message.getType();
1202
+
1203
+ switch (messageType) {
1204
+ case 'audio': {
1205
+ return (
1206
+ <View style={mergedStyles.messageItemStyle?.iconContainerStyle}>
1207
+ <View style={[mergedStyles.messageItemStyle?.audioPreviewStyle, {
1208
+ backgroundColor: theme.color.primary,
1209
+ borderRadius: 1000,
1210
+ justifyContent: 'center',
1211
+ alignItems: 'center',
1212
+ height: 32,
1213
+ width: 32,
1214
+ }]}>
1215
+ <Icon
1216
+ name='play-arrow-fill'
1217
+ size={theme.spacing.spacing.s7}
1218
+ height={32}
1219
+ width={32}
1220
+ color={theme.color.staticWhite}
1221
+ />
1222
+ </View>
1223
+ </View>
1224
+ );
1225
+ }
1226
+
1227
+ case 'file': {
1228
+ const fileMessage = message as CometChat.MediaMessage;
1229
+ const attachment = fileMessage.getAttachment();
1230
+ const fileName = attachment?.getName?.() || '';
1231
+ const fileTypeIcon = getFileTypeIcon(fileName);
1232
+
1233
+ return (
1234
+ <View style={mergedStyles.messageItemStyle?.iconContainerStyle}>
1235
+ <Icon
1236
+ name={fileTypeIcon}
1237
+ size={48}
1238
+ height={48}
1239
+ width={48}
1240
+ color={theme.color.iconSecondary}
1241
+ />
1242
+ </View>
1243
+ );
1244
+ }
1245
+
1246
+ case 'text': {
1247
+ // Check if this is a text message with link metadata (link preview)
1248
+ const textMessage = message as CometChat.TextMessage;
1249
+ const metadata = textMessage.getMetadata();
1250
+ const linkPreview = metadata && (metadata as any)['@injected'] && (metadata as any)['@injected']['extensions'] && (metadata as any)['@injected']['extensions']['link-preview'];
1251
+
1252
+ if (linkPreview && linkPreview.links && linkPreview.links.length > 0) {
1253
+ const firstLink = linkPreview.links[0];
1254
+ const thumbnailUrl = firstLink.image || firstLink.favicon;
1255
+
1256
+ if (thumbnailUrl) {
1257
+ return (
1258
+ <LinkPreviewImage
1259
+ uri={thumbnailUrl}
1260
+ mergedStyles={mergedStyles}
1261
+ theme={theme}
1262
+ />
1263
+ );
1264
+ } else {
1265
+ // Fallback to link icon if no thumbnail
1266
+ return (
1267
+ <View style={mergedStyles.messageItemStyle?.iconContainerStyle}>
1268
+ <Icon
1269
+ name='link-fill'
1270
+ size={48}
1271
+ height={48}
1272
+ width={48}
1273
+ color={theme.color.iconSecondary}
1274
+ />
1275
+ </View>
1276
+ );
1277
+ }
1278
+ }
1279
+ return null;
1280
+ }
1281
+
1282
+ default:
1283
+ return null;
1284
+ }
1285
+ };
1286
+
1287
+ // Render message trailing view (content preview or date)
1288
+ const renderMessageTrailingView = (message: CometChat.BaseMessage) => {
1289
+ const timestamp = message.getSentAt();
1290
+ if (!timestamp) return null;
1291
+
1292
+ const messageType = message.getType();
1293
+
1294
+ // Handle different message types
1295
+ switch (messageType) {
1296
+ case 'image': {
1297
+ const imageMessage = message as CometChat.MediaMessage;
1298
+ const attachment = imageMessage.getAttachment();
1299
+ const imageUrl = attachment && (attachment as any).url;
1300
+ if (imageUrl) {
1301
+ return (
1302
+ <View style={mergedStyles.messageItemStyle?.previewContainerStyle}>
1303
+ <Image
1304
+ source={{ uri: imageUrl }}
1305
+ style={mergedStyles.messageItemStyle?.previewImageStyle}
1306
+ resizeMode="cover"
1307
+ />
1308
+ </View>
1309
+ );
1310
+ }
1311
+ break;
1312
+ }
1313
+
1314
+ case 'video': {
1315
+ const videoMessage = message as CometChat.MediaMessage;
1316
+ const attachment = videoMessage.getAttachment();
1317
+ const thumbnailUrl = attachment && ((attachment as any).thumbnail || (attachment as any).url);
1318
+ if (thumbnailUrl) {
1319
+ return (
1320
+ <View style={mergedStyles.messageItemStyle?.previewContainerStyle}>
1321
+ <Video
1322
+ source={{ uri: thumbnailUrl }}
1323
+ style={mergedStyles.messageItemStyle?.previewVideoStyle}
1324
+ resizeMode="cover"
1325
+ />
1326
+ <View style={mergedStyles.messageItemStyle?.videoPlayIconStyle}>
1327
+ <Icon
1328
+ name='play-arrow'
1329
+ size={16}
1330
+ height={16}
1331
+ width={16}
1332
+ color="white"
1333
+ />
1334
+ </View>
1335
+ </View>
1336
+ );
1337
+ }
1338
+ break;
1339
+ }
1340
+
1341
+
1342
+
1343
+ default:
1344
+ // For text messages and other types, show timestamp
1345
+ return (
1346
+ <View style={mergedStyles.messageItemStyle?.trailingContainerStyle}>
1347
+ <CometChatDate
1348
+ timeStamp={timestamp * 1000}
1349
+ pattern={"dayDateFormat"}
1350
+ />
1351
+ </View>
1352
+ );
1353
+ }
1354
+
1355
+ // Fallback to timestamp
1356
+ return (
1357
+ <View style={mergedStyles.messageItemStyle?.trailingContainerStyle}>
1358
+ <CometChatDate
1359
+ timeStamp={timestamp * 1000}
1360
+ pattern={"dayDateFormat"}
1361
+ />
1362
+ </View>
1363
+ );
1364
+ };
1365
+
1366
+ // Render conversations section
1367
+ const renderConversationsSection = () => {
1368
+ const { conversationList, fetchState } = conversationState;
1369
+
1370
+ if (fetchState === States.loading && conversationList.length === 0) {
1371
+ return loadingView ? loadingView() : <Skeleton />;
1372
+ }
1373
+
1374
+ if (fetchState === States.empty || conversationList.length === 0) {
1375
+ return null; // Don't show empty conversations section
1376
+ }
1377
+
1378
+ if (fetchState === States.error) {
1379
+ if (errorView) {
1380
+ return errorView();
1381
+ }
1382
+
1383
+ return (
1384
+ <View style={[mergedStyles.errorStateStyle?.containerStyle]}>
1385
+ <Icon
1386
+ name="empty-search"
1387
+ size={120}
1388
+ height={120}
1389
+ width={120}
1390
+ imageStyle={mergedStyles.errorStateStyle?.iconStyle}
1391
+ containerStyle={mergedStyles.errorStateStyle?.iconContainerStyle}
1392
+ />
1393
+ <Text style={[mergedStyles.errorStateStyle?.titleStyle]}>
1394
+ {t("SEARCH_ERROR_LOADING_CONVERSATIONS") || "Error Loading Conversations"}
1395
+ </Text>
1396
+ <Text style={[mergedStyles.errorStateStyle?.subtitleStyle]}>
1397
+ {t("SEARCH_TRY_AGAIN") || "Please try again later"}
1398
+ </Text>
1399
+ </View>
1400
+ );
1401
+ }
1402
+
1403
+ return (
1404
+ <View>
1405
+ <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>
1406
+ {conversationList.map((conversation) => {
1407
+ // Use custom conversation item view if provided
1408
+ if (conversationItemView) {
1409
+ return (
1410
+ <TouchableOpacity
1411
+ key={conversation.getConversationId()}
1412
+ onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1413
+ >
1414
+ {conversationItemView(conversation, searchState.searchText)}
1415
+ </TouchableOpacity>
1416
+ );
1417
+ }
1418
+
1419
+ // Default conversation item rendering
1420
+ return (
1421
+ <TouchableOpacity
1422
+ key={conversation.getConversationId()}
1423
+ style={mergedStyles.conversationItemStyle?.containerStyle}
1424
+ onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1425
+ >
1426
+ {renderConversationLeadingView(conversation)}
1427
+ <View style={mergedStyles.conversationItemStyle?.contentStyle}>
1428
+ <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
1429
+ {conversation.getConversationWith().getName()}
1430
+ </Text>
1431
+ <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
1432
+ {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
1433
+ </Text>
1434
+ </View>
1435
+ {renderConversationTrailingView(conversation)}
1436
+ </TouchableOpacity>
1437
+ );
1438
+ })}
1439
+ {conversationState.hasMoreResults && (
1440
+ <TouchableOpacity
1441
+ style={mergedStyles.seeMoreButtonStyle}
1442
+ onPress={loadMoreConversations}
1443
+ disabled={isConversationMoreResultsLoading.current}
1444
+ >
1445
+ <Text style={mergedStyles.seeMoreTextStyle}>
1446
+ {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1447
+ </Text>
1448
+ </TouchableOpacity>
1449
+ )}
1450
+ </View>
1451
+ );
1452
+ };
1453
+
1454
+ // Helper to format date for headers
1455
+ const getDateHeaderDate = useCallback((timestamp: number) => {
1456
+ return new Date(timestamp * 1000).toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
1457
+ }, []);
1458
+
1459
+ // Render messages section
1460
+ const renderMessagesSection = () => {
1461
+ const { messageList, fetchState } = messageState;
1462
+
1463
+ if (fetchState === States.loading && messageList.length === 0) {
1464
+ return loadingView ? loadingView() : <Skeleton />;
1465
+ }
1466
+
1467
+ if (fetchState === States.empty || messageList.length === 0) {
1468
+ return null; // Don't show empty messages section
1469
+ }
1470
+
1471
+ if (fetchState === States.error) {
1472
+ if (errorView) {
1473
+ return errorView();
1474
+ }
1475
+
1476
+ return (
1477
+ <View style={[mergedStyles.errorStateStyle?.containerStyle]}>
1478
+ <Icon
1479
+ name="empty-search"
1480
+ size={120}
1481
+ height={120}
1482
+ width={120}
1483
+ imageStyle={mergedStyles.errorStateStyle?.iconStyle}
1484
+ containerStyle={mergedStyles.errorStateStyle?.iconContainerStyle}
1485
+ />
1486
+ <Text style={[mergedStyles.errorStateStyle?.titleStyle]}>
1487
+ {t("SEARCH_ERROR_LOADING_MESSAGES") || "Error Loading M essages"}
1488
+ </Text>
1489
+ <Text style={[mergedStyles.errorStateStyle?.subtitleStyle]}>
1490
+ {t("SEARCH_TRY_AGAIN") || "Please try again later"}
1491
+ </Text>
1492
+ </View>
1493
+ );
1494
+ }
1495
+
1496
+ return (
1497
+ <View>
1498
+ <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>
1499
+ {messageList.map((message, index) => {
1500
+ const messageType = message.getType();
1501
+
1502
+ // Date header logic for media items
1503
+ let dateHeader: React.ReactNode = null;
1504
+ if (['image', 'video'].includes(messageType)) {
1505
+ const sentAt = message.getSentAt();
1506
+ const currentDateStr = getDateHeaderDate(sentAt);
1507
+ const prevMessage = index > 0 ? messageList[index - 1] : null;
1508
+ const prevDateStr = prevMessage ? getDateHeaderDate(prevMessage.getSentAt()) : null;
1509
+
1510
+ if (currentDateStr !== prevDateStr) {
1511
+ dateHeader = (
1512
+ <CometChatDate
1513
+ timeStamp={sentAt * 1000}
1514
+ customDateString={currentDateStr}
1515
+ style={{
1516
+ textStyle: mergedStyles.sectionTitleStyle
1517
+ }}
1518
+ />
1519
+ );
1520
+ }
1521
+ }
1522
+
1523
+ // Check if message is a text message with link preview
1524
+ const isLinkMessage = messageType === 'text' && (() => {
1525
+ const textMessage = message as CometChat.TextMessage;
1526
+ const metadata = textMessage.getMetadata();
1527
+ return metadata && (metadata as any)['@injected'] && (metadata as any)['@injected']['extensions'] && (metadata as any)['@injected']['extensions']['link-preview'];
1528
+ })();
1529
+
1530
+ // Determine which custom view to use based on message type
1531
+ let customView: (() => React.ReactElement) | undefined;
1532
+
1533
+ if (isLinkMessage && linkMessageItemView) {
1534
+ customView = () => linkMessageItemView(message, searchState.searchText);
1535
+ } else if (messageType === 'text' && textMessageItemView) {
1536
+ customView = () => textMessageItemView(message, searchState.searchText);
1537
+ } else if (messageType === 'image' && imageMessageItemView) {
1538
+ customView = () => imageMessageItemView(message, searchState.searchText);
1539
+ } else if (messageType === 'video' && videoMessageItemView) {
1540
+ customView = () => videoMessageItemView(message, searchState.searchText);
1541
+ } else if (messageType === 'audio' && audioMessageItemView) {
1542
+ customView = () => audioMessageItemView(message, searchState.searchText);
1543
+ } else if (messageType === 'file' && documentMessageItemView) {
1544
+ customView = () => documentMessageItemView(message, searchState.searchText);
1545
+ }
1546
+
1547
+ // Use custom view if available
1548
+ if (customView) {
1549
+ return (
1550
+ <View key={`${message.getId()}-${index}`}>
1551
+ {dateHeader}
1552
+ <TouchableOpacity
1553
+ onPress={() => onMessageClicked?.(message, searchState.searchText)}
1554
+ >
1555
+ {customView()}
1556
+ </TouchableOpacity>
1557
+ </View>
1558
+ );
1559
+ }
1560
+
1561
+ // Default message item rendering
1562
+ return (
1563
+ <View key={`${message.getId()}-${index}`}>
1564
+ {dateHeader}
1565
+ <TouchableOpacity
1566
+ style={mergedStyles.messageItemStyle?.containerStyle}
1567
+ onPress={() => onMessageClicked?.(message, searchState.searchText)}
1568
+ >
1569
+ {renderMessageLeadingView(message)}
1570
+ <View style={[
1571
+ mergedStyles.messageItemStyle?.contentStyle,
1572
+ (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
1573
+ ]}>
1574
+ <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
1575
+ {message.getSender().getName()}
1576
+ </Text>
1577
+ <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
1578
+ {(() => {
1579
+ const messageType = message.getType();
1580
+
1581
+ // For media messages (image, video, file, audio), show file name
1582
+ if (['image', 'video', 'file', 'audio'].includes(messageType)) {
1583
+ const mediaMessage = message as CometChat.MediaMessage;
1584
+ const attachment = mediaMessage.getAttachment?.();
1585
+ return attachment?.getName?.() || messageType;
1586
+ }
1587
+
1588
+ // For text messages, show the text content
1589
+ if (messageType === 'text') {
1590
+ const raw = (message as CometChat.TextMessage).getText?.();
1591
+ const formatted = formatMentionsInText(raw, message);
1592
+ return formatted || messageType || 'Message';
1593
+ }
1594
+
1595
+ // For custom messages, try to localize the type
1596
+ const customTypeKey = `CUSTOM_MESSAGE_${messageType.toUpperCase()}`;
1597
+ const localizedType = t(customTypeKey);
1598
+
1599
+ // If localization exists and is different from key, use it
1600
+ if (localizedType && localizedType !== customTypeKey) {
1601
+ return localizedType;
1602
+ }
1603
+
1604
+ // Handle specific extension types mapping to existing keys
1605
+ if (messageType === 'extension_poll') return t("CUSTOM_MESSAGE_POLL") || "Poll";
1606
+ if (messageType === 'extension_sticker') return t("CUSTOM_MESSAGE_STICKER") || "Sticker";
1607
+ if (messageType === 'extension_whiteboard') return t("CUSTOM_MESSAGE_WHITEBOARD") || "Whiteboard";
1608
+ if (messageType === 'extension_document') return t("CUSTOM_MESSAGE_DOCUMENT") || "Document";
1609
+ if (messageType === 'meeting') return t("meeting") || "Meeting";
1610
+
1611
+ return messageType || 'Message';
1612
+ })()}
1613
+ </Text>
1614
+ </View>
1615
+ {renderMessageTrailingView(message)}
1616
+ </TouchableOpacity>
1617
+ </View>
1618
+ );
1619
+ })}
1620
+ </View>
1621
+ );
1622
+ };
1623
+
1624
+ const renderResults = () => {
1625
+ const conversationsRendered = shouldRenderConversations();
1626
+ const messagesRendered = shouldRenderMessages();
1627
+
1628
+ // Initial empty state - no search text and no filters
1629
+ if ((!searchState.searchText || searchState.searchText.trim() === "") && searchState.activeFilters.length === 0) {
1630
+ if (emptyView) {
1631
+ return emptyView();
1632
+ }
1633
+
1634
+ return (
1635
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1636
+ <Icon
1637
+ name="empty-search"
1638
+ size={120}
1639
+ height={120}
1640
+ width={120}
1641
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1642
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1643
+ />
1644
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1645
+ {t("SEARCH_NO_RESULTS_TITLE") || "No Results"}
1646
+ </Text>
1647
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1648
+ {t("SEARCH_NO_RESULTS_SUBTITLE") || "Start typing to search for messages and conversations"}
1649
+ </Text>
1650
+ </View>
1651
+ );
1652
+ }
1653
+
1654
+ // Show loading shimmer if we have search/filters active and both sections are loading
1655
+ if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1656
+ (conversationState.fetchState === States.loading || messageState.fetchState === States.loading) &&
1657
+ conversationState.conversationList.length === 0 &&
1658
+ messageState.messageList.length === 0) {
1659
+ return loadingView ? loadingView() : <Skeleton />;
1660
+ }
1661
+
1662
+ // Check if we have search text or filters but no actual results
1663
+ if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1664
+ conversationState.conversationList.length === 0 &&
1665
+ messageState.messageList.length === 0 &&
1666
+ conversationState.fetchState !== States.loading &&
1667
+ messageState.fetchState !== States.loading &&
1668
+ conversationState.fetchState !== States.error &&
1669
+ messageState.fetchState !== States.error) {
1670
+ // No results found state
1671
+ if (emptyView) {
1672
+ return emptyView();
1673
+ }
1674
+
1675
+ return (
1676
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1677
+ <Icon
1678
+ name="empty-search"
1679
+ size={120}
1680
+ height={120}
1681
+ width={120}
1682
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1683
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1684
+ />
1685
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1686
+ {t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
1687
+ </Text>
1688
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1689
+ {t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
1690
+ </Text>
1691
+ </View>
1692
+ );
1693
+ }
1694
+
1695
+ // Show search results with actual item lists
1696
+ return (
1697
+ <ScrollView
1698
+ style={[mergedStyles.resultsContainerStyle]}
1699
+ contentContainerStyle={{ paddingHorizontal: theme.spacing.padding.p4 }}
1700
+ showsVerticalScrollIndicator={false}
1701
+ onMomentumScrollEnd={handleScrollEnd}
1702
+ >
1703
+ {conversationsRendered && renderConversationsSection()}
1704
+ {messagesRendered && renderMessagesSection()}
1705
+ </ScrollView>
1706
+ );
1707
+ };
1708
+
1709
+ return (
1710
+ <View style={[mergedStyles.containerStyle]}>
1711
+ {renderHeader()}
1712
+ {renderFilters()}
1713
+ {renderResults()}
1714
+ </View>
1715
+ );
1716
+ };
1717
+
1718
+ export default CometChatSearch;