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 const recentMediaItems = messages
.filter(message => message.attachments !== undefined) .filter(message => message.attachments !== undefined)
.reduce( .reduce(
(acc, message) => [ (acc, message) => [
...acc, ...acc,
...(message.attachments || []).map( ...(message.attachments || []).map(
(attachment: AttachmentType, index: number): MediaItemType => { (attachment: AttachmentType): MediaItemType => {
const { thumbnail } = attachment; const { thumbnail } = attachment;
return { const result = {
objectURL: getAbsoluteAttachmentPath(attachment.path || ''), objectURL: getAbsoluteAttachmentPath(attachment.path || ''),
thumbnailObjectUrl: thumbnail?.path thumbnailObjectUrl: thumbnail?.path
? getAbsoluteAttachmentPath(thumbnail.path) ? getAbsoluteAttachmentPath(thumbnail.path)
@ -3429,6 +3430,10 @@ function loadRecentMediaItems(
sent_at: message.sent_at, 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 const media: Array<MediaType> = rawMedia
.flatMap(message => { .flatMap(message => {
return (message.attachments || []).map( return (message.attachments || []).map(
( (attachment: AttachmentType): MediaType | undefined => {
attachment: AttachmentType,
index: number
): MediaType | undefined => {
if ( if (
!attachment.path || !attachment.path ||
!attachment.thumbnail || !attachment.thumbnail ||
@ -133,7 +131,7 @@ function loadMediaItems(
} }
const { thumbnail } = attachment; const { thumbnail } = attachment;
return { const result = {
path: attachment.path, path: attachment.path,
objectURL: getAbsoluteAttachmentPath(attachment.path), objectURL: getAbsoluteAttachmentPath(attachment.path),
thumbnailObjectUrl: thumbnail?.path thumbnailObjectUrl: thumbnail?.path
@ -156,6 +154,10 @@ function loadMediaItems(
sent_at: message.sent_at, sent_at: message.sent_at,
}, },
}; };
index += 1;
return result;
} }
); );
}) })