isometrik-chat 0.1.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.
Files changed (188) hide show
  1. package/README.md +74 -0
  2. package/babel.config.js +6 -0
  3. package/dist/index.js +684 -0
  4. package/package.json +59 -0
  5. package/public/Logo-192x192.png +0 -0
  6. package/public/Logo-512x512.png +0 -0
  7. package/public/favicon.ico +0 -0
  8. package/public/fonts/BenjaminVictoria.ttf +0 -0
  9. package/public/icons/arrow_logo.svg +9 -0
  10. package/public/icons/assets/ic_placeholder_banner.svg +1 -0
  11. package/public/icons/attach-file.svg +9 -0
  12. package/public/icons/audio_pause.svg +1 -0
  13. package/public/icons/audio_play.svg +6 -0
  14. package/public/icons/back.svg +3 -0
  15. package/public/icons/bell.svg +1 -0
  16. package/public/icons/block.svg +1 -0
  17. package/public/icons/bottom-arrow.svg +1 -0
  18. package/public/icons/camera-switch.svg +12 -0
  19. package/public/icons/camera.svg +4 -0
  20. package/public/icons/cancel.svg +1 -0
  21. package/public/icons/chat empty placeholder.svg +58 -0
  22. package/public/icons/chat_audio_pause.png +0 -0
  23. package/public/icons/chat_audio_play.png +0 -0
  24. package/public/icons/close.svg +5 -0
  25. package/public/icons/crossCarousel.svg +3 -0
  26. package/public/icons/delete.svg +3 -0
  27. package/public/icons/disappear.svg +24 -0
  28. package/public/icons/document.png +0 -0
  29. package/public/icons/document.svg +1 -0
  30. package/public/icons/downloadCarousel.svg +6 -0
  31. package/public/icons/edit-pencil.svg +6 -0
  32. package/public/icons/emoji.svg +8 -0
  33. package/public/icons/emojiCarousel.svg +3 -0
  34. package/public/icons/filter.svg +1 -0
  35. package/public/icons/forwardCarousel.svg +3 -0
  36. package/public/icons/gallery.svg +1 -0
  37. package/public/icons/goToMessageCarousel.svg +3 -0
  38. package/public/icons/ic_uil_arrow-left.svg +1 -0
  39. package/public/icons/ic_uil_eye-slash.svg +1 -0
  40. package/public/icons/ic_uil_eye.svg +1 -0
  41. package/public/icons/leftArrowCarousel.svg +6 -0
  42. package/public/icons/light-mode.svg +14 -0
  43. package/public/icons/lock.svg +1 -0
  44. package/public/icons/login_background.png +0 -0
  45. package/public/icons/menu .svg +5 -0
  46. package/public/icons/menuCarousel.svg +5 -0
  47. package/public/icons/message.svg +3 -0
  48. package/public/icons/placeholder.svg +958 -0
  49. package/public/icons/poll.svg +1 -0
  50. package/public/icons/retake.png +0 -0
  51. package/public/icons/right-arrow.svg +3 -0
  52. package/public/icons/right.svg +3 -0
  53. package/public/icons/round-star.svg +1 -0
  54. package/public/icons/search.svg +3 -0
  55. package/public/icons/send.svg +10 -0
  56. package/public/icons/starCarousel.svg +3 -0
  57. package/public/icons/status.svg +1 -0
  58. package/public/icons/sticker.svg +1 -0
  59. package/public/icons/thumb-down.svg +1 -0
  60. package/public/icons/user.svg +1 -0
  61. package/public/icons/users.svg +1 -0
  62. package/public/icons/voice.png +0 -0
  63. package/public/index.html +38 -0
  64. package/public/logo192.png +0 -0
  65. package/public/logo512.png +0 -0
  66. package/public/manifest.json +25 -0
  67. package/public/offline.html +12 -0
  68. package/public/robots.txt +3 -0
  69. package/public/service-worker.js +81 -0
  70. package/src/App.js +15 -0
  71. package/src/App.test.js +8 -0
  72. package/src/Authpage.js +16 -0
  73. package/src/ChatContext.js +172 -0
  74. package/src/Data/index.js +110 -0
  75. package/src/assets/icons.js +49 -0
  76. package/src/assets/images/WhatsApp.html +258 -0
  77. package/src/assets/images/WhatsApp_files/301446776_522918349234681_1974693392291574064_n.jpg +0 -0
  78. package/src/assets/images/WhatsApp_files/app-bf223f825866ee433b07.css +242 -0
  79. package/src/assets/images/WhatsApp_files/app.77ee8aa7a4c593101105.js +77 -0
  80. package/src/assets/images/WhatsApp_files/lazy_loaded_high_priority_components.85a06e74a0a4ade1640b.css +16 -0
  81. package/src/assets/images/WhatsApp_files/lazy_loaded_low_priority_components.8621270bc215a9298a97.css +47 -0
  82. package/src/assets/images/WhatsApp_files/libsignal-protocol-ee5b8ba.min.js +21 -0
  83. package/src/assets/images/WhatsApp_files/main.48b845d68e066fb27a75.css +161 -0
  84. package/src/assets/images/WhatsApp_files/runtime.e6018f3c1e255e8f4dc7.js +2 -0
  85. package/src/assets/images/WhatsApp_files/stylex-d50abd61e6cf7eab2afd855adccf14e5.css +2841 -0
  86. package/src/assets/images/WhatsApp_files/vendor1_app.58a51d93a250f83ab555.js +79 -0
  87. package/src/assets/images/bg.jpeg +0 -0
  88. package/src/assets/images/drkbg.jpg +0 -0
  89. package/src/assets/images/notFound.jpeg +0 -0
  90. package/src/assets/images/watsapp.jpg +0 -0
  91. package/src/assets/images/watsappbg.png +0 -0
  92. package/src/assets/images/wb.jpg +0 -0
  93. package/src/assets/images/whatsapp.jpeg +0 -0
  94. package/src/components/ChatBox/AudioBubble.js +162 -0
  95. package/src/components/ChatBox/ChatBubble.js +232 -0
  96. package/src/components/ChatBox/DocumentBubble.js +87 -0
  97. package/src/components/ChatBox/MessagesBox.js +533 -0
  98. package/src/components/CustomModal.js +60 -0
  99. package/src/components/Icon.js +10 -0
  100. package/src/components/ImageComponent.js +24 -0
  101. package/src/components/MediaDocs.js +155 -0
  102. package/src/components/MediaDocumentContainer.js +55 -0
  103. package/src/components/MessageInfoDropdown.js +124 -0
  104. package/src/components/Modal/AllowMicPermissionModal.js +63 -0
  105. package/src/components/Modal/BlockUnblockChatModal.js +78 -0
  106. package/src/components/Modal/CameraPermissionBlockedModal.js +61 -0
  107. package/src/components/Modal/CameraPermissionRequestModal.js +60 -0
  108. package/src/components/Modal/ClearChatModal.js +78 -0
  109. package/src/components/Modal/DeleteChatModal.js +79 -0
  110. package/src/components/Modal/MicPermissionDisableModal.js +63 -0
  111. package/src/components/Modal/Modal.js +103 -0
  112. package/src/components/Modal/ModalDialog.js +103 -0
  113. package/src/components/Modal/ProfilePictureUploadPreview.js +160 -0
  114. package/src/components/OutsideAlerter/OutsideAlerter.js +38 -0
  115. package/src/components/ProfilePicture/ProfilePicture.js +127 -0
  116. package/src/components/Registration/Login.js +265 -0
  117. package/src/components/Registration/SignUp.js +322 -0
  118. package/src/components/SnackBar.js +42 -0
  119. package/src/components/common/Modal/useDetectOutsideClick.js +23 -0
  120. package/src/components/common/styled/PageWrapper.js +25 -0
  121. package/src/components/formcontrol/CustomButton.js +38 -0
  122. package/src/components/formcontrol/InputText.js +60 -0
  123. package/src/global-styles.js +42 -0
  124. package/src/hooks/useDeviceType.js +28 -0
  125. package/src/hooks/useThrottle.js +29 -0
  126. package/src/index.css +225 -0
  127. package/src/index.js +23 -0
  128. package/src/lib/constant.js +21 -0
  129. package/src/lib/functionality.js +13 -0
  130. package/src/lib/helpers.js +320 -0
  131. package/src/lib/mockData/index.js +76 -0
  132. package/src/lib/session/index.js +31 -0
  133. package/src/lib/validation.js +4 -0
  134. package/src/logo.svg +1 -0
  135. package/src/pages/WhatsappMainBox/index.js +574 -0
  136. package/src/reportWebVitals.js +13 -0
  137. package/src/services/deliveryStatus.js +27 -0
  138. package/src/setupTests.js +5 -0
  139. package/src/utils/chatSdk.js +14 -0
  140. package/src/utils/global.js +57 -0
  141. package/src/utils/media.js +79 -0
  142. package/src/view/component/BlockedContactSlide.js +134 -0
  143. package/src/view/component/Carousle/UpperMenuBar.js +106 -0
  144. package/src/view/component/Carousle/index.js +204 -0
  145. package/src/view/component/Chatbox.js/AudioRecorder.js +311 -0
  146. package/src/view/component/Chatbox.js/ChatBubbleReply.js +27 -0
  147. package/src/view/component/Chatbox.js/TakePhoto.js +363 -0
  148. package/src/view/component/Chatbox.js/index.js +856 -0
  149. package/src/view/component/Chatbox.js/styles.css +231 -0
  150. package/src/view/component/Contact/index.js +56 -0
  151. package/src/view/component/Contact/styles.css +208 -0
  152. package/src/view/component/ContactInfo/index.js +543 -0
  153. package/src/view/component/ContactInfo/styles.css +289 -0
  154. package/src/view/component/Context/index.js +3 -0
  155. package/src/view/component/DialogBox.js +15 -0
  156. package/src/view/component/ImageCropper/ImageCropper.js +128 -0
  157. package/src/view/component/Loader/Loader.js +52 -0
  158. package/src/view/component/Loader/UserPagingLoader.js +62 -0
  159. package/src/view/component/MainChatBox/index.js +819 -0
  160. package/src/view/component/MainChatBox/styles.css +124 -0
  161. package/src/view/component/Menu/index.js +261 -0
  162. package/src/view/component/Menu/styles.css +68 -0
  163. package/src/view/component/Profile/ProfileInfoContainer.js +112 -0
  164. package/src/view/component/Profile/ProfileUpdate.js +178 -0
  165. package/src/view/component/Profile/TakeProfilePhoto.js +391 -0
  166. package/src/view/component/Profile/index.js +550 -0
  167. package/src/view/component/Profile/styles.css +370 -0
  168. package/src/view/component/ReplyChatMessage/ReplyChatMessage.js +48 -0
  169. package/src/view/component/SeachBar/index.js +106 -0
  170. package/src/view/component/SeachBar/styles.css +53 -0
  171. package/src/view/component/Siderbar/index.js +512 -0
  172. package/src/view/component/Siderbar/styles.css +138 -0
  173. package/src/view/component/Toaster/Toaster.js +117 -0
  174. package/src/view/component/UserDetailsCard/UserDetailCard.js +337 -0
  175. package/src/view/component/deleteMessageMoal.js +80 -0
  176. package/src/view/component/emoji/index.js +22 -0
  177. package/src/view/component/emoji/sstyles.css +0 -0
  178. package/src/view/component/forwardData/index.js +327 -0
  179. package/src/view/component/forwardData/styles.css +112 -0
  180. package/src/view/component/forwardPopup/index.js +55 -0
  181. package/src/view/component/forwardPopup/styles.css +144 -0
  182. package/src/view/component/mediaList/index.js +92 -0
  183. package/src/view/component/menuDialog/index.js +71 -0
  184. package/src/view/component/menuDialog/styles.css +24 -0
  185. package/src/view/component/pagination/pagination.js +52 -0
  186. package/src/view/component/pagination/paginationForMsg.js +43 -0
  187. package/src/view/component/sidebarChat/index.js +321 -0
  188. package/src/view/component/sidebarChat/styles.css +109 -0
