Skip to content

Commit

Permalink
Support message with multiple attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello committed Jan 10, 2025
1 parent 029da86 commit 8717d5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
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

0 comments on commit 8717d5a

Please sign in to comment.