index.tsx 35 KB

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