- {!isSystemMessage && !isNotCurrentUserMessage && emojiButton}
+ {!isSystemMessage && !isNotCurrentUserMessage && (
+
+ )}
{isNotCurrentUserMessage &&
(isUserDiscussionMessage || isBotMessage) && (
@@ -584,7 +575,19 @@ const ChatMessage = ({
>
)}
- {!isSystemMessage && isNotCurrentUserMessage && emojiButton}
+ {!isSystemMessage && isNotCurrentUserMessage && (
+
+ )}
diff --git a/src/shared/hooks/useCases/useDiscussionMessagesById.ts b/src/shared/hooks/useCases/useDiscussionMessagesById.ts
index 1b7370a5b..3f5bd77aa 100644
--- a/src/shared/hooks/useCases/useDiscussionMessagesById.ts
+++ b/src/shared/hooks/useCases/useDiscussionMessagesById.ts
@@ -238,75 +238,79 @@ export const useDiscussionMessagesById = ({
setIsBatchLoading(true);
}
- DiscussionMessageService.subscribeToDiscussionMessagesByDiscussionId(
- discussionId,
- lastVisible && lastVisible[discussionId],
- async (
- addedDiscussionMessages,
- modifiedDiscussionMessages,
- removedDiscussionMessages,
- lastVisibleDocument,
- ) => {
- const updatedDiscussionMessages = [
- ...addedDiscussionMessages,
- ...modifiedDiscussionMessages,
- ];
- setLastVisible((prevVisible) => ({
- ...prevVisible,
- [discussionId]: lastVisibleDocument,
- }));
-
- const hasLastVisibleDocument = !!lastVisibleDocument?.data();
-
- const discussionsWithText = await Promise.all(
- updatedDiscussionMessages.map(async (discussionMessage) => {
- const isUserDiscussionMessage =
- checkIsUserDiscussionMessage(discussionMessage);
- const isSystemMessage =
- checkIsSystemDiscussionMessage(discussionMessage);
-
- const parsedText = await getTextFromTextEditorString({
- userId,
- ownerId: isUserDiscussionMessage
- ? discussionMessage.ownerId
- : null,
- textEditorString: discussionMessage.text,
- users,
- commonId: discussionMessage.commonId,
- systemMessage: isSystemMessage ? discussionMessage : undefined,
- getCommonPagePath,
- getCommonPageAboutTabPath,
- directParent,
- onUserClick,
- onFeedItemClick,
- onInternalLinkClick,
- });
-
- return {
- ...discussionMessage,
- parsedText,
- };
- }),
- );
- if (
- discussionsWithText.length < MESSAGES_NUMBER_IN_BATCH &&
- !hasLastVisibleDocument
- ) {
- setIsEndOfList((prevIsEndOfList) => ({
- ...prevIsEndOfList,
- [discussionId]: true,
+ try {
+ DiscussionMessageService.subscribeToDiscussionMessagesByDiscussionId(
+ discussionId,
+ lastVisible && lastVisible[discussionId],
+ async (
+ addedDiscussionMessages,
+ modifiedDiscussionMessages,
+ removedDiscussionMessages,
+ lastVisibleDocument,
+ ) => {
+ const updatedDiscussionMessages = [
+ ...addedDiscussionMessages,
+ ...modifiedDiscussionMessages,
+ ];
+ setLastVisible((prevVisible) => ({
+ ...prevVisible,
+ [discussionId]: lastVisibleDocument,
}));
- }
- dispatch(
- cacheActions.updateDiscussionMessagesStateByDiscussionId({
- discussionId,
- removedDiscussionMessages,
- updatedDiscussionMessages: discussionsWithText,
- }),
- );
- setIsBatchLoading(false);
- },
- );
+
+ const hasLastVisibleDocument = !!lastVisibleDocument?.data();
+
+ const discussionsWithText = await Promise.all(
+ updatedDiscussionMessages.map(async (discussionMessage) => {
+ const isUserDiscussionMessage =
+ checkIsUserDiscussionMessage(discussionMessage);
+ const isSystemMessage =
+ checkIsSystemDiscussionMessage(discussionMessage);
+
+ const parsedText = await getTextFromTextEditorString({
+ userId,
+ ownerId: isUserDiscussionMessage
+ ? discussionMessage.ownerId
+ : null,
+ textEditorString: discussionMessage.text,
+ users,
+ commonId: discussionMessage.commonId,
+ systemMessage: isSystemMessage ? discussionMessage : undefined,
+ getCommonPagePath,
+ getCommonPageAboutTabPath,
+ directParent,
+ onUserClick,
+ onFeedItemClick,
+ onInternalLinkClick,
+ });
+
+ return {
+ ...discussionMessage,
+ parsedText,
+ };
+ }),
+ );
+ if (
+ discussionsWithText.length < MESSAGES_NUMBER_IN_BATCH &&
+ !hasLastVisibleDocument
+ ) {
+ setIsEndOfList((prevIsEndOfList) => ({
+ ...prevIsEndOfList,
+ [discussionId]: true,
+ }));
+ }
+ dispatch(
+ cacheActions.updateDiscussionMessagesStateByDiscussionId({
+ discussionId,
+ removedDiscussionMessages,
+ updatedDiscussionMessages: discussionsWithText,
+ }),
+ );
+ setIsBatchLoading(false);
+ },
+ );
+ } catch(err) {
+ setIsBatchLoading(false);
+ }
};
useDeepCompareEffect(() => {
@@ -316,70 +320,74 @@ export const useDiscussionMessagesById = ({
return;
}
- const discussionMessages = [...state.data];
-
- // if (discussionMessages.length > 0 && users.length === 0) {
- // return;
- // }
+ try {
+ const discussionMessages = [...state.data];
- const filteredMessages = discussionMessages.filter(
- ({ moderation }) =>
- moderation?.flag !== ModerationFlags.Hidden || hasPermissionToHide,
- );
- const loadedDiscussionMessages = await Promise.all(
- filteredMessages.map(async (d) => {
- const newDiscussionMessage = { ...d };
- const parentMessage = filteredMessages.find(
- ({ id }) => id === d.parentId,
- );
- if (
- checkIsUserDiscussionMessage(d) &&
- checkIsUserDiscussionMessage(newDiscussionMessage)
- ) {
- const commonMemberMessageOwner = [
- AI_USER,
- AI_PRO_USER,
- ...users,
- ...externalCommonUsers,
- ].find((o) => o.uid === d.ownerId);
- const messageOwner =
- commonMemberMessageOwner ||
- (await UserService.getUserById(d.ownerId));
- newDiscussionMessage.owner = messageOwner;
- if (!commonMemberMessageOwner && messageOwner) {
- dispatch(
- cacheActions.addUserToExternalCommonUsers({
- user: messageOwner,
- }),
- );
- }
- }
- newDiscussionMessage.parentMessage = parentMessage
- ? {
- id: parentMessage.id,
- text: parentMessage.text,
- ownerName: parentMessage?.ownerName,
- ...(checkIsUserDiscussionMessage(parentMessage) && {
- ownerId: parentMessage.ownerId,
- }),
- moderation: parentMessage?.moderation,
- images: parentMessage?.images,
- files: parentMessage?.files,
- createdAt: parentMessage.createdAt,
+ const filteredMessages = discussionMessages.filter(
+ ({ moderation }) =>
+ moderation?.flag !== ModerationFlags.Hidden || hasPermissionToHide,
+ );
+ const loadedDiscussionMessages = await Promise.all(
+ filteredMessages.map(async (d) => {
+ const newDiscussionMessage = { ...d };
+ const parentMessage = filteredMessages.find(
+ ({ id }) => id === d.parentId,
+ );
+ if (
+ checkIsUserDiscussionMessage(d) &&
+ checkIsUserDiscussionMessage(newDiscussionMessage)
+ ) {
+ const commonMemberMessageOwner = [
+ AI_USER,
+ AI_PRO_USER,
+ ...users,
+ ...externalCommonUsers,
+ ].find((o) => o.uid === d.ownerId);
+ const messageOwner =
+ commonMemberMessageOwner ||
+ (await UserService.getUserById(d.ownerId));
+ newDiscussionMessage.owner = messageOwner;
+ if (!commonMemberMessageOwner && messageOwner) {
+ dispatch(
+ cacheActions.addUserToExternalCommonUsers({
+ user: messageOwner,
+ }),
+ );
}
- : null;
-
- return newDiscussionMessage;
- }),
- );
-
- setDiscussionMessagesWithOwners(loadedDiscussionMessages);
- setIsFirstBatchLoaded((prev) => ({
- ...prev,
- [discussionId]: true,
- }));
+ }
+ newDiscussionMessage.parentMessage = parentMessage
+ ? {
+ id: parentMessage.id,
+ text: parentMessage.text,
+ ownerName: parentMessage?.ownerName,
+ ...(checkIsUserDiscussionMessage(parentMessage) && {
+ ownerId: parentMessage.ownerId,
+ }),
+ moderation: parentMessage?.moderation,
+ images: parentMessage?.images,
+ files: parentMessage?.files,
+ createdAt: parentMessage.createdAt,
+ }
+ : null;
+
+ return newDiscussionMessage;
+ }),
+ );
+
+ setDiscussionMessagesWithOwners(loadedDiscussionMessages);
+ setIsFirstBatchLoaded((prev) => ({
+ ...prev,
+ [discussionId]: true,
+ }));
+ } catch(err) {
+ setDiscussionMessagesWithOwners([]);
+ setIsFirstBatchLoaded((prev) => ({
+ ...prev,
+ [discussionId]: true,
+ }));
+ }
})();
- }, [state.data, hasPermissionToHide, users, externalCommonUsers]);
+ }, [state.data, hasPermissionToHide, users, externalCommonUsers, discussionId]);
return {
...state,
diff --git a/src/shared/hooks/useCases/usePreloadDiscussionMessagesById.ts b/src/shared/hooks/useCases/usePreloadDiscussionMessagesById.ts
index 00a0343d6..2fba3af49 100644
--- a/src/shared/hooks/useCases/usePreloadDiscussionMessagesById.ts
+++ b/src/shared/hooks/useCases/usePreloadDiscussionMessagesById.ts
@@ -59,48 +59,58 @@ export const usePreloadDiscussionMessagesById = ({
return;
}
- const discussionMessages =
- await DiscussionMessageService.getPreloadDiscussionMessagesByDiscussionId(
- discussionId,
+ try {
+ const discussionMessages =
+ await DiscussionMessageService.getPreloadDiscussionMessagesByDiscussionId(
+ discussionId,
+ );
+
+ const users = commonMembers.map(({ user }) => user);
+
+ const discussionsWithText = await Promise.all(
+ discussionMessages.map(async (discussionMessage) => {
+ const isUserDiscussionMessage =
+ checkIsUserDiscussionMessage(discussionMessage);
+ const isSystemMessage =
+ checkIsSystemDiscussionMessage(discussionMessage);
+
+ const parsedText = await getTextFromTextEditorString({
+ userId,
+ ownerId: isUserDiscussionMessage ? discussionMessage.ownerId : null,
+ textEditorString: discussionMessage.text,
+ users,
+ commonId: discussionMessage.commonId,
+ systemMessage: isSystemMessage ? discussionMessage : undefined,
+ getCommonPagePath,
+ getCommonPageAboutTabPath,
+ onUserClick,
+ onFeedItemClick,
+ onInternalLinkClick,
+ });
+
+ return {
+ ...discussionMessage,
+ parsedText,
+ };
+ }),
);
-
- const users = commonMembers.map(({ user }) => user);
-
- const discussionsWithText = await Promise.all(
- discussionMessages.map(async (discussionMessage) => {
- const isUserDiscussionMessage =
- checkIsUserDiscussionMessage(discussionMessage);
- const isSystemMessage =
- checkIsSystemDiscussionMessage(discussionMessage);
-
- const parsedText = await getTextFromTextEditorString({
- userId,
- ownerId: isUserDiscussionMessage ? discussionMessage.ownerId : null,
- textEditorString: discussionMessage.text,
- users,
- commonId: discussionMessage.commonId,
- systemMessage: isSystemMessage ? discussionMessage : undefined,
- getCommonPagePath,
- getCommonPageAboutTabPath,
- onUserClick,
- onFeedItemClick,
- onInternalLinkClick,
- });
-
- return {
- ...discussionMessage,
- parsedText,
- };
- }),
- );
-
- dispatch(
- cacheActions.updateDiscussionMessagesStateByDiscussionId({
- discussionId,
- updatedDiscussionMessages: discussionsWithText,
- removedDiscussionMessages: [],
- }),
- );
+
+ dispatch(
+ cacheActions.updateDiscussionMessagesStateByDiscussionId({
+ discussionId,
+ updatedDiscussionMessages: discussionsWithText,
+ removedDiscussionMessages: [],
+ }),
+ );
+ } catch(err) {
+ dispatch(
+ cacheActions.updateDiscussionMessagesStateByDiscussionId({
+ discussionId,
+ updatedDiscussionMessages: [],
+ removedDiscussionMessages: [],
+ }),
+ );
+ }
};
useEffect(() => {