Skip to content
Open
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
58 changes: 46 additions & 12 deletions app/containers/message/Message.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export const WithImage = () => (
attachments={[
{
title: 'This is a title',
description: 'This is a description',
description: 'This is a description :nyan_rocket:',
image_url: '/dummypath'
}
]}
Expand All @@ -387,7 +387,21 @@ export const WithImage = () => (
attachments={[
{
title: 'This is a title',
description: 'This is a description :nyan_rocket:',
description: 'Header false',
image_url: '/dummypath'
}
]}
isHeader={false}
/>
<Message
msg='multi file'
attachments={[
{
title: 'This is a title',
image_url: '/dummypath'
},
{
title: 'This is a title',
image_url: '/dummypath'
}
]}
Expand Down Expand Up @@ -417,6 +431,21 @@ export const WithVideo = () => (
/>
<Message
attachments={[
{
title: 'This is a title',
description: 'Header false',
video_url: '/dummypath'
}
]}
isHeader={false}
/>
<Message
msg='multi file'
attachments={[
{
title: 'This is a title',
video_url: '/dummypath'
},
{
title: 'This is a title',
video_url: '/dummypath'
Expand All @@ -437,34 +466,28 @@ export const WithAudio = () => (
}
]}
/>
<Message msg='First message' isHeader={false} />
<Message
attachments={[
{
title: 'This is a title',
description: 'This is a description',
description: 'Header false',
audio_url: '/dummypath'
}
]}
isHeader={false}
/>
<Message
msg='multi file'
attachments={[
{
title: 'This is a title',
audio_url: '/dummypath'
}
]}
isHeader={false}
/>
<Message
attachments={[
},
{
title: 'This is a title',
audio_url: '/dummypath'
}
]}
isHeader={false}
/>
</>
);
Expand All @@ -483,11 +506,22 @@ export const WithFile = () => (
attachments={[
{
text: 'File.pdf',
description: 'This is a description :nyan_rocket:'
description: 'Header false'
}
]}
isHeader={false}
/>
<Message
msg='multi file'
attachments={[
{
text: 'File.pdf'
},
{
text: 'File.pdf'
}
]}
/>
</>
);

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