@cometchat/chat-uikit-react-native 5.5.4 → 5.6.0
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/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/FileManager.m +70 -6
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +124 -55
- package/src/CometChatConversations/CometChatConversations.tsx +240 -117
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
- package/src/CometChatGroups/CometChatGroups.tsx +61 -52
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +146 -66
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageList/CometChatMessageList.tsx +1371 -188
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
- package/src/CometChatSearch/CometChatSearch.tsx +353 -101
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
- package/src/CometChatUsers/CometChatUsers.tsx +2 -0
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
- package/src/index.ts +6 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
- package/src/shared/events/index.ts +4 -0
- package/src/shared/events/offline.ts +28 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
- package/src/shared/framework/MessageDataSource.tsx +34 -14
- package/src/shared/index.ts +2 -0
- package/src/shared/offline/OfflineHub.ts +651 -0
- package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
- package/src/shared/offline/OfflineViews.tsx +218 -0
- package/src/shared/offline/conversationPins.ts +137 -0
- package/src/shared/offline/conversations.ts +325 -0
- package/src/shared/offline/frameProbe.ts +24 -0
- package/src/shared/offline/gate.ts +94 -0
- package/src/shared/offline/groupActions.ts +81 -0
- package/src/shared/offline/identity.ts +162 -0
- package/src/shared/offline/index.ts +76 -0
- package/src/shared/offline/media.ts +247 -0
- package/src/shared/offline/notices.ts +90 -0
- package/src/shared/offline/reconcile.ts +296 -0
- package/src/shared/offline/searchOutcome.ts +62 -0
- package/src/shared/offline/send.ts +430 -0
- package/src/shared/offline/stateContract.ts +85 -0
- package/src/shared/offline/threadReplies.ts +125 -0
- package/src/shared/offline/twoPhase.ts +372 -0
- package/src/shared/offline/unsentActions.ts +168 -0
- package/src/shared/offline/useOfflineMediaUri.ts +87 -0
- package/src/shared/offline/useOfflineReconnect.ts +25 -0
- package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
- package/src/shared/offline/useOfflineUploadTray.ts +76 -0
- package/src/shared/offline/usePresenceHidden.ts +33 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/theme/type.ts +17 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -26,6 +26,16 @@ import { CometChatTextFormatter } from '../shared/formatters/CometChatTextFormat
|
|
|
26
26
|
import { applyRawFormatters } from '../shared/formatters/applyRawFormatters';
|
|
27
27
|
import { ExtensionConstants } from '../extensions/ExtensionConstants';
|
|
28
28
|
import { getExtensionData } from '../extensions/ExtensionModerator';
|
|
29
|
+
import { readListPage } from "../shared/offline/twoPhase";
|
|
30
|
+
import { useOfflineSessionEnded } from "../shared/offline/useOfflineSessionEnded";
|
|
31
|
+
import { useOfflineReconnect } from "../shared/offline/useOfflineReconnect";
|
|
32
|
+
import { isOfflineOn } from "../shared/offline/gate";
|
|
33
|
+
import { ConnectStateView } from "../shared/offline/OfflineViews";
|
|
34
|
+
import { searchOfflineOutcome, type SearchRead } from "../shared/offline/searchOutcome";
|
|
35
|
+
import { OFFLINE_STRING_KEYS } from "../shared/offline/notices";
|
|
36
|
+
import { CONTRACT_IDS } from "../shared/offline/stateContract";
|
|
37
|
+
import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
|
|
38
|
+
import { CometChatRetryButton } from "../shared/views/CometChatRetryButton/CometChatRetryButton";
|
|
29
39
|
|
|
30
40
|
|
|
31
41
|
/** Module-level formatter for search previews — reused across renders (no GC churn). */
|
|
@@ -123,6 +133,85 @@ function hasValidMessageSearchCriteria(searchKeyword: string, filters: CometChat
|
|
|
123
133
|
return filters.some(filter => validMessageFilters.includes(filter));
|
|
124
134
|
}
|
|
125
135
|
|
|
136
|
+
const CONVERSATION_SCOPE_FILTERS = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
|
|
137
|
+
const MESSAGE_SCOPE_FILTERS = [
|
|
138
|
+
CometChatSearchFilter.Photos,
|
|
139
|
+
CometChatSearchFilter.Videos,
|
|
140
|
+
CometChatSearchFilter.Documents,
|
|
141
|
+
CometChatSearchFilter.Audio,
|
|
142
|
+
CometChatSearchFilter.Links
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
interface SearchScopeContext {
|
|
146
|
+
searchText: string;
|
|
147
|
+
activeFilters: CometChatSearchFilter[];
|
|
148
|
+
searchIn: CometChatSearchScope[];
|
|
149
|
+
uid?: string;
|
|
150
|
+
guid?: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Whether the conversations scope is part of the search. It decides both what is shown and what is read,
|
|
155
|
+
* so a scope that is not shown is never read and cannot leave a stale state behind (as Android's
|
|
156
|
+
* getSearchMode: a keyword with only message filters searches messages only).
|
|
157
|
+
*/
|
|
158
|
+
function isConversationScopeActive({ searchText, activeFilters, searchIn, uid, guid }: SearchScopeContext): boolean {
|
|
159
|
+
// If searchIn is empty, search in both conversations and messages
|
|
160
|
+
const effectiveSearchIn = searchIn.length === 0
|
|
161
|
+
? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
|
|
162
|
+
: searchIn;
|
|
163
|
+
|
|
164
|
+
// Don't render conversations if searchIn doesn't include conversations scope
|
|
165
|
+
if (!effectiveSearchIn.includes(CometChatSearchScope.Conversations)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Don't render conversations if uid or guid is present (searching within specific user/group)
|
|
170
|
+
if (uid || guid) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (searchText && searchText.trim() !== "" && activeFilters.length === 0) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (activeFilters.length > 0) {
|
|
179
|
+
return activeFilters.some(filter => CONVERSATION_SCOPE_FILTERS.includes(filter));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Whether the messages scope is part of the search; see isConversationScopeActive. */
|
|
186
|
+
function isMessageScopeActive({ searchText, activeFilters, searchIn, uid, guid }: SearchScopeContext): boolean {
|
|
187
|
+
// If searchIn is empty, search in both conversations and messages
|
|
188
|
+
const effectiveSearchIn = searchIn.length === 0
|
|
189
|
+
? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
|
|
190
|
+
: searchIn;
|
|
191
|
+
|
|
192
|
+
// Don't render messages if searchIn doesn't include messages scope
|
|
193
|
+
if (!effectiveSearchIn.includes(CometChatSearchScope.Messages)) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Always render messages if uid or guid is present (searching within specific user/group)
|
|
198
|
+
if (uid || guid) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (searchText && searchText.trim() !== "" && activeFilters.length === 0) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (activeFilters.length > 0) {
|
|
207
|
+
// Show messages if any message filter is selected and no conversation filter is selected
|
|
208
|
+
return activeFilters.some(filter => MESSAGE_SCOPE_FILTERS.includes(filter)) &&
|
|
209
|
+
!activeFilters.some(filter => CONVERSATION_SCOPE_FILTERS.includes(filter));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
126
215
|
interface SearchState {
|
|
127
216
|
searchText: string;
|
|
128
217
|
conversations: CometChat.Conversation[];
|
|
@@ -1048,6 +1137,22 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1048
1137
|
// ============================================================================
|
|
1049
1138
|
// CONVERSATIONS SEARCH LOGIC (moved from useCometChatSearchConversationsList.ts)
|
|
1050
1139
|
// ============================================================================
|
|
1140
|
+
// Offline ON (D84 rule 7, as Android's updateFinalStateIfCompleted): a scope whose read ended not connected
|
|
1141
|
+
// with nothing saved for it. Whether that shows "Connect to search" depends on both scopes (see
|
|
1142
|
+
// searchOfflineOutcome): a keyword that could not reach the server, or both scopes failed. A keyword
|
|
1143
|
+
// has no cache (BEH-SNAP-04); a filter may. `keyword` = the read carried one. Never set with offline off.
|
|
1144
|
+
type OfflineMiss = { keyword: boolean } | null;
|
|
1145
|
+
const [offlineSearchError, setOfflineSearchError] = useState<{ conversations: OfflineMiss; messages: OfflineMiss }>({
|
|
1146
|
+
conversations: null,
|
|
1147
|
+
messages: null,
|
|
1148
|
+
});
|
|
1149
|
+
// Offline ON: a real failure's onError is held until both scopes have ended, because Android reports it
|
|
1150
|
+
// only when both scopes failed or results stay on screen; one failing scope with nothing shown is the plain
|
|
1151
|
+
// empty state with no onError. Never filled with offline off (onError fires at once, as before).
|
|
1152
|
+
const pendingSearchErrorsRef = useRef<{
|
|
1153
|
+
conversations: { error: unknown; context: string } | null;
|
|
1154
|
+
messages: { error: unknown; context: string } | null;
|
|
1155
|
+
}>({ conversations: null, messages: null });
|
|
1051
1156
|
const [conversationState, setConversationState] = useState({
|
|
1052
1157
|
conversationList: [] as CometChat.Conversation[],
|
|
1053
1158
|
fetchState: States.loaded,
|
|
@@ -1058,6 +1163,9 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1058
1163
|
const lastConversationSearchKeyword = useRef<string>(searchState.searchText);
|
|
1059
1164
|
const lastConversationActiveFilters = useRef<CometChatSearchFilter[]>(searchState.activeFilters);
|
|
1060
1165
|
const isConversationMoreResultsLoading = useRef<boolean>(false);
|
|
1166
|
+
// Bumped by every new conversation search (and a session end): a read for an older keyword or filter
|
|
1167
|
+
// that answers late is dropped, so it never replaces or extends the newer search's results.
|
|
1168
|
+
const conversationSearchGenRef = useRef(0);
|
|
1061
1169
|
|
|
1062
1170
|
// ============================================================================
|
|
1063
1171
|
// MESSAGES SEARCH LOGIC (moved from useCometChatSearchMessagesList.ts)
|
|
@@ -1067,11 +1175,22 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1067
1175
|
fetchState: States.loaded,
|
|
1068
1176
|
hasMoreResults: false,
|
|
1069
1177
|
});
|
|
1178
|
+
// Offline ON: nothing of the old session stays on screen (UIK-LIFE-01).
|
|
1179
|
+
useOfflineSessionEnded(() => {
|
|
1180
|
+
conversationSearchGenRef.current++;
|
|
1181
|
+
messageSearchGenRef.current++;
|
|
1182
|
+
conversationRequestRef.current = null;
|
|
1183
|
+
messageRequestRef.current = null;
|
|
1184
|
+
setOfflineSearchError({ conversations: null, messages: null });
|
|
1185
|
+
setConversationState({ conversationList: [], fetchState: States.loaded, hasMoreResults: false });
|
|
1186
|
+
setMessageState({ messageList: [], fetchState: States.loaded, hasMoreResults: false });
|
|
1187
|
+
});
|
|
1070
1188
|
|
|
1071
1189
|
const messageRequestRef = useRef<CometChat.MessagesRequest | null>(null);
|
|
1072
1190
|
const lastMessageSearchKeyword = useRef<string>(searchState.searchText);
|
|
1073
1191
|
const lastMessageActiveFilters = useRef<CometChatSearchFilter[]>(searchState.activeFilters);
|
|
1074
1192
|
const isMessageMoreResultsLoading = useRef<boolean>(false);
|
|
1193
|
+
const messageSearchGenRef = useRef(0); // as conversationSearchGenRef, for message results
|
|
1075
1194
|
|
|
1076
1195
|
// ============================================================================
|
|
1077
1196
|
// CONVERSATION SEARCH FUNCTIONS
|
|
@@ -1105,9 +1224,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1105
1224
|
return;
|
|
1106
1225
|
}
|
|
1107
1226
|
|
|
1227
|
+
const searchGen = conversationSearchGenRef.current;
|
|
1108
1228
|
try {
|
|
1109
1229
|
isConversationMoreResultsLoading.current = true;
|
|
1110
|
-
|
|
1230
|
+
// Offline ON: two-phase (a filter is answered from the device); OFF: today's fetch.
|
|
1231
|
+
const page = await readListPage<CometChat.Conversation>(conversationRequestRef.current, "next");
|
|
1232
|
+
if (searchGen !== conversationSearchGenRef.current) return; // the search changed while it read
|
|
1233
|
+
const moreConversations = page.rows;
|
|
1234
|
+
if (page.offline && moreConversations.length === 0) return;
|
|
1111
1235
|
|
|
1112
1236
|
if (moreConversations.length > 0) {
|
|
1113
1237
|
setConversationState(prev => ({
|
|
@@ -1124,15 +1248,22 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1124
1248
|
} catch (error) {
|
|
1125
1249
|
errorHandler(error, "loadMoreConversations");
|
|
1126
1250
|
} finally {
|
|
1127
|
-
|
|
1251
|
+
// A newer search reset the flag for its own reads: this stale one must not clear it.
|
|
1252
|
+
if (searchGen === conversationSearchGenRef.current) isConversationMoreResultsLoading.current = false;
|
|
1128
1253
|
}
|
|
1129
1254
|
}, [errorHandler, conversationState.hasMoreResults]);
|
|
1130
1255
|
|
|
1131
1256
|
const searchConversations = useCallback(async () => {
|
|
1257
|
+
const searchGen = ++conversationSearchGenRef.current;
|
|
1258
|
+
isConversationMoreResultsLoading.current = false; // a load-more of the old search is dropped when it lands
|
|
1259
|
+
setOfflineSearchError(prev => (prev.conversations ? { ...prev, conversations: null } : prev));
|
|
1260
|
+
pendingSearchErrorsRef.current.conversations = null;
|
|
1132
1261
|
try {
|
|
1133
1262
|
setConversationState(prev => ({ ...prev, fetchState: States.loading }));
|
|
1134
1263
|
|
|
1135
|
-
|
|
1264
|
+
// A scope that is not part of this search (not shown) is not read, as on Android.
|
|
1265
|
+
if (!isConversationScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }) ||
|
|
1266
|
+
!hasValidConversationSearchCriteria(searchState.searchText, searchState.activeFilters)) {
|
|
1136
1267
|
setConversationState(prev => ({
|
|
1137
1268
|
...prev,
|
|
1138
1269
|
conversationList: [],
|
|
@@ -1144,7 +1275,23 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1144
1275
|
|
|
1145
1276
|
const request = buildConversationsRequest();
|
|
1146
1277
|
conversationRequestRef.current = request;
|
|
1147
|
-
|
|
1278
|
+
// Offline ON: two-phase, so a filter is answered from the device; a keyword has no cache.
|
|
1279
|
+
// OFF: today's fetch.
|
|
1280
|
+
const page = await readListPage<CometChat.Conversation>(request, "next");
|
|
1281
|
+
if (searchGen !== conversationSearchGenRef.current) return; // a newer search owns the results
|
|
1282
|
+
const conversations = page.rows;
|
|
1283
|
+
// D84 rule 7 (as Android): not connected with nothing saved is a failed read when it carried a keyword
|
|
1284
|
+
// (no cache) or the SDK gave no cached phase. A filter read answered by its (empty) cached phase found
|
|
1285
|
+
// nothing: not a failure, so it falls through to the empty list below. What a failed read shows (no
|
|
1286
|
+
// onError) is decided across both scopes in searchOfflineOutcome.
|
|
1287
|
+
const conversationKeyword = searchState.searchText.trim() !== "";
|
|
1288
|
+
if (page.offline && conversations.length === 0 && (conversationKeyword || !page.cachedDelivered)) {
|
|
1289
|
+
setOfflineSearchError(prev => ({ ...prev, conversations: { keyword: conversationKeyword } }));
|
|
1290
|
+
setConversationState({ conversationList: [], fetchState: States.error, hasMoreResults: false });
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
// D84 rule 2: saved rows are shown and the server read could not be reached: the rows stay,
|
|
1294
|
+
// nothing is reported (not connected is not an error).
|
|
1148
1295
|
|
|
1149
1296
|
if (conversations.length > 0) {
|
|
1150
1297
|
const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
|
|
@@ -1161,10 +1308,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1161
1308
|
});
|
|
1162
1309
|
}
|
|
1163
1310
|
} catch (error) {
|
|
1164
|
-
|
|
1165
|
-
|
|
1311
|
+
if (isOfflineOn() && searchGen === conversationSearchGenRef.current) {
|
|
1312
|
+
// Offline ON: onError waits until both scopes have ended (see the flush effect below).
|
|
1313
|
+
pendingSearchErrorsRef.current.conversations = { error, context: "searchConversations" };
|
|
1314
|
+
} else {
|
|
1315
|
+
errorHandler(error, "searchConversations");
|
|
1316
|
+
}
|
|
1317
|
+
if (searchGen === conversationSearchGenRef.current) {
|
|
1318
|
+
setConversationState(prev => ({ ...prev, fetchState: States.error }));
|
|
1319
|
+
}
|
|
1166
1320
|
}
|
|
1167
|
-
}, [searchState.searchText, searchState.activeFilters, buildConversationsRequest, guid, uid, errorHandler]);
|
|
1321
|
+
}, [searchState.searchText, searchState.activeFilters, buildConversationsRequest, guid, uid, searchIn, errorHandler]);
|
|
1168
1322
|
|
|
1169
1323
|
// ============================================================================
|
|
1170
1324
|
// MESSAGE SEARCH FUNCTIONS
|
|
@@ -1228,9 +1382,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1228
1382
|
return;
|
|
1229
1383
|
}
|
|
1230
1384
|
|
|
1385
|
+
const searchGen = messageSearchGenRef.current;
|
|
1231
1386
|
try {
|
|
1232
1387
|
isMessageMoreResultsLoading.current = true;
|
|
1233
|
-
|
|
1388
|
+
// Offline ON: two-phase (a filter is answered from the device); OFF: today's fetch.
|
|
1389
|
+
const page = await readListPage<CometChat.BaseMessage>(messageRequestRef.current, "previous");
|
|
1390
|
+
if (searchGen !== messageSearchGenRef.current) return; // the search changed while it read
|
|
1391
|
+
const moreMessages = page.rows;
|
|
1392
|
+
if (page.offline && moreMessages.length === 0) return;
|
|
1234
1393
|
|
|
1235
1394
|
if (moreMessages.length > 0) {
|
|
1236
1395
|
|
|
@@ -1254,15 +1413,21 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1254
1413
|
} catch (error) {
|
|
1255
1414
|
errorHandler(error, "loadMoreMessages");
|
|
1256
1415
|
} finally {
|
|
1257
|
-
isMessageMoreResultsLoading.current = false;
|
|
1416
|
+
if (searchGen === messageSearchGenRef.current) isMessageMoreResultsLoading.current = false;
|
|
1258
1417
|
}
|
|
1259
1418
|
}, [errorHandler, messageState.hasMoreResults]);
|
|
1260
1419
|
|
|
1261
1420
|
const searchMessages = useCallback(async () => {
|
|
1421
|
+
const searchGen = ++messageSearchGenRef.current;
|
|
1422
|
+
isMessageMoreResultsLoading.current = false; // a load-more of the old search is dropped when it lands
|
|
1423
|
+
setOfflineSearchError(prev => (prev.messages ? { ...prev, messages: null } : prev));
|
|
1424
|
+
pendingSearchErrorsRef.current.messages = null;
|
|
1262
1425
|
try {
|
|
1263
1426
|
setMessageState(prev => ({ ...prev, fetchState: States.loading }));
|
|
1264
1427
|
|
|
1265
|
-
|
|
1428
|
+
// A scope that is not part of this search (not shown) is not read, as on Android.
|
|
1429
|
+
if (!isMessageScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }) ||
|
|
1430
|
+
!hasValidMessageSearchCriteria(searchState.searchText, searchState.activeFilters)) {
|
|
1266
1431
|
setMessageState(prev => ({
|
|
1267
1432
|
...prev,
|
|
1268
1433
|
messageList: [],
|
|
@@ -1274,7 +1439,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1274
1439
|
|
|
1275
1440
|
const request = buildMessagesRequest();
|
|
1276
1441
|
messageRequestRef.current = request;
|
|
1277
|
-
|
|
1442
|
+
// Offline ON: as for conversations above. OFF: today's fetch.
|
|
1443
|
+
const page = await readListPage<CometChat.BaseMessage>(request, "previous");
|
|
1444
|
+
if (searchGen !== messageSearchGenRef.current) return; // a newer search owns the results
|
|
1445
|
+
const messages = page.rows;
|
|
1446
|
+
const messageKeyword = searchState.searchText.trim() !== "";
|
|
1447
|
+
if (page.offline && messages.length === 0 && (messageKeyword || !page.cachedDelivered)) {
|
|
1448
|
+
setOfflineSearchError(prev => ({ ...prev, messages: { keyword: messageKeyword } }));
|
|
1449
|
+
setMessageState({ messageList: [], fetchState: States.error, hasMoreResults: false });
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
// D84 rule 2: saved rows stay, nothing is reported offline.
|
|
1278
1453
|
|
|
1279
1454
|
if (messages.length > 0) {
|
|
1280
1455
|
const reversedList = messages.reverse();
|
|
@@ -1299,10 +1474,16 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1299
1474
|
});
|
|
1300
1475
|
}
|
|
1301
1476
|
} catch (error) {
|
|
1302
|
-
|
|
1303
|
-
|
|
1477
|
+
if (isOfflineOn() && searchGen === messageSearchGenRef.current) {
|
|
1478
|
+
pendingSearchErrorsRef.current.messages = { error, context: "searchMessages" };
|
|
1479
|
+
} else {
|
|
1480
|
+
errorHandler(error, "searchMessages");
|
|
1481
|
+
}
|
|
1482
|
+
if (searchGen === messageSearchGenRef.current) {
|
|
1483
|
+
setMessageState(prev => ({ ...prev, fetchState: States.error }));
|
|
1484
|
+
}
|
|
1304
1485
|
}
|
|
1305
|
-
}, [searchState.searchText, searchState.activeFilters, buildMessagesRequest, guid, uid, errorHandler]);
|
|
1486
|
+
}, [searchState.searchText, searchState.activeFilters, buildMessagesRequest, guid, uid, searchIn, errorHandler]);
|
|
1306
1487
|
|
|
1307
1488
|
// ============================================================================
|
|
1308
1489
|
// SEARCH EFFECTS - Trigger searches when search text or filters change
|
|
@@ -1329,76 +1510,62 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1329
1510
|
}
|
|
1330
1511
|
}, [searchState.searchText, searchState.activeFilters, searchMessages]);
|
|
1331
1512
|
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
// Define conversation filters
|
|
1349
|
-
const conversationFilters = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
|
|
1350
|
-
|
|
1351
|
-
if (searchState.searchText && searchState.searchText.trim() !== "" && searchState.activeFilters.length === 0) {
|
|
1352
|
-
return true;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
if (searchState.activeFilters.length > 0) {
|
|
1356
|
-
return searchState.activeFilters.some(filter => conversationFilters.includes(filter));
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
return false;
|
|
1360
|
-
}, [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]);
|
|
1361
|
-
|
|
1362
|
-
const shouldRenderMessages = useCallback(() => {
|
|
1363
|
-
// If searchIn is empty, search in both conversations and messages
|
|
1364
|
-
const effectiveSearchIn = searchIn.length === 0
|
|
1365
|
-
? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
|
|
1366
|
-
: searchIn;
|
|
1367
|
-
|
|
1368
|
-
// Don't render messages if searchIn doesn't include messages scope
|
|
1369
|
-
if (!effectiveSearchIn.includes(CometChatSearchScope.Messages)) {
|
|
1370
|
-
return false;
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
// Always render messages if uid or guid is present (searching within specific user/group)
|
|
1374
|
-
if (uid || guid) {
|
|
1375
|
-
return true;
|
|
1376
|
-
}
|
|
1513
|
+
// D84 rule 8: a search showing "Connect to search" runs again once, by itself, when the
|
|
1514
|
+
// connection is back. Only offline ON listens; any other error is not re-run.
|
|
1515
|
+
const searchConversationsRef = useRef(searchConversations);
|
|
1516
|
+
searchConversationsRef.current = searchConversations;
|
|
1517
|
+
const searchMessagesRef = useRef(searchMessages);
|
|
1518
|
+
searchMessagesRef.current = searchMessages;
|
|
1519
|
+
// Which scopes to read again: set on every render from what the screen shows (see renderResults).
|
|
1520
|
+
// "Connect to search" runs the whole search again, as Android's reconnect re-run does; an error view
|
|
1521
|
+
// that has a not-connected scope runs that scope again (as before); the plain empty state of a
|
|
1522
|
+
// filter-only search runs nothing.
|
|
1523
|
+
const reconnectRerunRef = useRef({ conversations: false, messages: false });
|
|
1524
|
+
useOfflineReconnect(() => {
|
|
1525
|
+
const rerun = reconnectRerunRef.current;
|
|
1526
|
+
if (rerun.conversations) void searchConversationsRef.current();
|
|
1527
|
+
if (rerun.messages) void searchMessagesRef.current();
|
|
1528
|
+
});
|
|
1377
1529
|
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
CometChatSearchFilter.Audio,
|
|
1384
|
-
CometChatSearchFilter.Links
|
|
1385
|
-
];
|
|
1530
|
+
/** The error view's Retry: both searches again. */
|
|
1531
|
+
const retrySearch = () => {
|
|
1532
|
+
void searchConversations();
|
|
1533
|
+
void searchMessages();
|
|
1534
|
+
};
|
|
1386
1535
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1536
|
+
const shouldRenderConversations = useCallback(
|
|
1537
|
+
() => isConversationScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }),
|
|
1538
|
+
[searchState.activeFilters, searchState.searchText, uid, guid, searchIn]
|
|
1539
|
+
);
|
|
1389
1540
|
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1541
|
+
const shouldRenderMessages = useCallback(
|
|
1542
|
+
() => isMessageScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }),
|
|
1543
|
+
[searchState.activeFilters, searchState.searchText, uid, guid, searchIn]
|
|
1544
|
+
);
|
|
1393
1545
|
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1546
|
+
/**
|
|
1547
|
+
* Offline ON: report the held real failures once both scopes have ended (Android updateFinalStateIfCompleted).
|
|
1548
|
+
* One scope failed and nothing is on screen: the plain empty state, nothing reported. Both scopes failed, or
|
|
1549
|
+
* rows stay on screen: onError, as before.
|
|
1550
|
+
*/
|
|
1551
|
+
useEffect(() => {
|
|
1552
|
+
const pending = pendingSearchErrorsRef.current;
|
|
1553
|
+
if (!pending.conversations && !pending.messages) return;
|
|
1554
|
+
if (conversationState.fetchState === States.loading || messageState.fetchState === States.loading) return;
|
|
1555
|
+
const conversationsRendered = shouldRenderConversations();
|
|
1556
|
+
const messagesRendered = shouldRenderMessages();
|
|
1557
|
+
const nothingShown = conversationState.conversationList.length === 0 && messageState.messageList.length === 0;
|
|
1558
|
+
const failedScopes =
|
|
1559
|
+
(conversationsRendered && conversationState.fetchState === States.error ? 1 : 0) +
|
|
1560
|
+
(messagesRendered && messageState.fetchState === States.error ? 1 : 0);
|
|
1561
|
+
const report = !(nothingShown && failedScopes < 2);
|
|
1562
|
+
const held = [pending.conversations, pending.messages];
|
|
1563
|
+
pendingSearchErrorsRef.current = { conversations: null, messages: null };
|
|
1564
|
+
if (!report) return;
|
|
1565
|
+
for (const entry of held) {
|
|
1566
|
+
if (entry) errorHandler(entry.error, entry.context);
|
|
1398
1567
|
}
|
|
1399
|
-
|
|
1400
|
-
return false;
|
|
1401
|
-
}, [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]);
|
|
1568
|
+
});
|
|
1402
1569
|
|
|
1403
1570
|
// Handle scroll-based fetching for messages
|
|
1404
1571
|
const handleScrollEnd = useCallback((event: any) => {
|
|
@@ -1767,10 +1934,70 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1767
1934
|
return new Date(timestamp * 1000).toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
|
|
1768
1935
|
}, []);
|
|
1769
1936
|
|
|
1937
|
+
/** "No results found": the app's own empty view, or the kit's. */
|
|
1938
|
+
const renderNoResults = () => {
|
|
1939
|
+
if (emptyView) {
|
|
1940
|
+
return emptyView();
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
return (
|
|
1944
|
+
<View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
|
|
1945
|
+
<Icon
|
|
1946
|
+
name="empty-search"
|
|
1947
|
+
size={120}
|
|
1948
|
+
height={120}
|
|
1949
|
+
width={120}
|
|
1950
|
+
imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
|
|
1951
|
+
containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
|
|
1952
|
+
/>
|
|
1953
|
+
<Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
|
|
1954
|
+
{t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
|
|
1955
|
+
</Text>
|
|
1956
|
+
<Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
|
|
1957
|
+
{t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
|
|
1958
|
+
</Text>
|
|
1959
|
+
</View>
|
|
1960
|
+
);
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1770
1963
|
const renderResults = () => {
|
|
1771
1964
|
const conversationsRendered = shouldRenderConversations();
|
|
1772
1965
|
const messagesRendered = shouldRenderMessages();
|
|
1773
1966
|
|
|
1967
|
+
// Offline ON, nothing to show and a scope that ended in an error (D84): what shows is decided across both
|
|
1968
|
+
// scopes, as Android does (searchOfflineOutcome). "Connect to search" (rule 7): a keyword that could not
|
|
1969
|
+
// reach the server, or both scopes failed, and every failure was not-connected: an offline state, not an
|
|
1970
|
+
// error (no onError). A filter-only search where only one scope failed is the plain empty state. Any real
|
|
1971
|
+
// failure (rule 4) is the error view. The app's own empty / error view wins over the kit's. Never over rows.
|
|
1972
|
+
const nothingShown = conversationState.conversationList.length === 0 && messageState.messageList.length === 0;
|
|
1973
|
+
const readOf = (
|
|
1974
|
+
rendered: boolean,
|
|
1975
|
+
fetchState: States,
|
|
1976
|
+
miss: OfflineMiss
|
|
1977
|
+
): SearchRead => ({
|
|
1978
|
+
ran: rendered,
|
|
1979
|
+
failure: rendered && fetchState === States.error ? (miss ? "notConnected" : "error") : null,
|
|
1980
|
+
keyword: !!miss?.keyword,
|
|
1981
|
+
});
|
|
1982
|
+
const searchActive = searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0;
|
|
1983
|
+
const offlineOutcome = searchOfflineOutcome({
|
|
1984
|
+
offlineOn: isOfflineOn() && searchActive,
|
|
1985
|
+
nothingShown,
|
|
1986
|
+
conversations: readOf(conversationsRendered, conversationState.fetchState, offlineSearchError.conversations),
|
|
1987
|
+
messages: readOf(messagesRendered, messageState.fetchState, offlineSearchError.messages),
|
|
1988
|
+
});
|
|
1989
|
+
// Read again once on reconnect (D84 rule 8): the whole search for "Connect to search"; a not-connected
|
|
1990
|
+
// scope of an error view; nothing for the plain empty state.
|
|
1991
|
+
reconnectRerunRef.current =
|
|
1992
|
+
offlineOutcome === "connectToSearch"
|
|
1993
|
+
? { conversations: conversationsRendered, messages: messagesRendered }
|
|
1994
|
+
: offlineOutcome === "error"
|
|
1995
|
+
? {
|
|
1996
|
+
conversations: conversationsRendered && !!offlineSearchError.conversations,
|
|
1997
|
+
messages: messagesRendered && !!offlineSearchError.messages,
|
|
1998
|
+
}
|
|
1999
|
+
: { conversations: false, messages: false };
|
|
2000
|
+
|
|
1774
2001
|
// Initial empty state - no search text and no filters
|
|
1775
2002
|
if ((!searchState.searchText || searchState.searchText.trim() === "") && searchState.activeFilters.length === 0) {
|
|
1776
2003
|
if (emptyView) {
|
|
@@ -1805,6 +2032,52 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1805
2032
|
return loadingView ? loadingView() : <Skeleton />;
|
|
1806
2033
|
}
|
|
1807
2034
|
|
|
2035
|
+
if (offlineOutcome === "connectToSearch") {
|
|
2036
|
+
if (emptyView) {
|
|
2037
|
+
return emptyView();
|
|
2038
|
+
}
|
|
2039
|
+
return (
|
|
2040
|
+
<ConnectStateView
|
|
2041
|
+
testID={CONTRACT_IDS.emptyConnectToSearch}
|
|
2042
|
+
title={t(OFFLINE_STRING_KEYS.connectToSearchMessages)}
|
|
2043
|
+
subtitle={t(OFFLINE_STRING_KEYS.connectToSearchSubtitle)}
|
|
2044
|
+
containerStyle={mergedStyles.errorStateStyle?.containerStyle}
|
|
2045
|
+
titleStyle={mergedStyles.errorStateStyle?.titleStyle}
|
|
2046
|
+
subtitleStyle={mergedStyles.errorStateStyle?.subtitleStyle}
|
|
2047
|
+
/>
|
|
2048
|
+
);
|
|
2049
|
+
}
|
|
2050
|
+
if (offlineOutcome === "empty") {
|
|
2051
|
+
return renderNoResults();
|
|
2052
|
+
}
|
|
2053
|
+
if (offlineOutcome === "error") {
|
|
2054
|
+
if (errorView) {
|
|
2055
|
+
return errorView();
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
return (
|
|
2059
|
+
<ErrorEmptyView
|
|
2060
|
+
testID="CometChatSearch.error"
|
|
2061
|
+
title={t("OOPS")}
|
|
2062
|
+
subTitle={t("SOMETHING_WENT_WRONG")}
|
|
2063
|
+
tertiaryTitle={t("WRONG_TEXT_TRY_AGAIN")}
|
|
2064
|
+
Icon={
|
|
2065
|
+
<Icon
|
|
2066
|
+
name="error-state"
|
|
2067
|
+
size={theme.spacing.margin.m15 << 1}
|
|
2068
|
+
icon={mergedStyles.errorStateStyle?.icon}
|
|
2069
|
+
imageStyle={mergedStyles.errorStateStyle?.iconStyle}
|
|
2070
|
+
containerStyle={mergedStyles.errorStateStyle?.iconContainerStyle}
|
|
2071
|
+
/>
|
|
2072
|
+
}
|
|
2073
|
+
containerStyle={mergedStyles.errorStateStyle?.containerStyle}
|
|
2074
|
+
titleStyle={mergedStyles.errorStateStyle?.titleStyle}
|
|
2075
|
+
subTitleStyle={mergedStyles.errorStateStyle?.subtitleStyle}
|
|
2076
|
+
RetryView={<CometChatRetryButton onPress={retrySearch} />}
|
|
2077
|
+
/>
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
|
|
1808
2081
|
// Check if we have search text or filters but no actual results
|
|
1809
2082
|
if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
|
|
1810
2083
|
conversationState.conversationList.length === 0 &&
|
|
@@ -1814,28 +2087,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1814
2087
|
conversationState.fetchState !== States.error &&
|
|
1815
2088
|
messageState.fetchState !== States.error) {
|
|
1816
2089
|
// No results found state
|
|
1817
|
-
|
|
1818
|
-
return emptyView();
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
return (
|
|
1822
|
-
<View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
|
|
1823
|
-
<Icon
|
|
1824
|
-
name="empty-search"
|
|
1825
|
-
size={120}
|
|
1826
|
-
height={120}
|
|
1827
|
-
width={120}
|
|
1828
|
-
imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
|
|
1829
|
-
containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
|
|
1830
|
-
/>
|
|
1831
|
-
<Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
|
|
1832
|
-
{t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
|
|
1833
|
-
</Text>
|
|
1834
|
-
<Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
|
|
1835
|
-
{t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
|
|
1836
|
-
</Text>
|
|
1837
|
-
</View>
|
|
1838
|
-
);
|
|
2090
|
+
return renderNoResults();
|
|
1839
2091
|
}
|
|
1840
2092
|
|
|
1841
2093
|
// Show search results with actual item lists - USING SINGLE FLATLIST FOR VIRTUALIZATION
|
|
@@ -23,6 +23,8 @@ import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNe
|
|
|
23
23
|
import { ExtensionConstants } from "../extensions";
|
|
24
24
|
import { getExtensionData } from "../shared/helper/functions";
|
|
25
25
|
import { urlPattern } from "../shared/constants/UIKitConstants";
|
|
26
|
+
import { OfflineHub } from "../shared/offline/OfflineHub";
|
|
27
|
+
import { createThreadReplyTracker } from "../shared/offline/threadReplies";
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Unique UI event identifier for CometChatUIEventHandler.
|
|
@@ -129,6 +131,17 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
|
|
|
129
131
|
} = props;
|
|
130
132
|
const [message, setMessage] = useState<CometChat.BaseMessage>(parentMessage);
|
|
131
133
|
const [replyCount, setReplyCount] = useState<number>(parentMessage.getReplyCount() || 0);
|
|
134
|
+
// Offline (ON path) reply-count adjustments (README §3.9); inert with offline off.
|
|
135
|
+
const parentIdRef = React.useRef<any>(parentMessage.getId());
|
|
136
|
+
parentIdRef.current = message.getId();
|
|
137
|
+
const replyTracker = React.useRef(
|
|
138
|
+
createThreadReplyTracker(
|
|
139
|
+
() => parentIdRef.current,
|
|
140
|
+
() => OfflineHub.getInstance().gen,
|
|
141
|
+
(delta) => setReplyCount((prev) => Math.max(0, prev + delta)),
|
|
142
|
+
(count) => setReplyCount(count)
|
|
143
|
+
)
|
|
144
|
+
);
|
|
132
145
|
|
|
133
146
|
const theme = useTheme();
|
|
134
147
|
const { t } = useCometChatTranslation();
|
|
@@ -161,8 +174,11 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
|
|
|
161
174
|
* @param {{ message: CometChat.BaseMessage, status: string }} param0 - The message and its status.
|
|
162
175
|
*/
|
|
163
176
|
const ccMessageSentFunc = ({ message: msg, status }: any): void => {
|
|
177
|
+
// Offline (ON path): an own reply is counted once, at its pending; its ack adds nothing.
|
|
178
|
+
replyTracker.current.onPublicSent(msg, status, () => {
|
|
179
|
+
if (status === messageStatus.success) checkAndUpdateRepliesCount(msg);
|
|
180
|
+
});
|
|
164
181
|
if (status === messageStatus.success) {
|
|
165
|
-
checkAndUpdateRepliesCount(msg);
|
|
166
182
|
if (message.getId() == msg.id) setMessage(message);
|
|
167
183
|
}
|
|
168
184
|
};
|
|
@@ -243,8 +259,14 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
|
|
|
243
259
|
},
|
|
244
260
|
});
|
|
245
261
|
|
|
262
|
+
const hub = OfflineHub.getInstance();
|
|
263
|
+
const sendStates = hub.sendState$.subscribe((event) => replyTracker.current.onSendState(event));
|
|
264
|
+
const updates = hub.messagesUpdated$.subscribe((event) => replyTracker.current.onMessagesUpdated(event));
|
|
265
|
+
|
|
246
266
|
return () => {
|
|
247
267
|
CometChatUIEventHandler.removeMessageListener(uiEventId);
|
|
268
|
+
sendStates.unsubscribe();
|
|
269
|
+
updates.unsubscribe();
|
|
248
270
|
};
|
|
249
271
|
}, []);
|
|
250
272
|
|