index.tsx 29 KB

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