index.tsx 32 KB

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