index.tsx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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},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. avatarUrl={avatarUrl}
  271. color={color}
  272. createdAt={createdAt}
  273. name={name}
  274. lastName={lastName}
  275. caption={caption}
  276. emoji={emoji}
  277. emojiCompanion={emojiCompanion}
  278. pinned={pinned}
  279. isSomeSelected={isSomeSelected}
  280. isSelected={isSelected}
  281. handleSelected={handleSelected}
  282. _id={_id}
  283. nightMode={nightMode}
  284. handleReply={handleReply}
  285. handleForward={handleForward}
  286. /></div>)
  287. if (type === 'text' && companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  288. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  289. {isUnread&&<MessageDivider message='Unread Messages'/>}
  290. <MessageLeftForward
  291. url={urlForward}
  292. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  293. oldId={oldId}
  294. tongue={isTongue}
  295. watched={!unread}
  296. avatarUrl={avatarUrl}
  297. color={color}
  298. name={name}
  299. lastName={lastName}
  300. forwardName={forwardName}
  301. forwardLastName={forwardLastName}
  302. forwardMessage={forwardMessage}
  303. forwardCaption={forwardCaption}
  304. message={message}
  305. createdAt={createdAt}
  306. caption={caption}
  307. emoji={emoji}
  308. emojiCompanion={emojiCompanion}
  309. pinned={pinned}
  310. isSomeSelected={isSomeSelected}
  311. isSelected={isSelected}
  312. handleSelected={handleSelected}
  313. _id={_id}
  314. nightMode={nightMode}
  315. handleReply={handleReply}
  316. handleForward={handleForward}
  317. fullType={fullType}
  318. handleScrollToTheChat={handleScrollToTheChat}
  319. /></div>)
  320. if (type === 'text' && oldId) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  321. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  322. {isUnread&&<MessageDivider message='Unread Messages'/>}
  323. <MessageLeftReply
  324. url={urlReply}
  325. tongue={isTongue}
  326. watched={!unread}
  327. avatarUrl={avatarUrl}
  328. color={color}
  329. replyMessage={replyMessage}
  330. message={message}
  331. createdAt={createdAt}
  332. name={name}
  333. lastName={lastName}
  334. replyName={replyName}
  335. replyLastName={replyLastName}
  336. replyCaption={replyCaption}
  337. caption={caption}
  338. emoji={emoji}
  339. emojiCompanion={emojiCompanion}
  340. pinned={pinned}
  341. isSomeSelected={isSomeSelected}
  342. isSelected={isSelected}
  343. handleSelected={handleSelected}
  344. _id={_id}
  345. nightMode={nightMode}
  346. handleReply={handleReply}
  347. handleForward={handleForward}
  348. fullType={fullType}
  349. handleScrollToTheMessage={handleScrollToTheMessage}
  350. oldId={oldId}
  351. /></div>)
  352. if (type === 'image') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  353. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  354. {isUnread&&<MessageDivider message='Unread Messages'/>}
  355. <MessageLeftImage
  356. url={url}
  357. tongue={isTongue}
  358. watched={!unread}
  359. avatarUrl={avatarUrl}
  360. color={color}
  361. createdAt={createdAt}
  362. fullType={fullType}
  363. caption={caption}
  364. emoji={emoji}
  365. emojiCompanion={emojiCompanion}
  366. pinned={pinned}
  367. isSomeSelected={isSomeSelected}
  368. isSelected={isSelected}
  369. handleSelected={handleSelected}
  370. _id={_id}
  371. name={name}
  372. lastName={lastName}
  373. nightMode={nightMode}
  374. handleReply={handleReply}
  375. handleForward={handleForward}
  376. /></div>)
  377. if (type === 'audio') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  378. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  379. {isUnread&&<MessageDivider message='Unread Messages'/>}
  380. <MessageLeftAudio
  381. url={url}
  382. tongue={isTongue}
  383. watched={!unread}
  384. avatarUrl={avatarUrl}
  385. color={color}
  386. name={name}
  387. lastName={lastName}
  388. createdAt={createdAt}
  389. fullType={fullType}
  390. caption={caption}
  391. emoji={emoji}
  392. emojiCompanion={emojiCompanion}
  393. pinned={pinned}
  394. isSomeSelected={isSomeSelected}
  395. isSelected={isSelected}
  396. handleSelected={handleSelected}
  397. _id={_id}
  398. nightMode={nightMode}
  399. handleReply={handleReply}
  400. handleForward={handleForward}
  401. /></div>)
  402. if (type === 'video') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  403. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  404. {isUnread&&<MessageDivider message='Unread Messages'/>}
  405. <MessageLeftVideo
  406. url={url}
  407. tongue={isTongue}
  408. watched={!unread}
  409. avatarUrl={avatarUrl}
  410. color={color}
  411. name={name}
  412. lastName={lastName}
  413. createdAt={createdAt}
  414. fullType={fullType}
  415. caption={caption}
  416. emoji={emoji}
  417. emojiCompanion={emojiCompanion}
  418. pinned={pinned}
  419. isSomeSelected={isSomeSelected}
  420. isSelected={isSelected}
  421. handleSelected={handleSelected}
  422. _id={_id}
  423. nightMode={nightMode}
  424. handleReply={handleReply}
  425. handleForward={handleForward}
  426. /></div>)
  427. if (type) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  428. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  429. {isUnread&&<MessageDivider message='Unread Messages'/>}
  430. <MessageLeftFile
  431. url={url}
  432. tongue={isTongue}
  433. watched={!unread}
  434. avatarUrl={avatarUrl}
  435. color={color}
  436. name={name}
  437. lastName={lastName}
  438. createdAt={createdAt}
  439. type={type}
  440. caption={caption}
  441. emoji={emoji}
  442. emojiCompanion={emojiCompanion}
  443. pinned={pinned}
  444. isSomeSelected={isSomeSelected}
  445. isSelected={isSelected}
  446. handleSelected={handleSelected}
  447. _id={_id}
  448. nightMode={nightMode}
  449. handleReply={handleReply}
  450. handleForward={handleForward}
  451. /></div>)
  452. } else {
  453. if (type === 'text' && !oldId && !companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  454. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  455. {isUnread&&<MessageDivider message='Unread Messages'/>}
  456. <MessageRightText
  457. message={message}
  458. tongue={isTongue}
  459. watched={watched}
  460. avatarUrl={avatarUrl}
  461. color={color}
  462. createdAt={createdAt}
  463. name={name}
  464. lastName={lastName}
  465. caption={caption}
  466. emoji={emoji}
  467. emojiCompanion={emojiCompanion}
  468. pinned={pinned}
  469. isSomeSelected={isSomeSelected}
  470. isSelected={isSelected}
  471. handleSelected={handleSelected}
  472. _id={_id}
  473. nightMode={nightMode}
  474. handleReply={handleReply}
  475. handleForward={handleForward}
  476. handleEdit={handleEdit}
  477. /></div>)
  478. if (type === 'text' && companionIdForwardToAndFrom) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  479. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  480. {isUnread&&<MessageDivider message='Unread Messages'/>}
  481. <MessageRightForward
  482. url={urlForward}
  483. oldId={oldId}
  484. companionIdForwardToAndFrom={companionIdForwardToAndFrom}
  485. tongue={isTongue}
  486. watched={watched}
  487. avatarUrl={avatarUrl}
  488. color={color}
  489. name={name}
  490. lastName={lastName}
  491. forwardName={forwardName}
  492. forwardLastName={forwardLastName}
  493. forwardMessage={forwardMessage}
  494. forwardCaption={forwardCaption}
  495. message={message}
  496. createdAt={createdAt}
  497. caption={caption}
  498. emoji={emoji}
  499. emojiCompanion={emojiCompanion}
  500. pinned={pinned}
  501. isSomeSelected={isSomeSelected}
  502. isSelected={isSelected}
  503. handleSelected={handleSelected}
  504. _id={_id}
  505. nightMode={nightMode}
  506. handleReply={handleReply}
  507. handleForward={handleForward}
  508. handleEdit={handleEdit}
  509. fullType={fullType}
  510. handleScrollToTheChat={handleScrollToTheChat}
  511. /></div>)
  512. if (type === 'text' && oldId) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  513. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  514. {isUnread&&<MessageDivider message='Unread Messages'/>}
  515. <MessageRightReply
  516. url={urlReply}
  517. tongue={isTongue}
  518. watched={watched}
  519. avatarUrl={avatarUrl}
  520. color={color}
  521. replyMessage={replyMessage}
  522. message={message}
  523. createdAt={createdAt}
  524. name={name}
  525. lastName={lastName}
  526. replyName={replyName}
  527. replyLastName={replyLastName}
  528. replyCaption={replyCaption}
  529. caption={caption}
  530. emoji={emoji}
  531. emojiCompanion={emojiCompanion}
  532. pinned={pinned}
  533. isSomeSelected={isSomeSelected}
  534. isSelected={isSelected}
  535. handleSelected={handleSelected}
  536. _id={_id}
  537. nightMode={nightMode}
  538. handleReply={handleReply}
  539. handleForward={handleForward}
  540. handleEdit={handleEdit}
  541. fullType={fullType}
  542. handleScrollToTheMessage={handleScrollToTheMessage}
  543. oldId={oldId}
  544. /></div>)
  545. if (type === 'image') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  546. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  547. {isUnread&&<MessageDivider message='Unread Messages'/>}
  548. <MessageRightImage
  549. url={url}
  550. tongue={isTongue}
  551. watched={watched}
  552. avatarUrl={avatarUrl}
  553. color={color}
  554. createdAt={createdAt}
  555. fullType={fullType}
  556. caption={caption}
  557. emoji={emoji}
  558. emojiCompanion={emojiCompanion}
  559. pinned={pinned}
  560. isSomeSelected={isSomeSelected}
  561. isSelected={isSelected}
  562. handleSelected={handleSelected}
  563. _id={_id}
  564. name={name}
  565. lastName={lastName}
  566. nightMode={nightMode}
  567. handleReply={handleReply}
  568. handleForward={handleForward}
  569. handleEdit={handleEdit}
  570. /></div>)
  571. if (type === 'audio') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  572. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  573. {isUnread&&<MessageDivider message='Unread Messages'/>}
  574. <MessageRightAudio
  575. url={url}
  576. tongue={isTongue}
  577. watched={watched}
  578. avatarUrl={avatarUrl}
  579. color={color}
  580. name={name}
  581. lastName={lastName}
  582. createdAt={createdAt}
  583. fullType={fullType}
  584. caption={caption}
  585. emoji={emoji}
  586. emojiCompanion={emojiCompanion}
  587. pinned={pinned}
  588. isSomeSelected={isSomeSelected}
  589. isSelected={isSelected}
  590. handleSelected={handleSelected}
  591. _id={_id}
  592. nightMode={nightMode}
  593. handleReply={handleReply}
  594. handleForward={handleForward}
  595. handleEdit={handleEdit}
  596. /></div>)
  597. if (type === 'video') return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  598. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  599. {isUnread&&<MessageDivider message='Unread Messages'/>}
  600. <MessageRightVideo
  601. url={url}
  602. tongue={isTongue}
  603. watched={watched}
  604. avatarUrl={avatarUrl}
  605. color={color}
  606. name={name}
  607. lastName={lastName}
  608. createdAt={createdAt}
  609. fullType={fullType}
  610. caption={caption}
  611. emoji={emoji}
  612. emojiCompanion={emojiCompanion}
  613. pinned={pinned}
  614. isSomeSelected={isSomeSelected}
  615. isSelected={isSelected}
  616. handleSelected={handleSelected}
  617. _id={_id}
  618. nightMode={nightMode}
  619. handleReply={handleReply}
  620. handleForward={handleForward}
  621. handleEdit={handleEdit}
  622. /></div>)
  623. if (type) return (<div key={createdAt} id={_id} style={{borderRadius: 7}}>
  624. {isTime&&<MessageDivider message={timeStampFilter(createdAt)}/>}
  625. {isUnread&&<MessageDivider message='Unread Messages'/>}
  626. <MessageRightFile
  627. url={url}
  628. tongue={isTongue}
  629. watched={watched}
  630. avatarUrl={avatarUrl}
  631. color={color}
  632. name={name}
  633. lastName={lastName}
  634. createdAt={createdAt}
  635. type={type}
  636. caption={caption}
  637. emoji={emoji}
  638. emojiCompanion={emojiCompanion}
  639. pinned={pinned}
  640. isSomeSelected={isSomeSelected}
  641. isSelected={isSelected}
  642. handleSelected={handleSelected}
  643. _id={_id}
  644. nightMode={nightMode}
  645. handleReply={handleReply}
  646. handleForward={handleForward}
  647. handleEdit={handleEdit}
  648. /></div>)
  649. }
  650. }) : <AlertInfo name='You do not have messages yet!' />}
  651. </div>
  652. </div>
  653. {!openPinned && !isSomeSelected && <SendMessage isArrow={isArrow} silentMode={silentMode} isReply={isReply} setIsReply={setIsReply}
  654. isForward={isForward} setIsForward={setIsForward}
  655. isEdit={isEdit} setIsEdit={setIsEdit}
  656. modalForward={modalForward} setModalForward={setModalForward}
  657. handleScrollToTheMessage={handleScrollToTheMessage}/>}
  658. {openPinned&&!isSomeSelected&&<UnpinBar pinnedMessagesMemo={pinnedMessagesMemo} handleUnpinAll={handleUnpinAll} />}
  659. </div>
  660. );
  661. }
  662. export default ChatBar