diff --git a/ts/models/message.ts b/ts/models/message.ts index 4fa0382ff..a41693d40 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -19,7 +19,6 @@ import { import autoBind from 'auto-bind'; import { saveMessage } from '../../ts/data/data'; import { ConversationModel, ConversationTypeEnum } from './conversation'; -import { getSuggestedFilenameSending } from '../types/Attachment'; import { actions as conversationActions } from '../state/ducks/conversations'; import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage'; import { buildSyncMessage } from '../session/utils/syncUtils'; @@ -745,15 +744,7 @@ export class MessageModel extends Backbone.Model { (this.get('attachments') || []).map(window.Signal.Migrations.loadAttachmentData) ); const body = this.get('body'); - const finalAttachments = attachmentsWithData; - - const filenameOverridenAttachments = finalAttachments.map((attachment: any) => ({ - ...attachment, - fileName: getSuggestedFilenameSending({ - attachment, - timestamp: Date.now(), - }), - })); + const finalAttachments = attachmentsWithData as Array; const quoteWithData = await window.Signal.Migrations.loadQuoteData(this.get('quote')); const previewWithData = await window.Signal.Migrations.loadPreviewData(this.get('preview')); @@ -768,13 +759,13 @@ export class MessageModel extends Backbone.Model { // we want to go for the v1, if this is an OpenGroupV1 or not an open group at all if (conversation?.isOpenGroupV2()) { const openGroupV2 = conversation.toOpenGroupV2(); - attachmentPromise = uploadAttachmentsV2(filenameOverridenAttachments, openGroupV2); + attachmentPromise = uploadAttachmentsV2(finalAttachments, openGroupV2); linkPreviewPromise = uploadLinkPreviewsV2(previewWithData, openGroupV2); quotePromise = uploadQuoteThumbnailsV2(openGroupV2, quoteWithData); } else { // NOTE: we want to go for the v1 if this is an OpenGroupV1 or not an open group at all // because there is a fallback invoked on uploadV1() for attachments for not open groups attachments - attachmentPromise = AttachmentFsV2Utils.uploadAttachmentsToFsV2(filenameOverridenAttachments); + attachmentPromise = AttachmentFsV2Utils.uploadAttachmentsToFsV2(finalAttachments); linkPreviewPromise = AttachmentFsV2Utils.uploadLinkPreviewsToFsV2(previewWithData); quotePromise = AttachmentFsV2Utils.uploadQuoteThumbnailsToFsV2(quoteWithData); } diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts index 2c8d6cc74..9dab0f735 100644 --- a/ts/receiver/closedGroups.ts +++ b/ts/receiver/closedGroups.ts @@ -193,10 +193,8 @@ export async function handleNewClosedGroup( const maybeConvo = ConversationController.getInstance().get(groupId); - const groupExists = !!maybeConvo; - - if (groupExists) { - if (maybeConvo && (maybeConvo.get('isKickedFromGroup') || maybeConvo.get('left'))) { + if (maybeConvo) { + if (maybeConvo.get('isKickedFromGroup') || maybeConvo.get('left')) { // TODO: indicate that we've been re-invited // to the group if that is the case @@ -205,10 +203,30 @@ export async function handleNewClosedGroup( maybeConvo.set('left', false); maybeConvo.set('lastJoinedTimestamp', _.toNumber(envelope.timestamp)); } else { - window?.log?.warn( - 'Ignoring a closed group message of type NEW: the conversation already exists' + const ecKeyPairAlreadyExistingConvo = new ECKeyPair( + // tslint:disable: no-non-null-assertion + encryptionKeyPair!.publicKey, + encryptionKeyPair!.privateKey ); + const isKeyPairAlreadyHere = await isKeyPairAlreadySaved( + groupId, + ecKeyPairAlreadyExistingConvo.toHexKeyPair() + ); + + if (isKeyPairAlreadyHere) { + await getAllEncryptionKeyPairsForGroup(groupId); + window.log.info('Dropping already saved keypair for group', groupId); + await removeFromCache(envelope); + return; + } + + window.log.info(`Received the encryptionKeyPair for new group ${groupId}`); + + await addClosedGroupEncryptionKeyPair(groupId, ecKeyPairAlreadyExistingConvo.toHexKeyPair()); await removeFromCache(envelope); + window.log.warn( + 'Closed group message of type NEW: the conversation already exists, but we saved the new encryption keypair' + ); return; } } diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index cdb632a37..bc2984fb0 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -346,22 +346,6 @@ export const getSuggestedFilename = ({ return `${prefix}${suffix}${indexSuffix}${extension}`; }; -// Used for overriden the sent filename of an attachment, but keeping the file extension the same -export const getSuggestedFilenameSending = ({ - attachment, - timestamp, -}: { - attachment: AttachmentType; - timestamp?: number | Date; -}): string => { - const prefix = 'session-attachment'; - const suffix = timestamp ? moment(timestamp).format('-YYYY-MM-DD-HHmmss') : ''; - const fileType = getFileExtension(attachment); - const extension = fileType ? `.${fileType}` : ''; - - return `${prefix}${suffix}${extension}`; -}; - export const getFileExtension = (attachment: AttachmentType): string | undefined => { // we override textplain to the extension of the file // for contenttype starting with application, the mimetype is probably wrong so just use the extension of the file instead