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.
		
		
		
		
		
			
		
			
				
	
	
		
			91 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			91 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			TypeScript
		
	
| import React from 'react';
 | |
| import styled from 'styled-components';
 | |
| import { getMessageById, getMessagesByConversation } from '../../../data/data';
 | |
| import { getConversationController } from '../../../session/conversations';
 | |
| import { AttachmentDownloads } from '../../../session/utils';
 | |
| import { updateConfirmModal } from '../../../state/ducks/modalDialog';
 | |
| import { SessionIcon } from '../../session/icon';
 | |
| import { SessionButtonColor } from '../../session/SessionButton';
 | |
| 
 | |
| const StyledTrustSenderUI = styled.div`
 | |
|   padding: 'var(--margins-md)';
 | |
|   display: flex;
 | |
|   align-items: center;
 | |
| `;
 | |
| 
 | |
| const ClickToDownload = styled.div`
 | |
|   cursor: pointer;
 | |
|   padding: var(--margins-xs) var(--margins-md);
 | |
| `;
 | |
| 
 | |
| export const ClickToTrustSender = (props: { messageId: string }) => {
 | |
|   const openConfirmationModal = async (e: any) => {
 | |
|     e.stopPropagation();
 | |
|     e.preventDefault();
 | |
|     const found = await getMessageById(props.messageId);
 | |
|     if (!found) {
 | |
|       window.log.warn('message not found ClickToTrustSender');
 | |
|       return;
 | |
|     }
 | |
|     const sender = found.getSource();
 | |
|     const convo = getConversationController().get(sender);
 | |
|     window.inboxStore?.dispatch(
 | |
|       updateConfirmModal({
 | |
|         title: window.i18n(
 | |
|           'trustThisContactDialogTitle',
 | |
|           convo.getContactProfileNameOrShortenedPubKey()
 | |
|         ),
 | |
|         message: window.i18n(
 | |
|           'trustThisContactDialogDescription',
 | |
|           convo.getContactProfileNameOrShortenedPubKey()
 | |
|         ),
 | |
|         okTheme: SessionButtonColor.Green,
 | |
|         onClickOk: async () => {
 | |
|           convo.set({ isTrustedForAttachmentDownload: true });
 | |
|           await convo.commit();
 | |
|           const messagesInConvo = await getMessagesByConversation(convo.id, {
 | |
|             limit: 100,
 | |
|           });
 | |
| 
 | |
|           await Promise.all(
 | |
|             messagesInConvo.map(async message => {
 | |
|               const msgAttachments = message.get('attachments');
 | |
|               if (message.get('direction') !== 'incoming') {
 | |
|                 return;
 | |
|               }
 | |
|               if (!msgAttachments || msgAttachments.length === 0) {
 | |
|                 return;
 | |
|               }
 | |
| 
 | |
|               const downloadedAttachments = await Promise.all(
 | |
|                 msgAttachments.map(async (attachment: any, index: any) => {
 | |
|                   if (attachment.path) {
 | |
|                     return { ...attachment, pending: false };
 | |
|                   }
 | |
|                   return AttachmentDownloads.addJob(attachment, {
 | |
|                     messageId: message.id,
 | |
|                     type: 'attachment',
 | |
|                     index,
 | |
|                     isOpenGroupV2: false,
 | |
|                     openGroupV2Details: undefined,
 | |
|                   });
 | |
|                 })
 | |
|               );
 | |
| 
 | |
|               message.set({ attachments: downloadedAttachments });
 | |
|               await message.commit();
 | |
|             })
 | |
|           );
 | |
|         },
 | |
|       })
 | |
|     );
 | |
|   };
 | |
| 
 | |
|   return (
 | |
|     <StyledTrustSenderUI onClick={openConfirmationModal}>
 | |
|       <SessionIcon iconSize={'small'} iconType="gallery" />
 | |
|       <ClickToDownload>{window.i18n('clickToTrustContact')}</ClickToDownload>
 | |
|     </StyledTrustSenderUI>
 | |
|   );
 | |
| };
 |