From 92ed15c6c485e209bf325659c8e8762672fac17d Mon Sep 17 00:00:00 2001 From: William Grant Date: Mon, 15 May 2023 15:24:30 +1000 Subject: [PATCH] feat: pass yarn ready --- .../SessionQuotedMessageComposition.tsx | 71 +++++++++++++------ .../StagedPlaceholderAttachment.tsx | 9 +-- .../message/message-content/quote/Quote.tsx | 2 +- .../message-content/quote/QuoteAuthor.tsx | 2 +- .../quote/QuoteIconContainer.tsx | 2 +- .../message-content/quote/QuoteImage.tsx | 4 +- ts/data/data.ts | 4 +- ts/node/sql.ts | 4 +- ts/state/ducks/conversations.ts | 17 ++--- ts/state/selectors/conversations.ts | 2 + 10 files changed, 70 insertions(+), 47 deletions(-) diff --git a/ts/components/conversation/SessionQuotedMessageComposition.tsx b/ts/components/conversation/SessionQuotedMessageComposition.tsx index a555f5d2f..1ed2366e0 100644 --- a/ts/components/conversation/SessionQuotedMessageComposition.tsx +++ b/ts/components/conversation/SessionQuotedMessageComposition.tsx @@ -47,6 +47,38 @@ const StyledText = styled(Flex)` } `; +function checkHasAttachments(attachments: Array | undefined) { + const hasAttachments = attachments && attachments.length > 0 && attachments[0]; + + // NOTE could be a video as well which will load a thumbnail + const firstImageLikeAttachment = + hasAttachments && attachments[0].contentType !== AUDIO_MP3 && attachments[0].thumbnail + ? attachments[0] + : undefined; + + return { hasAttachments, firstImageLikeAttachment }; +} + +function renderSubtitleText( + quoteText: string | undefined, + hasAudioAttachment: boolean, + isGenericFile: boolean, + isVideo: boolean, + isImage: boolean +): string | null { + return quoteText && quoteText !== '' + ? quoteText + : hasAudioAttachment + ? window.i18n('audio') + : isGenericFile + ? window.i18n('document') + : isVideo + ? window.i18n('video') + : isImage + ? window.i18n('image') + : null; +} + export const SessionQuotedMessageComposition = () => { const dispatch = useDispatch(); const quotedMessageProps = useSelector(getQuotedMessage); @@ -66,32 +98,25 @@ export const SessionQuotedMessageComposition = () => { const contact = findAndFormatContact(author); const authorName = contact?.profileName || contact?.name || author || window.i18n('unknown'); - const hasAttachments = attachments && attachments.length > 0 && attachments[0]; - const firstImageAttachment = - hasAttachments && attachments[0].contentType !== AUDIO_MP3 && attachments[0].thumbnail - ? attachments[0] - : undefined; + const { hasAttachments, firstImageLikeAttachment } = checkHasAttachments(attachments); const isImage = Boolean( - firstImageAttachment && GoogleChrome.isImageTypeSupported(firstImageAttachment.contentType) + firstImageLikeAttachment && + GoogleChrome.isImageTypeSupported(firstImageLikeAttachment.contentType) ); const isVideo = Boolean( - firstImageAttachment && GoogleChrome.isVideoTypeSupported(firstImageAttachment.contentType) + firstImageLikeAttachment && + GoogleChrome.isVideoTypeSupported(firstImageLikeAttachment.contentType) ); const hasAudioAttachment = Boolean(hasAttachments && isAudio(attachments)); const isGenericFile = !hasAudioAttachment && !isVideo && !isImage; - const subtitleText = - quoteText !== '' - ? quoteText - : hasAudioAttachment - ? window.i18n('audio') - : isGenericFile - ? window.i18n('document') - : isVideo - ? window.i18n('video') - : isImage - ? window.i18n('image') - : null; + const subtitleText = renderSubtitleText( + quoteText, + hasAudioAttachment, + isGenericFile, + isVideo, + isImage + ); return ( { > {hasAttachments && ( - {firstImageAttachment ? ( + {firstImageLikeAttachment ? ( {getAlt(firstImageAttachment)} ) : hasAudioAttachment ? ( diff --git a/ts/components/conversation/StagedPlaceholderAttachment.tsx b/ts/components/conversation/StagedPlaceholderAttachment.tsx index 4154a84a9..5d2773647 100644 --- a/ts/components/conversation/StagedPlaceholderAttachment.tsx +++ b/ts/components/conversation/StagedPlaceholderAttachment.tsx @@ -1,8 +1,9 @@ -import React from 'react'; +import React, { MouseEvent } from 'react'; import styled from 'styled-components'; +// tslint:disable: react-unused-props-and-state interface Props { - onClick: () => void; + onClick: (e: MouseEvent) => void; } const StyledStagedPlaceholderAttachment = styled.div` @@ -21,7 +22,7 @@ const StyledStagedPlaceholderAttachment = styled.div` } `; -export function StagedPlaceholderAttachment(props: Props) { +export const StagedPlaceholderAttachment = (props: Props) => { const { onClick } = props; return ( @@ -29,4 +30,4 @@ export function StagedPlaceholderAttachment(props: Props) {
); -} +}; diff --git a/ts/components/conversation/message/message-content/quote/Quote.tsx b/ts/components/conversation/message/message-content/quote/Quote.tsx index 157fa2c02..f28ee40db 100644 --- a/ts/components/conversation/message/message-content/quote/Quote.tsx +++ b/ts/components/conversation/message/message-content/quote/Quote.tsx @@ -1,4 +1,4 @@ -import React, { useState, MouseEvent } from 'react'; +import React, { MouseEvent, useState } from 'react'; import * as MIME from '../../../../../types/MIME'; diff --git a/ts/components/conversation/message/message-content/quote/QuoteAuthor.tsx b/ts/components/conversation/message/message-content/quote/QuoteAuthor.tsx index 252fc0483..49ef0ea8b 100644 --- a/ts/components/conversation/message/message-content/quote/QuoteAuthor.tsx +++ b/ts/components/conversation/message/message-content/quote/QuoteAuthor.tsx @@ -1,4 +1,4 @@ -import React = require('react'); +import React from 'react'; import { ContactName } from '../../../ContactName'; import { PubKey } from '../../../../../session/types'; import styled from 'styled-components'; diff --git a/ts/components/conversation/message/message-content/quote/QuoteIconContainer.tsx b/ts/components/conversation/message/message-content/quote/QuoteIconContainer.tsx index b0a77989f..83c25e503 100644 --- a/ts/components/conversation/message/message-content/quote/QuoteIconContainer.tsx +++ b/ts/components/conversation/message/message-content/quote/QuoteIconContainer.tsx @@ -6,7 +6,7 @@ import { MIME } from '../../../../../types'; import { isEmpty, noop } from 'lodash'; import { QuoteImage } from './QuoteImage'; import styled from 'styled-components'; -import { SessionIconType, icons } from '../../../../icon'; +import { icons, SessionIconType } from '../../../../icon'; function getObjectUrl(thumbnail: Attachment | undefined): string | undefined { if (thumbnail && thumbnail.objectUrl) { diff --git a/ts/components/conversation/message/message-content/quote/QuoteImage.tsx b/ts/components/conversation/message/message-content/quote/QuoteImage.tsx index 3e33c56be..2eb4b5117 100644 --- a/ts/components/conversation/message/message-content/quote/QuoteImage.tsx +++ b/ts/components/conversation/message/message-content/quote/QuoteImage.tsx @@ -82,8 +82,8 @@ export const QuoteImage = (props: { {showPlayButton && (
- - + +
diff --git a/ts/data/data.ts b/ts/data/data.ts index d6397158a..166c2256e 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -452,8 +452,8 @@ async function filterAlreadyFetchedOpengroupMessage( /** * Fetch all messages that match the sender pubkey and sent_at timestamp - * @param {Object[]} propsList An array of objects containing a source (the sender id) and timestamp of the message - not to be confused with the serverTimestamp. This is equivalent to sent_at - * @returns + * @param propsList An array of objects containing a source (the sender id) and timestamp of the message - not to be confused with the serverTimestamp. This is equivalent to sent_at + * @returns the fetched messageModels */ async function getMessagesBySenderAndSentAt( propsList: Array<{ diff --git a/ts/node/sql.ts b/ts/node/sql.ts index 2faebc858..a4d93bd82 100644 --- a/ts/node/sql.ts +++ b/ts/node/sql.ts @@ -1073,8 +1073,8 @@ function getMessagesBySenderAndSentAt( const db = assertGlobalInstance(); const rows = []; - for (let i = 0; i < propsList.length; i++) { - const { source, timestamp } = propsList[i]; + for (const msgProps of propsList) { + const { source, timestamp } = msgProps; const _rows = db .prepare( diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index b9beb1c17..816f4aae3 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -347,9 +347,9 @@ export type MentionsMembersType = Array<{ /** * Fetches the messages for a conversation to put into redux. - * @param {string} conversationKey - the id of the conversation - * @param {string} messageId - the id of the message in view so we can fetch the messages around it - * @returns + * @param conversationKey - the id of the conversation + * @param messageId - the id of the message in view so we can fetch the messages around it + * @returns the fetched models for messages and quoted messages */ async function getMessages({ conversationKey, @@ -408,7 +408,6 @@ async function getMessages({ } } - // window.log.debug(`WIP: duck quotesProps`, quotesProps); return { messagesProps, quotesProps }; } @@ -575,15 +574,11 @@ function handleMessageExpiredOrDeleted( if (timestamp && sender) { const message2Delete = editedQuotes[`${timestamp}-${sender}`]; window.log.debug( - `WIP: deleting quote {${timestamp}-${sender}} ${JSON.stringify(message2Delete)}` - ); - window.log.debug( - `WIP: editedQuotes count before delete ${Object.keys(editedQuotes).length}` + `Deleting quote {${timestamp}-${sender}} ${JSON.stringify(message2Delete)}` ); + + // tslint:disable-next-line: no-dynamic-delete delete editedQuotes[`${timestamp}-${sender}`]; - window.log.debug( - `WIP: editedQuotes count after delete ${Object.keys(editedQuotes).length}` - ); } // we cannot edit the array directly, so slice the first part, and slice the second part, diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index e61e4d4c7..b5c1c7602 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -980,6 +980,7 @@ export const getMessageLinkPreviewProps = createSelector(getMessagePropsByMessag return msgProps; }); +// tslint:disable: cyclomatic-complexity export const getMessageQuoteProps = createSelector( getConversationQuotes, getMessagePropsByMessageId, @@ -1050,6 +1051,7 @@ export const getMessageQuoteProps = createSelector( return { direction, quote }; } ); +// tslint:enable: cyclomatic-complexity export const getMessageStatusProps = createSelector(getMessagePropsByMessageId, (props): | MessageStatusSelectorProps