Fixes for media index

This commit is contained in:
Josh Perez 2023-10-17 15:09:09 -04:00 committed by GitHub
parent e920db2148
commit 156cbca1a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -3401,16 +3401,17 @@ function loadRecentMediaItems(
);
});
let index = 0;
const recentMediaItems = messages
.filter(message => message.attachments !== undefined)
.reduce(
(acc, message) => [
...acc,
...(message.attachments || []).map(
(attachment: AttachmentType, index: number): MediaItemType => {
(attachment: AttachmentType): MediaItemType => {
const { thumbnail } = attachment;
return {
const result = {
objectURL: getAbsoluteAttachmentPath(attachment.path || ''),
thumbnailObjectUrl: thumbnail?.path
? getAbsoluteAttachmentPath(thumbnail.path)
@ -3429,6 +3430,10 @@ function loadRecentMediaItems(
sent_at: message.sent_at,
},
};
index += 1;
return result;
}
),
],

View file

@ -116,13 +116,11 @@ function loadMediaItems(
})
);
let index = 0;
const media: Array<MediaType> = rawMedia
.flatMap(message => {
return (message.attachments || []).map(
(
attachment: AttachmentType,
index: number
): MediaType | undefined => {
(attachment: AttachmentType): MediaType | undefined => {
if (
!attachment.path ||
!attachment.thumbnail ||
@ -133,7 +131,7 @@ function loadMediaItems(
}
const { thumbnail } = attachment;
return {
const result = {
path: attachment.path,
objectURL: getAbsoluteAttachmentPath(attachment.path),
thumbnailObjectUrl: thumbnail?.path
@ -156,6 +154,10 @@ function loadMediaItems(
sent_at: message.sent_at,
},
};
index += 1;
return result;
}
);
})