index.tsx 29 KB

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