You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			100 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			100 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			TypeScript
		
	
| 
											4 years ago
										 | import React, { useCallback } from 'react'; | ||
| 
											4 years ago
										 | import { SessionIcon, SessionIconButton } from '../icon'; | ||
| 
											4 years ago
										 | import styled from 'styled-components'; | ||
| 
											4 years ago
										 | import { useDispatch, useSelector } from 'react-redux'; | ||
| 
											4 years ago
										 | import { quoteMessage } from '../../state/ducks/conversations'; | ||
|  | import { getQuotedMessage } from '../../state/selectors/conversations'; | ||
|  | import { getAlt, isAudio } from '../../types/Attachment'; | ||
|  | import { AUDIO_MP3 } from '../../types/MIME'; | ||
|  | import { Flex } from '../basic/Flex'; | ||
|  | import { Image } from '../../../ts/components/conversation/Image'; | ||
| 
											5 years ago
										 | 
 | ||
|  | const QuotedMessageComposition = styled.div`
 | ||
| 
											5 years ago
										 |   width: 100%; | ||
| 
											4 years ago
										 |   padding-inline-end: var(--margins-md); | ||
|  |   padding-inline-start: var(--margins-md); | ||
| 
											5 years ago
										 | `;
 | ||
|  | 
 | ||
|  | const QuotedMessageCompositionReply = styled.div`
 | ||
| 
											4 years ago
										 |   background: var(--color-quote-bottom-bar-background); | ||
|  |   border-radius: var(--margins-sm); | ||
|  |   padding: var(--margins-xs); | ||
| 
											4 years ago
										 |   box-shadow: var(--color-session-shadow); | ||
| 
											4 years ago
										 |   margin: var(--margins-xs); | ||
| 
											5 years ago
										 | `;
 | ||
|  | 
 | ||
|  | const Subtle = styled.div`
 | ||
|  |   overflow: hidden; | ||
|  |   text-overflow: ellipsis; | ||
|  |   word-break: break-all; | ||
|  |   -webkit-line-clamp: 3; | ||
|  |   -webkit-box-orient: vertical; | ||
|  |   display: -webkit-box; | ||
| 
											4 years ago
										 |   color: var(--color-text); | ||
| 
											5 years ago
										 | `;
 | ||
|  | 
 | ||
|  | const ReplyingTo = styled.div`
 | ||
| 
											4 years ago
										 |   color: var(--color-text); | ||
| 
											5 years ago
										 | `;
 | ||
|  | 
 | ||
| 
											4 years ago
										 | export const SessionQuotedMessageComposition = () => { | ||
|  |   const quotedMessageProps = useSelector(getQuotedMessage); | ||
|  | 
 | ||
|  |   const dispatch = useDispatch(); | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |   const { text: body, attachments } = quotedMessageProps || {}; | ||
| 
											5 years ago
										 |   const hasAttachments = attachments && attachments.length > 0; | ||
| 
											5 years ago
										 | 
 | ||
|  |   let hasImageAttachment = false; | ||
|  | 
 | ||
|  |   let firstImageAttachment; | ||
| 
											4 years ago
										 |   // we have to handle the case we are trying to reply to an audio message
 | ||
|  | 
 | ||
|  |   if (attachments?.length && attachments[0].contentType !== AUDIO_MP3 && attachments[0].thumbnail) { | ||
| 
											5 years ago
										 |     firstImageAttachment = attachments[0]; | ||
|  |     hasImageAttachment = true; | ||
|  |   } | ||
|  | 
 | ||
|  |   const hasAudioAttachment = | ||
|  |     hasAttachments && attachments && attachments.length > 0 && isAudio(attachments); | ||
|  | 
 | ||
| 
											4 years ago
										 |   const removeQuotedMessage = useCallback(() => { | ||
|  |     dispatch(quoteMessage(undefined)); | ||
|  |   }, []); | ||
|  | 
 | ||
|  |   if (!quotedMessageProps?.id) { | ||
|  |     return null; | ||
|  |   } | ||
|  | 
 | ||
| 
											5 years ago
										 |   return ( | ||
| 
											4 years ago
										 |     <QuotedMessageComposition> | ||
| 
											5 years ago
										 |       <Flex | ||
|  |         container={true} | ||
|  |         justifyContent="space-between" | ||
|  |         flexGrow={1} | ||
| 
											4 years ago
										 |         margin={'var(--margins-xs)'} | ||
| 
											5 years ago
										 |       > | ||
|  |         <ReplyingTo>{window.i18n('replyingToMessage')}</ReplyingTo> | ||
| 
											4 years ago
										 |         <SessionIconButton iconType="exit" iconSize="small" onClick={removeQuotedMessage} /> | ||
| 
											5 years ago
										 |       </Flex> | ||
|  |       <QuotedMessageCompositionReply> | ||
| 
											4 years ago
										 |         <Flex container={true} justifyContent="space-between" margin={'var(--margins-xs)'}> | ||
| 
											5 years ago
										 |           <Subtle>{(hasAttachments && window.i18n('mediaMessage')) || body}</Subtle> | ||
|  | 
 | ||
|  |           {hasImageAttachment && ( | ||
|  |             <Image | ||
| 
											4 years ago
										 |               alt={getAlt(firstImageAttachment)} | ||
| 
											5 years ago
										 |               attachment={firstImageAttachment} | ||
|  |               height={100} | ||
|  |               width={100} | ||
|  |               url={firstImageAttachment.thumbnail.objectUrl} | ||
|  |             /> | ||
|  |           )} | ||
|  | 
 | ||
| 
											4 years ago
										 |           {hasAudioAttachment && <SessionIcon iconType="microphone" iconSize="huge" />} | ||
| 
											5 years ago
										 |         </Flex> | ||
| 
											5 years ago
										 |       </QuotedMessageCompositionReply> | ||
|  |     </QuotedMessageComposition> | ||
|  |   ); | ||
|  | }; |