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,819 @@
1
+ import React, { useState, useEffect, useRef } from "react";
2
+ import Chatbox from "../Chatbox.js/index.js";
3
+ import "./styles.css";
4
+ import { fontSize } from "../../../Data";
5
+ import ContactInfo from "../ContactInfo";
6
+ import MenuDialog from "../menuDialog/index.js";
7
+ import client from "../../../utils/chatSdk.js";
8
+ import {
9
+ BACKICON,
10
+ MENU_ICON,
11
+ SEARCH,
12
+ placeholdeImage,
13
+ } from "../../../utils/global.js";
14
+ import { getCookie, setCookie } from "../../../lib/session/index.js";
15
+ import ImageComponent from "../../../components/ImageComponent.js";
16
+ import styled, { css } from "styled-components";
17
+ import { useDetectOutsideClick } from "../../../components/common/Modal/useDetectOutsideClick.js";
18
+ import { mobile } from "../../../utils/media.js";
19
+ import OutsideAlerter from "../../../components/OutsideAlerter/OutsideAlerter.js";
20
+ import {
21
+ clearConversationSelfMessages,
22
+ deleteConversationSelfMessages,
23
+ getTimeWithMeridian,
24
+ getUserConversationDetails,
25
+ postBlockUser,
26
+ postUnblockUser,
27
+ } from "../../../lib/helpers.js";
28
+ import useThrottle from "../../../hooks/useThrottle.js";
29
+ import { DAYS, HOURS, MINUTES, MONTHS, SECONDS, YEARS } from "../../../lib/constant.js";
30
+ import Toaster from "../Toaster/Toaster.js";
31
+ import DialogBox from "../DialogBox.js";
32
+ import UpperMenuBar from "../Carousle/UpperMenuBar.js";
33
+ import SliderCarousal from "../Carousle/index.js";
34
+ import { ChatState } from "../../../ChatContext.js";
35
+
36
+ const PlaceholderBackGround = styled.div`
37
+ padding: 28px;
38
+ background-color: var(--intro-background);
39
+ position: absolute;
40
+ box-sizing: border-box;
41
+ display: flex;
42
+ flex-grow: 1;
43
+ align-items: center;
44
+ justify-content: center;
45
+ width: 70vw;
46
+ height: 100%;
47
+ flex-direction: column;
48
+ ${mobile(css`
49
+ display: none;
50
+ `)}
51
+ `;
52
+
53
+ const MenuContainer = styled.div`
54
+ position: absolute;
55
+ background: var(--modal_color);
56
+ color: var(--black);
57
+ top: 45px;
58
+ right: 20px;
59
+ z-index: 999;
60
+ padding: 1rem 0;
61
+ display: flex;
62
+ justify-content: center;
63
+ align-items: center;
64
+ visibility: hidden;
65
+ transform: translateY(-10px);
66
+ transition: opacity 331ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
67
+ transform 220ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
68
+ transform-origin: right top;
69
+ width: 230px;
70
+ ${(props) =>
71
+ props.isActive &&
72
+ css`
73
+ opacity: 1;
74
+ visibility: visible;
75
+ transform: translateY(0);
76
+ `}
77
+ `;
78
+
79
+ const ModalContainer = styled.div`
80
+ background-color: var(--modal_color);
81
+ position: absolute;
82
+ top: 45px;
83
+ right: 20px;
84
+ z-index: 999;
85
+ width: 230px;
86
+ color: var(--black);
87
+ box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
88
+ visibility: hidden;
89
+ transform: translateY(-10px);
90
+ transition: opacity 331ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
91
+ transform 220ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
92
+ transform-origin: right top;
93
+ padding: 1rem 0;
94
+
95
+ ${(props) =>
96
+ props.isMenu &&
97
+ css`
98
+ opacity: 1;
99
+ visibility: visible;
100
+ transform: translateY(0);
101
+ `}
102
+
103
+ ${mobile(css`
104
+ top: 50px;
105
+ left: 150px;
106
+ `)}
107
+ `;
108
+
109
+ const ModalMenu = styled.ul`
110
+ background: var(--modal_color);
111
+ color: var(--black);
112
+ box-shadow: -3px 0px 4px rgba(194, 194, 194, 0.25);
113
+ border-radius: 4px;
114
+ padding: 1rem 0;
115
+ position: absolute;
116
+ top: 8px;
117
+ right: 0px;
118
+ width: 180px;
119
+ opacity: 0;
120
+ cursor: pointer;
121
+ visibility: hidden;
122
+ transform: translateY(-10px);
123
+ transform-origin: left top;
124
+ transition: opacity 331ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
125
+ transform 220ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
126
+ z-index: 999;
127
+ ${(props) =>
128
+ props.isActive &&
129
+ css`
130
+ opacity: 1;
131
+ visibility: visible;
132
+ transform: translateY(0);
133
+ `}
134
+ `;
135
+
136
+ const ItemList = styled.li`
137
+ padding: 0 2rem;
138
+ margin: 0;
139
+ line-height: 2.5rem;
140
+ display: flex;
141
+ justify-content: space-between;
142
+ align-items: center;
143
+ font-size: 14.5px;
144
+ color: var(--primary);
145
+ padding-right: 58px !important;
146
+ `;
147
+
148
+ let contactHeaderMenu = [
149
+ "Contact info",
150
+ "Select message",
151
+ "Close chat",
152
+ "Mute notifications",
153
+ "Disappering message",
154
+ "Clear message",
155
+ "Delete chat",
156
+ "Report",
157
+ "Block",
158
+ ];
159
+
160
+ const getSelfMenuBar = (blockStatus) => {
161
+ return [
162
+ {
163
+ id: 1,
164
+ header: "Contact info",
165
+ },
166
+ // {
167
+ // id: 2,
168
+ // header: "Select message",
169
+ // },
170
+ // {
171
+ // id: 3,
172
+ // header: "Close chat",
173
+ // },
174
+ // {
175
+ // id: 4,
176
+ // header: "Mute notifications",
177
+ // },
178
+ // {
179
+ // id: 5,
180
+ // header: "Disappering message",
181
+ // },
182
+ {
183
+ id: 6,
184
+ header: "Clear chat",
185
+ },
186
+ {
187
+ id: 7,
188
+ header: "Delete chat",
189
+ },
190
+ // {
191
+ // id: 8,
192
+ // header: "Report",
193
+ // },
194
+ {
195
+ id: 9,
196
+ header: blockStatus ? 'Unblock' : "Block", },
197
+ ];
198
+ };
199
+
200
+ const ChatBoxContainer = styled.div`
201
+ height: calc(100vh - 62px);
202
+ `;
203
+
204
+ const TypingText = styled.div`
205
+ color: var(--black);
206
+ visibility: visible;
207
+ user-select: text;
208
+ overflow-y: hidden;
209
+ text-overflow: ellipsis;
210
+ white-space: nowrap;
211
+ flex-grow: 1;
212
+ align-items: flex-start;
213
+ font-size: 0.8125rem;
214
+ line-height: 1.5385;
215
+ min-height: 20px;
216
+ `;
217
+
218
+ function MainChat(props) {
219
+ const {
220
+ sidebarChatItem,
221
+ state,
222
+ setState,
223
+ setIsSidebarShow,
224
+ preventMessageRef,
225
+ getPaginationMessagesData,
226
+ isSidebarShow,
227
+ setShowProfilePicture,
228
+ findUserId,
229
+ setUserBlockModal,
230
+ setClearChatModal,
231
+ setDeleteChatModal,
232
+ setslideShow,
233
+ slideShow,
234
+ setSearchShow,
235
+ searchShow,
236
+ setUserConversationDetail,
237
+ userConversationDetail,
238
+ setMessageInfo,
239
+ messageInfo,
240
+ debounceSearchMessages,
241
+ enteredSearchQuery,
242
+ searchedMessageArray,
243
+ searchMessageLoaderStatus,
244
+ setMediaDocs,
245
+ mediaDocs,
246
+ sidebarData,
247
+ userDetails,
248
+ } = props;
249
+
250
+ // const [slideShow, setslideShow] = useState(false);
251
+ const [footer, setFooter] = useState(false);
252
+ // const [searchShow, setSearchShow] = useState(false);
253
+ const [anchorEl, setAnchorEl] = React.useState(null);
254
+ const [isMenu, setIsMenu] = useState(false);
255
+ // const [clearChatModal, setClearChatModal] = useState(false);
256
+ // const [deleteChatModal, setDeleteChatModal] = useState(false);
257
+ const [typing, setTyping] = useState(false);
258
+ const [online, setOnline] = useState(false);
259
+ const [userLastSeen, setUserLastSeen] = useState('');
260
+ const [getUserCurrentTime, setGetUserCurrentTime] = useState("");
261
+ const [getMessageTextLength, setGetMessageTextLength] = useState("");
262
+ // const [userBlockModal, setUserBlockModal] = useState(false);
263
+ // const [userConversationDetail, setUserConversationDetail] = useState({});
264
+ const [chatMediaAttachments, setChatMediaAttachments ] = useState([]);
265
+ const [chatMedia, setChatMedia ] = useState([]);
266
+ const [selectedMediaIndex, setSelectedMediaIndex] = useState(0);
267
+ const scrolledPositionRef = useRef(0);
268
+ const dialogueBoxRef = useRef(null);
269
+ const [messageChat , setMessageChat] = useState();
270
+ const [toastStatus, setToastStatus] = useState({open: false, message: '', variant: ''});
271
+ const open = Boolean(anchorEl);
272
+ const [isOpen, setIsOpen] = useState(false);
273
+
274
+ const { theme } = ChatState();
275
+
276
+ const handleClickSlideShow = () => {
277
+ getMediaDocs();
278
+ setslideShow(true);
279
+ setSearchShow(false);
280
+ setMessageInfo(false);
281
+ setFooter(true);
282
+ };
283
+
284
+ const searchShowHandler = () => {
285
+ setslideShow(false);
286
+ setSearchShow(true);
287
+ setMessageInfo(false);
288
+ };
289
+
290
+ const handleClosee = () => {
291
+ setslideShow(false);
292
+ setSearchShow(false);
293
+ setMessageInfo(false);
294
+ };
295
+
296
+ const handler = () => {
297
+ setFooter(false);
298
+ };
299
+
300
+ const mediaContact = () => {
301
+ setslideShow(true);
302
+ };
303
+
304
+ function getLastSeen(lastSeenTimestamp) {
305
+ console.log('getLastSeen -- ', lastSeenTimestamp, new Date(lastSeenTimestamp));
306
+ try {
307
+ const lastSeenDate = new Date(lastSeenTimestamp);
308
+ const currentDate = new Date();
309
+
310
+ if (lastSeenDate.getTime() > currentDate.getTime())
311
+ console.log("Invalid input");
312
+ else {
313
+ const timeDiffInYears = Math.round(
314
+ (currentDate.getTime() - lastSeenDate.getTime()) / YEARS
315
+ );
316
+ const timeDiffInMonths = Math.round(
317
+ (currentDate.getTime() - lastSeenDate.getTime()) / MONTHS
318
+ );
319
+ const timeDiffInDays = Math.round(
320
+ (currentDate.getTime() - lastSeenDate.getTime()) / DAYS
321
+ );
322
+ const timeDiffInHours = Math.round(
323
+ (currentDate.getTime() - lastSeenDate.getTime()) / HOURS
324
+ );
325
+ const timeDiffInMinutes = Math.round(
326
+ (currentDate.getTime() - lastSeenDate.getTime()) / MINUTES
327
+ );
328
+ const timeDiffInSeconds = Math.round(
329
+ (currentDate.getTime() - lastSeenDate.getTime()) / SECONDS
330
+ );
331
+ if (timeDiffInSeconds < 60) {
332
+ setGetUserCurrentTime("🟢 last seen just now");
333
+ } else if (timeDiffInMinutes < 60) {
334
+ setGetUserCurrentTime(
335
+ `Last seen ${
336
+ timeDiffInMinutes === 1
337
+ ? "a minute"
338
+ : timeDiffInMinutes + " minutes"
339
+ } ago`
340
+ );
341
+ } else if (timeDiffInHours < 24) {
342
+ if (timeDiffInHours === 1) {
343
+ setGetUserCurrentTime(
344
+ `Last seen an hour ago at ${getTimeWithMeridian(lastSeenDate)}`
345
+ );
346
+ } else {
347
+ setGetUserCurrentTime(
348
+ `Last seen ${
349
+ lastSeenDate.getDate() === currentDate.getDate()
350
+ ? "today"
351
+ : "yesterday"
352
+ } at ${getTimeWithMeridian(lastSeenDate)}`
353
+ );
354
+ }
355
+ } else if (timeDiffInDays < 30) {
356
+ setGetUserCurrentTime(
357
+ `Last seen ${
358
+ timeDiffInDays === 1 ? "a day" : timeDiffInDays + " days"
359
+ } ago`
360
+ );
361
+ } else if (timeDiffInMonths < 12) {
362
+ setGetUserCurrentTime(
363
+ `Last seen ${
364
+ timeDiffInMonths === 1 ? "a month" : timeDiffInMonths + " months"
365
+ } ago`
366
+ );
367
+ } else {
368
+ setGetUserCurrentTime(
369
+ `Last seen ${
370
+ timeDiffInYears === 1 ? "an year" : timeDiffInYears + " years"
371
+ } ago`
372
+ );
373
+ }
374
+ }
375
+ }
376
+ catch(err) {
377
+ console.error('Error calculating lastSeen from getLastSeen()');
378
+ }
379
+ }
380
+
381
+ const throttledTyping = useThrottle(
382
+ async () => {
383
+ const payload = {
384
+ conversationId: sidebarChatItem?.conversationId,
385
+ };
386
+ try {
387
+ if (getMessageTextLength) {
388
+ await client.message.postIndicateTyping(payload).then((res) => {
389
+ // setTyping(res.msg === "Typing event sent successfully.");
390
+ });
391
+ }
392
+ } catch (error) {
393
+ console.error(error);
394
+ }
395
+ },
396
+ 3000,
397
+ false
398
+ );
399
+
400
+
401
+ const throttledOnline = async (conId) => {
402
+ const payload = {
403
+ conversationId: conId,
404
+ };
405
+ try {
406
+ if (Object?.keys(conId)?.length > 0) {
407
+ // if (findUserId !== undefined && Object?.keys(findUserId)?.length > 0) {
408
+ await client.Conversation.getConversationDetails(
409
+ payload,
410
+ conId
411
+ ).then((res) => {
412
+ if (res?.conversationDetails?.opponentDetails?.lastSeen === -1) {
413
+ setOnline(true);
414
+ }else{
415
+ setOnline(false);
416
+ console.log('last Seen from API - ', res?.conversationDetails?.opponentDetails?.lastSeen, new Date(res?.conversationDetails?.opponentDetails?.lastSeen));
417
+ setUserLastSeen(
418
+ res?.conversationDetails?.opponentDetails?.lastSeen
419
+ );
420
+ }
421
+ });
422
+ // }
423
+ }
424
+ } catch (error) {
425
+ console.error(error);
426
+ }
427
+ }
428
+
429
+ useEffect(() => {
430
+ if(!sidebarChatItem) return;
431
+ setSearchShow(false);
432
+ setUserLastSeen(sidebarChatItem?.opponentDetails?.lastSeen);
433
+ const intervalId = setInterval(() => {
434
+ throttledOnline(sidebarChatItem?.conversationId);
435
+ }, 30000);
436
+
437
+ return () => clearInterval(intervalId);
438
+ }, [sidebarChatItem]);
439
+
440
+ useEffect(() => {
441
+ if (!userLastSeen) return;
442
+ getLastSeen(userLastSeen);
443
+ }, [userLastSeen]);
444
+
445
+ useEffect(() => {
446
+ if (sidebarChatItem?.opponentDetails?.lastSeen === -1) {
447
+ setOnline(true);
448
+ }else{
449
+ setOnline(false);
450
+ }
451
+ throttledTyping();
452
+ }, [findUserId, getMessageTextLength, sidebarChatItem?.conversationId]);
453
+
454
+ const userId = getCookie("userId");
455
+ useEffect(() => {
456
+ if (
457
+ findUserId?.action === "typingEvent" &&
458
+ findUserId.conversationId === sidebarChatItem?.conversationId &&
459
+ findUserId.userId !== userId
460
+ ) {
461
+ setTyping(true);
462
+ }
463
+
464
+ if (findUserId) {
465
+ const timeoutId = setTimeout(() => {
466
+ return setTyping(false);
467
+ }, 3000);
468
+ return(() => clearTimeout(timeoutId));
469
+ } else {
470
+ return setTyping(true);
471
+ }
472
+ }, [ findUserId]);
473
+
474
+ useEffect(() => {
475
+ const fetchUserConversationDetail = async () => {
476
+ const response = await getUserConversationDetails(sidebarChatItem?.conversationId);
477
+ setUserConversationDetail(response);
478
+ }
479
+ fetchUserConversationDetail();
480
+ }, [sidebarChatItem?.conversationId])
481
+
482
+
483
+ useEffect(() => {
484
+ const payload = {
485
+ conversationId: sidebarChatItem?.conversationId,
486
+ };
487
+ sidebarChatItem &&
488
+ client?.message
489
+ ?.getMessages(payload)
490
+ .then((res) => {
491
+ const filteredResponseData = res.messages.filter(data => data?.body?.length > 0);
492
+
493
+ setState((prev) => {
494
+ return {
495
+ ...prev,
496
+ messages: {
497
+ ...prev?.messages,
498
+ [sidebarChatItem?.conversationId]: filteredResponseData,
499
+ },
500
+ };
501
+ });
502
+ })
503
+ .catch((err) => console.log(err, "err"));
504
+ }, [sidebarChatItem]);
505
+
506
+ const dropdownRef = useRef(null);
507
+ const [isActive, setIsActive] = useDetectOutsideClick(true);
508
+ const onClick = () => setIsActive(!isActive);
509
+
510
+ const arrowClick = () => {
511
+ setState({...state, selectedConvId : ''});
512
+ sidebarData(null);
513
+ setIsSidebarShow(false);
514
+ setCookie("isShow", false);
515
+ };
516
+
517
+ const getUserStatus = () => {
518
+ let value = -1;
519
+ if (
520
+ typing
521
+ && findUserId?.conversationId === sidebarChatItem?.conversationId
522
+ ) {
523
+ value = 0;
524
+ } else if (!typing && online) {
525
+ value = 1;
526
+ } else if (!typing && !online) {
527
+ value = 2;
528
+ }
529
+ switch (value) {
530
+ case 0:
531
+ return "typing...";
532
+ case 1:
533
+ return "Online";
534
+ case 2:
535
+ return getUserCurrentTime;
536
+ default:
537
+ return getUserCurrentTime;
538
+ }
539
+ };
540
+
541
+ // const clearChatMessages = async () => {
542
+ // const res = await clearConversationSelfMessages(sidebarChatItem?.conversationId);
543
+ // setToastStatus({open: true, variant:"success", message: res.msg});
544
+ // const getLastIndexValue = state.messages[sidebarChatItem?.conversationId].pop();
545
+ // state.messages[sidebarChatItem?.conversationId] = [getLastIndexValue];
546
+ // setState((prev) => {
547
+ // return {
548
+ // ...prev,
549
+ // messages: {
550
+ // [sidebarChatItem?.conversationId]: [getLastIndexValue]
551
+ // }
552
+ // }
553
+ // })
554
+ // setClearChatModal(false);
555
+ // }
556
+ // const handleBlockUser = async() => {
557
+ // try {
558
+ // const res = await postBlockUser(sidebarChatItem?.opponentDetails?.userId);
559
+ // setToastStatus({open: true, variant:"success", message: res.msg});
560
+ // const response = await getUserConversationDetails(sidebarChatItem?.conversationId);
561
+ // setUserConversationDetail(response);
562
+ // setUserBlockModal(false);
563
+ // } catch (error) {
564
+ // setUserBlockModal(false);
565
+ // setToastStatus({open: true, variant:"success", message: error.messages});
566
+ // console.error('error', error)
567
+ // }
568
+ // }
569
+
570
+ // const handleUnblockUser = async () => {
571
+ // try {
572
+ // const res = await postUnblockUser(sidebarChatItem?.opponentDetails?.userId);
573
+ // setToastStatus({open: true, variant:"success", message: res.msg});
574
+ // const response = await getUserConversationDetails(sidebarChatItem?.conversationId);
575
+ // setUserConversationDetail(response);
576
+ // setUserBlockModal(false);
577
+ // } catch (error) {
578
+ // setUserBlockModal(false);
579
+ // setToastStatus({open: true, variant:"success", message: error.messages});
580
+ // console.error('error', error);
581
+ // }
582
+ // }
583
+
584
+ // const deleteChatMessages = async () => {
585
+ // try {
586
+ // const res = await deleteConversationSelfMessages(sidebarChatItem?.conversationId);
587
+ // setToastStatus({open: true, variant:"success", message: res.msg});
588
+ // handleClosee();
589
+ // setDeleteChatModal(false);
590
+ // } catch (error) {
591
+ // setToastStatus({open: true, variant:"success", message: error.messages});
592
+ // handleClosee();
593
+ // setDeleteChatModal(false);
594
+ // console.error('error', error);
595
+ // }
596
+ // };
597
+
598
+ const getMediaDocs = async () => {
599
+ const conversationId = sidebarChatItem?.conversationId;
600
+ const payload = {
601
+ limit: 20,
602
+ skip: 0,
603
+ isGroup: false,
604
+ conversationId,
605
+ attachmentTypes: 0 // to get all media of particular conversation
606
+ };
607
+ try {
608
+ const res = await client.message.getMessages(payload);
609
+ setChatMedia([...res?.messages]);
610
+ setMediaDocs([...res?.messages]);
611
+ const mediaItems = [];
612
+ res?.messages.forEach((message) => message.attachments.forEach((media) => mediaItems.push(media)));
613
+ setChatMediaAttachments([...mediaItems]);
614
+ return res;
615
+ } catch (error) {
616
+ setToastStatus({open: true, variant:"error", message: 'No media or docs found.'});
617
+ }
618
+ }
619
+
620
+ const handleImgVidClick = async (mediaId) => {
621
+ const selectedIndex = chatMediaAttachments.findIndex(data => data.mediaId === mediaId);
622
+ if (selectedIndex === -1) {
623
+ try {
624
+ const res = await getMediaDocs();
625
+ if (res) {
626
+ const selectedIndex = res.messages.findIndex(data => data?.attachments[0]?.mediaId === mediaId);
627
+ scrolledPositionRef.current = selectedIndex;
628
+ setSelectedMediaIndex(selectedIndex);
629
+ dialogueBoxRef.current.showModal();
630
+ }
631
+ } catch (error) {
632
+ console.error('error', error);
633
+ setToastStatus({open: true, variant:"error", message: error.messages});
634
+ }
635
+
636
+ }else{
637
+ scrolledPositionRef.current = selectedIndex;
638
+ setSelectedMediaIndex(selectedIndex);
639
+ dialogueBoxRef.current.showModal();
640
+ }
641
+ };
642
+
643
+
644
+ return (
645
+ <>
646
+ {props?.sidebarChatItem ? (
647
+ <div className={slideShow || searchShow || messageInfo ? "mainChatt" : "mainChat"}>
648
+ <div
649
+ className={slideShow || searchShow || messageInfo ? "chat_Header" : "chat_header"}
650
+ >
651
+ <span className="arrow_icon">
652
+ <ImageComponent
653
+ src={BACKICON}
654
+ className={props?.theme ? "darkicons" : "lighticons"}
655
+ style={{ marginRight: "10px" }}
656
+ onClick={arrowClick}
657
+ />
658
+ </span>
659
+ <img
660
+ onClick={handleClickSlideShow}
661
+ src={sidebarChatItem?.opponentDetails?.userProfileImageUrl}
662
+ className="user_image pointer"
663
+ alt="opponent_profile_picture"
664
+ />
665
+
666
+ <div className="chat_headerInfo">
667
+ <p
668
+ style={{ fontSize: fontSize?.name }}
669
+ onClick={handleClickSlideShow}
670
+ className="pointer"
671
+ >
672
+ {sidebarChatItem?.opponentDetails?.userName}
673
+ </p>
674
+ <TypingText>{getUserStatus()}</TypingText>
675
+ <div className="chat_headerInfo">
676
+ {JSON.stringify(sidebarChatItem?.online)}
677
+ </div>
678
+ </div>
679
+ <div className="chat_header_right">
680
+ <span className="m-4 icons pointer search_icon">
681
+ <ImageComponent
682
+ onClick={searchShowHandler}
683
+ src={SEARCH}
684
+ className={theme ? "darkicons" : "lighticons"}
685
+ />
686
+ </span>
687
+ <span className="icons pointer menu_icon">
688
+ <ImageComponent
689
+ isActive={isActive}
690
+ onClick={() => setIsActive(!isActive)}
691
+ src={MENU_ICON}
692
+ className={theme ? "darkicons" : "lighticons"}
693
+ />
694
+
695
+ </span>
696
+
697
+ <OutsideAlerter onClose={() => setIsActive(false)}>
698
+ <MenuContainer isActive={isActive}>
699
+ <MenuDialog
700
+ menuData={getSelfMenuBar(userConversationDetail?.messagingDisabled)}
701
+ isMenu={isActive}
702
+ setIsMenu={setIsActive}
703
+ setClearChatModal={setClearChatModal}
704
+ setDeleteChatModal={setDeleteChatModal}
705
+ setUserBlockModal={setUserBlockModal}
706
+ handleClickSlideShow={handleClickSlideShow}
707
+ userConversationDetail={userConversationDetail}
708
+ />
709
+ </MenuContainer>
710
+ </OutsideAlerter>
711
+ </div>
712
+ </div>
713
+
714
+ <ChatBoxContainer className="chatBox">
715
+ <Chatbox
716
+ sidebarChatItem={sidebarChatItem}
717
+ messages={state?.messages}
718
+ theme={theme}
719
+ getPaginationMessagesData={getPaginationMessagesData}
720
+ preventMessageRef={preventMessageRef}
721
+ findUserId={findUserId}
722
+ state={state}
723
+ setState={setState}
724
+ setGetMessageTextLength={setGetMessageTextLength}
725
+ userConversationDetail={userConversationDetail}
726
+ setslideShow={setslideShow}
727
+ setMessageInfo={setMessageInfo}
728
+ messageInfo={messageInfo}
729
+ setMessageChat={setMessageChat}
730
+ slideShow={slideShow}
731
+ setSearchShow={setSearchShow}
732
+ setMediaDocs={setMediaDocs}
733
+ userDetails={userDetails}
734
+ handleImgVidClick={handleImgVidClick}
735
+ setIsOpen={setIsOpen}
736
+ isOpen={isOpen}
737
+ getMediaDocs={getMediaDocs}
738
+ setToastStatus={setToastStatus}
739
+ />
740
+ </ChatBoxContainer>
741
+ </div>
742
+ ) : (
743
+ <div className="chatbox_Bg">
744
+ <PlaceholderBackGround className="bg">
745
+ <div>
746
+ <div>
747
+ <ImageComponent src={placeholdeImage} />
748
+ </div>
749
+ <div>
750
+ <h1>Isometrik Chat</h1>
751
+ </div>
752
+ <div className="text_Color text">
753
+ Isometrik web chat is fully sync with mobile isomterik chat , all charts are synced when connected to the network
754
+ </div>
755
+ </div>
756
+ </PlaceholderBackGround>
757
+ </div>
758
+ )}
759
+ <div className={slideShow || searchShow || messageInfo ? "contactInfo" : "contact"}>
760
+ <ContactInfo
761
+ handleClosee={handleClosee}
762
+ searchShow={searchShow}
763
+ sidebarChatItem={props?.sidebarChatItem}
764
+ handler={handler}
765
+ slideShow={slideShow}
766
+ mediaContact={mediaContact}
767
+ theme={theme}
768
+ setShowProfilePicture={setShowProfilePicture}
769
+ setDeleteChatModal={setDeleteChatModal}
770
+ userConversationDetail={userConversationDetail}
771
+ setUserBlockModal={setUserBlockModal}
772
+ Messages={state}
773
+ setMessageInfo={setMessageInfo}
774
+ messageInfo={messageInfo}
775
+ conversationId={sidebarChatItem?.conversationId}
776
+ setMessageChat={setMessageChat}
777
+ messageChat={messageChat}
778
+ mediaDocs={mediaDocs}
779
+ debounceSearchMessages={debounceSearchMessages}
780
+ enteredSearchQuery={enteredSearchQuery}
781
+ searchedMessageArray={searchedMessageArray}
782
+ searchMessageLoaderStatus={searchMessageLoaderStatus}
783
+ handleImgVidClick={handleImgVidClick}
784
+ />
785
+ </div>
786
+ {
787
+ !isOpen &&
788
+ <DialogBox dialogueBoxRef={dialogueBoxRef} >
789
+ <div className='d-flex justify-content-center h-100' style={{ flexDirection: 'column' }}>
790
+ <UpperMenuBar chatMedia={chatMedia} selectedMediaIndex={selectedMediaIndex} scrolledPositionRef={scrolledPositionRef} />
791
+ <SliderCarousal assets={chatMediaAttachments} selectedMediaIndex={selectedMediaIndex} scrolledPositionRef={scrolledPositionRef} />
792
+ </div>
793
+ </DialogBox>
794
+ }
795
+ <>
796
+ {
797
+ <Toaster message={toastStatus.message} variant={toastStatus.variant} open={toastStatus.open} onClose={() => setToastStatus({open: false})} theme={theme} />
798
+ }
799
+ </>
800
+ <style jsx>{`
801
+ @media (max-width: 48rem) {
802
+ .mainChat {
803
+ width: 100vw;
804
+ display: ${!isSidebarShow ? "none" : "block"};
805
+ }
806
+ .contactInfo {
807
+ width: 100vw;
808
+ }
809
+ }
810
+ @media (min-width: 48rem) {
811
+ .mainChat .arrow_icon {
812
+ display: none;
813
+ }
814
+ }
815
+ `}</style>
816
+ </>
817
+ );
818
+ }
819
+ export default MainChat;