@@ -0,0 +1,92 @@
1
+ import React, { useState } from "react";
2
+ import styled from "styled-components";
3
+ import ImageComponent from "../../../components/ImageComponent";
4
+ import { isImage, isVideo } from "../../../lib/helpers";
5
+ import { mediaListing } from "../../../lib/mockData/index";
6
+
7
+ const MediaListConatiner = styled.div`
8
+ display: flex;
9
+ padding: 0px 30px;
10
+ overflow: scroll;
11
+ ::-webkit-scrollbar {
12
+ display: none;
13
+ }
14
+ -ms-overflow-style: none;
15
+ scrollbar-width: none;
16
+ `;
17
+
18
+ const MediaBody = styled.div`
19
+ height: 100px;
20
+ width: 100px;
21
+ margin: 4px;
22
+ `;
23
+
24
+ const MediaDocs = styled.div`
25
+ display: flex;
26
+ background-color: var(--chat-info-drawer-media-background);
27
+ border-radius: 10px;
28
+ background-image: linear-gradient(
29
+ rgba(0, 0, 0, 0) 70%,
30
+ rgba(0, 0, 0, 0.6) 100%
31
+ );
32
+
33
+ .media-images {
34
+ height: 100px;
35
+ width: 100px;
36
+ padding: 5px;
37
+ backgroundrepeat: no-repeat;
38
+ backgroundsize: cover;
39
+ object-fit: cover;
40
+ }
41
+ `;
42
+
43
+ function MediaList(props) {
44
+ const { conversationId, message, setTotalMediaFiles, totalMediaFiles } =
45
+ props;
46
+ const mediaFile = message?.messages[conversationId]?.filter((data) => {
47
+ return data?.attachments && data?.attachments?.[0]?.mediaUrl.length > 0;
48
+ });
49
+ // const filteredData = mediaFile.filter(item => item.customType !== 'audio');
50
+ const filteredData = mediaFile.filter(item => isImage(item.attachments[0]?.extension) || isVideo(item.attachments[0]?.extension));
51
+
52
+ setTotalMediaFiles(filteredData.length);
53
+ // filteredData.length = 3;
54
+ return (
55
+ <MediaListConatiner>
56
+ {filteredData?.map((data) => {
57
+ const fileExtension = data?.attachments[0]?.extension;
58
+ if (isImage(fileExtension)) {
59
+ return (
60
+ <MediaBody key={data?.id}>
61
+ <MediaDocs>
62
+ <ImageComponent
63
+ className="media-images"
64
+ src={data.attachments[0]?.mediaUrl}
65
+ />
66
+ </MediaDocs>
67
+ </MediaBody>
68
+ );
69
+ } else if (isVideo(fileExtension)) {
70
+ return (
71
+ <MediaBody key={data?.id}>
72
+ <MediaDocs>
73
+ <video
74
+ controls
75
+ style={{ objectFit: "contain" }}
76
+ className="media-images"
77
+ >
78
+ <source
79
+ src={data.attachments[0]?.mediaUrl}
80
+ type="video/mp4"
81
+ />
82
+ </video>
83
+ </MediaDocs>
84
+ </MediaBody>
85
+ );
86
+ }
87
+ })}
88
+ </MediaListConatiner>
89
+ );
90
+ }
91
+
92
+ export default MediaList;
@@ -0,0 +1,71 @@
1
+ import React, { useState } from "react";
2
+ import "./styles.css";
3
+ import client from "../../../utils/chatSdk";
4
+
5
+ function MenuDialog(props) {
6
+ const { state, dispatch,menuData,setIsMenu,setIsLogOut, modalRef, setClearChatModal, setDeleteChatModal, handleClickSlideShow, setUserBlockModal, userConversationDetail,setIsBlockedList,setMessageInfo, setIsOpen, chat, setMessageChat,messageChat,setslideShow,setSearchShow,setIsReply,setReply,reply,setDeleteMessage,deleteMessage,getReplyMessageData} = props;
7
+ const [isForword, setIsForword] = useState(false);
8
+
9
+ const menuClick = (data, index) => {
10
+ if (index === 0) {
11
+ client?.user
12
+ ?.getUsers()
13
+ .then((res) =>
14
+ {}
15
+ // dispatch({ type: "ProfileAllUsers", payload: res?.users })
16
+ )
17
+ .catch((err) => console.log(err, "err"));
18
+ }
19
+ if (data == "Forword message") {
20
+ setIsForword(data);
21
+ props?.childData(data);
22
+ }else if (data.header === 'Clear chat') {
23
+ setClearChatModal(true);
24
+ }else if (data.header === 'Delete chat') {
25
+ setDeleteChatModal(true);
26
+ }else if (data.header === 'Contact info') {
27
+ handleClickSlideShow();
28
+ }else if (data.header === 'Block' || data.header === 'Unblock') {
29
+ setUserBlockModal(true);
30
+ }
31
+ else if (data.header === "Message info") {
32
+ setMessageInfo(true);
33
+ setslideShow(false);
34
+ setSearchShow(false);
35
+ setMessageChat(chat)
36
+ }
37
+ // if (data.header === "Reply") {
38
+ // setIsReply(true);
39
+ // setReply({ ...reply , isreply:true , data:{chat}})
40
+ // getReplyMessageData(chat);
41
+ // }
42
+
43
+ if (data.header === "Delete Message") {
44
+ setDeleteMessage({...deleteMessage,delete:true,data:{chat}})
45
+ }
46
+
47
+ if (data.id === 5) {
48
+ setIsLogOut(true);
49
+ }
50
+ if (data.id === 4) {
51
+ setIsBlockedList(true);
52
+ }
53
+ setIsMenu(false);
54
+ };
55
+
56
+
57
+
58
+ return (
59
+ <div ref={modalRef} className="menu">
60
+ {menuData?.length>0 && menuData.map((data, index) => {
61
+ return (
62
+ <div className="menuBox pointer" key={index}>
63
+ <p onClick={() => menuClick(data, index)}>{data.header} </p>
64
+ </div>
65
+ );
66
+ })}
67
+ </div>
68
+ );
69
+ }
70
+
71
+ export default MenuDialog;
@@ -0,0 +1,24 @@
1
+ .menuBox p {
2
+ padding: 0 2rem;
3
+ margin: 0;
4
+ line-height: 2.5rem;
5
+ display: flex;
6
+ justify-content: space-between;
7
+ align-items: center;
8
+ font-size: 14.5px;
9
+ color: var(--primary);
10
+ padding-right: 58px !important;
11
+ white-space: nowrap;
12
+ }
13
+
14
+ .menu p:hover {
15
+ background-color: var(--white);
16
+ }
17
+
18
+ .menu{
19
+ z-index: 999;
20
+ width:100%;
21
+
22
+
23
+ box-shadow:none !important
24
+ }
@@ -0,0 +1,52 @@
1
+ import React, { useEffect, useState } from 'react';
2
+
3
+ const around = (n, value) => (value >= n - 5 && value <= n + 5);
4
+
5
+ const PaginationIndicator = (props) => {
6
+ const { id, totalData, pageEventHandler, elementRef, ...others } = props;
7
+ const [pageChange, setPageChange] = useState(0);
8
+
9
+ useEffect(() => {
10
+ const elementNode = document.getElementById(id)
11
+ || (elementRef && elementRef.current);
12
+ if (elementNode) {
13
+ elementNode.addEventListener('scroll', () => {
14
+ const isScrollTouchingBottom = around(
15
+ parseInt(elementNode.scrollHeight), // eslint-disable-line
16
+ parseInt(elementNode.scrollTop) + parseInt(elementNode.clientHeight) // eslint-disable-line
17
+ );
18
+ if (isScrollTouchingBottom && parseInt(elementNode.scrollTop)) { // eslint-disable-line
19
+ setPageChange(Math.random());
20
+ }
21
+ });
22
+ }
23
+ }, []);
24
+
25
+ useEffect(() => {
26
+ const elementNode = document.getElementById(id)
27
+ || (elementRef && elementRef.current);
28
+ if (elementNode) {
29
+ const isScrollTouchingBottom = around(
30
+ parseInt(elementNode.scrollHeight), // eslint-disable-line
31
+ parseInt(elementNode.scrollTop) + parseInt(elementNode.clientHeight) // eslint-disable-line
32
+ );
33
+ if (isScrollTouchingBottom) {
34
+ if (pageEventHandler) {
35
+ pageEventHandler();
36
+ }
37
+ }
38
+ }
39
+ }, [pageChange]);
40
+
41
+ useEffect(() => (
42
+ () => {
43
+ const elementNode = document.getElementById(id)
44
+ || (elementRef && elementRef.current);
45
+ if (elementNode) {
46
+ elementNode.removeEventListener('scroll', () => null);
47
+ }
48
+ }
49
+ ), []);
50
+ return <div {...others}>{props.children}</div>;
51
+ };
52
+ export default PaginationIndicator;
@@ -0,0 +1,43 @@
1
+ import React, { useEffect, useState } from 'react';
2
+
3
+ const PaginationForMsg = (props) => {
4
+ const { id, totalData, pageEventHandler, elementRef, ...others } = props;
5
+ const [pageChange, setPageChange] = useState(0);
6
+ useEffect(() => {
7
+ const elementNode = document.getElementById(id)
8
+ || (elementRef && elementRef.current);
9
+ if (elementNode) {
10
+ elementNode.addEventListener('scroll', () => {
11
+ const isScrollTouchingTop = parseInt(elementNode.scrollTop) === 0;
12
+ if (isScrollTouchingTop) {
13
+ setPageChange(Math.random());
14
+ }
15
+ });
16
+ }
17
+ }, []);
18
+
19
+ useEffect(() => {
20
+ const elementNode = document.getElementById(id)
21
+ || (elementRef && elementRef.current);
22
+ if (elementNode) {
23
+ const isScrollTouchingTop = parseInt(elementNode.scrollTop) === 0;
24
+ if (isScrollTouchingTop) {
25
+ if (pageEventHandler) {
26
+ pageEventHandler();
27
+ }
28
+ }
29
+ }
30
+ }, [pageChange]);
31
+
32
+ useEffect(() => (
33
+ () => {
34
+ const elementNode = document.getElementById(id)
35
+ || (elementRef && elementRef.current);
36
+ if (elementNode) {
37
+ elementNode.removeEventListener('scroll', () => null);
38
+ }
39
+ }
40
+ ), []);
41
+ return <div {...others}>{props.children}</div>;
42
+ };
43
+ export default PaginationForMsg;
@@ -0,0 +1,321 @@
1
+ import React, { useEffect, useRef, useState } from "react";
2
+ import "./styles.css";
3
+ import { chatList } from "../../../Data";
4
+ import { fontSize } from "../../../Data";
5
+ import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
6
+ // import Menu from "../Menu";
7
+ import { createContext } from "react";
8
+ import { ArrowContext } from "../Context";
9
+ import notFound from "../../../assets/images/notFound.jpeg";
10
+ import Badge from "@mui/material/Badge";
11
+ import MenuDialog from "../menuDialog/index";
12
+ import Menu from "@mui/material/Menu";
13
+ import ImageComponent from "../../../components/ImageComponent";
14
+ import {
15
+ ARROW_LOGO,
16
+ BOTTOM_ARROW,
17
+ Empty_Chat_Placeholder,
18
+ } from "../../../utils/global";
19
+ import styled from "styled-components";
20
+ import PaginationIndicator from "../pagination/pagination";
21
+ import UserDetailCard from "../UserDetailsCard/UserDetailCard";
22
+ import { getUserConversationDetails } from "../../../lib/helpers";
23
+ import UserPagingLoader from "../Loader/UserPagingLoader";
24
+ import client from "../../../utils/chatSdk";
25
+ import { CLEAR_CHAT, DELETE_CHAT, MESSAGE_DELETE_FOR_ALL, MESSAGE_DELETE_LOCAL, MESSAGE_DELIVERED, MESSAGE_READ } from "../../../lib/constant";
26
+ import { markMessagesAsRead, putIndicateMessageRead } from "../../../services/deliveryStatus";
27
+ import { getCookie } from "../../../lib/session";
28
+
29
+ let dataCollection = [];
30
+ let aar = [];
31
+ let markRead = [];
32
+
33
+ const EmptyChatPlaceholder = styled.div`
34
+ position: absolute;
35
+ bottom: 50%;
36
+ .emptyImage {
37
+ vertical-align: bottom;
38
+ height: 1005;
39
+ height: 100%;
40
+ width: 100%;
41
+ }
42
+ `;
43
+
44
+ const TextPlaceholder = styled.div`
45
+ padding:0px 35px;
46
+ align-items:center;
47
+ margin:auto;
48
+ text-align: center;
49
+ cursor:pointer;
50
+ color:var(--black);
51
+ }
52
+ `;
53
+
54
+ function SidebarChat({
55
+ sideData,
56
+ dataHandler,
57
+ disabledKey,
58
+ state,
59
+ dispatch,
60
+ getPaginationHomePageData,
61
+ findUserId,
62
+ currentUserConversationDetails,
63
+ setCurrentUserConversationDetails,
64
+ getHomePageConversationData,
65
+ sidebarChatItem,
66
+ setShowLoader,
67
+ showConversationPagingLoader,
68
+ sidebarData,
69
+ userDetails,
70
+ messageSlidebar,
71
+ profileClose,
72
+ setMediaDocs
73
+ }) {
74
+ const [isShown, setIsShown] = useState();
75
+ const [pinChat, setPinChat] = useState(false);
76
+ const AppContext = createContext();
77
+ const [isModalShow, setIsMdalShow] = useState(false);
78
+ const [chatListItem, setChatListItem] = useState();
79
+ const Delete = localStorage.getItem("deleteIndex");
80
+ const Pin = localStorage.getItem("pinIndex");
81
+ const [pinIcon, setPinIcon] = useState(false);
82
+ const [key, setKey] = useState();
83
+ const [pinedData, setPinedData] = useState();
84
+ const [markedData, setMarkedData] = useState();
85
+ const [anchorEl, setAnchorEl] = React.useState(null);
86
+ const [currentUserId, setCurrentUserId ] = useState('');
87
+ const open = Boolean(anchorEl);
88
+ const pageScrollHomePageRef = useRef(null);
89
+
90
+ const handleClick = (event) => {
91
+ setAnchorEl(event.currentTarget);
92
+ };
93
+
94
+ const handleClosemodal = () => {
95
+ setAnchorEl(null);
96
+ };
97
+
98
+ const arrowHandler = (index, event, data) => {
99
+ setAnchorEl(event.currentTarget);
100
+ // setIsMdalShow(false);
101
+ // setIsShown(index);
102
+ // setPinedData(data);
103
+ // setMarkedData(data);
104
+ // console.log("nnn", index,data)
105
+ };
106
+
107
+ const userId = getCookie("userId");
108
+
109
+ useEffect(() => {
110
+ setChatListItem(sideData);
111
+ }, [sideData?.length]);
112
+
113
+ const getUnreadMessageCount = async (conId) => {
114
+ try {
115
+ const unreadCount = await client.message.getUnreadCount({conversationId: conId});
116
+ return unreadCount;
117
+ } catch (error) {
118
+ console.error('error', error);
119
+ }
120
+ }
121
+
122
+ const getNewUserData = async(conId) => {
123
+ try {
124
+ const newUserData = await getUserConversationDetails(conId);
125
+ return newUserData;
126
+ } catch (error) {
127
+ console.error('error', error);
128
+ }
129
+ }
130
+
131
+ const getConversationListSorted = async () => {
132
+ if (chatListItem?.length) {
133
+ const currIndex = chatListItem.findIndex(
134
+ (obj) =>
135
+ obj?.conversationId === findUserId?.conversationId
136
+ );
137
+ const filteredData = chatListItem.filter(
138
+ (obj) =>
139
+ obj?.conversationId === findUserId?.conversationId
140
+ )[0];
141
+ if (findUserId?.messageId && findUserId.action !== MESSAGE_DELIVERED ) {
142
+ if (currIndex !== -1) {
143
+ if (findUserId?.conversationId === state.selectedConvId) {
144
+ if (findUserId?.body && userId !== findUserId?.senderId) {
145
+ putIndicateMessageRead(findUserId?.messageId, findUserId?.conversationId);
146
+ chatListItem[currIndex].unreadMessagesCount = 0;
147
+ }
148
+ }else {
149
+ const unreadCount = await getUnreadMessageCount(findUserId.conversationId);
150
+ chatListItem[currIndex].unreadMessagesCount = unreadCount?.count || 0;
151
+ }
152
+ if(findUserId.action === MESSAGE_READ) return; // to prevent new message to disappear from sidechat bar
153
+ chatListItem[currIndex].lastMessageDetails.body = findUserId.body;
154
+ chatListItem[currIndex].lastMessageDetails.sentAt = findUserId.sentAt;
155
+ chatListItem.splice(currIndex, 1);
156
+ chatListItem.unshift(filteredData);
157
+ setChatListItem([...chatListItem]);
158
+ } else {
159
+ const newUserData = await getNewUserData(findUserId.conversationId);
160
+ setChatListItem([newUserData, ...chatListItem]);
161
+ }
162
+ }
163
+ else if ((findUserId?.action === MESSAGE_DELETE_FOR_ALL || findUserId?.action === MESSAGE_DELETE_LOCAL) ) {
164
+ const currentChatObj = state.messages[findUserId?.conversationId].filter(data => data?.body);
165
+ const findMessageIndex = state?.messages[findUserId?.conversationId].findIndex(
166
+ (obj) =>
167
+ (obj.messageId === findUserId?.messageIds[0])
168
+ );
169
+ chatListItem[currIndex].lastMessageDetails.body = currentChatObj[findMessageIndex === 0 ? 1 : 0]?.body;
170
+ chatListItem[currIndex].lastMessageDetails.sentAt = currentChatObj[findMessageIndex === 0 ? 1 : 0]?.sentAt;
171
+ }
172
+ else if (findUserId.action === CLEAR_CHAT) {
173
+ chatListItem[currIndex].lastMessageDetails.body = "";
174
+ }
175
+ else if (findUserId.action === DELETE_CHAT) {
176
+ sidebarData(false);
177
+ chatListItem.splice(currIndex, 1);
178
+ setChatListItem([...chatListItem]);
179
+ }
180
+
181
+ if (findUserId.messageId) {
182
+ pageScrollHomePageRef.current.scrollTop = 0;
183
+ }
184
+ }else if (findUserId?.messageId) { // When user don't have any chats(chatListItem.length === 0)
185
+ const newUserData = await getNewUserData(findUserId.conversationId);
186
+ setChatListItem([newUserData, ...chatListItem]);
187
+ }
188
+ };
189
+
190
+ useEffect(() => {
191
+ getConversationListSorted();
192
+ setCurrentUserId(findUserId?.userId);
193
+ }, [findUserId]);
194
+
195
+ // const chatDelete = (deleteItem) => {
196
+ // const chat = chatListItem.filter((data) => data?.id != deleteItem);
197
+ // setChatListItem(chat);
198
+ // setIsMdalShow(!isModalShow);
199
+ // chatListItem?.map((data, _) => {
200
+ // if (data?.id == deleteItem) {
201
+ // }
202
+ // });
203
+ // };
204
+
205
+ const handleClose = () => {
206
+ setIsMdalShow(!isModalShow);
207
+ };
208
+
209
+ const chatUnPin = (unpinItem) => {
210
+ const result = chatListItem?.filter((data) => data?.id == unpinItem);
211
+ chatListItem.push(result[0]);
212
+ chatListItem.shift();
213
+ const unpin = aar.filter((data) => data != unpinItem);
214
+ aar = [];
215
+ aar = [...unpin];
216
+ setIsMdalShow(!isModalShow);
217
+ };
218
+
219
+ const markChatPin = (markItem) => {
220
+ markRead.push(markItem);
221
+ const result = chatListItem.filter((data) => data?.id == markItem);
222
+ result.forEach((object) => {
223
+ object.mark = "marked";
224
+ });
225
+
226
+ setIsMdalShow(!isModalShow);
227
+ };
228
+
229
+ const markUnchat = (unMarkItem) => {
230
+ const unmark = markRead.filter((data) => data != unMarkItem);
231
+ markRead = [];
232
+ markRead = [...unmark];
233
+ setIsMdalShow(!isModalShow);
234
+ };
235
+
236
+ const chatPin = (pinItem) => {
237
+ const result = chatListItem.filter((data) => data?.id == pinItem);
238
+ result.forEach((object) => {
239
+ object.pin = "pined";
240
+ });
241
+ chatListItem.unshift(result[0]);
242
+ setKey(result[0]?.id);
243
+ aar.push(result[0]?.id);
244
+ setPinChat(true);
245
+
246
+ var uniq = {};
247
+ var arrFiltered = chatListItem.filter(
248
+ (obj) => !uniq[obj.id] && (uniq[obj.id] = true)
249
+ );
250
+
251
+ setChatListItem(arrFiltered);
252
+ setPinIcon(true);
253
+ setIsMdalShow(!isModalShow);
254
+ };
255
+ if (aar.length > "3") {
256
+ }
257
+
258
+ const messagesReadCount = (timeStamp, conversationId) => {
259
+ const payload = {
260
+ timestamp: timeStamp,
261
+ conversationId: conversationId,
262
+ }
263
+ markMessagesAsRead(payload);
264
+ }
265
+
266
+ const getCurrentUserDetailsHandler = async (data) => {
267
+ // console.log(data, 'selecteddata---');
268
+ setCurrentUserConversationDetails({
269
+ id: data.opponentDetails.userId,
270
+ conversationId: data.conversationId,
271
+ });
272
+ messagesReadCount(data.lastMessageSentAt, data.conversationId);
273
+ data.unreadMessagesCount = 0;
274
+ };
275
+
276
+ return (
277
+ <>
278
+ <PaginationIndicator
279
+ elementRef={pageScrollHomePageRef}
280
+ pageEventHandler={getPaginationHomePageData}
281
+ />
282
+ <div ref={pageScrollHomePageRef} className="sidebarChat">
283
+ {chatListItem?.length > 0 ? (
284
+ chatListItem?.map((data, index) => {
285
+ return (
286
+ <UserDetailCard
287
+ key={index}
288
+ getCurrentUserDetailsHandler={getCurrentUserDetailsHandler}
289
+ dataHandler={dataHandler}
290
+ data={data}
291
+ index={index}
292
+ anchorEl={anchorEl}
293
+ open={open}
294
+ handleClosemodal={handleClosemodal}
295
+ dispatch={dispatch}
296
+ state={state}
297
+ isActiveChat={ currentUserConversationDetails.id === data?.opponentDetails?.userId &&
298
+ currentUserConversationDetails.id !== findUserId?.senderId
299
+ }
300
+ findUserId={findUserId}
301
+ profileClose={profileClose}
302
+ setMediaDocs={setMediaDocs}
303
+ />
304
+ );
305
+ })
306
+ ) : (
307
+ <EmptyChatPlaceholder>
308
+ <ImageComponent
309
+ className="emptyImage"
310
+ src={Empty_Chat_Placeholder}
311
+ />
312
+ <TextPlaceholder >you have no active chats ,<bold onClick={()=>messageSlidebar()} style={{color:"blue"}}> CLICK HERE </bold> to find the users to chat with</TextPlaceholder>
313
+ </EmptyChatPlaceholder>
314
+ )}
315
+ {showConversationPagingLoader && <UserPagingLoader />}
316
+ </div>
317
+ </>
318
+ );
319
+ }
320
+
321
+ export default SidebarChat;