index.tsx 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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. avatarUrl={avatarUrl}
  288. color={color}
  289. createdAt={createdAt}
  290. name={name}
  291. lastName={lastName}
  292. emoji={emoji}
  293. emojiCompanion={emojiCompanion}
  294. isSomeSelected={isSomeSelected}
  295. isSelected={isSelected}
  296. handleSelected={handleSelected}
  297. _id={_id}
  298. nightMode={nightMode}
  299. handleReply={handleReply}
  300. /></div>)
  301. if (type === 'text' && !oldId && !companionIdForwardToAndFrom && !deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  302. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  303. {isUnread&&<MessageDivider message='Unread Messages'/>}
  304. <MessageLeftText
  305. message={message}
  306. tongue={isTongue}
  307. watched={!unread}
  308. edited={edited}
  309. avatarUrl={avatarUrl}
  310. color={color}
  311. createdAt={createdAt}
  312. name={name}
  313. lastName={lastName}
  314. caption={caption}
  315. emoji={emoji}
  316. emojiCompanion={emojiCompanion}
  317. pinned={pinned}
  318. isSomeSelected={isSomeSelected}
  319. isSelected={isSelected}
  320. handleSelected={handleSelected}
  321. _id={_id}
  322. nightMode={nightMode}
  323. handleReply={handleReply}
  324. handleForward={handleForward}
  325. /></div>)
  326. if (type === 'text' && deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  327. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  328. {isUnread&&<MessageDivider message='Unread Messages'/>}
  329. <MessageLeftDeleted
  330. tongue={isTongue}
  331. watched={watched}
  332. edited={edited}
  333. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  334. avatarUrl={avatarUrl}
  335. color={color}
  336. name={name}
  337. lastName={lastName}
  338. forwardReplyName={companionIdForwardToAndFrom?forwardName:replyName}
  339. forwardReplyLastName={companionIdForwardToAndFrom?forwardLastName:replyLastName}
  340. message={message}
  341. createdAt={createdAt}
  342. caption={caption}
  343. emoji={emoji}
  344. emojiCompanion={emojiCompanion}
  345. pinned={pinned}
  346. isSomeSelected={isSomeSelected}
  347. isSelected={isSelected}
  348. handleSelected={handleSelected}
  349. _id={_id}
  350. nightMode={nightMode}
  351. handleReply={handleReply}
  352. handleForward={handleForward}
  353. handleEdit={handleEdit}
  354. handleOpenTheChat={handleOpenTheChat}
  355. /></div>)
  356. if (type === 'text' && companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  357. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  358. {isUnread&&<MessageDivider message='Unread Messages'/>}
  359. <MessageLeftForward
  360. url={urlForward}
  361. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  362. oldId={oldId}
  363. tongue={isTongue}
  364. watched={!unread}
  365. edited={edited}
  366. avatarUrl={avatarUrl}
  367. color={color}
  368. name={name}
  369. lastName={lastName}
  370. forwardName={forwardName}
  371. forwardLastName={forwardLastName}
  372. forwardMessage={forwardMessage}
  373. forwardCaption={forwardCaption}
  374. message={message}
  375. createdAt={createdAt}
  376. caption={caption}
  377. emoji={emoji}
  378. emojiCompanion={emojiCompanion}
  379. pinned={pinned}
  380. isSomeSelected={isSomeSelected}
  381. isSelected={isSelected}
  382. handleSelected={handleSelected}
  383. _id={_id}
  384. nightMode={nightMode}
  385. handleReply={handleReply}
  386. handleForward={handleForward}
  387. fullType={fullType}
  388. handleScrollToTheChat={handleScrollToTheChat}
  389. /></div>)
  390. if (type === 'text' && oldId) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  391. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  392. {isUnread&&<MessageDivider message='Unread Messages'/>}
  393. <MessageLeftReply
  394. url={urlReply}
  395. tongue={isTongue}
  396. watched={!unread}
  397. edited={edited}
  398. avatarUrl={avatarUrl}
  399. color={color}
  400. replyMessage={replyMessage}
  401. message={message}
  402. createdAt={createdAt}
  403. name={name}
  404. lastName={lastName}
  405. replyName={replyName}
  406. replyLastName={replyLastName}
  407. replyCaption={replyCaption}
  408. caption={caption}
  409. emoji={emoji}
  410. emojiCompanion={emojiCompanion}
  411. pinned={pinned}
  412. isSomeSelected={isSomeSelected}
  413. isSelected={isSelected}
  414. handleSelected={handleSelected}
  415. _id={_id}
  416. nightMode={nightMode}
  417. handleReply={handleReply}
  418. handleForward={handleForward}
  419. fullType={fullType}
  420. handleScrollToTheMessage={handleScrollToTheMessage}
  421. oldId={oldId}
  422. /></div>)
  423. if (type === 'image') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  424. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  425. {isUnread&&<MessageDivider message='Unread Messages'/>}
  426. <MessageLeftImage
  427. url={url}
  428. tongue={isTongue}
  429. watched={!unread}
  430. edited={edited}
  431. avatarUrl={avatarUrl}
  432. color={color}
  433. createdAt={createdAt}
  434. fullType={fullType}
  435. caption={caption}
  436. emoji={emoji}
  437. emojiCompanion={emojiCompanion}
  438. pinned={pinned}
  439. isSomeSelected={isSomeSelected}
  440. isSelected={isSelected}
  441. handleSelected={handleSelected}
  442. _id={_id}
  443. name={name}
  444. lastName={lastName}
  445. nightMode={nightMode}
  446. handleReply={handleReply}
  447. handleForward={handleForward}
  448. /></div>)
  449. if (type === 'audio') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  450. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  451. {isUnread&&<MessageDivider message='Unread Messages'/>}
  452. <MessageLeftAudio
  453. url={url}
  454. tongue={isTongue}
  455. watched={!unread}
  456. edited={edited}
  457. avatarUrl={avatarUrl}
  458. color={color}
  459. name={name}
  460. lastName={lastName}
  461. createdAt={createdAt}
  462. fullType={fullType}
  463. caption={caption}
  464. emoji={emoji}
  465. emojiCompanion={emojiCompanion}
  466. pinned={pinned}
  467. isSomeSelected={isSomeSelected}
  468. isSelected={isSelected}
  469. handleSelected={handleSelected}
  470. _id={_id}
  471. nightMode={nightMode}
  472. handleReply={handleReply}
  473. handleForward={handleForward}
  474. /></div>)
  475. if (type === 'video') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  476. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  477. {isUnread&&<MessageDivider message='Unread Messages'/>}
  478. <MessageLeftVideo
  479. url={url}
  480. tongue={isTongue}
  481. watched={!unread}
  482. edited={edited}
  483. avatarUrl={avatarUrl}
  484. color={color}
  485. name={name}
  486. lastName={lastName}
  487. createdAt={createdAt}
  488. fullType={fullType}
  489. caption={caption}
  490. emoji={emoji}
  491. emojiCompanion={emojiCompanion}
  492. pinned={pinned}
  493. isSomeSelected={isSomeSelected}
  494. isSelected={isSelected}
  495. handleSelected={handleSelected}
  496. _id={_id}
  497. nightMode={nightMode}
  498. handleReply={handleReply}
  499. handleForward={handleForward}
  500. /></div>)
  501. if (type) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  502. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  503. {isUnread&&<MessageDivider message='Unread Messages'/>}
  504. <MessageLeftFile
  505. url={url}
  506. tongue={isTongue}
  507. watched={!unread}
  508. edited={edited}
  509. avatarUrl={avatarUrl}
  510. color={color}
  511. name={name}
  512. lastName={lastName}
  513. createdAt={createdAt}
  514. type={type}
  515. caption={caption}
  516. emoji={emoji}
  517. emojiCompanion={emojiCompanion}
  518. pinned={pinned}
  519. isSomeSelected={isSomeSelected}
  520. isSelected={isSelected}
  521. handleSelected={handleSelected}
  522. _id={_id}
  523. nightMode={nightMode}
  524. handleReply={handleReply}
  525. handleForward={handleForward}
  526. /></div>)
  527. } else {
  528. if (type === 'text' && duration !== null) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  529. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  530. {isUnread&&<MessageDivider message='Unread Messages'/>}
  531. <MessageRightCall
  532. message={message}
  533. initiator={initiator}
  534. duration={duration}
  535. tongue={isTongue}
  536. watched={watched}
  537. avatarUrl={avatarUrl}
  538. color={color}
  539. createdAt={createdAt}
  540. name={name}
  541. lastName={lastName}
  542. emoji={emoji}
  543. emojiCompanion={emojiCompanion}
  544. isSomeSelected={isSomeSelected}
  545. isSelected={isSelected}
  546. handleSelected={handleSelected}
  547. _id={_id}
  548. nightMode={nightMode}
  549. handleReply={handleReply}
  550. /></div>)
  551. if (type === 'text' && !oldId && !companionIdForwardToAndFrom && !deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  552. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  553. {isUnread&&<MessageDivider message='Unread Messages'/>}
  554. <MessageRightText
  555. message={message}
  556. tongue={isTongue}
  557. watched={watched}
  558. edited={edited}
  559. avatarUrl={avatarUrl}
  560. color={color}
  561. createdAt={createdAt}
  562. name={name}
  563. lastName={lastName}
  564. caption={caption}
  565. emoji={emoji}
  566. emojiCompanion={emojiCompanion}
  567. pinned={pinned}
  568. isSomeSelected={isSomeSelected}
  569. isSelected={isSelected}
  570. handleSelected={handleSelected}
  571. _id={_id}
  572. nightMode={nightMode}
  573. handleReply={handleReply}
  574. handleForward={handleForward}
  575. handleEdit={handleEdit}
  576. /></div>)
  577. if (type === 'text' && deleted) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  578. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  579. {isUnread&&<MessageDivider message='Unread Messages'/>}
  580. <MessageRightDeleted
  581. tongue={isTongue}
  582. watched={watched}
  583. edited={edited}
  584. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  585. avatarUrl={avatarUrl}
  586. color={color}
  587. name={name}
  588. lastName={lastName}
  589. forwardReplyName={companionIdForwardToAndFrom?forwardName:replyName}
  590. forwardReplyLastName={companionIdForwardToAndFrom?forwardLastName:replyLastName}
  591. message={message}
  592. createdAt={createdAt}
  593. caption={caption}
  594. emoji={emoji}
  595. emojiCompanion={emojiCompanion}
  596. pinned={pinned}
  597. isSomeSelected={isSomeSelected}
  598. isSelected={isSelected}
  599. handleSelected={handleSelected}
  600. _id={_id}
  601. nightMode={nightMode}
  602. handleReply={handleReply}
  603. handleForward={handleForward}
  604. handleEdit={handleEdit}
  605. handleOpenTheChat={handleOpenTheChat}
  606. /></div>)
  607. if (type === 'text' && companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  608. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  609. {isUnread&&<MessageDivider message='Unread Messages'/>}
  610. <MessageRightForward
  611. url={urlForward}
  612. oldId={oldId}
  613. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  614. tongue={isTongue}
  615. watched={watched}
  616. edited={edited}
  617. avatarUrl={avatarUrl}
  618. color={color}
  619. name={name}
  620. lastName={lastName}
  621. forwardName={forwardName}
  622. forwardLastName={forwardLastName}
  623. forwardMessage={forwardMessage}
  624. forwardCaption={forwardCaption}
  625. message={message}
  626. createdAt={createdAt}
  627. caption={caption}
  628. emoji={emoji}
  629. emojiCompanion={emojiCompanion}
  630. pinned={pinned}
  631. isSomeSelected={isSomeSelected}
  632. isSelected={isSelected}
  633. handleSelected={handleSelected}
  634. _id={_id}
  635. nightMode={nightMode}
  636. handleReply={handleReply}
  637. handleForward={handleForward}
  638. handleEdit={handleEdit}
  639. fullType={fullType}
  640. handleScrollToTheChat={handleScrollToTheChat}
  641. /></div>)
  642. if (type === 'text' && oldId) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  643. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  644. {isUnread&&<MessageDivider message='Unread Messages'/>}
  645. <MessageRightReply
  646. url={urlReply}
  647. tongue={isTongue}
  648. watched={watched}
  649. edited={edited}
  650. avatarUrl={avatarUrl}
  651. color={color}
  652. replyMessage={replyMessage}
  653. message={message}
  654. createdAt={createdAt}
  655. name={name}
  656. lastName={lastName}
  657. replyName={replyName}
  658. replyLastName={replyLastName}
  659. replyCaption={replyCaption}
  660. caption={caption}
  661. emoji={emoji}
  662. emojiCompanion={emojiCompanion}
  663. pinned={pinned}
  664. isSomeSelected={isSomeSelected}
  665. isSelected={isSelected}
  666. handleSelected={handleSelected}
  667. _id={_id}
  668. nightMode={nightMode}
  669. handleReply={handleReply}
  670. handleForward={handleForward}
  671. handleEdit={handleEdit}
  672. fullType={fullType}
  673. handleScrollToTheMessage={handleScrollToTheMessage}
  674. oldId={oldId}
  675. /></div>)
  676. if (type === 'image') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  677. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  678. {isUnread&&<MessageDivider message='Unread Messages'/>}
  679. <MessageRightImage
  680. url={url}
  681. tongue={isTongue}
  682. watched={watched}
  683. edited={edited}
  684. avatarUrl={avatarUrl}
  685. color={color}
  686. createdAt={createdAt}
  687. fullType={fullType}
  688. caption={caption}
  689. emoji={emoji}
  690. emojiCompanion={emojiCompanion}
  691. pinned={pinned}
  692. isSomeSelected={isSomeSelected}
  693. isSelected={isSelected}
  694. handleSelected={handleSelected}
  695. _id={_id}
  696. name={name}
  697. lastName={lastName}
  698. nightMode={nightMode}
  699. handleReply={handleReply}
  700. handleForward={handleForward}
  701. handleEdit={handleEdit}
  702. /></div>)
  703. if (type === 'audio') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  704. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  705. {isUnread&&<MessageDivider message='Unread Messages'/>}
  706. <MessageRightAudio
  707. url={url}
  708. tongue={isTongue}
  709. watched={watched}
  710. edited={edited}
  711. avatarUrl={avatarUrl}
  712. color={color}
  713. name={name}
  714. lastName={lastName}
  715. createdAt={createdAt}
  716. fullType={fullType}
  717. caption={caption}
  718. emoji={emoji}
  719. emojiCompanion={emojiCompanion}
  720. pinned={pinned}
  721. isSomeSelected={isSomeSelected}
  722. isSelected={isSelected}
  723. handleSelected={handleSelected}
  724. _id={_id}
  725. nightMode={nightMode}
  726. handleReply={handleReply}
  727. handleForward={handleForward}
  728. handleEdit={handleEdit}
  729. /></div>)
  730. if (type === 'video') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  731. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  732. {isUnread&&<MessageDivider message='Unread Messages'/>}
  733. <MessageRightVideo
  734. url={url}
  735. tongue={isTongue}
  736. watched={watched}
  737. edited={edited}
  738. avatarUrl={avatarUrl}
  739. color={color}
  740. name={name}
  741. lastName={lastName}
  742. createdAt={createdAt}
  743. fullType={fullType}
  744. caption={caption}
  745. emoji={emoji}
  746. emojiCompanion={emojiCompanion}
  747. pinned={pinned}
  748. isSomeSelected={isSomeSelected}
  749. isSelected={isSelected}
  750. handleSelected={handleSelected}
  751. _id={_id}
  752. nightMode={nightMode}
  753. handleReply={handleReply}
  754. handleForward={handleForward}
  755. handleEdit={handleEdit}
  756. /></div>)
  757. if (type) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  758. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  759. {isUnread&&<MessageDivider message='Unread Messages'/>}
  760. <MessageRightFile
  761. url={url}
  762. tongue={isTongue}
  763. watched={watched}
  764. edited={edited}
  765. avatarUrl={avatarUrl}
  766. color={color}
  767. name={name}
  768. lastName={lastName}
  769. createdAt={createdAt}
  770. type={type}
  771. caption={caption}
  772. emoji={emoji}
  773. emojiCompanion={emojiCompanion}
  774. pinned={pinned}
  775. isSomeSelected={isSomeSelected}
  776. isSelected={isSelected}
  777. handleSelected={handleSelected}
  778. _id={_id}
  779. nightMode={nightMode}
  780. handleReply={handleReply}
  781. handleForward={handleForward}
  782. handleEdit={handleEdit}
  783. /></div>)
  784. }
  785. }) : <AlertInfo name='You do not have messages yet!' />}
  786. </div>
  787. </div>
  788. {!openPinned && !isSomeSelected && <SendMessage isArrow={isArrow} silentMode={silentMode} isReply={isReply} setIsReply={setIsReply}
  789. isForward={isForward} setIsForward={setIsForward}
  790. isEdit={isEdit} setIsEdit={setIsEdit}
  791. modalForward={modalForward} handleScrollToTheMessage={handleScrollToTheMessage}/>}
  792. {openPinned&&!isSomeSelected&&<UnpinBar pinnedMessagesMemo={pinnedMessagesMemo} handleUnpinAll={handleUnpinAll} />}
  793. </div>
  794. );
  795. }
  796. export default ChatBar