- {!isSystemMessage && !isNotCurrentUserMessage && emojiButton}
+ {!isSystemMessage && !isNotCurrentUserMessage && }
{isNotCurrentUserMessage &&
(isUserDiscussionMessage || isBotMessage) && (
@@ -577,13 +583,13 @@ const ChatMessage = ({
>
)}
- {!isSystemMessage && isNotCurrentUserMessage && emojiButton}
+ {!isSystemMessage && isNotCurrentUserMessage && }
);
};
-const MemoizedChatMessage = React.memo(ChatMessage)
+const MemoizedChatMessage = React.memo(ChatMessage);
export default MemoizedChatMessage;
diff --git a/src/shared/constants/endpoint.ts b/src/shared/constants/endpoint.ts
index 45ac8aab6c..cf5c27a9af 100644
--- a/src/shared/constants/endpoint.ts
+++ b/src/shared/constants/endpoint.ts
@@ -8,6 +8,7 @@ export const ApiEndpoint = {
CreateCommon: "/commons/create",
UpdateCommon: "/commons/update",
CreateSubCommon: "/commons/subcommon/create",
+ MarkCommonSeenForUser: "/commons/mark-seen-for-user",
MarkFeedObjectSeenForUser: "/commons/mark-feed-object-seen-for-user",
MarkFeedObjectUnseenForUser: "/commons/mark-feed-object-unseen-for-user",
LinkStream: "/commons/link-stream",
diff --git a/src/shared/hooks/useCases/index.ts b/src/shared/hooks/useCases/index.ts
index 3b63789e06..683dbce471 100644
--- a/src/shared/hooks/useCases/index.ts
+++ b/src/shared/hooks/useCases/index.ts
@@ -47,5 +47,6 @@ export { useEligibleVoters } from "./useEligibleVoters";
export { useDiscussionMessageReaction } from "./useDiscussionMessageReaction";
export { useChatMessageReaction } from "./useChatMessageReaction";
export { useUserReaction } from "./useUserReaction";
+export { useUpdateCommonSeenState } from "./useUpdateCommonSeenState";
export * from "./useCommonFollow";
export * from "./usePreloadDiscussionMessagesById";
diff --git a/src/shared/hooks/useCases/useDiscussionMessagesById.ts b/src/shared/hooks/useCases/useDiscussionMessagesById.ts
index 1b7370a5b5..a2921fb4a1 100644
--- a/src/shared/hooks/useCases/useDiscussionMessagesById.ts
+++ b/src/shared/hooks/useCases/useDiscussionMessagesById.ts
@@ -238,148 +238,164 @@ 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(() => {
(async () => {
- if (!state.data || state.data.length === 0) {
+ if(Array.isArray(state.data) && state.data.length === 0) {
+ setIsFirstBatchLoaded((prev) => ({
+ ...prev,
+ [discussionId]: true,
+ }));
setDiscussionMessagesWithOwners([]);
- return;
}
- const discussionMessages = [...state.data];
+ if (!state.data) {
+ setDiscussionMessagesWithOwners([]);
+ return;
+ }
- // 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 00a0343d6e..2fba3af495 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(() => {
diff --git a/src/shared/hooks/useCases/useUpdateCommonSeenState.ts b/src/shared/hooks/useCases/useUpdateCommonSeenState.ts
new file mode 100644
index 0000000000..fc7b1f91e5
--- /dev/null
+++ b/src/shared/hooks/useCases/useUpdateCommonSeenState.ts
@@ -0,0 +1,43 @@
+import { useCallback } from "react";
+import { useSelector } from "react-redux";
+import { selectUser } from "@/pages/Auth/store/selectors";
+import { CommonService } from "@/services";
+import useNotification from "../useNotification";
+
+interface Return {
+ markCommonAsSeen: (
+ commonId: string,
+ delay?: number,
+ ) => ReturnType