index.tsx 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { useState, useEffect, useCallback, useMemo } from "react";
  3. import { useSelector,useDispatch } from "react-redux";
  4. import ArrowBack from "./ArrowBack";
  5. import SendMessage from "./SendMessage";
  6. import UnpinBar from "./UnpinBar";
  7. import MessageLeftCall from "./Messages/MessageLeftCall";
  8. import MessageLeftDeleted from "./Messages/MessageLeftDeleted";
  9. import MessageLeftText from './Messages/MessageLeftText'
  10. import MessageLeftReply from "./Messages/MessageLeftReply";
  11. import MessageLeftForward from "./Messages/MessageLeftForward";
  12. import MessageLeftImage from './Messages/MessageLeftImage'
  13. import MessageLeftAudio from './Messages/MessageLeftAudio'
  14. import MessageLeftVideo from './Messages/MessageLeftVideo'
  15. import MessageLeftFile from "./Messages/MessageLeftFile";
  16. import MessageRightCall from "./Messages/MessageRightCall";
  17. import MessageRightDeleted from "./Messages/MessageRightDeleted";
  18. import MessageRightText from './Messages/MessageRightText'
  19. import MessageRightReply from "./Messages/MessageRightReply";
  20. import MessageRightForward from "./Messages/MessageRightForward";
  21. import MessageRightImage from './Messages/MessageRightImage'
  22. import MessageRightAudio from './Messages/MessageRightAudio'
  23. import MessageRightVideo from './Messages/MessageRightVideo'
  24. import MessageRightFile from "./Messages/MessageRightFile";
  25. import MessageDivider from "./Messages/MessageDivider";
  26. import AlertInfo from "../../../reusableComponents/AlertInfo";
  27. import ForwardSearchList from "./ForwardSearchList";
  28. import { getMessagesMemo } from '../../../../redux/messages/selector'
  29. import { getAuthorizationState } from '../../../../redux/authorization/selector'
  30. import { getChat } from '../../../../redux/chat/selector'
  31. import { getScrollChat } from '../../../../redux/control/selector'
  32. import { actionScrollChat,actionOpenPinned,actionRightIsOpen } from '../../../../redux/control/action'
  33. import { asyncGetMessagesById } from '../../../../redux/messages/operations'
  34. import { asyncGetChatById,asyncStartChatById } from "../../../../redux/chat/operations";
  35. import { seenChat } from "../../../../api-data";
  36. import { TPinnedMessages } from "../../../../typescript/redux/pinnedMessages/types";
  37. import { TMessage } from "../../../../typescript/redux/allMessages/types";
  38. import { timeStampFilter,prodAwsS3,refreshAppTime } from "../../../../helpers";
  39. const debounce = require('lodash.debounce');
  40. const useStyles = makeStyles({
  41. container: {
  42. height: '93vh',
  43. width: "100%",
  44. display: "flex",
  45. alignItems: "center",
  46. alignContent:"center",
  47. flexDirection: "column",
  48. position: "relative",
  49. },
  50. messagesScroll: {
  51. paddingTop: 30,
  52. overflowY: "scroll",
  53. maxHeight: '83vh',
  54. width: "100%",
  55. display: "flex",
  56. justifyContent: 'center',
  57. '&::-webkit-scrollbar': {
  58. width: '0.4em'
  59. },
  60. '&::-webkit-scrollbar-track': {
  61. boxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  62. webkitBoxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  63. backgroundColor: '#eceeec',
  64. },
  65. '&::-webkit-scrollbar-thumb': {
  66. backgroundColor: '#ccc8c8',
  67. },
  68. "&::-webkit-scrollbar-thumb:focus": {
  69. backgroundColor: "#959595",
  70. },
  71. "&::-webkit-scrollbar-thumb:active": {
  72. backgroundColor: "#959595",
  73. },
  74. },
  75. messagesEmpty: {
  76. overflowY: "hidden",
  77. width: "100%",
  78. display: "flex",
  79. justifyContent: 'center',
  80. paddingTop: 30,
  81. },
  82. messagesBody: {
  83. width: "60%",
  84. },
  85. });
  86. interface IChatBar {
  87. chatDivRef: any | null,
  88. selectedArr: string[] | [],
  89. setSelectedArr: React.Dispatch<React.SetStateAction<string[] | []>>,
  90. isSomeSelected: boolean,
  91. setIsSomeSelected: React.Dispatch<React.SetStateAction<boolean>>,
  92. openPinned: boolean,
  93. pinnedMessagesMemo: TPinnedMessages,
  94. handleUnpinAll: () => void,
  95. }
  96. const ChatBar = ({chatDivRef,selectedArr,setSelectedArr,isSomeSelected,setIsSomeSelected,openPinned,pinnedMessagesMemo,handleUnpinAll}:IChatBar) => {
  97. const classes = useStyles();
  98. const dispatch = useDispatch()
  99. const messagesMemo = useSelector(getMessagesMemo)
  100. const { number:userNumber,nightMode,silentMode} = useSelector(getAuthorizationState)
  101. const { companionId,total,seen,mute,seenCompanion,number:chatNumber } = useSelector(getChat)
  102. const scrollChat = useSelector(getScrollChat)
  103. const [isArrow, setIsArrow] = useState<boolean>(false)
  104. const [isNew, setIsNew] = useState<{ new: number, mute: boolean }>({ new: 0, mute: false })
  105. const [isReply, setIsReply] = useState<TMessage | undefined>(undefined)
  106. const [isForward, setIsForward] = useState<TMessage | undefined>(undefined)
  107. const [isEdit, setIsEdit] = useState<TMessage | undefined>(undefined)
  108. const [modalForward, setModalForward] = useState<boolean>(false)
  109. let time: any
  110. let tongue: any
  111. let unread: any
  112. const getSeconds = (createdAt:string) => Math.round(new Date(createdAt).getTime()/ 1000)
  113. const isSelected = (_id: string) => selectedArr.some((el: string) => el === _id)
  114. const handleSelected = (_id: string) => {
  115. !isSomeSelected&&setIsSomeSelected(true)
  116. if (selectedArr.some((el: string) => el === _id))
  117. setSelectedArr(selectedArr.filter((el:string) => el !== _id))
  118. else setSelectedArr([...selectedArr,_id])
  119. }
  120. const handleReply = (_id: string) => {
  121. openPinned && dispatch(actionOpenPinned(false))
  122. isEdit&&setIsEdit(undefined)
  123. setIsReply(renderArr.find((el) => el._id ===_id))
  124. }
  125. const handleForward = (_id: string) => {
  126. openPinned && dispatch(actionOpenPinned(false))
  127. isReply && setIsReply(undefined)
  128. isEdit&&setIsEdit(undefined)
  129. setIsForward(renderArr.find((el) => el._id === _id))
  130. setModalForward(true)
  131. }
  132. const handleEdit = (_id: string) => {
  133. openPinned && dispatch(actionOpenPinned(false))
  134. isReply && setIsReply(undefined)
  135. setIsEdit(renderArr.find((el) => el._id ===_id))
  136. }
  137. const handleScrollTo = useCallback(() => {
  138. chatDivRef.current&&chatDivRef.current.scrollTo({
  139. top: chatDivRef.current.scrollHeight,
  140. behavior: 'smooth'
  141. })
  142. },[chatDivRef])
  143. const handleScroll = useCallback(({ target:{scrollHeight,scrollTop,clientHeight}}: any) => {
  144. const different = scrollHeight - Math.floor(scrollTop)
  145. const reached = different - clientHeight
  146. if (total !== seen&&reached < 10 && !openPinned) seenChat(companionId)
  147. setIsArrow(different === clientHeight ? false : true)
  148. }, [total,seen, companionId,openPinned])
  149. const debouncedHandleScroll = debounce(handleScroll, 300)
  150. const renderArr = useMemo(() => {
  151. return !openPinned ? messagesMemo : pinnedMessagesMemo
  152. }, [messagesMemo, pinnedMessagesMemo, openPinned])
  153. const handleScrollToTheMessage = (_id:string) => {
  154. const childNodes = chatDivRef.current.childNodes[0].childNodes
  155. let toScrollNode = [...childNodes].find((el: any) => el.id === _id)
  156. if (toScrollNode) {
  157. toScrollNode = [...toScrollNode.childNodes].slice(-1)[0]
  158. toScrollNode.style.backgroundColor = 'rgba(70, 70, 70, 0.4)'
  159. toScrollNode.style.boxShadow = '0px 0px 6px 0px #ffffff'
  160. toScrollNode.scrollIntoView({ behavior: 'smooth' })
  161. setTimeout(() => {
  162. toScrollNode.style.backgroundColor = 'unset'
  163. toScrollNode.style.boxShadow = 'unset'
  164. }, 2000)
  165. }
  166. }
  167. const handleScrollToTheChat = (companionIdForwardToAndFrom:string,oldId:string) => {
  168. if (companionId === companionIdForwardToAndFrom) return handleScrollToTheMessage(oldId)
  169. dispatch(actionRightIsOpen(''))
  170. dispatch(actionOpenPinned(false))
  171. dispatch(asyncStartChatById(companionIdForwardToAndFrom))
  172. setTimeout(() => handleScrollToTheMessage(oldId), 2000)
  173. }
  174. const handleOpenTheChat = (companionIdForwardToAndFrom: string | null) => {
  175. if (companionIdForwardToAndFrom&&companionId !== companionIdForwardToAndFrom) {
  176. dispatch(actionRightIsOpen(''))
  177. dispatch(actionOpenPinned(false))
  178. dispatch(asyncStartChatById(companionIdForwardToAndFrom))
  179. }
  180. }
  181. useEffect(() => {
  182. if (scrollChat) {
  183. dispatch(asyncGetMessagesById(companionId, handleScrollTo))
  184. dispatch(actionScrollChat(false))
  185. }
  186. }, [dispatch,handleScrollTo, scrollChat, companionId])
  187. useEffect(() => {
  188. const handleReset = () => {
  189. dispatch(asyncGetChatById(companionId))
  190. dispatch(asyncGetMessagesById(companionId, null))
  191. }
  192. handleReset()
  193. const idInterval = setInterval(handleReset, refreshAppTime);
  194. return () => clearInterval(idInterval);
  195. }, [dispatch, companionId]);
  196. useEffect(() => {
  197. setIsNew({ new:total-seen,mute})
  198. }, [total, seen, mute]);
  199. useEffect(() => {
  200. if (chatDivRef.current&&openPinned) {
  201. const { scrollHeight, clientHeight } = chatDivRef.current
  202. if (scrollHeight === clientHeight && isArrow) setIsArrow(false)
  203. }
  204. }, [chatDivRef,openPinned,pinnedMessagesMemo.length, isArrow]);
  205. useEffect(() => {
  206. const handleReset = () => {
  207. if (chatDivRef.current&&!openPinned) {
  208. const { scrollHeight, clientHeight } = chatDivRef.current
  209. if (total !== seen && scrollHeight === clientHeight) seenChat(companionId)
  210. }
  211. }
  212. const idInterval = setInterval(handleReset, refreshAppTime);
  213. return () => clearInterval(idInterval);
  214. }, [total, seen, chatDivRef, companionId, openPinned]);
  215. return (
  216. <div className={classes.container} >
  217. <ArrowBack isArrow={isArrow} isNew={isNew} handleScrollTo={handleScrollTo} openPinned={openPinned}/>
  218. {isForward && modalForward && <ForwardSearchList setModalForward={setModalForward}
  219. setIsForward={setIsForward} companionId={companionId}/>}
  220. <div id={companionId} ref={chatDivRef} onScroll={debouncedHandleScroll}
  221. className={messagesMemo.length > 0 ? classes.messagesScroll : classes.messagesEmpty}>
  222. <div className={classes.messagesBody}>
  223. {messagesMemo.length > 0 ? renderArr.map(({ replyMessage,message, name, lastName,avatarUrl,color,pinned,
  224. createdAt, number, type, fullType, replyName, replyLastName, replyCaption, caption, emoji, emojiCompanion,
  225. _id, oldId, forwardName, forwardLastName, companionIdForwardToAndFrom, forwardMessage, forwardCaption, edited,
  226. deleted, initiator, duration }, i) => {
  227. const watched = seenCompanion - (i + 1) < 0 ? false : true
  228. let isUnread
  229. let isTime
  230. let isTongue = false
  231. const nextTongue = renderArr[i + 1]
  232. if (!unread && chatNumber === number&& seen - (i + 1) < 0) {
  233. isUnread = true
  234. unread = true
  235. }
  236. if (!time) {
  237. isTime = true
  238. time = createdAt
  239. } else if (timeStampFilter(time) !== timeStampFilter(createdAt)) {
  240. time = createdAt
  241. isTime = true
  242. }
  243. if (!tongue&&nextTongue&&nextTongue.number === number) {
  244. if (getSeconds(nextTongue.createdAt) - getSeconds(createdAt) < 600) {
  245. isTongue = false
  246. } else {
  247. isTongue = true
  248. }
  249. tongue = number
  250. } else if (!tongue&&nextTongue&&nextTongue.number !== number) {
  251. isTongue = true
  252. tongue = null
  253. } else if (tongue&&nextTongue&&tongue === number&&nextTongue.number === number) {
  254. if (getSeconds(nextTongue.createdAt) - getSeconds(createdAt) < 600) {
  255. isTongue = false
  256. } else {
  257. isTongue = true
  258. }
  259. tongue = number
  260. } else if (tongue&&nextTongue&&tongue === number&&nextTongue.number !== number) {
  261. isTongue = true
  262. tongue = null
  263. } else if (tongue&&!nextTongue&&tongue === number) {
  264. isTongue = true
  265. tongue = null
  266. } else if (tongue&&!nextTongue&&tongue !== number) {
  267. isTongue = false
  268. tongue = number
  269. }
  270. if(renderArr.length-1 === i) isTongue = true
  271. if (nextTongue && timeStampFilter(nextTongue.createdAt) !== timeStampFilter(createdAt)) {
  272. isTongue = true
  273. }
  274. const url = `${prodAwsS3}/${message}`
  275. const urlForward = `${prodAwsS3}/${forwardMessage}`
  276. const urlReply = `${prodAwsS3}/${replyMessage}`
  277. if (number !== userNumber) {
  278. if (type === 'text' && duration !== null) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  279. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  280. {isUnread&&<MessageDivider message='Unread Messages'/>}
  281. <MessageLeftCall
  282. message={message}
  283. initiator={initiator}
  284. duration={duration}
  285. tongue={isTongue}
  286. watched={!unread}
  287. edited={edited}
  288. avatarUrl={avatarUrl}
  289. color={color}
  290. createdAt={createdAt}
  291. name={name}
  292. lastName={lastName}
  293. caption={caption}
  294. emoji={emoji}
  295. emojiCompanion={emojiCompanion}
  296. pinned={pinned}
  297. isSomeSelected={isSomeSelected}
  298. isSelected={isSelected}
  299. handleSelected={handleSelected}
  300. _id={_id}
  301. nightMode={nightMode}
  302. handleReply={handleReply}
  303. handleForward={handleForward}
  304. /></div>)
  305. if (type === 'text' && !oldId && !companionIdForwardToAndFrom && !deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  306. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  307. {isUnread&&<MessageDivider message='Unread Messages'/>}
  308. <MessageLeftText
  309. message={message}
  310. tongue={isTongue}
  311. watched={!unread}
  312. edited={edited}
  313. avatarUrl={avatarUrl}
  314. color={color}
  315. createdAt={createdAt}
  316. name={name}
  317. lastName={lastName}
  318. caption={caption}
  319. emoji={emoji}
  320. emojiCompanion={emojiCompanion}
  321. pinned={pinned}
  322. isSomeSelected={isSomeSelected}
  323. isSelected={isSelected}
  324. handleSelected={handleSelected}
  325. _id={_id}
  326. nightMode={nightMode}
  327. handleReply={handleReply}
  328. handleForward={handleForward}
  329. /></div>)
  330. if (type === 'text' && deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  331. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  332. {isUnread&&<MessageDivider message='Unread Messages'/>}
  333. <MessageLeftDeleted
  334. tongue={isTongue}
  335. watched={watched}
  336. edited={edited}
  337. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  338. avatarUrl={avatarUrl}
  339. color={color}
  340. name={name}
  341. lastName={lastName}
  342. forwardReplyName={companionIdForwardToAndFrom?forwardName:replyName}
  343. forwardReplyLastName={companionIdForwardToAndFrom?forwardLastName:replyLastName}
  344. message={message}
  345. createdAt={createdAt}
  346. caption={caption}
  347. emoji={emoji}
  348. emojiCompanion={emojiCompanion}
  349. pinned={pinned}
  350. isSomeSelected={isSomeSelected}
  351. isSelected={isSelected}
  352. handleSelected={handleSelected}
  353. _id={_id}
  354. nightMode={nightMode}
  355. handleReply={handleReply}
  356. handleForward={handleForward}
  357. handleEdit={handleEdit}
  358. handleOpenTheChat={handleOpenTheChat}
  359. /></div>)
  360. if (type === 'text' && companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  361. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  362. {isUnread&&<MessageDivider message='Unread Messages'/>}
  363. <MessageLeftForward
  364. url={urlForward}
  365. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  366. oldId={oldId}
  367. tongue={isTongue}
  368. watched={!unread}
  369. edited={edited}
  370. avatarUrl={avatarUrl}
  371. color={color}
  372. name={name}
  373. lastName={lastName}
  374. forwardName={forwardName}
  375. forwardLastName={forwardLastName}
  376. forwardMessage={forwardMessage}
  377. forwardCaption={forwardCaption}
  378. message={message}
  379. createdAt={createdAt}
  380. caption={caption}
  381. emoji={emoji}
  382. emojiCompanion={emojiCompanion}
  383. pinned={pinned}
  384. isSomeSelected={isSomeSelected}
  385. isSelected={isSelected}
  386. handleSelected={handleSelected}
  387. _id={_id}
  388. nightMode={nightMode}
  389. handleReply={handleReply}
  390. handleForward={handleForward}
  391. fullType={fullType}
  392. handleScrollToTheChat={handleScrollToTheChat}
  393. /></div>)
  394. if (type === 'text' && oldId) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  395. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  396. {isUnread&&<MessageDivider message='Unread Messages'/>}
  397. <MessageLeftReply
  398. url={urlReply}
  399. tongue={isTongue}
  400. watched={!unread}
  401. edited={edited}
  402. avatarUrl={avatarUrl}
  403. color={color}
  404. replyMessage={replyMessage}
  405. message={message}
  406. createdAt={createdAt}
  407. name={name}
  408. lastName={lastName}
  409. replyName={replyName}
  410. replyLastName={replyLastName}
  411. replyCaption={replyCaption}
  412. caption={caption}
  413. emoji={emoji}
  414. emojiCompanion={emojiCompanion}
  415. pinned={pinned}
  416. isSomeSelected={isSomeSelected}
  417. isSelected={isSelected}
  418. handleSelected={handleSelected}
  419. _id={_id}
  420. nightMode={nightMode}
  421. handleReply={handleReply}
  422. handleForward={handleForward}
  423. fullType={fullType}
  424. handleScrollToTheMessage={handleScrollToTheMessage}
  425. oldId={oldId}
  426. /></div>)
  427. if (type === 'image') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  428. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  429. {isUnread&&<MessageDivider message='Unread Messages'/>}
  430. <MessageLeftImage
  431. url={url}
  432. tongue={isTongue}
  433. watched={!unread}
  434. edited={edited}
  435. avatarUrl={avatarUrl}
  436. color={color}
  437. createdAt={createdAt}
  438. fullType={fullType}
  439. caption={caption}
  440. emoji={emoji}
  441. emojiCompanion={emojiCompanion}
  442. pinned={pinned}
  443. isSomeSelected={isSomeSelected}
  444. isSelected={isSelected}
  445. handleSelected={handleSelected}
  446. _id={_id}
  447. name={name}
  448. lastName={lastName}
  449. nightMode={nightMode}
  450. handleReply={handleReply}
  451. handleForward={handleForward}
  452. /></div>)
  453. if (type === 'audio') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  454. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  455. {isUnread&&<MessageDivider message='Unread Messages'/>}
  456. <MessageLeftAudio
  457. url={url}
  458. tongue={isTongue}
  459. watched={!unread}
  460. edited={edited}
  461. avatarUrl={avatarUrl}
  462. color={color}
  463. name={name}
  464. lastName={lastName}
  465. createdAt={createdAt}
  466. fullType={fullType}
  467. caption={caption}
  468. emoji={emoji}
  469. emojiCompanion={emojiCompanion}
  470. pinned={pinned}
  471. isSomeSelected={isSomeSelected}
  472. isSelected={isSelected}
  473. handleSelected={handleSelected}
  474. _id={_id}
  475. nightMode={nightMode}
  476. handleReply={handleReply}
  477. handleForward={handleForward}
  478. /></div>)
  479. if (type === 'video') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  480. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  481. {isUnread&&<MessageDivider message='Unread Messages'/>}
  482. <MessageLeftVideo
  483. url={url}
  484. tongue={isTongue}
  485. watched={!unread}
  486. edited={edited}
  487. avatarUrl={avatarUrl}
  488. color={color}
  489. name={name}
  490. lastName={lastName}
  491. createdAt={createdAt}
  492. fullType={fullType}
  493. caption={caption}
  494. emoji={emoji}
  495. emojiCompanion={emojiCompanion}
  496. pinned={pinned}
  497. isSomeSelected={isSomeSelected}
  498. isSelected={isSelected}
  499. handleSelected={handleSelected}
  500. _id={_id}
  501. nightMode={nightMode}
  502. handleReply={handleReply}
  503. handleForward={handleForward}
  504. /></div>)
  505. if (type) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  506. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  507. {isUnread&&<MessageDivider message='Unread Messages'/>}
  508. <MessageLeftFile
  509. url={url}
  510. tongue={isTongue}
  511. watched={!unread}
  512. edited={edited}
  513. avatarUrl={avatarUrl}
  514. color={color}
  515. name={name}
  516. lastName={lastName}
  517. createdAt={createdAt}
  518. type={type}
  519. caption={caption}
  520. emoji={emoji}
  521. emojiCompanion={emojiCompanion}
  522. pinned={pinned}
  523. isSomeSelected={isSomeSelected}
  524. isSelected={isSelected}
  525. handleSelected={handleSelected}
  526. _id={_id}
  527. nightMode={nightMode}
  528. handleReply={handleReply}
  529. handleForward={handleForward}
  530. /></div>)
  531. } else {
  532. if (type === 'text' && duration !== null) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  533. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  534. {isUnread&&<MessageDivider message='Unread Messages'/>}
  535. <MessageRightCall
  536. message={message}
  537. initiator={initiator}
  538. duration={duration}
  539. tongue={isTongue}
  540. watched={watched}
  541. edited={edited}
  542. avatarUrl={avatarUrl}
  543. color={color}
  544. createdAt={createdAt}
  545. name={name}
  546. lastName={lastName}
  547. caption={caption}
  548. emoji={emoji}
  549. emojiCompanion={emojiCompanion}
  550. pinned={pinned}
  551. isSomeSelected={isSomeSelected}
  552. isSelected={isSelected}
  553. handleSelected={handleSelected}
  554. _id={_id}
  555. nightMode={nightMode}
  556. handleReply={handleReply}
  557. handleForward={handleForward}
  558. handleEdit={handleEdit}
  559. /></div>)
  560. if (type === 'text' && !oldId && !companionIdForwardToAndFrom && !deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  561. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  562. {isUnread&&<MessageDivider message='Unread Messages'/>}
  563. <MessageRightText
  564. message={message}
  565. tongue={isTongue}
  566. watched={watched}
  567. edited={edited}
  568. avatarUrl={avatarUrl}
  569. color={color}
  570. createdAt={createdAt}
  571. name={name}
  572. lastName={lastName}
  573. caption={caption}
  574. emoji={emoji}
  575. emojiCompanion={emojiCompanion}
  576. pinned={pinned}
  577. isSomeSelected={isSomeSelected}
  578. isSelected={isSelected}
  579. handleSelected={handleSelected}
  580. _id={_id}
  581. nightMode={nightMode}
  582. handleReply={handleReply}
  583. handleForward={handleForward}
  584. handleEdit={handleEdit}
  585. /></div>)
  586. if (type === 'text' && deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  587. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  588. {isUnread&&<MessageDivider message='Unread Messages'/>}
  589. <MessageRightDeleted
  590. tongue={isTongue}
  591. watched={watched}
  592. edited={edited}
  593. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  594. avatarUrl={avatarUrl}
  595. color={color}
  596. name={name}
  597. lastName={lastName}
  598. forwardReplyName={companionIdForwardToAndFrom?forwardName:replyName}
  599. forwardReplyLastName={companionIdForwardToAndFrom?forwardLastName:replyLastName}
  600. message={message}
  601. createdAt={createdAt}
  602. caption={caption}
  603. emoji={emoji}
  604. emojiCompanion={emojiCompanion}
  605. pinned={pinned}
  606. isSomeSelected={isSomeSelected}
  607. isSelected={isSelected}
  608. handleSelected={handleSelected}
  609. _id={_id}
  610. nightMode={nightMode}
  611. handleReply={handleReply}
  612. handleForward={handleForward}
  613. handleEdit={handleEdit}
  614. handleOpenTheChat={handleOpenTheChat}
  615. /></div>)
  616. if (type === 'text' && companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  617. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  618. {isUnread&&<MessageDivider message='Unread Messages'/>}
  619. <MessageRightForward
  620. url={urlForward}
  621. oldId={oldId}
  622. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  623. tongue={isTongue}
  624. watched={watched}
  625. edited={edited}
  626. avatarUrl={avatarUrl}
  627. color={color}
  628. name={name}
  629. lastName={lastName}
  630. forwardName={forwardName}
  631. forwardLastName={forwardLastName}
  632. forwardMessage={forwardMessage}
  633. forwardCaption={forwardCaption}
  634. message={message}
  635. createdAt={createdAt}
  636. caption={caption}
  637. emoji={emoji}
  638. emojiCompanion={emojiCompanion}
  639. pinned={pinned}
  640. isSomeSelected={isSomeSelected}
  641. isSelected={isSelected}
  642. handleSelected={handleSelected}
  643. _id={_id}
  644. nightMode={nightMode}
  645. handleReply={handleReply}
  646. handleForward={handleForward}
  647. handleEdit={handleEdit}
  648. fullType={fullType}
  649. handleScrollToTheChat={handleScrollToTheChat}
  650. /></div>)
  651. if (type === 'text' && oldId) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  652. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  653. {isUnread&&<MessageDivider message='Unread Messages'/>}
  654. <MessageRightReply
  655. url={urlReply}
  656. tongue={isTongue}
  657. watched={watched}
  658. edited={edited}
  659. avatarUrl={avatarUrl}
  660. color={color}
  661. replyMessage={replyMessage}
  662. message={message}
  663. createdAt={createdAt}
  664. name={name}
  665. lastName={lastName}
  666. replyName={replyName}
  667. replyLastName={replyLastName}
  668. replyCaption={replyCaption}
  669. caption={caption}
  670. emoji={emoji}
  671. emojiCompanion={emojiCompanion}
  672. pinned={pinned}
  673. isSomeSelected={isSomeSelected}
  674. isSelected={isSelected}
  675. handleSelected={handleSelected}
  676. _id={_id}
  677. nightMode={nightMode}
  678. handleReply={handleReply}
  679. handleForward={handleForward}
  680. handleEdit={handleEdit}
  681. fullType={fullType}
  682. handleScrollToTheMessage={handleScrollToTheMessage}
  683. oldId={oldId}
  684. /></div>)
  685. if (type === 'image') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  686. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  687. {isUnread&&<MessageDivider message='Unread Messages'/>}
  688. <MessageRightImage
  689. url={url}
  690. tongue={isTongue}
  691. watched={watched}
  692. edited={edited}
  693. avatarUrl={avatarUrl}
  694. color={color}
  695. createdAt={createdAt}
  696. fullType={fullType}
  697. caption={caption}
  698. emoji={emoji}
  699. emojiCompanion={emojiCompanion}
  700. pinned={pinned}
  701. isSomeSelected={isSomeSelected}
  702. isSelected={isSelected}
  703. handleSelected={handleSelected}
  704. _id={_id}
  705. name={name}
  706. lastName={lastName}
  707. nightMode={nightMode}
  708. handleReply={handleReply}
  709. handleForward={handleForward}
  710. handleEdit={handleEdit}
  711. /></div>)
  712. if (type === 'audio') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  713. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  714. {isUnread&&<MessageDivider message='Unread Messages'/>}
  715. <MessageRightAudio
  716. url={url}
  717. tongue={isTongue}
  718. watched={watched}
  719. edited={edited}
  720. avatarUrl={avatarUrl}
  721. color={color}
  722. name={name}
  723. lastName={lastName}
  724. createdAt={createdAt}
  725. fullType={fullType}
  726. caption={caption}
  727. emoji={emoji}
  728. emojiCompanion={emojiCompanion}
  729. pinned={pinned}
  730. isSomeSelected={isSomeSelected}
  731. isSelected={isSelected}
  732. handleSelected={handleSelected}
  733. _id={_id}
  734. nightMode={nightMode}
  735. handleReply={handleReply}
  736. handleForward={handleForward}
  737. handleEdit={handleEdit}
  738. /></div>)
  739. if (type === 'video') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  740. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  741. {isUnread&&<MessageDivider message='Unread Messages'/>}
  742. <MessageRightVideo
  743. url={url}
  744. tongue={isTongue}
  745. watched={watched}
  746. edited={edited}
  747. avatarUrl={avatarUrl}
  748. color={color}
  749. name={name}
  750. lastName={lastName}
  751. createdAt={createdAt}
  752. fullType={fullType}
  753. caption={caption}
  754. emoji={emoji}
  755. emojiCompanion={emojiCompanion}
  756. pinned={pinned}
  757. isSomeSelected={isSomeSelected}
  758. isSelected={isSelected}
  759. handleSelected={handleSelected}
  760. _id={_id}
  761. nightMode={nightMode}
  762. handleReply={handleReply}
  763. handleForward={handleForward}
  764. handleEdit={handleEdit}
  765. /></div>)
  766. if (type) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  767. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  768. {isUnread&&<MessageDivider message='Unread Messages'/>}
  769. <MessageRightFile
  770. url={url}
  771. tongue={isTongue}
  772. watched={watched}
  773. edited={edited}
  774. avatarUrl={avatarUrl}
  775. color={color}
  776. name={name}
  777. lastName={lastName}
  778. createdAt={createdAt}
  779. type={type}
  780. caption={caption}
  781. emoji={emoji}
  782. emojiCompanion={emojiCompanion}
  783. pinned={pinned}
  784. isSomeSelected={isSomeSelected}
  785. isSelected={isSelected}
  786. handleSelected={handleSelected}
  787. _id={_id}
  788. nightMode={nightMode}
  789. handleReply={handleReply}
  790. handleForward={handleForward}
  791. handleEdit={handleEdit}
  792. /></div>)
  793. }
  794. }) : <AlertInfo name='You do not have messages yet!' />}
  795. </div>
  796. </div>
  797. {!openPinned && !isSomeSelected && <SendMessage isArrow={isArrow} silentMode={silentMode} isReply={isReply} setIsReply={setIsReply}
  798. isForward={isForward} setIsForward={setIsForward}
  799. isEdit={isEdit} setIsEdit={setIsEdit}
  800. modalForward={modalForward} handleScrollToTheMessage={handleScrollToTheMessage}/>}
  801. {openPinned&&!isSomeSelected&&<UnpinBar pinnedMessagesMemo={pinnedMessagesMemo} handleUnpinAll={handleUnpinAll} />}
  802. </div>
  803. );
  804. }
  805. export default ChatBar