Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support message with multiple attachments #6068

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/containers/AudioPlayer/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const styles = StyleSheet.create({
alignItems: 'center',
height: 56,
borderWidth: 1,
borderRadius: 4,
marginBottom: 8
borderRadius: 4
},
playPauseButton: {
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useContext } from 'react';
import { dequal } from 'dequal';
import { View } from 'react-native';

import Image from './Image';
import Audio from './Audio';
Expand Down Expand Up @@ -87,7 +88,7 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
/>
);
});
return <>{attachmentsElements}</>;
return <View style={{ gap: 4 }}>{attachmentsElements}</View>;
},
(prevProps, nextProps) => dequal(prevProps.attachments, nextProps.attachments)
);
Expand Down
16 changes: 9 additions & 7 deletions app/lib/methods/handleMediaDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,42 +202,44 @@ export async function cancelDownload(messageUrl: string): Promise<void> {
const mapAttachments = ({
attachments,
uri,
encryption
encryption,
downloadUrl
}: {
attachments?: IAttachment[];
uri: string;
encryption: boolean;
downloadUrl: string;
}): TMessageModel['attachments'] =>
attachments?.map(att => ({
...att,
title_link: uri,
title_link: att.image_url && downloadUrl.includes(att.image_url) ? uri : att.title_link,
e2e: encryption ? 'done' : undefined
}));

const persistMessage = async (messageId: string, uri: string, encryption: boolean) => {
const persistMessage = async (messageId: string, uri: string, encryption: boolean, downloadUrl: string) => {
const db = database.active;
const batch: Model[] = [];
const messageRecord = await getMessageById(messageId);
if (messageRecord) {
batch.push(
messageRecord.prepareUpdate(m => {
m.attachments = mapAttachments({ attachments: m.attachments, uri, encryption });
m.attachments = mapAttachments({ attachments: m.attachments, uri, encryption, downloadUrl });
})
);
}
const threadRecord = await getThreadById(messageId);
if (threadRecord) {
batch.push(
threadRecord.prepareUpdate(m => {
m.attachments = mapAttachments({ attachments: m.attachments, uri, encryption });
m.attachments = mapAttachments({ attachments: m.attachments, uri, encryption, downloadUrl });
})
);
}
const threadMessageRecord = await getThreadMessageById(messageId);
if (threadMessageRecord) {
batch.push(
threadMessageRecord.prepareUpdate(m => {
m.attachments = mapAttachments({ attachments: m.attachments, uri, encryption });
m.attachments = mapAttachments({ attachments: m.attachments, uri, encryption, downloadUrl });
})
);
}
Expand Down Expand Up @@ -282,7 +284,7 @@ export function downloadMediaFile({
await Encryption.addFileToDecryptFileQueue(messageId, result.uri, encryption, originalChecksum);
}

await persistMessage(messageId, result.uri, !!encryption);
await persistMessage(messageId, result.uri, !!encryption, downloadUrl);

emitter.emit(`downloadMedia${downloadUrl}`, result.uri);
return resolve(result.uri);
Expand Down