From 0bb72fc1a1ca901c11f12e93aed47df6170a7ee3 Mon Sep 17 00:00:00 2001 From: William Grant Date: Fri, 20 Oct 2023 11:32:53 +1100 Subject: [PATCH] feat: updated getPropsForMessageDetail attachments now have fileSize, url and screenshots and removed contacts --- ts/components/icon/SessionIcon.tsx | 11 ++--- ts/models/message.ts | 75 ++++++++++++++++-------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/ts/components/icon/SessionIcon.tsx b/ts/components/icon/SessionIcon.tsx index 5d00fbb57..e190abf42 100644 --- a/ts/components/icon/SessionIcon.tsx +++ b/ts/components/icon/SessionIcon.tsx @@ -102,7 +102,7 @@ const animation = (props: { }) => { if (props.rotateDuration) { return css` - ${rotate} ${props.rotateDuration}s linear infinite; + animation: ${rotate} ${props.rotateDuration}s linear infinite; `; } if (props.noScale) { @@ -111,11 +111,8 @@ const animation = (props: { if (props.glowDuration !== undefined && props.glowStartDelay !== undefined && props.iconColor) { return css` - ${glow( - props.iconColor, - props.glowDuration, - props.glowStartDelay - )} ${props.glowDuration}s ease infinite; + animation: ${glow(props.iconColor, props.glowDuration, props.glowStartDelay)} + ${props.glowDuration}s ease infinite; `; } return undefined; @@ -124,7 +121,7 @@ const animation = (props: { const Svg = React.memo(styled.svg` width: ${props => props.width}; transform: ${props => `rotate(${props.iconRotation}deg)`}; - animation: ${props => animation(props)}; + ${props => animation(props)}; border-radius: ${props => props.borderRadius}; background-color: ${props => props.backgroundColor ? props.backgroundColor : '--button-icon-background-color'}; diff --git a/ts/models/message.ts b/ts/models/message.ts index fd0bde8f1..791d9dce7 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -5,14 +5,11 @@ import filesize from 'filesize'; import { cloneDeep, debounce, - groupBy, isEmpty, size as lodashSize, map, partition, pick, - reject, - sortBy, uniq, } from 'lodash'; import { SignalService } from '../protobuf'; @@ -80,6 +77,7 @@ import { messagesChanged, } from '../state/ducks/conversations'; import { AttachmentTypeWithPath, isVoiceMessage } from '../types/Attachment'; +import { isAudio } from '../types/MIME'; import { deleteExternalMessageFiles, getAbsoluteAttachmentPath, @@ -88,8 +86,10 @@ import { loadQuoteData, } from '../types/MessageAttachment'; import { ReactionList } from '../types/Reaction'; +import { getAudioDuration, getVideoDuration } from '../types/attachments/VisualAttachment'; import { getAttachmentMetadata } from '../types/message/initializeAttachmentMetadata'; import { roomHasBlindEnabled } from '../types/sqlSharedTypes'; +import { GoogleChrome } from '../util'; import { LinkPreviews } from '../util/linkPreviews'; import { Notifications } from '../util/notifications'; import { Storage } from '../util/storage'; @@ -680,39 +680,45 @@ export class MessageModel extends Backbone.Model { } public async getPropsForMessageDetail(): Promise { - // We include numbers we didn't successfully send to so we can display errors. - // Older messages don't have the recipients included on the message, so we fall - // back to the conversation's current recipients - const contacts: Array = this.isIncoming() - ? [this.get('source')] - : this.get('sent_to') || []; + // process attachments so we have the fileSize, url and screenshots + const attachments = this.get('attachments') || []; + for (let i = 0; i < attachments.length; i++) { + let props = this.getPropsForAttachment(attachments[i]); + if ( + props?.contentType && + GoogleChrome.isVideoTypeSupported(props?.contentType) && + !props.duration && + props.url + ) { + // eslint-disable-next-line no-await-in-loop + const duration = await getVideoDuration({ + objectUrl: props.url, + contentType: props.contentType, + }); + props = { + ...props, + duration, + }; + } + if (props?.contentType && isAudio(props?.contentType) && !props.duration && props.url) { + // eslint-disable-next-line no-await-in-loop + const duration = await getAudioDuration({ + objectUrl: props.url, + contentType: props.contentType, + }); + props = { + ...props, + duration, + }; + } + attachments[i] = props; + } // This will make the error message for outgoing key errors a bit nicer - const allErrors = (this.get('errors') || []).map((error: any) => { + const errors = (this.get('errors') || []).map((error: any) => { return error; }); - // If an error has a specific number it's associated with, we'll show it next to - // that contact. Otherwise, it will be a standalone entry. - const errors = reject(allErrors, error => Boolean(error.number)); - const errorsGroupedById = groupBy(allErrors, 'number'); - const finalContacts = await Promise.all( - (contacts || []).map(async id => { - const errorsForContact = errorsGroupedById[id]; - - const contact = findAndFormatContact(id); - return { - ...contact, - status: this.getMessagePropStatus(), - errors: errorsForContact, - profileName: contact.profileName, - }; - }) - ); - - // sort by pubkey - const sortedContacts = sortBy(finalContacts, contact => contact.pubkey); - const toRet: MessagePropsDetails = { sentAt: this.get('sent_at') || 0, receivedAt: this.get('received_at') || 0, @@ -724,7 +730,6 @@ export class MessageModel extends Backbone.Model { attachments, timestamp: this.get('timestamp'), serverTimestamp: this.get('serverTimestamp'), - contacts: sortedContacts || [], }; return toRet; @@ -843,7 +848,7 @@ export class MessageModel extends Backbone.Model { const conversation: ConversationModel | undefined = this.getConversation(); if (!conversation) { window?.log?.info( - 'cannot retry send message, the corresponding conversation was not found.' + '[retrySend] Cannot retry send message, the corresponding conversation was not found.' ); return null; } @@ -861,7 +866,7 @@ export class MessageModel extends Backbone.Model { }; const roomInfos = OpenGroupData.getV2OpenGroupRoom(conversation.id); if (!roomInfos) { - throw new Error('Could not find roomInfos for this conversation'); + throw new Error('[retrySend] Could not find roomInfos for this conversation'); } const openGroupMessage = new OpenGroupVisibleMessage(openGroupParams); @@ -912,7 +917,7 @@ export class MessageModel extends Backbone.Model { // as they are all polling from the same group swarm pubkey if (!conversation.isClosedGroup()) { throw new Error( - 'We should only end up with a closed group here. Anything else is an error' + '[retrySend] We should only end up with a closed group here. Anything else is an error' ); }