index.tsx 27 KB

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