l-min-components 1.6.1244 → 1.6.1247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -279,6 +279,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
279
279
|
const [state, setState] = useState({
|
|
280
280
|
roomsByCourses: [],
|
|
281
281
|
chats: {},
|
|
282
|
+
loadingRoomIds: new Set(), // Track which rooms are currently loading
|
|
282
283
|
});
|
|
283
284
|
// State for rooms that should be automatically marked as read
|
|
284
285
|
const [autoReadRoomIds, setAutoReadRoomIds] = useState(() => new Set());
|
|
@@ -370,7 +371,14 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
370
371
|
const getIndividualChats = async (nextPage, roomId, limit = 1000) => {
|
|
371
372
|
if (!selectedAccount) return;
|
|
372
373
|
|
|
373
|
-
|
|
374
|
+
// Add roomId to loading state
|
|
375
|
+
setState((prevState) => ({
|
|
376
|
+
...prevState,
|
|
377
|
+
loadingRoomIds: new Set([...prevState.loadingRoomIds, roomId])
|
|
378
|
+
}));
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
let response;
|
|
374
382
|
if (String(selectedAccount.type).toLowerCase() === "enterprise") {
|
|
375
383
|
response = await request({
|
|
376
384
|
url: nextPage || "/notify/v1/enterprise/chats/",
|
|
@@ -480,10 +488,34 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
480
488
|
});
|
|
481
489
|
}
|
|
482
490
|
|
|
491
|
+
// Only remove from loading state if this is the last page or there was an error
|
|
492
|
+
if (!responseData.next) {
|
|
493
|
+
setState((prevState) => {
|
|
494
|
+
const updatedLoadingRoomIds = new Set(prevState.loadingRoomIds);
|
|
495
|
+
updatedLoadingRoomIds.delete(roomId);
|
|
496
|
+
return {
|
|
497
|
+
...prevState,
|
|
498
|
+
loadingRoomIds: updatedLoadingRoomIds
|
|
499
|
+
};
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
483
503
|
// Pass roomId correctly in the recursive call
|
|
484
504
|
if (responseData.next) getIndividualChats(responseData.next, roomId);
|
|
485
505
|
return responseData;
|
|
486
|
-
}
|
|
506
|
+
} catch (error) {
|
|
507
|
+
// Remove from loading state in case of error
|
|
508
|
+
setState((prevState) => {
|
|
509
|
+
const updatedLoadingRoomIds = new Set(prevState.loadingRoomIds);
|
|
510
|
+
updatedLoadingRoomIds.delete(roomId);
|
|
511
|
+
return {
|
|
512
|
+
...prevState,
|
|
513
|
+
loadingRoomIds: updatedLoadingRoomIds
|
|
514
|
+
};
|
|
515
|
+
});
|
|
516
|
+
throw error; // Re-throw to allow error handling upstream
|
|
517
|
+
}
|
|
518
|
+
};
|
|
487
519
|
|
|
488
520
|
// read messages (using the latest message ID passed) and update counts
|
|
489
521
|
const readRoomMessages = async ({ latestMessageId, roomId }) => {
|
|
@@ -926,10 +958,49 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
926
958
|
setState(previousState);
|
|
927
959
|
}
|
|
928
960
|
};
|
|
961
|
+
const reportChat = async ({
|
|
962
|
+
reasons,
|
|
963
|
+
accountId,
|
|
964
|
+
messageIds,
|
|
965
|
+
others, // optional
|
|
966
|
+
}) => {
|
|
967
|
+
let response;
|
|
968
|
+
const data = {
|
|
969
|
+
reasons,
|
|
970
|
+
account_id: accountId,
|
|
971
|
+
message_ids: messageIds,
|
|
972
|
+
others,
|
|
973
|
+
};
|
|
974
|
+
if (selectedAccount.type.toLowerCase() === "enterprise") {
|
|
975
|
+
console.log("Reporting chat in enterprise", data);
|
|
976
|
+
response = await request({
|
|
977
|
+
url: `/notify/v1/enterprise/chats/reports/`,
|
|
978
|
+
method: "post",
|
|
979
|
+
data,
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
if (
|
|
983
|
+
selectedAccount.type.toLowerCase() === "instructor" &&
|
|
984
|
+
affiliateAccount
|
|
985
|
+
) {
|
|
986
|
+
response = await request({
|
|
987
|
+
url: `/notify/v1/instructor/${affiliateAccount}/chats/reports/`,
|
|
988
|
+
method: "post",
|
|
989
|
+
data,
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
return response;
|
|
993
|
+
};
|
|
929
994
|
// Initial data fetch effect
|
|
930
995
|
useEffect(() => {
|
|
931
996
|
(async () => {
|
|
932
997
|
await getMessageRoomsByCourses();
|
|
998
|
+
// reportChat({
|
|
999
|
+
// reasons: ["Verbal harassment"],
|
|
1000
|
+
// accountId: "24dbaeede1",
|
|
1001
|
+
// messageIds: ["438745c081564ee9aeb76ed29052bd4b"],
|
|
1002
|
+
// // others: "",
|
|
1003
|
+
// });
|
|
933
1004
|
// await deleteRoom("5be9b48281ac4c2885d3b719654ed59d");
|
|
934
1005
|
// await pinRoom("5be9b48281ac4c2885d3b719654ed59d");
|
|
935
1006
|
// Example: Fetch initial chat for a specific room if needed on load
|
|
@@ -1152,6 +1223,9 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
1152
1223
|
removeAutoReadRooms, // Expose new function
|
|
1153
1224
|
pinRoom,
|
|
1154
1225
|
deleteRoom,
|
|
1226
|
+
reportChat,
|
|
1227
|
+
// Helper method to check if a specific room is loading
|
|
1228
|
+
isRoomLoading: (roomId) => state.loadingRoomIds.has(roomId),
|
|
1155
1229
|
};
|
|
1156
1230
|
};
|
|
1157
1231
|
|